unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: wip-rtl return location
Date: Thu, 2 Aug 2012 18:21:02 -0400	[thread overview]
Message-ID: <CA+U71=OPKDCOWWSDXYW33GRzEoph2KYewNNKvPRWXSwVO_AnAQ@mail.gmail.com> (raw)
In-Reply-To: <87mx2dv02q.fsf@pobox.com>

That sounds interesting, but I have a question - why not make the MVRA
return address immediately after the call, instead of immediately
before it? In the common case when returning to the regular return
address, that would eliminate the extra branch (although it's a very
small branch anyway).

I would guess the reason to put it before is for variable-length
instructions, but you could handle that by reserving enough bytes for
a jump instruction. So it would look like

CALL:
  call f
MVRA:
  jump mv-handler
RA:
  ... rest of function ...

I really don't know if this is better or not. I'm just curious why it
isn't arranged like this.

Thanks,
Noah

On Thu, Aug 2, 2012 at 10:29 AM, Andy Wingo <wingo@pobox.com> wrote:
> Hi,
>
> Some brief thoughts on the wip-rtl branch.  Currently it has this
> strange "return location" thing, where it specifies the register(s) to
> which to return value(s), and the number of expected values and whether
> it expects a rest list or not.  Problem is, this return location is like
> a little program that needs to be interpreted at runtime.  Worse, it
> seems to assume that return values will have to be passed in memory.
>
> Instead I'd rather just use Dybvig's suggestion: every call instruction
> is preceded by an MV return address.  For e.g. (values (f)), calling `f'
> would be:
>
>     ...
>     goto CALL
> MVRA:
>     truncate-and-jump RA
> CALL:
>     call f
> RA:
>     return
>
> So the overhead of multiple values in the normal single-value case is
> one jump per call.  When we do native compilation, this cost will be
> negligible.  OTOH for MV returns, we return to a different address than
> the one on the stack, which will cause a branch misprediction (google
> "return stack buffers" for more info).  Of course this is not relevant
> to the interpreter, because all of these branches are indirect, but it
> will be in the future, so it's a good idea to think about these things
> now.  With this design, the caller is responsible for handling MV
> returns, not the callee.
>
> Anyway, MV return will cause a branch misprediction.  Oh well.  I think
> we can live with it.  Single-valued returns are the common case, and
> they will be predicted correctly.
>
> So, another thing.  The reason for the previous "return location" design
> was because I wanted to have just two registers reserved by the
> implementation: the instruction pointer and the frame pointer.  Wanting
> an IP is obvious.  It's important to locate frame pointers so that
> various pieces of code can walk the stack frames: for example the
> delimited continuation code, the backtrace printer, the debugger, etc.
> It's possible to just using a stack pointer and use dynamic tables to
> find where the frame pointer is, like the x86-64 architecture does (or
> -fomit-frame-pointer), but that requires more sophistication on the part
> of the runtime, and I don't think we're really ready for that right now.
>
> As I said, I wanted just the IP and the FP.  I didn't want an SP because
> it causes so much performance noise in the current VM.  But then I
> realized that in the RTL VM, it doesn't need to be accessed frequently,
> because more values are addressed against the FP, and we're not pushing
> and popping temporaries.  So we can actually keep it around, and it
> might not need to be in a register.  It retains its useful
> characteristics of allowing variable-sized data to be (temporarily)
> allocated on the stack, as in procedure calls or MV returns, and as a
> stack delimiter for GC.
>
> In summary:
>
>   - I will remove the "return location" stuff from wip-rtl;
>
>   - All calls will be mv-calls
>
>   - MV returns will return to 1 instruction before the RA
>
>   - All calls will be preceded by a jump over the MVRA
>
>   - Eventually we can remove the MVRA slot from stack frames, because it
>     is computable from the RA
>
>   - The stack pointer is back in town!
>
> Andy
> --
> http://wingolog.org/
>



  reply	other threads:[~2012-08-02 22:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-02 14:29 wip-rtl return location Andy Wingo
2012-08-02 22:21 ` Noah Lavine [this message]
2012-08-03  8:06   ` Andy Wingo
2012-08-03  2:29 ` Mark H Weaver
2012-08-03  8:24   ` Andy Wingo
2012-08-03 11:54   ` Stefan Israelsson Tampe
2012-08-03 12:38     ` Andy Wingo
2012-08-03 13:13       ` Stefan Israelsson Tampe

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='CA+U71=OPKDCOWWSDXYW33GRzEoph2KYewNNKvPRWXSwVO_AnAQ@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /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).