Mail Archives: djgpp/1996/12/22/05:39:07
Daniel Everton wrote:
>
> Hi all,
>
> In a program I'm currently writing I need to copy some biggish (64k)
> shunks of memory around. I'm using memcpy() at the moment but it's not
> quite fast enough. Is there some other function that any one can
> suggest? The memory has all been allocated with malloc() and I'm not
> copying between conventional memory or something like that. Any help
> appreciated.
Here's some code I originally got from Mihai Moise's port of GL, it
copies lng bytes from buffer src to buffer dst using movsl, with a movsb/movsw
attached at the beginning & the end to even things out. For variable
buffer sizes it should be faster than memcpy().
void CopyBuffer(void * dst, const void * src, int lng)
{
asm("cld \n\t"
"movl %%edi,%%ecx \n\t"
"andl $1,%%ecx \n\t"
"subl %%ecx,%%edx \n\t"
"rep ; movsb \n\t"
"movl %%edx,%%ecx \n\t"
"shrl $2,%%ecx \n\t"
"rep ; movsl \n\t"
"testb $1,%%dl \n\t"
"je 1f \n\t"
"movsb \n"
"1:\ttestb $2,%%dl \n\t"
"je 2f \n\t"
"movsw \n"
"2: \n"
::"d" (lng),"D" ((long) dst),"S" ((long) src)
: "cx","dx","di","si");
}
Elliott
- Raw text -