usermode/library/mtm/src/mode/common/memset.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 _MEMSET_H
00034 #define _MEMSET_H
00035 
00036 #define BUFSIZE (sizeof(mtm_word_t)*16)
00037 
00038 /* TODO: A more efficient implementation of memset */
00039 
00040 #define MEMSET_DEFINITION(PREFIX, VARIANT)                                     \
00041 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memset##VARIANT(mtm_tx_t *tx,         \
00042                                                         void *dst,             \
00043                                                         int c,                 \
00044                                                         size_t size)           \
00045 {                                                                              \
00046   volatile uint8_t *daddr=dst;                                                 \
00047   uint8_t          buf[BUFSIZE];                                               \
00048   int              i;                                                          \
00049                                                                                \
00050   if (size == 0) {                                                             \
00051     return;                                                                    \
00052   }                                                                            \
00053   for (i=0; i<BUFSIZE; i++) {                                                  \
00054     buf[i] = c;                                                                \
00055   }                                                                            \
00056   while (size>BUFSIZE) {                                                       \
00057     mtm_##PREFIX##_store_bytes(tx, daddr, buf, BUFSIZE);                       \
00058     daddr += BUFSIZE;                                                          \
00059     size -= BUFSIZE;                                                           \
00060   }                                                                                \
00061   if (size > 0) {                                                              \
00062     mtm_##PREFIX##_store_bytes(tx, daddr, buf, size);                          \
00063   }                                                                            \
00064 }
00065 
00066 
00067 
00068 #define MEMSET_DECLARATION(PREFIX, VARIANT)                                    \
00069 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memset##VARIANT(mtm_tx_t * tx,        \
00070                                                         void *dst,             \
00071                                                         int c, size_t size);
00072 
00073 #define FORALL_MEMSET_VARIANTS(ACTION, PREFIX)                                 \
00074 ACTION(PREFIX, W)                                                              \
00075 ACTION(PREFIX, WaR)                                                            \
00076 ACTION(PREFIX, WaW)
00077 
00078 FORALL_MEMSET_VARIANTS(MEMSET_DECLARATION, wbetl)
00079 
00080 #endif

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