fast string copy

Andrew Koenig ark at alice.UUCP
Sat Mar 30 01:13:01 AEST 1985


> 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.



More information about the Comp.lang.c mailing list