[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A different stack discipline

From: Mikael Djurfeldt
Subject: Re: A different stack discipline
Date: Sat, 3 Nov 2018 19:49:16 +0100

Den lör 3 nov. 2018 19:16 skrev Mikael Djurfeldt <address@hidden>:
On Sat, Nov 3, 2018 at 4:30 PM Hugo Hörnquist <address@hidden> wrote:
The section, as far as I can see, just describes a machine
which pushes continuation instead of the PC counter to the

Also, while in theory quite nice it has the problem that
Guile is really slow in restoring continuations, due to the
fact that we have complete C interoperability.

There's some misunderstanding here. The SICP register machine model is not very different from common register machine models. There's just a difference in how to handle subroutine calls. A short example:

Let's first write out all operations involved in a call in a conventional register machine:

        ; The following three micro operations consitute "call foo ()"
        (sp) <- pc + offset(L1) ; NOTE the external memory access
        sp <- sp - 1
        pc <- pc + offset(foo)
L1:    [...]
foo:   [...]
        ; the following two micro operations constitute "ret"
        sp <- sp + 1
        pc <- (sp) ; NOTE the external memory access

Now look at the call in the SICP register machine:

        continue <- pc + offset(L1)
        pc <- pc + offset(foo)
L1:   [...]

foo:  [...]
        pc <- continue

It is fewer operations and every operation is immediate with no memory access. I *have* cheated since I omit a need to push the continue register onto the stack, but while this is needed at *every* call for the conventional machine, this is only required once at the beginning of a function in the SICP machine *unless* the function has a tail call, in which case we don't need to push anything. So, while one can say that we only "push around the pushes", we make gains for every tal call.

(consitute -> constitute; tal -> tail; also, when saying "this is needed" above, I was referring to the *stack pushes*, not the push of the continue register specifically)

In addition to not having to push continue in functions with tail calls, we also gain for every function that do not call a subroutine.

For C compatibility, we can do an ordinary call when calling C.

None of this affects the restoration of continuations. Also, it does not slow down but speeds up!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]