From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: A vm for native code in guile
Date: Mon, 2 Jul 2012 09:53:43 +0200 [thread overview]
Message-ID: <CAGua6m2iG9F=Gy5E_ipF0UXRC95SVF3_bHih1K8uqowRQZnf9A@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2221 bytes --]
Hi,
As Noha said, it's not that difficult to hook native code in. But to have
something maintainable
and bug less will be a challenge. To mitigate this having all code in
scheme could be wise.
Anyway I can now compile simple functions to native sequences of machine
code but with some
tools around it so let me explain the setup.
The idea is that To have a set of registers that is not touched, the
registers are
vm - points to a table with vm specific datastructures like free
variables etc.
jmp - a pointer to a jump table
rbx - neeeded to be maintained because of C conventions.
The sellected registers will not be changed during a C call and is
therefore not needed to be stored when calling out
to C (for x86-64, for x86 you do not have this possibility)
The vm contains at the moment,
vm-rbx
vm-r12 |
vm-r14 | Stored registers according to the C convention
vm-clo | free variable table
vm-obj | object table
vm-c | C - function table
ret | A return adress
The generated instruction could feature
1. Pure machine instructions for fastpaths.
2. The option to jump to a vm instruction like a named goto. Then ret needs
to contain a return adress
3. The option to call a C function using the function table
So the idea here is to keep some of the vm:ness of the setup in order to
keep code complexity low.
Also rsp ands tbp are used to match sp and fp in the guile-2.0 VM.
The general impression after looking at about 142 instructions are that the
bytevectors will be typical 10x
larger then the VM bytevectors e.g. there is a good compression ratio by
using the VM ops. On the other hand
we do save space by not inlining everything.
Anyway this is indeed a fun exercise and I see it as a testbed for
implementation strategies and as a fun testbed
for assemblers in guile. The examples that can be run does not include
looping (yet) so it's really not that useful but
in a matter of a week I would expect that some loop benchmarks can be done.
An example currently look like,
(use-modules (native vm init))
(use-modules (native vm jit))
(define (f) (vector 1 2 3 4 5 6))
(jit f)
(f)
execute native
execute native/finish
$2 = #(1 2 3 4 5 6)
/stefan
[-- Attachment #2: Type: text/html, Size: 2444 bytes --]
next reply other threads:[~2012-07-02 7:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-02 7:53 Stefan Israelsson Tampe [this message]
2012-07-02 22:16 ` A vm for native code in guile Andy Wingo
2012-07-03 14:24 ` Stefan Israelsson Tampe
2012-07-07 20:12 ` Stefan Israelsson Tampe
2012-08-01 20:59 ` Stefan Israelsson Tampe
2013-01-14 2:51 ` Nala Ginrut
[not found] ` <CAGua6m0x-W4kdWCSoonjn-+xY=RvSjvniN=wQH53h+MzEQPpbw@mail.gmail.com>
2013-01-14 9:10 ` Nala Ginrut
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='CAGua6m2iG9F=Gy5E_ipF0UXRC95SVF3_bHih1K8uqowRQZnf9A@mail.gmail.com' \
--to=stefan.itampe@gmail.com \
--cc=guile-devel@gnu.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).