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@gnu.org
Subject: Re: A Working (but Minimal) JIT
Date: Mon, 6 Dec 2010 17:53:25 -0500	[thread overview]
Message-ID: <AANLkTikHkUkaP0ueRzxyQM0W38Q49RHgVj8bMtr4B5fa@mail.gmail.com> (raw)
In-Reply-To: <m3bp4yftdw.fsf@unquote.localdomain>

Hi,

> Regarding whether or not to jit, I'm OK with doing that in the `call'
> instruction.

Sounds good. I'll put it in there. (And also in 'mv-call' and 'tail-call'.)

> But regarding how to call a natively-compiled function -- I think this
> is really, really critical.  It's an important decision that will have
> some far-reaching effects.  I would like for natively-compiled functions
> to get their objcode replaced with a short stub that tail-calls the
> native code -- maybe the stub would consist of just one instruction,
> `native-call' or something.  (Obviously this instruction doesn't exist
> yet).  That instruction would do a tail call in such a way that the vm
> engine is no longer on the stack.
>
> I am concerned about JIT libraries precisely because they tend to impose
> a C calling convention on native code, without allowing for more
> appropriate conventions that allow for tail calls and multiple values on
> the stack.

I see what you mean, but I don't know of a library that fixes that.

The problem I'm having with the current code is that (I think) there
is no portable way to jump from C code to another function (or block
of machine code of any sort) without pushing a frame on the stack. A
normal C function call makes the stack deeper (unless the compiler
optimizes it, which is a GCC thing), and using a goto where the target
isn't fixed at compile time is a GCC extension. And the only other way
for a C program to do a jump is setjmp and longjmp, but I don't see a
way to use those for this.

I think that the best way is to use inline assembly to make the tail
call. But in order to do that portably, we would need a macro that
expanded to different code for GCC, MSVC, and any other compilers that
Guile wanted to support, as well as different code for different
architectures. My idea is to first do it with a trampoline, and then
maybe replace the trampoline with a macro like that.

How does all of this sound?

> Anyway, these are my concerns.  Obviously you're the one hacking the
> code, so do what you like :)

I agree with your concerns. Thanks a lot for showing me how to do this.

Noah



  reply	other threads:[~2010-12-06 22:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-22  4:29 A Working (but Minimal) JIT Noah Lavine
2010-10-22 21:46 ` Phil
2010-10-27 21:17   ` Ludovic Courtès
2010-10-27 21:10 ` Ludovic Courtès
2010-10-27 22:53   ` Noah Lavine
2010-11-02 22:51     ` Ludovic Courtès
2010-11-20 13:37 ` Andy Wingo
2010-11-28 20:56   ` Noah Lavine
2010-11-29 21:25     ` Andy Wingo
2010-12-02  3:58       ` Noah Lavine
2010-12-06 22:06         ` Andy Wingo
2010-12-06 22:53           ` Noah Lavine [this message]
2010-11-28 20:58   ` Noah Lavine
2010-11-28 22:36     ` Ludovic Courtès
2010-11-29  7:18       ` Ken Raeburn

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=AANLkTikHkUkaP0ueRzxyQM0W38Q49RHgVj8bMtr4B5fa@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).