Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: net.lang.c Subject: Re: fast string copy Message-ID: <3505@alice.UUCP> Date: Fri, 29-Mar-85 10:13:01 EST Article-I.D.: alice.3505 Posted: Fri Mar 29 10:13:01 1985 Date-Received: Sat, 30-Mar-85 01:19:15 EST References: <1049@gloria.UUCP> Organization: Bell Labs, Murray Hill Lines: 40 > I think this is cute, how VAX/VMS beats Unix at its own game. The VMS C > compiler generates code as good as or better than anything I have seen posted > so far! > > char *s,*t; > while (*s++ = *t++); > > generates (on a VAX 780): > > movb (r2)+,(r1)+ > beql sym.2 > sym.1: > movb (r2)+,(r1)+ > bneq sym.1 > sym.2: > > This is as fast as you can get. Ummm... I hate to be a spoilsport, but I do not understand why the code above is any faster than sym.1: movb (r2)+,(r1)+ bneq sym.1 which is essentially what the Unix compilers generate. Apparently, the VMS compiler is trying to be clever by rewriting while (cond) stmt; into if (cond) { do stmt; while (cond);} This rewriting generally buys speed at the expense of space, but in this particular case the speed gain is 0 and the space cost is a factor of two. By the way, Colonel, this loop is not improved by unrolling.