register variables

Mike Schloss mhs at enmasse.UUCP
Fri Jun 28 06:34:15 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

Easier said than done.  For example, what do you mean by most heavily used?
Do you mean occurs most often in the code or encountered more often during
execution.  Assume two variables, one with 16 references in the first half
of the routine and none in the second half, another variable with only one
reference in the second half, in a loop, where the program spend 98% of its
time.  Get the picture?  Also the is some cost to using registers, the
overhead of storing and restoring them.  A compiler does not know about
execution paths so it can not deal with this properly.  Better left to the
programmer who shoud know better about variable usage and possible input data.



More information about the Comp.lang.c mailing list