Unix Stack Frame Questions

Israel Pinkas pinkas at st860.intel.com
Thu Apr 4 08:08:56 AEST 1991


In article <3465 at unisoft.UUCP> greywolf at unisoft.UUCP (The Grey Wolf) writes:

> /* <GOEHRING.91Mar25113709 at gnu.ai.mit.edu> by goehring at gnu.ai.mit.edu
>  * In article <125 at epic.epic.com> tan at epic.epic.com (Andy Tan) writes:
>  * 
>  *    1. Is it right to assume that the address of the last automatic
>  *       variable is the bottom of stack frame ?
>  * 
>  * it is not right to assume that there is a stack frame, and some
>  * compilers aren't going to put autos in the frame even if a frame
>  * exists since they can be more cheaply handled with registers.
>
> If, of course, you have the registers (68K only have so many).
> If there's not a stack frame, how are parameters passed to the
> function...?  And how would you return...?

The Intel i860 passes most parameters in registers.  The processor has a
total of 15 integer and 15 float (32 bit) registers (actually 16, but r0
and f0 are hardwired 0).  The float registers can be combined to form 64
bit doubles and 128 bit long doubles.

r16-r27 are used to pass scalar parameters.  f8-f15 are used to pass up to
4 double parameters (all compilers promote floats to doubles).  If a
struct, more than 12 scalar arguments, or more than 4 doubles are passed, a
block of memory is reserved on the "stack" and r28 is set to point to this
block.  varargs/stdargs routines receive their parameters in this block as
well.  Scalar return values are returned in f16, double return values are
returned in f16/f17.

The i860 does not have a real stack, although one of the integer registers
is used to point to a software stack.  The return address for a call is
kept in r1.  If the callee make a call, it is responsible for saving r1 on
the "stack".

>  * every cpu is going to have varying stack frame format(s), assuming the
>  * cpu enforces one at all, and OS and compiler vendors are more than happy
>  * to create oddball parameter passing and stack frame conventions.

> I didn't think that a CPU ever "enforced" a stack frame; ostensibly one
> could ignore the references to "4(fp)" in the manual and do it their own
> way.

> But a stack frame seems to be the most efficient way of dealing with
> calls and returns.

We discovered that having a frame pointer and a true stack was more
expensive, CPU wise.  A large percentage of CPU is spent in leaf routines,
where having the parameters in registers speeds things up.

-Israel Pinkas
 Intel Corp
--
--------------------------------------
Disclaimer: The above are my personal opinions, and in no way represent
the opinions of Intel Corporation.  In no way should the above be taken
to be a statement of Intel.

UUCP:	{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!st860!pinkas
ARPA:	pinkas%st860.intel.com at relay.cs.net
CSNET:	pinkas at st860.intel.com



More information about the Comp.lang.c mailing list