心寄笔端 附庸风雅

甘草的技术博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

刚刚写了一个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;
}


posted on 2008-11-20 11:37  甘草  阅读(547)  评论(0编辑  收藏  举报
Baidu
Google
心寄笔端
TEST
以后我会加上Power By的,先别介意