Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" To: Elliott Oti , djgpp AT delorie DOT com Date: Mon, 23 Dec 1996 15:47:34 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: memcpy(); is there something faster? 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