00001
00002 #ifndef __CMI_MEMCPY_H__
00003 #define __CMI_MEMCPY_H__
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <assert.h>
00015 #include <stdio.h>
00016
00017 #if !defined(__xlC__) && !defined(__xlc__)
00018 #if !defined(__cplusplus) //for gcc to compile c programs
00019 static
00020 #endif
00021 #endif
00022 inline void *bg_bcopy( void *dest, const void *src, size_t bytes )
00023 {
00024 const unsigned char *r1 = (const unsigned char *)src;
00025 unsigned char *r2 = (unsigned char *)dest;
00026 size_t b4 = bytes >> 2;
00027 size_t remainder = bytes & 3;
00028
00029 while ( b4-- ) {
00030 unsigned char u1 = *(r1+0);
00031 unsigned char u2 = *(r1+1);
00032 unsigned char u3 = *(r1+2);
00033 unsigned char u4 = *(r1+3);
00034 *(r2+0) = u1;
00035 *(r2+1) = u2;
00036 *(r2+2) = u3;
00037 *(r2+3) = u4;
00038 r1 += 4;
00039 r2 += 4;
00040 }
00041
00042 while( remainder -- )
00043 *r2++ = *r1++;
00044
00045 return( dest );
00046 }
00047
00048 #if !defined(__xlC__) && !defined(__xlc__)
00049 #if !defined(__cplusplus) //for gcc to compile c programs
00050 static
00051 #endif
00052 #endif
00053 inline void *bg_wcopy ( void *dest, const void *src , size_t bytes )
00054 {
00055 const unsigned *r1 = (const unsigned *)src;
00056 unsigned *r2 = (unsigned *)dest;
00057 size_t nw = bytes >> 3;
00058 size_t remainder = bytes & 0x7;
00059
00060 while ( nw -- ) {
00061 unsigned u1 = *(r1+0);
00062 unsigned u2 = *(r1+1);
00063 *(r2+0) = u1;
00064 *(r2+1) = u2;
00065 r1 += 2;
00066 r2 += 2;
00067 }
00068
00069 if ( remainder )
00070 bg_bcopy ( r2, r1, remainder );
00071
00072 return( dest );
00073 }
00074
00075 void *bg_dcopy128 ( void * dest, const void *src, size_t n );
00076
00077 #if !defined(__xlC__) && !defined(__xlc__)
00078 #if !defined(__cplusplus) //for gcc to compile c programs
00079 static
00080 #endif
00081 #endif
00082 inline void *CmiMemcpy ( void * dest, const void *src, size_t n ) {
00083 unsigned long daddr = (unsigned long) dest;
00084 unsigned long saddr = (unsigned long) src;
00085
00086 if ( (n >= 128) && ( ((daddr & 0x07) == 0) && ((saddr & 0x07) == 0) ))
00087 return bg_dcopy128 (dest, src, n);
00088 else if ( ((daddr & 0x03) == 0) && ((saddr & 0x03) == 0) ) {
00089 return bg_wcopy (dest, src, n);
00090 }
00091 else {
00092 return bg_bcopy (dest, src, n);
00093 }
00094
00095 return 0;
00096 }
00097
00098 #endif