Re: Using memory below the SP (Was: Q: P6 branch prediction)

zalman@macromedia.com (Zalman Stern)
18 May 1996 23:10:23 -0400

          From comp.compilers

Related articles
Re: Q: P6 branch prediction conway@rimmer.cs.mu.OZ.AU (1996-05-01)
Re: Q: P6 branch prediction khays@sequent.com (1996-05-14)
Re: Using memory below the SP (Was: Q: P6 branch prediction) zalman@macromedia.com (1996-05-18)
Re: Using memory above TOS bart@time.cirl.uoregon.edu (1996-05-19)
Using memory above TOS fjh@cs.mu.OZ.AU (Fergus Henderson) (1996-05-21)
Re: Using memory below the SP (Was: Q: P6 branch prediction) meissner@cygnus.com (Michael Meissner) (1996-05-24)
Re: Using memory above TOS markt@harlequin.co.uk (1996-05-29)
| List of all articles for this month |

From: zalman@macromedia.com (Zalman Stern)
Newsgroups: comp.arch,comp.compilers
Date: 18 May 1996 23:10:23 -0400
Organization: Macromedia Video Products Group
References: <3179B05D.2781@cs.princeton.edu> <4m6ufs$msc@mulga.cs.mu.OZ.AU> 96-05-012 96-05-100
Keywords: architecture, optimize



Thomas Charles CONWAY <conway@rimmer.cs.mu.OZ.AU> wrote:
>To avoid wasting the cycle, what the Mercury compiler now does is emit
>code to save the return continuation one slot above the stack top,
>then the conditional branch and then, in the appropriate arm of the
>code, the stack pointer increment. Because the store of the return
>continuation is above the stack top, it doesn't clobber anything
>live.


khays@sequent.com (Kirk Hays) wrote:
> Am I correct in assuming interrupts and faults are not an issue
> on this machine?
>
> If they are, and you take an interrupt or fault between the time the
> information is stored above the stack top, and when the stack pointer
> is finally incremented, you'll have garbaged the stored return
> continuation.
>
> This is not a safe optimization on most architectures, IOW.


Using the IBM calling convention on PowerPC, the 64 bytes immediately
below the stack pointer (that is just outside the stack region) are
guaranteed to be useable by a fucntion. This gives a function access
to a small amount of memory without the expense of buying a stack
frame. So on that platform, this technique is undeniably safe.


But I expect one doesn't even need that to get the optimization Thomas
describes to work reliably. Most OSes don't use the user stack space
to handle interrupts or for running the kernel code that handles a
fault. Rather they use an alternate stack. (E.g. the kernel stack in
the U area of a UNIX process.) This is done for security and
reliabilty reasons as one has no idea what a user process has stuffed
in the stack pointer register.


That leaves asynchronous events delivered to the user process
e.g. UNIX signals. With a BSDish UNIX, one can assign an alternate
stack to be used for signal delivery (on a per signal type basis as I
recall). If all async signals are put on a different stack, one
doesn't have to worry about any bytes in the main stack region
changing without "compiler knowledge." Hence the optimization given
is safe.


Zalman Stern, Caveman Programmer, Macromedia Video Products, (415) 378 4539
3 Waters Dr. #100, San Mateo CA, 94403, zalman@macromedia.com
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.