usermode/library/mtm/src/mode/common/memcpy.h

00001 /*
00002     Copyright (C) 2011 Computer Sciences Department, 
00003     University of Wisconsin -- Madison
00004 
00005     ----------------------------------------------------------------------
00006 
00007     This file is part of Mnemosyne: Lightweight Persistent Memory, 
00008     originally developed at the University of Wisconsin -- Madison.
00009 
00010     Mnemosyne was originally developed primarily by Haris Volos
00011     with contributions from Andres Jaan Tack.
00012 
00013     ----------------------------------------------------------------------
00014 
00015     Mnemosyne is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU General Public License
00017     as published by the Free Software Foundation, version 2
00018     of the License.
00019  
00020     Mnemosyne is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024 
00025     You should have received a copy of the GNU General Public License
00026     along with this program; if not, write to the Free Software
00027     Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00028     Boston, MA  02110-1301, USA.
00029 
00030 ### END HEADER ###
00031 */
00032 
00033 #ifndef _MEMCPY_H
00034 #define _MEMCPY_H
00035 
00036 #define BUFSIZE (sizeof(mtm_word_t)*16)
00037 
00038 /* FIXME: The implementations here are not the most efficient possible. */
00039 
00040 #define MEMCPY_DEFINITION(PREFIX, VARIANT, READ, WRITE)                        \
00041 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memcpy##VARIANT(mtm_tx_t *tx,         \
00042                                                    void *dst,                  \
00043                                                    const void *src,            \
00044                                                    size_t size)                \
00045 {                                                                              \
00046   volatile uint8_t *saddr=((volatile uint8_t *) src);                          \
00047   volatile uint8_t *daddr=((volatile uint8_t *) dst);                          \
00048   uint8_t buf[BUFSIZE];                                                        \
00049                                                                                \
00050   if (size == 0) {                                                             \
00051     return;                                                                    \
00052   }                                                                                \
00053   while (size>BUFSIZE) {                                                       \
00054     mtm_##PREFIX##_load_bytes(tx, saddr, buf, BUFSIZE);                        \
00055     mtm_##PREFIX##_store_bytes(tx, daddr, buf, BUFSIZE);                       \
00056     saddr += BUFSIZE;                                                          \
00057     daddr += BUFSIZE;                                                          \
00058     size -= BUFSIZE;                                                           \
00059   }                                                                                \
00060   if (size > 0) {                                                              \
00061     mtm_##PREFIX##_load_bytes(tx, saddr, buf, size);                           \
00062     mtm_##PREFIX##_store_bytes(tx, daddr, buf, size);                          \
00063   }                                                                            \
00064 }
00065 
00066 
00067 #define MEMMOVE_DEFINITION(PREFIX, VARIANT, READ, WRITE)                       \
00068 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memmove##VARIANT(mtm_tx_t *tx,        \
00069                                                     void *dst,                 \
00070                                                     const void *src,           \
00071                                                     size_t size)               \
00072 {                                                                              \
00073   volatile uint8_t *saddr=((volatile uint8_t *) src);                          \
00074   volatile uint8_t *daddr=((volatile uint8_t *) dst);                          \
00075   uint8_t buf[BUFSIZE];                                                        \
00076                                                                                \
00077   if (size == 0) {                                                             \
00078     return;                                                                    \
00079   }                                                                                \
00080   if (saddr < daddr && daddr < saddr + size) {                                 \
00081     /* Destructive overlap...have to copy backwards */                         \
00082     saddr=((volatile uint8_t *) src) +size;                                    \
00083     daddr=((volatile uint8_t *) dst) +size;                                    \
00084     while (size>BUFSIZE) {                                                     \
00085       mtm_##PREFIX##_load_bytes(tx, saddr-BUFSIZE, buf, BUFSIZE);              \
00086       mtm_##PREFIX##_store_bytes(tx, daddr-BUFSIZE, buf, BUFSIZE);             \
00087       saddr -= BUFSIZE;                                                        \
00088       daddr -= BUFSIZE;                                                        \
00089       size -= BUFSIZE;                                                         \
00090     }                                                                          \
00091     if (size > 0) {                                                            \
00092       mtm_##PREFIX##_load_bytes(tx, saddr-size, buf, size);                    \
00093       mtm_##PREFIX##_store_bytes(tx, daddr-size, buf, size);                   \
00094     }                                                                          \
00095   } else {                                                                     \
00096     saddr=((volatile uint8_t *) src);                                          \
00097     daddr=((volatile uint8_t *) dst);                                          \
00098     while (size>BUFSIZE) {                                                     \
00099       mtm_##PREFIX##_load_bytes(tx, saddr, buf, BUFSIZE);                      \
00100       mtm_##PREFIX##_store_bytes(tx, daddr, buf, BUFSIZE);                     \
00101       saddr += BUFSIZE;                                                        \
00102       daddr += BUFSIZE;                                                        \
00103       size -= BUFSIZE;                                                         \
00104     }                                                                          \
00105     if (size > 0) {                                                            \
00106       mtm_##PREFIX##_load_bytes(tx, saddr, buf, size);                         \
00107       mtm_##PREFIX##_store_bytes(tx, daddr, buf, size);                        \
00108     }                                                                          \
00109   }                                                                            \
00110 }
00111 
00112 
00113 #define MEMCPY_DECLARATION(PREFIX, VARIANT, READ, WRITE)                       \
00114 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memcpy##VARIANT(mtm_tx_t *tx,         \
00115                                                    void *dst,                  \
00116                                                    const void *src,            \
00117                                                    size_t size);
00118 
00119 #define MEMMOVE_DECLARATION(PREFIX, VARIANT, READ, WRITE)                      \
00120 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memmove##VARIANT(mtm_tx_t *tx,        \
00121                                                     void *dst,                 \
00122                                                     const void *src,           \
00123                                                     size_t size);
00124 
00125 
00126 #define FORALL_MEMCOPY_VARIANTS(ACTION, prefix)   \
00127 ACTION(prefix, RnWt,     false, true)             \
00128 ACTION(prefix, RnWtaR,   false, true)             \
00129 ACTION(prefix, RnWtaW,   false, true)             \
00130 ACTION(prefix, RtWn,     true,  false)            \
00131 ACTION(prefix, RtWt,     true,  true)             \
00132 ACTION(prefix, RtWtaR,   true,  true)             \
00133 ACTION(prefix, RtWtaW,   true,  true)             \
00134 ACTION(prefix, RtaRWn,   true,  false)            \
00135 ACTION(prefix, RtaRWt,   true,  true)             \
00136 ACTION(prefix, RtaRWtaR, true,  true)             \
00137 ACTION(prefix, RtaRWtaW, true,  true)             \
00138 ACTION(prefix, RtaWWn,   true,  false)            \
00139 ACTION(prefix, RtaWWt,   true,  true)             \
00140 ACTION(prefix, RtaWWtaR, true,  true)             \
00141 ACTION(prefix, RtaWWtaW, true,  true)
00142 
00143 
00144 #define FORALL_MEMMOVE_VARIANTS(ACTION, prefix)   \
00145 ACTION(prefix, RnWt,     false, true)             \
00146 ACTION(prefix, RnWtaR,   false, true)             \
00147 ACTION(prefix, RnWtaW,   false, true)             \
00148 ACTION(prefix, RtWn,     true,  false)            \
00149 ACTION(prefix, RtWt,     true,  true)             \
00150 ACTION(prefix, RtWtaR,   true,  true)             \
00151 ACTION(prefix, RtWtaW,   true,  true)             \
00152 ACTION(prefix, RtaRWn,   true,  false)            \
00153 ACTION(prefix, RtaRWt,   true,  true)             \
00154 ACTION(prefix, RtaRWtaR, true,  true)             \
00155 ACTION(prefix, RtaRWtaW, true,  true)             \
00156 ACTION(prefix, RtaWWn,   true,  false)            \
00157 ACTION(prefix, RtaWWt,   true,  true)             \
00158 ACTION(prefix, RtaWWtaR, true,  true)             \
00159 ACTION(prefix, RtaWWtaW, true,  true)
00160 
00161 
00162 #endif

Generated on Sat Apr 23 11:43:36 2011 for Mnemosyne by  doxygen 1.4.7