Re: Few questions about LuaJIT internals on 64 bit

  • From: Javier Guerra Giraldez <javier@xxxxxxxxxxx>
  • To: LuaJIT <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 24 Mar 2017 10:37:49 +0000

On 24 March 2017 at 09:51, Blaise R. <rex2k8@xxxxxxxxx> wrote:

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.


There are a several different preprocessor symbols, used heavily
around the code to change things at different levels:

- the processor architecture: intel, ARM, MIPS, etc  Mostly to select
the backend code generator and the interpreter implementation (it's in
hand-written assembly, so a totally different one for each)

- the processor bit width: LJ_64 vs LJ_32.  These affects mostly how
some bit operations are executed.  for example:

#if LJ_64
#define tviszero(o) (((o)->u64 << 1) == 0)
#else
#define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0)
#endif

both cases do the same thing, but the first one can be much slower if
the C compiler is targeting 32-bit code.

- the memory layout of low level structures: LJ_FR2 and LJ_GC64
currently they're either both true or both false; but it's conceivable
some new conditions to separate them.  LJ_FR2 is the "new" frame
structure, that allows for some 64-bit constants to use two frame
slots, while LJ_GC64 is the new 47-bit GC format, with corresponding
new TValue layout.


These (and many others) are defined in lj_arch.h, where you can see
the interdependency between them, and how to pick the exact result by
changing flags in the Makefile

-- 
Javier

Other related posts: