RISC perspective

Guy Harris guy at rlgvax.UUCP
Sat Mar 10 13:07:21 AEST 1984


This is a spinoff from a comment about speeding up C programs by advising
the C compiler what to put into registers.

The idea is good, but there's one problem with its current implementation;
there's no way to make those hints truly "machine-independent".  The problem
is that you want to use all the registers you can (actually, there's even
a tradeoff here; you get extra performance from instructions referencing
registers, but you do have to save and restore those registers, and if you
have complicated expressions you may run out of scratch registers and be
forced to use temporaries in memory), but "all the registers you can" is
machine-dependent.  On the PDP-11, "all the registers you can" in the Ritchie
and Johnson compilers is 3; on the VAX-11, it's 6, and on the M68000, it's
(at least on our compiler) 6 registers not containing pointers and four
registers containing pointers.  Just declaring everything you can to be
"register" wins only if 1) there are enough registers to satisfy your requests
or 2) the variables that will cause the greatest improvement when put in
registers are assigned to registers first, and the less important ones cause
the compiler to ignore the "register" declaration.

You can sort of rig it to work right, on compilers that assign "register"
variables to registers in the order they encounter them in the source text,
buy putting the "best" candidates first; however, 1) this means you may not
be able to use the "register parameter" feature, 2) it makes your code a
little less readable, and 3) most importantly, it requires you to know what the
compiler does - but what happens if the compiler doesn't work that way?
Writing portable code to use registers efficiently is tricky at times.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list