A note for those not consumed by efficiency worries (was: function calls)

Jim Miller jamiller at hpcupt1.HP.COM
Thu Mar 22 07:20:34 AEST 1990


OOPS, sorry about the last note.
I didn't mean to send a duplicate of the message I was remarking
on.  Here is what I thought I was sayin.
    jim - is my face red - miller

>> .......................  Statistics from a large
>> collection of programs and library routines (a mix of general and
>> scientific applications written in C) show that of 782 functions (620
>> of which were non-leaf functions), an average of 6.5 registers per
>> function were live across function calls.
>
>This statistic can only be interpreted in one way: the C compiler in
>question didn't allocate registers very well.  Especially in scientific
>packages, there are _HUGE_ numbers of 'live' _VALUES_ to deal with during
>execution of even simple routines.  Vectors, arrays, lists, strings, etc,
>are alle being either produced or consumed.  The fact that none of these
>_VALUES_ were in registers at the time of the call indicates one of two
>things: 1) the code in question was fragmented to the point that most
>procedures had only a few data items (and scalar at that), or 2) the
>compiler simply wasn't using the registers to anywhere near their potential.
>Since you imply the code was well written, I reject the first explanation.
>That leaves the compiler.

"This statistic can only be interpreted in one way: ", oh really?
"a mix of ..." and the reply is "Especially in scientific packages ..."
No conflict, just fruit salad.  

The dividing up the registers into mine and yours is not necessarily
as bad as you think, there are lots of registers that get set for
temporary values which do not need to be preserved across procedure
calls.  If the compiler is clever, guess which registers get used for
the temporary values?  

another complicating part of the problem is that with a fast cache, saving
in memory is not as much of a penalty as one might think.  One
must be careful about cache lines, working sets, etc.

Part of this discussion may be impacted by what machine one is using.
Cray (bunch), PDP-8(1), HP-PA(32), etc.  If one must save 512 registers,
often calling a subroutine to do some simple function is a real time waster
(factor of >2 in one application on a Cray).  However, with fewer
registers to dump (no matter how you manage it), the coder/compiler/OS
can and will use more small routines.

So, are we really talking about fruit salad (cray v.s. one part of the rest
of the world v.s. another part v.s. ... )?  

    jim - it's my opinion so it's the truth - miller



More information about the Comp.lang.c mailing list