Skip to content
Felix S. Klock II edited this page Jul 28, 2013 · 2 revisions

ContIsEsp (aka cont-is-esp) refers to the change in IasnLarceny where the Intel stack pointer (esp) is used as the stack-cache pointer (rather than being the globals pointer like it was prior to changeset:4000).

The main reasons to do this is to make the call/return instruction sequences efficient; by choosing the stack slot for the return address very carefully, we can allow a MacScheme invoke to be implemented with a IA32 call instruction (along with a bunch of non-branching instructions) and a MacScheme return with a IA32 ret instruction. Without cont-is-esp, an invoke had to go through a bit of patch code before transferring control to the target code vector.

One complication introduced by cont-is-esp is that continuation points in the instruction stream now need to do some fixup of the stack pointer (because the IA32 ret transfers control and pops the address off the stack; the MacScheme return instruction only transfers control without popping anything off the stack.)

This change was developed on a [source:branches/pnkfelix/callret-measurements/codealign/cont-is-esp/larceny_src branch] during investigation of alternative call/return instruction sequences.


One reason it is good for setrtn; invoke to be an IA32 call and return to be an IA32 ret is that (PnkFelix believes) the processor does branch prediction for returns (by maintaining an internal stack of addresses based on calls). So by using call/ret, we get better performance for the common case of procedure invocations following a stack discipline. (All performance bets are off when first class continuations are installed, but in terms of correctness we are okay, because the IA32 semantics demand that the processor actually check that the predicted branch target actually matches the address that is fetched off the stack when executing a ret instruction.)


See also:

Clone this wiki locally