Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!agate!e260-3f!c60c-3cf From: c60c-3cf@e260-3f.berkeley.edu (Dan Kogai) Newsgroups: comp.unix.wizards Subject: Re: fastest way to copy hunks of memory Summary: How about the following? Keywords: bcopy, memcpy Message-ID: <1990May4.172145.4085@agate.berkeley.edu> Date: 4 May 90 17:21:45 GMT References: <5531@helios.ee.lbl.gov> <1990May2.200732.11851@eci386.uucp> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Organization: UC Bezerkeley Lines: 34 In article <1990May2.200732.11851@eci386.uucp> clewis@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@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.