Comparing strings...

Thomas Truscott trt at rti.rti.org
Fri Oct 26 00:52:32 AEST 1990


Some years ago, while working on a fast DES implementation,
I discovered that:

	int i;
	unsigned char table[8];

	i = table[0];

ran faster than the obvious "char table[8]" on VAX, Gould,
MC680X0, and Convex.  I was rather surprised by that.
And it was as fast as "char table[8]" on all
the other machines I tried (e.g. MIPS, SPARC).

As a practical :-) example of this, the fastest VAX bitcount reported
by Chris Torek can be sped up 30% just by declaring nbits[] unsigned.
A strcmp() routine might take advantage of this with:
    while ((c = *(unsigned char *)p) != '\0' && c == *(unsigned char *)q)
Of course one must be careful about lexical ordering.

Perhaps there are exceptions, but I did not encounter any.
I am sure the PDP-11 would be an exception, but there wasn't one handy!
	Tom Truscott



More information about the Comp.lang.c mailing list