[C++] 自己实现快速memcpy

仅在Win32上使用,Win64上不允许内嵌汇编= =

__declspec(naked)
void* __stdcall __memcpy (
__in void* Dest, // ebp+0x08
__in const void* Src, // ebp+0x0C
__in unsigned int Count // ebp+0x10
)
{
__asm {
push ebp
mov ebp, esp
push edi
push esi mov edi, Dest // edi = Dest
mov esi, Src // esi = Src
mov ecx, Count // ecx = Count mov eax, esi // eax = Src;
add eax, ecx // eax = eax + ecx == Src + Count;
mov edx, [eax-] // edx = [eax-4] == *(int32*)(Src + Count - 4)
mov eax, edi // eax = Dest;
add eax, ecx // eax = eax + ecx == Dest + Count;
mov [eax-], edx // [eax-4] == *(int32*)(Dest + Count - 4)
// = edx == *(int32*)(Src + Count - 4); shr ecx, // ecx = ecx >> 2 == Count >> 2;
rep movsd mov eax, Dest
pop esi
pop edi
pop ebp
retn 0x0C
};
}
上一篇:IntelliJ 2016.02设置maven 阿里云加速


下一篇:OI学习过程记录