Re: Few questions about LuaJIT internals on 64 bit

  • From: "Blaise R." <rex2k8@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 24 Mar 2017 10:51:29 +0100

2017-03-24 0:07 GMT+01:00 Peter Cawley <corsix@xxxxxxxxxx>:

The general pattern is to spend a bunch of time designing the
object/TValue layout, and then write a bunch of assembly code on top
of that design (i.e. the LuaJIT interpreter), and then write a bunch
of C code which generates machine code on top of that design (i.e. the
LuaJIT compiler). Changing the design after the fact is somewhat
difficult, hence LuaJIT having the following three designs in
chronological order:
1. (x86 mode) All pointers are 32 bits wide; TValues for pointer-y
types are 32 bits of pointer and 32 bits of NaN/type tag.
2. (x64 mode) Almost all pointers are 32 bits wide, except for light
userdata, which can be 47 bits wide.
3. (x64 GC64 mode) All pointers are 47 bits wide; TValues for
pointer-y types are 47 bits of pointer and 17 bits of NaN/type tag.

Going from design 1 to design 2 was a large chunk of work, but
substantially less than going from design 1 to design 3 (hence design
3 being a relatively recent thing).


Thank you for your answer. As I said I now know a lot about the PUC-Rio Lua
but nearly nothing concrete about JITing, runtime code generation, proper
assembler programming, etc. which is why obvious decisions like that are
very foreign to me, changing TValue layout in vanilla 5.1 would be much
simpler compared to this.
So there IS an effort to move to 'real 64 bit' (as in - 48 or 47 bit ones)
pointers for GC objects too by changing the TValue layout? Wouldn't that
complicate the 32 vs. 64 bit implementation or will they be synchronized
(I've already seen a few ifdef LJ_64 in the code relating to TValue) so
pointers will always be stored in 64 bit/47 bit fields? Is there anywhere I
can read about these plans and designs? On the official site there is only
http://wiki.luajit.org/New-Garbage-Collector which mentions current
algorithm and new ones for 3.0 but nothing concrete or about layout of
TValue.

Other related posts: