soundex algorithm wanted

Guy Harris guy at sun.uucp
Fri Sep 5 06:50:39 AEST 1986


> All the compilers I have used ignore the `register' on `register
> char' declarations.

This was a change made to the System III compiler for 4(3?)BSD.  The claim
was that the compiler produced "poor, and sometimes incorrect, code" for
register variables less than 32 bits long.  The System V compiler, like the
System III compiler, puts "char" and "short" data into registers.  I have no
idea whether the S5 compiler produces the "poor, and sometimes incorrect,
code" mentioned or not, as I don't know what the code in question was.

> Are there any extant compilers for which the latter will generate *worse*
> code?

Script started on Thu Sep  4 13:41:45 1986
gorodish$ cat foo.c
foo()
{
	register char c;
	register int i;

	if (i == 'c')
		bar();
	if (c == 'c')
		bar();
}
gorodish$ cc -S -O foo.c
gorodish$ cat foo.s
	...(boring preamble deleted)...
	moveq	#99,d1
	cmpl	d1,d6
	jne	L14
	jbsr	_bar
L14:
	cmpb	#99,d7
	jne	LE12
	jbsr	_bar
LE12:
	moveml	a6@(-8),#192
	unlk	a6
	rts
gorodish$ 

Script done on Thu Sep  4 13:42:01 1986

As the M68000 Programmer's Reference Manual says for CMPI, "The size of the
immediate data matches the operation size", so it uses a scratch register
and a "moveq"/"cmp.l" pair rather than a "cmpi.l".  Even given that, it'd
rather compare 8 bits of immediate data against 8 bits in a register than
compare 32 bits of data against 32 bits in a register, especially on the
M68XXX for XXX < 020.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list