Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ccice6.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!rochester!ritcv!ccice5!ccice6!dwd From: dwd@ccice6.UUCP (David W. Donald) Newsgroups: net.lang.c Subject: Re: String copy idiom. Message-ID: <366@ccice6.UUCP> Date: Wed, 20-Mar-85 18:50:30 EST Article-I.D.: ccice6.366 Posted: Wed Mar 20 18:50:30 1985 Date-Received: Fri, 22-Mar-85 01:33:25 EST References: <7042@watdaisy.UUCP> <7044@watdaisy.UUCP> <7047@watdaisy.UUCP> Distribution: net Organization: CCI Central Engineering, Rochester, NY Lines: 32 > > The idiom "while (*s++ = *t++);" generates the fastest possible code > if s and t are declared to be registers ... > Beware of saying things like "the fastest possible". I found a better way for for any string longer than two characters. The following is from 4.2BSD on a VAX. main() { register char *s, *d; while( *d++ = *s++ ); /* ok */ if (*d) do {} while ( *d++ = *s++ ); /* <-- FAST -- */ } _main: L16: /* ok: a 3 instruction loop */ movb (r11)+,(r10)+ jeql L17 jbr L16 L17: /* FAST: a two instruction loop */ tstb (r10) jeql L18 L21: L20: movb (r11)+,(r10)+ jneq L21 L19: L18: ret