All pastes #908152 Raw Edit

Custom memcpy

public cpp v1 · immutable
·published 2008-02-18 04:24 UTC
rendered paste body
// Custom implementation of memcpy.// This routine copies memory in DWORDS (4 bytes at a time) until there are only 3// or less bytes to copy. Faster than the normal memcpy.void CopyMem(void* dest, void* src, UINT16 size){	// Yes, toraton, I get it. It's assembly.	__asm	{		push eax		push ecx		push esi		push edi		mov eax, size		mov ecx, eax		shr ecx, 2		push ecx		mov esi, dest		mov edi, src		rep movsd		pop ecx		shl ecx, 2		sub eax, ecx		jz epilog		mov ecx, eax		rep movsbepilog:		pop edi		pop esi		pop ecx		pop eax	}}