register variables

Pat Shanahan ps at celerity.UUCP
Tue Jul 2 04:04:50 AEST 1985


> Speaking of register variables -- does anybody know what various C
> compilers do when you don't declare variables as register, but there
> are spare registers to use? From what I hear, neither ccom nor c2 are
> smart enough to put local variables in registers when they are
> available. It seems that it would be simple to just take the first few,
> or even the most heavily used local variables that don't ever get &'d
> and make them register...
> 
> 	Wayne

Release 2.1 of the Celerity C1200 C compiler implements simple automatic
register allocation for  optimized compiles. Declared register variables
have priority for allocation of registers. The remaining registers are
allocated for an arbitary selection of the simple automatic variables,
excluding any that have their addresses calculated.

Automatic register allocation is particularly important for the C1200,
because it provides an unusually large number of registers and a wide range
of types of register variables. The C1200 supports all integer types and
both floating point types in registers. Depending on the number of registers
that the function needs for arguments, up to 26 integer registers can be
allocated. The C1200 also has 15 floating point registers, of which the C
compiler will allocate up to 9 for variables. Each floating point register
can contain either a float or a double. This large supply of registers is
very desirable for big FORTRAN subroutines.

The C compiler makes no attempt to do usage based allocation and allocates
registers for the whole scope of the variables, since the number of
registers exceeds the number of suitable variables in most C functions. For
example, all suitable automatic variables in the C compiler first pass fit
into registers.

Excessive register allocation is not a concern on the C1200, because the
architecture supports rapid saving and restoring of blocks of registers. 

The C1200 C compiler first pass user time improved by 5% due to automatic
register allocation. This is probably typical of UNIX code that already has
many register declarations, and that does not use floating point much. The
largest improvement I have seen so far was in a small artificial benchmark.
The user time reduced from 13.4 seconds to 8.6 seconds. Obviously, there
would be no improvement in a program that already had all possible variables
declared register.

-- 
	ps
	(Pat Shanahan)
	uucp : {decvax!ucbvax || ihnp4 || philabs}!sdcsvax!celerity!ps
	arpa : sdcsvax!celerity!ps at nosc



More information about the Comp.lang.c mailing list