Mail Archives: djgpp/1996/12/23/14:05:28
Hi Elliott
> 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");
> }
That's practically equal to memcpy (you will save some little test at
the begining of memcpy => 6 o 10 cicles in 128000)
SET
--------------- 0 --------------------------------
Salvador Eduardo Tropea (SET).
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013
- Raw text -