unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: wip-rtl return location
Date: Fri, 03 Aug 2012 10:24:30 +0200	[thread overview]
Message-ID: <87y5lwtmbl.fsf@pobox.com> (raw)
In-Reply-To: <501B376F.3060505@netris.org> (Mark H. Weaver's message of "Thu,  02 Aug 2012 22:29:03 -0400")

Heya Mark,

Thanks for the comments :-)

So the current thing is:

  CALL:
       call f
  MVRA:
       truncate
  RA:
       return

In interpreted code it's fine that we return to a different address, as
they are all indirect jumps anyway.  For compiled code, the "call"
instruction won't be just one instruction -- in RTL it's a
macro-instruction that also handles shuffling the arguments into place,
whereas with native compilation you would handle the shuffling then do
the call.  So for native compilation you could put the MVRA before the
call because the call would have fixed width.

Anyway, on to your point:

On Fri 03 Aug 2012 04:29, Mark H Weaver <mhw@netris.org> writes:

> I wonder if it might be better to avoid this branch misprediction by
> always returning to the same address.  Upon return, a special register
> would contain N-1, where N is the number of return values.  The first
> few return values would also be stored in registers (hopefully at least
> two), and if necessary the remaining values would be stored elsewhere,
> perhaps on the stack or in a list or vector pointed to by another
> register.

It's a good idea for the native-compilation case.  I don't think the
overhead of the conditional jump in interpreted code would be worth it,
though.  Dunno.  Probably wouldn't matter?

> In the common case where a given call site expects a small constant
> number of return values, the compiler could emit a statically-predicted
> conditional branch to verify that N-1 is the expected value (usually
> zero), and then generate code that expects to find the return values in
> the appropriate registers.

But here's the rub, this introduces a conditional branch into the
calling sequence where there was no conditional branch before (for the
single-valued case, which is empirically the majority of cases).

Apparently the intel Core architecture ignores static branch
predictions:

  http://www.agner.org/optimize/microarchitecture.pdf

So it would increase pressure on the branch target buffer.  OTOH the
dynamic predictions would almost always hit, in either case.

> On some architectures, it might also make sense for the callee to set
> the processor's "zero?" condition code as if N-1 had been tested, to
> allow for a shorter check in the common single-value case.
>
> Of course, the calling convention can be chosen independently for each
> instruction set architecture / ABI.
>
> What do you think?

I think it's definitely worth exploring.  I would be OK with it, and
receiving results in registers would be good.

In the context of what we do with the bytecode (as opposed to calling
convention optimizations that we will do with native code), WDYT about
the bytecode calling convention I outlined above?

Cheers,

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2012-08-03  8:24 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
2012-08-03  8:06   ` Andy Wingo
2012-08-03  2:29 ` Mark H Weaver
2012-08-03  8:24   ` Andy Wingo [this message]
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=87y5lwtmbl.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    /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).