[gclist] Stack allocation inneficiency.

Patrick C. Beard beard@apple.com
Thu, 5 Dec 1996 11:05:14 -0800


At 2:20 AM -0800 12/5/96, Charles Fiterman wrote:
>Optimizing compilers make very wasteful
>use of stack space with C.
>
>        aFun(lots, of, big, parms);
>
>Becomes in psudo assembler
>        push lots
>        push of
>        push big
>        push parms
>        call aFun
>        add  #size_of_parms, %SP
>
>But if this call is before the return that add at the
>end is useless as the stack will be restored from a
>register not arithmetic.

This isn't really a language issue, it's more of an Application Binary
Interface (ABI) or calling convention issue. The PowerPC calling
conventions used on Mac OS and AIX preallocate the stack space for the
largest number of parameters that will be passed to any of the functions
called by a given function, and deallocates it once at the end of the
function. And since parameters are typically passed in registers (r3-r10),
this memory is only committed and not typically written to, unless the
parameter registers have to be spilled. Functions with variable numbers of
arguments are the typical offenders here, and tend to slow things down.

So computer architecture can have a lot to do with how efficient a given
language's parameter passing is. I'm sure the SPARC has similar effects,
with its register windows.

- Patrick



--
// Patrick C. Beard, Java Runtime Architect
// System Software Architecture, Apple Computer
// beard@apple.com, http://webstuff.apple.com/~beard/