Available No. of Registers

jjw at celerity.UUCP jjw at celerity.UUCP
Fri Feb 13 03:12:13 AEST 1987


In response to my claim that compilers which conform to K&R should allocate
"registers" starting with the first declaration guy at sun.UUCP (Guy Harris)
indicates:
>Fortunately, the ANSI C standard does not promise which declarations
>will be effective.

I believe this is unfortunate.  If I have a program which can effectively
use differing numbers of registers how can I indicate which variables
should go into registers in a machine/compiler independent manner?

For example, postulate a function which has more than 6 variables  6 of
which have the following characteristics:

	a -- Is extremely frequently used.  It is critical to performance
	     that it be in a register.
	b, c -- Are used very frequently.  They should be in registers to
	        obtain optimal performance.
	d, e, f -- Are used frequently.  If possible, they should be in
	           registers.
	The remaining variables are only used infrequently and should never
	be in registers in preference to those listed.

The question is -- How do I declare these variables so that I get the best
performance on machines with 1, 3, 6, 8 ... registers available for register
variables?  I am trying to code in a machine and compiler independent
manner.  I do not want to reshuffle the declarations nor to have to
re-define a "REGISTER" macro.  In fact I don't even want to care about how
many register variables the compiler allocates.

K&R's suggestion that the register variables are assigned to registers in
order of appearance solves my problem -- I just put the variables in order
of importance and let the compilers handle it from there.  The reason for my
original posting was because of this.  I think the K&R statement, "Only the
first few such declarations are effective," is insightful and aids in
producing machine independent code.  Therefore I am saddened to see it
ignored or forgotten.

As Guy says:
>It's probably a Good Idea to process declarations in the Ritchie
>compiler/PCC fashion if you don't use any other information to decide
>which variables to put into registers, but it's probably a Good Idea
>to offer the programmer the option of using other information, since
>they may not know how many and what kind registers the machine the
>code is currently being compiled for has.

Except that I would replace his "but" with "because".  Also, I don't
understand what he means by "using other information."  I assume the
register declarations are the result of considering whatever information
the programmer has about the operation of the program.



More information about the Comp.lang.c mailing list