From: Mikael Djurfeldt <mikael@djurfeldt.com>
To: hugo@lysator.liu.se
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: A different stack discipline
Date: Sat, 3 Nov 2018 19:49:16 +0100 [thread overview]
Message-ID: <CAA2Xvw+aKRv-mH4EEBoRgs4CJ0EjXToM_DUeKmmgH9mRQ8vzgg@mail.gmail.com> (raw)
In-Reply-To: <CAA2XvwJXTFh9P_+uEidPWk-c7HoZr3jSLi=jCapB3dGAVu8uJg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2417 bytes --]
Den lör 3 nov. 2018 19:16 skrev Mikael Djurfeldt <mikael@djurfeldt.com>:
> On Sat, Nov 3, 2018 at 4:30 PM Hugo Hörnquist <hugo@lysator.liu.se> wrote:
>
>> The section, as far as I can see, just describes a machine
>> which pushes continuation instead of the PC counter to the
>> stack.
>>
>> 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!
>
[-- Attachment #2: Type: text/html, Size: 3778 bytes --]
prev parent reply other threads:[~2018-11-03 18:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-31 20:55 A different stack discipline Mikael Djurfeldt
2018-11-03 15:29 ` Hugo Hörnquist
2018-11-03 18:16 ` Mikael Djurfeldt
2018-11-03 18:49 ` Mikael Djurfeldt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA2Xvw+aKRv-mH4EEBoRgs4CJ0EjXToM_DUeKmmgH9mRQ8vzgg@mail.gmail.com \
--to=mikael@djurfeldt.com \
--cc=guile-devel@gnu.org \
--cc=hugo@lysator.liu.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).