# 加载中...

• 博客等级：
• 博客积分：0
• 博客访问：415,028
• 关注人气：59
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

## (转)VC 对 memcpy 的优化

(2011-06-13 16:27:15)

### 杂谈

void foo(void *d,const void *s)
{
memcpy(d,s,1);
}

mov eax, DWORD PTR _s\$[esp-4]
mov edx, DWORD PTR _d\$[esp-4]
mov cl, BYTE PTR [eax]
mov BYTE PTR [edx], cl

mov eax, DWORD PTR _s\$[esp-4]
mov edx, DWORD PTR _d\$[esp-4]
mov ecx, DWORD PTR [eax]
mov DWORD PTR [edx], ecx

mov eax, DWORD PTR _s\$[esp-4]
mov ecx, DWORD PTR _d\$[esp-4]
mov edx, DWORD PTR [eax]
mov DWORD PTR [ecx], edx
mov eax, DWORD PTR [eax+4]
mov DWORD PTR [ecx+4], eax

mov eax, DWORD PTR _s\$[esp-4]
mov ecx, DWORD PTR _d\$[esp-4]
mov edx, DWORD PTR [eax]
mov DWORD PTR [ecx], edx
mov edx, DWORD PTR [eax+4]
mov DWORD PTR [ecx+4], edx
mov edx, DWORD PTR [eax+8]
mov DWORD PTR [ecx+8], edx
mov edx, DWORD PTR [eax+12]
mov DWORD PTR [ecx+12], edx
mov dx, WORD PTR [eax+16]
mov WORD PTR [ecx+16], dx
mov al, BYTE PTR [eax+18]
mov BYTE PTR [ecx+18], al

push esi
mov esi, DWORD PTR _s\$[esp]
push edi
mov edi, DWORD PTR _d\$[esp+4]
mov ecx, 5
rep movsd

pop edi
pop esi

push esi
mov esi, DWORD PTR _s\$[esp]
push edi
mov edi, DWORD PTR _d\$[esp+4]
mov ecx, 5
rep movsd
movsw
movsb

pop edi
pop esi

void foo(void *d,const void *s,size_t size)
{
memcpy(d,s,size);
}

mov ecx, DWORD PTR _size\$[esp-4]
push esi
mov esi, DWORD PTR _s\$[esp]
mov eax, ecx
push edi
mov edi, DWORD PTR _d\$[esp+4]
shr ecx, 2
rep movsd
mov ecx, eax
and ecx, 3
rep movsb
pop edi
pop esi

mov ecx, DWORD PTR _size\$[esp-4]
push esi
mov esi, DWORD PTR _s\$[esp]
push edi
mov edi, DWORD PTR _d\$[esp+4]
rep movsd
pop edi
pop esi

0

• 评论加载中，请稍候...

发评论

以上网友发言只代表其个人观点，不代表新浪网的观点或立场。

新浪BLOG意见反馈留言板　电话：4000520066 提示音后按1键（按当地市话标准计费）　欢迎批评指正

新浪公司 版权所有