unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Burton Samograd <burton.samograd@autodesk.com>
To: Daniel Colascione <dancol@dancol.org>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Emacs Lisp JIT Compiler
Date: Mon, 5 Dec 2016 21:03:52 +0000	[thread overview]
Message-ID: <460FFFB2-04B6-4037-8282-5FCCBC2F4168@autodesk.com> (raw)
In-Reply-To: <3ca57bfc-72db-65ee-b7c4-4bf75a64c495@dancol.org>

[-- Attachment #1: Type: text/plain, Size: 3249 bytes --]


On Dec 5, 2016, at 12:32 PM, Daniel Colascione <dancol@dancol.org<mailto:dancol@dancol.org>> wrote:

Thanks for doing this work.

On 12/05/2016 10:16 AM, Burton Samograd wrote:
Hello,

I’ve published my Emacs Lisp JIT compiler for comments and review:

   https://github.com/burtonsamograd/emacs-jit

The JIT compiler implements a strategy of turning the byte code
execution loop into a series of function calls, moving the overhead of
the loop into the CPU execution unit.  I call this ‘compiling down the
spine’ of the byte code vector.  No other changes have been done to the
byte code instructions other than to map them to the new execution strategy.

This is work in progress and about ~90% complete and was done about 4
years ago, so it’s quite a bit off of HEAD right now.  It ‘works’ to the
point of being able to JIT compile and run my included ray-tracer with a
25% speed improvement.  Enabling full JIT during compilation shows bugs
and will fail; I haven’t been able to track down the cause of these
failures yet.

Let's benchmark it after making sure it's correct.

Understandable.


By default, this build will provide the Lisp function 'jit-compile’
which takes a lambda expression or a symbol.

A new byte code instruction has been added Bjitcall.  When a function is
JIT compiled, it’s code vector is replaced by the single Bjitcall
instruction followed by the JIT compiled code block.

I'm hesitant to call this work a "JIT compiler", since it's not doing any "compilation" --- CFG construction, register allocation, machine-code generation.

Technically, there is compilation into a linear series of function calls to the byte code interpreter code. That part is handled by libjit.  No, I didn’t write the entire JIT compiler that it uses, but it does compile the interpreter loop into a more efficient dispatch structure, giving the speed improvemet.  It’s a simple technique and easy to see where the improvement comes from, but yes, this implementation does cause maintenance problems by duplicating the code from the original interpreter loop.


we're still executing the same bits of the interpreter code ---- just reaching them more efficiency. (It's a step in that direction though.) Since each function pointer (four or eight bytes) is much larger than the corresponding bytecode instruction, for cache efficiency reasons, I'd apply this optimization only to hot functions.

That’s the intention with the stub jit_hotspot_compile, but of course, getting this correct is obviously more important first.

Four years ago, GCC's JIT API was unavailable. I suggest taking a close look at it. It will deliver far greater speedups to computation than the techniques in this work can, and it's much lower-maintenance to boot.

I didn’t realize GCC had a JIT API now.  Is that also linked in


BTW: we don't use C99 dynamic arrays in Emacs.

Noted, thanks.

By showing this ida/work I’m hoping not to get it included in emacs proper, but to show a relatively simple way to speed things up.  I’m sure there are better/alternate implementations that would both be cleaner and give better speedups, but this was as far as this POC went so far.


[-- Attachment #2: Type: text/html, Size: 11205 bytes --]

  reply	other threads:[~2016-12-05 21:03 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05 18:16 Emacs Lisp JIT Compiler Burton Samograd
2016-12-05 18:40 ` Eli Zaretskii
2016-12-05 19:32 ` Daniel Colascione
2016-12-05 21:03   ` Burton Samograd [this message]
2016-12-06 15:54     ` Lluís
  -- strict thread matches above, loose matches on Subject: below --
2016-12-11 17:37 Nickolas Lloyd
2016-12-12  6:07 ` John Wiegley
2016-12-12 11:51   ` Nickolas Lloyd
2016-12-12 16:45     ` John Wiegley
2016-12-23 17:22       ` Nickolas Lloyd
2016-12-13 22:24   ` Johan Bockgård
2018-08-13  4:01 Tom Tromey
2018-08-13  5:37 ` Paul Eggert
2018-08-13 15:15   ` Tom Tromey
2018-08-14  0:16   ` Tom Tromey
2018-08-14 20:11     ` Daniel Colascione
2018-08-14 20:55       ` Paul Eggert
2018-08-14 21:03         ` Daniel Colascione
2018-08-14 22:38           ` Paul Eggert
2018-08-15 16:41             ` Eli Zaretskii
2018-08-15 17:16               ` Paul Eggert
2018-08-15 17:47                 ` Eli Zaretskii
2018-08-16  0:29               ` Tom Tromey
2018-08-16 13:26                 ` Eli Zaretskii
2018-08-16 15:43                   ` Daniel Colascione
2018-08-16 16:22                     ` Andreas Schwab
2018-08-19 18:17                     ` Tom Tromey
2018-08-19 19:00                       ` Eli Zaretskii
2018-08-19 19:16                         ` Tom Tromey
2018-08-19 20:23                       ` Stefan Monnier
2018-08-18 10:10                   ` Steinar Bang
2018-08-18 11:31                     ` Eli Zaretskii
2018-08-19 10:00                       ` Robert Pluim
2018-08-19 15:01                         ` Eli Zaretskii
2018-08-19 15:26                   ` Tom Tromey
2018-08-23  0:47                 ` Tom Tromey
2018-08-23 16:48                   ` Eli Zaretskii
2018-08-24 17:54                     ` Tom Tromey
2018-08-24 20:23                       ` Eli Zaretskii
2018-08-24 21:03                         ` Tom Tromey
2018-08-25  6:51                           ` Eli Zaretskii
2018-09-10 11:03                             ` Ergus
2018-09-10 11:15                               ` Robert Pluim
2018-09-10 11:53                                 ` Tom Tromey
2018-09-12 13:37                                   ` Robert Pluim
2018-09-13  4:32                                     ` Tom Tromey
2018-08-16  0:03   ` Tom Tromey
2018-08-16  2:45     ` Eli Zaretskii
2018-08-16 18:07       ` Eli Zaretskii
2018-08-13 13:50 ` T.V Raman
2018-08-13 15:18   ` Tom Tromey
2018-08-13 15:23     ` T.V Raman
2018-08-13 15:15 ` Eli Zaretskii
2018-08-20 21:54   ` John Wiegley
2018-08-13 23:31 ` Richard Stallman
2018-08-13 23:51   ` Tom Tromey
2018-08-16  2:42     ` Richard Stallman
2018-08-15  0:21 ` Clément Pit-Claudel
2018-08-16  0:32   ` Tom Tromey
2018-08-16  2:14     ` Clément Pit-Claudel

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/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=460FFFB2-04B6-4037-8282-5FCCBC2F4168@autodesk.com \
    --to=burton.samograd@autodesk.com \
    --cc=dancol@dancol.org \
    --cc=emacs-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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).