Available No. of Registers

Gregory Smith greg at utcsri.UUCP
Wed Jan 21 03:12:31 AEST 1987


In article <2250 at jade.BERKELEY.EDU> mwm at eris.BERKELEY.EDU (Mike Meyer) writes:
>There is a false implication in the above: that it doesn't hurt to add
>register declerations. There is at least one compiler out there that
>effectively allocates registers from the last declared instead of the
>first, so that blindly adding registers to code can slow the generatred
>code down.

Furthermore, in most run-time environments, functions are expected to
preserve that set of registers which are available for 'register' vars.
So if you declare six register variables, they must be pushed on entry
and popped on exit. If the function in question does very little, this
pushing and popping may become a significant portion of the function's
execution time.

It may seem silly to want a large number of register vars on a function
that does very little. This problem applies, though, to any function
that *Usually* does very little:

/* update the data structure */

Update(){
	register foo *first, *last, *current;
	register int loops, item_count, *bats_knees;
	extern int Dirty;		/* dirty flag */
	extern ...

	if(Dirty){
		... mucho code using register vars ...
		Dirty = FALSE;
	}
}

Assume Update() is called very frequently, but that Dirty is false on 98%
of these calls. Then it looks bad, no? A fix might be to remove the 'Dirty'
test from Update(), and use if(Dirty)Update(); whenever Update() was
called.

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...



More information about the Comp.lang.c mailing list