刚刚写了一个fast的memcpy,叫做Pz_memcpy;至于Pz,就是Proze的缩写,而Proze是什么,你们以后就知道了。
代码随便用,no copyright。
/*
* healer
* healer_kx@163.com
* OR yuzhongm@cn.ibm.com
*/
void* Pz_memcpy(void* dest, void* src, size_t len)
{
size_t l = len / 8;
size_t m = len % 8;
int* si = (int*)src;
int* di = (int*)dest;
while (l--)
{
*di++ = *si++;
*di++ = *si++;
}
unsigned char* sc = (unsigned char*)si;
unsigned char* dc = (unsigned char*)di;
switch(m)
{
case 8: *dc++ = *sc++;
case 7: *dc++ = *sc++;
case 6: *dc++ = *sc++;
case 5: *dc++ = *sc++;
case 4: *dc++ = *sc++;
case 3: *dc++ = *sc++;
case 2: *dc++ = *sc++;
case 1: *dc++ = *sc++;
case 0:
default:
break;
}
return dest;
}