fastest way to copy hunks of memory
Dan Kogai
c60c-3cf at e260-3f.berkeley.edu
Sat May 5 03:21:45 AEST 1990
In article <1990May2.200732.11851 at eci386.uucp> clewis at eci386.UUCP (Chris Lewis) writes:
>Perhaps
>
> while(size--)
> *p1++ = *p2++;
or even
void *memcpy(void *to, void *from, size_t size){
register int size_l = size / 4, /* or (size >> log2(sizeof int)) */
tail = size % 4; /* or (size & log2(sizeof int)) */
void *result = to;
while(size_l--) (int *)to++ = (int *)from++;
while(tail--) (char *)p1++ = (char *)p2++;
return result;
}
This shold work almost 4 times as fast compared to just inclementing
by bytes--it uses full length of register. The problem is that it doesn't
work if either (void *to) and (void *from) is not aligned and the macine
architecure doesn't allow unaligned assignment. Such functions as
memcpy() should be written in assembler, I think...
---
################## Dan The "ioccc contestant this year" Man
+ ____ __ __ + (Aka Dan Kogai)
+ ||__||__| + E-mail: dankg at ocf.berkeley.edu
+ ____| ______ + Voice: 415-549-6111
+ | |__|__| + USnail: 1730 Laloma Berkeley, CA 94709
+ |___ |__|__| + U.S.A
+ |____|____ + Disclaimer: I'd rather be blackmailed for my long .sig
+ \_| | + than give up my cool name in Kanji. And my
+ <- THE MAN -> + citizenship of People's Republic o' Berkeley
################## has nothing 2 do w/ whatever I post, ThanQ.
More information about the Comp.unix.wizards
mailing list