LuaJIT

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
LuaJIT
Original authorMike Pall
Stable release
v2.1.ROLLING[1] / August 21, 2023; 2 years ago (2023-08-21)
Repositorygithub.com/LuaJIT/LuaJIT
Written inC, Lua
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemUnix-like, MacOS, Windows, iOS, Android, PlayStation
    Platformx86, x86-64, PowerPC, ARM, MIPS[2]
    TypeJust-in-time compiler
    LicenseMIT License[3]
    Websiteluajit.org

    LuaJIT is a tracing just-in-time compiler and interpreter for the Lua programming language.

    History

    [edit | edit source]

    The LuaJIT project was started in 2005 by developer Mike Pall, released under the MIT open source license.[4]

    The second major release of the compiler, 2.0.0, featured major performance increases.[5]

    LuaJIT uses rolling releases. Mike Pall, the creator and maintainer recommends using the tip of the v2.1 branch, and does not believe in releases.[6]

    Mike Pall resigned in 2015 making only occasional patching to the future 2.1 version since then.[7]

    Notable users

    [edit | edit source]

    Performance

    [edit | edit source]

    LuaJIT is often the fastest Lua runtime.[13] LuaJIT has also been named the fastest implementation of a dynamic programming language.[14][15]

    LuaJIT includes a Foreign Function Interface compatible with C data structures. Its use is encouraged for numerical computation.[16]

    Tracing

    [edit | edit source]

    LuaJIT is a tracing just-in-time compiler. LuaJIT chooses loops and function calls as trace anchors to begin recording possible hot paths. Function calls will require twice as many invocations to begin recording as a loop. Once LuaJIT begins recording, all control flow, including jumps and calls, are inlined to form a linear trace. All executed bytecode instructions are stored and incrementally converted into LuaJIT's static single-assignment intermediate representation. LuaJIT's trace compiler is often capable of inlining and removing dispatches from object orientation, operators, and type modifications.[17]

    Internal representation

    [edit | edit source]

    LuaJIT uses two types of internal representation. A stack-based bytecode is used for the interpreter, and a static single-assignment form is used for the just-in-time compiler. The interpreter bytecode is frequently patched by the JIT compiler, often to begin executing a compiled trace or to mark a segment of bytecode for causing too many trace aborts.[15]

    -- Loop with if-statement
    
    local x = 0
    
    for i=1,1e4 do
        x = x + 11
        if i%10 == 0 then -- if-statement
            x = x + 22
        end
        x = x + 33
    end
    
    ---- TRACE 1 start Ex.lua:5
    ---- TRACE 1 IR
    0001 int SLOAD #2 CI
    0002 > num SLOAD #1 T
    0003 num ADD 0002 +11
    0004 int MOD 0001 +10
    0005 > int NE 0004 +0
    0006 + num ADD 0003 +33
    0007 + int ADD 0001 +1
    0008 > int LE 0007 +10000
    0009 ------ LOOP ------------
    0010 num ADD 0006 +11
    0011 int MOD 0007 +10
    0012 > int NE 0011 +0
    0013 + num ADD 0010 +33
    0014 + int ADD 0007 +1
    0015 > int LE 0014 +10000
    0016 int PHI 0007 0014
    0017 num PHI 0006 0013
    ---- TRACE 1 stop -> loop
    ---- TRACE 2 start 1/4 Ex.lua:8
    ---- TRACE 2 IR
    0001 num SLOAD #1 PI
    0002 int SLOAD #2 PI
    0003 num ADD 0001 +22
    0004 num ADD 0003 +33
    0005 int ADD 0002 +1
    0006 > int LE 0005 +10000
    0007 num CONV 0005 num.int
    ---- TRACE 2 stop -> 1
    

    Extensions

    [edit | edit source]

    LuaJIT adds several extensions to its base implementation, Lua 5.1, most of which do not break compatibility.[18]

    • "BitOp" for binary operations on unsigned 32-bit integers (these operations are also compiled by the just-in-time compiler)[19]
    • "CoCo", which allows the VM to be fully resumable across all contexts[20]
    • A foreign function interface[21]
    • Portable bytecode (regardless of architecture, word size, or endianness, not version)[22]

    DynASM

    [edit | edit source]
    DynASM
    DeveloperMike Pall
    Repository
    • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Written inLua, C[23]
    Engine
      Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
      Platformx86, X86-64, PowerPC, ARM, MIPS
      TypePreprocessor, Linker
      LicenseMIT License[3]
      Websiteluajit.org/dynasm.html

      DynASM is a lightweight preprocessor for C that provides its own flavor of inline assembler, independent of the C compiler. DynASM replaces assembly code in C files with runtime writes to a 'code buffer', such that a developer may generate and then evoke code at runtime from a C program. It was created for LuaJIT 1.0.0 to make developing the just-in-time compiler easier.[citation needed]

      DynASM includes a bare-bones C header file which is used at compile time for logic the preprocessor generates. The actual preprocessor is written in Lua.

      References

      [edit | edit source]
      1. ^ LuaJIT tags
      2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      3. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      10. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      11. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      12. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      13. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      14. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      15. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      16. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      17. ^ Rottenkolber, Max. "Later Binding: Just-in-Time Compilation of a Younger Dynamic Programming Language." ELS. 2020
      18. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      19. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      20. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      21. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      22. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
      23. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).