diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-11-02 04:13:09 +0300 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-11-02 04:13:09 +0300 |
commit | 16e69f9fde6599d85060670acb68a3814159dcf2 (patch) | |
tree | c998f62a128348749e485cb8e42ddfc0a23bdd56 | |
parent | 386f490f2288db64d9fa486c9ea9b18893cdd297 (diff) | |
parent | b393759a80d17853a26f6cd4eb451709745badd9 (diff) |
Merge commit 'b393759a80d17853a26f6cd4eb451709745badd9'
48 files changed, 395 insertions, 138 deletions
diff --git a/luajit/Makefile b/luajit/Makefile index 900b43b..b23b648 100644 --- a/luajit/Makefile +++ b/luajit/Makefile @@ -15,7 +15,7 @@ MAJVER= 2 MINVER= 0 -RELVER= 2 +RELVER= 3 VERSION= $(MAJVER).$(MINVER).$(RELVER) ABIVER= 5.1 diff --git a/luajit/README b/luajit/README index b9351f6..902a6d2 100644 --- a/luajit/README +++ b/luajit/README @@ -1,4 +1,4 @@ -README for LuaJIT 2.0.2 +README for LuaJIT 2.0.3 ----------------------- LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. diff --git a/luajit/doc/changes.html b/luajit/doc/changes.html index f58cde8..9841229 100644 --- a/luajit/doc/changes.html +++ b/luajit/doc/changes.html @@ -63,7 +63,7 @@ div.major { max-width: 600px; padding: 1em; margin: 1em 0 1em 0; } <div id="main"> <p> This is a list of changes between the released versions of LuaJIT.<br> -The current <span style="color: #0000c0;">stable version</span> is <strong>LuaJIT 2.0.2</strong>.<br> +The current <span style="color: #0000c0;">stable version</span> is <strong>LuaJIT 2.0.3</strong>.<br> </p> <p> Please check the @@ -72,6 +72,42 @@ to see whether newer versions are available. </p> <div class="major" style="background: #d0d0ff;"> +<h2 id="LuaJIT-2.0.3">LuaJIT 2.0.3 — 2014-03-12</h2> +<ul> +<li>Add PS4 port.</li> +<li>Add support for multilib distro builds.</li> +<li>Fix OSX build.</li> +<li>Fix MinGW build.</li> +<li>Fix Xbox 360 build.</li> +<li>Improve ULOAD forwarding for open upvalues.</li> +<li>Fix GC steps threshold handling when called by JIT-compiled code.</li> +<li>Fix argument checks for <tt>math.deg()</tt> and <tt>math.rad()</tt>.</li> +<li>Fix <tt>jit.flush(func|true)</tt>.</li> +<li>Respect <tt>jit.off(func)</tt> when returning to a function, too.</li> +<li>Fix compilation of <tt>string.byte(s, nil, n)</tt>.</li> +<li>Fix line number for relocated bytecode after closure fixup</li> +<li>Fix frame traversal for backtraces.</li> +<li>Fix ABC elimination.</li> +<li>Fix handling of redundant PHIs.</li> +<li>Fix snapshot restore for exit to function header.</li> +<li>Fix type punning alias analysis for constified pointers</li> +<li>Fix call unroll checks in the presence of metamethod frames.</li> +<li>Fix initial maxslot for down-recursive traces.</li> +<li>Prevent BASE register coalescing if parent uses <tt>IR_RETF</tt>.</li> +<li>Don't purge modified function from stack slots in <tt>BC_RET</tt>.</li> +<li>Fix recording of <tt>BC_VARG</tt>.</li> +<li>Don't access dangling reference to reallocated IR.</li> +<li>Fix frame depth display for bytecode dump in <tt>-jdump</tt>.</li> +<li>ARM: Fix register allocation when rematerializing FPRs.</li> +<li>x64: Fix store to upvalue for lightuserdata values.</li> +<li>FFI: Add missing GC steps for callback argument conversions.</li> +<li>FFI: Properly unload loaded DLLs.</li> +<li>FFI: Fix argument checks for <tt>ffi.string()</tt>.</li> +<li>FFI/x64: Fix passing of vector arguments to calls.</li> +<li>FFI: Rehash finalizer table after GC cycle, if needed.</li> +<li>FFI: Fix <tt>cts->L</tt> for cdata unsinking in snapshot restore.</li> +</ul> + <h2 id="LuaJIT-2.0.2">LuaJIT 2.0.2 — 2013-06-03</h2> <ul> <li>Fix memory access check for fast string interning.</li> diff --git a/luajit/doc/ext_ffi_tutorial.html b/luajit/doc/ext_ffi_tutorial.html index 01fb899..8e4eaf7 100644 --- a/luajit/doc/ext_ffi_tutorial.html +++ b/luajit/doc/ext_ffi_tutorial.html @@ -564,7 +564,7 @@ Thus it's not helpful and actually counter-productive to cache individual C functions like this: </p> <pre class="code"> -local <b>funca</b>, <b>funcb</b> = ffi.C.funcb, ffi.C.funcb -- <span style="color:#c00000;">Not helpful!</span> +local <b>funca</b>, <b>funcb</b> = ffi.C.funca, ffi.C.funcb -- <span style="color:#c00000;">Not helpful!</span> local function foo(x, n) for i=1,n do <b>funcb</b>(<b>funca</b>(x, i), 1) end end diff --git a/luajit/doc/install.html b/luajit/doc/install.html index baf1469..f816315 100644 --- a/luajit/doc/install.html +++ b/luajit/doc/install.html @@ -127,7 +127,7 @@ operating systems, CPUs and compilers: <tr class="odd"> <td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td> <td class="compatos">GCC 4.2+</td> -<td class="compatos">GCC 4.2+</td> +<td class="compatos">GCC 4.2+<br>PSP2 (<a href="#psvita">PS VITA</a>)</td> <td class="compatos">GCC 4.2+</td> <td class="compatos compatno"> </td> </tr> @@ -188,8 +188,8 @@ open a terminal window and change to this directory. Now unpack the archive and change to the newly created directory: </p> <pre class="code"> -tar zxf LuaJIT-2.0.2.tar.gz -cd LuaJIT-2.0.2</pre> +tar zxf LuaJIT-2.0.3.tar.gz +cd LuaJIT-2.0.3</pre> <h3>Building LuaJIT</h3> <p> The supplied Makefiles try to auto-detect the settings needed for your @@ -458,41 +458,56 @@ ISDKF="-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER" make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \ TARGET_SYS=iOS </pre> + +<h3 id="consoles">Cross-compiling for consoles</h3> <p> -You can cross-compile for <b id="ps3">PS3</b> using the PS3 SDK from -a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host, -too). Due to restrictions on consoles, the JIT compiler is disabled and -only the fast interpreter is built: +Building LuaJIT for consoles requires both a supported host compiler +(x86 or x64) and a cross-compiler (to PPC or ARM) from the official +console SDK. </p> -<pre class="code"> -make HOST_CC="gcc -m32" CROSS=ppu-lv2- -</pre> <p> -You can cross-compile for <b id="ps4">PS4</b> from a Windows host using -the PS4 SDK (ORBIS) plus 64 bit MSVC. Due to restrictions on -consoles, the JIT compiler is disabled and only the fast interpreter -is built. +Due to restrictions on consoles, the JIT compiler is disabled and only +the fast interpreter is built. This is still faster than plain Lua, +but much slower than the JIT compiler. The FFI is disabled, too, since +it's not very useful in such an environment. </p> <p> -Open a "Visual Studio .NET Command Prompt" (64 bit host compiler), -<tt>cd</tt> to the directory where you've unpacked the sources and run -the following commands. This builds a static library <tt>libluajit.a</tt>, +The following commands build a static library <tt>libluajit.a</tt>, which can be linked against your game, just like the Lua library. </p> +<p> +To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires +32 bit GCC, i.e. multilib Linux/x64) or a Windows host (requires +32 bit MinGW), run this command: +</p> +<pre class="code"> +make HOST_CC="gcc -m32" CROSS=ppu-lv2- +</pre> +<p> +To cross-compile for <b id="ps4">PS4</b> from a Windows host, +open a "Visual Studio .NET Command Prompt" (64 bit host compiler), +<tt>cd</tt> to the directory where you've unpacked the sources and +run the following commands: +</p> <pre class="code"> cd src ps4build </pre> <p> -You can cross-compile for <b id="xbox360">Xbox 360</b> using the -Xbox 360 SDK (MSVC + XEDK). Due to restrictions on consoles, the -JIT compiler is disabled and only the fast interpreter is built. +To cross-compile for <b id="psvita">PS Vita</b> from a Windows host, +open a "Visual Studio .NET Command Prompt" (32 bit host compiler), +<tt>cd</tt> to the directory where you've unpacked the sources and +run the following commands: </p> +<pre class="code"> +cd src +psvitabuild +</pre> <p> -Open a "Visual Studio .NET Command Prompt" (32 bit host compiler), +To cross-compile for <b id="xbox360">Xbox 360</b> from a Windows host, +open a "Visual Studio .NET Command Prompt" (32 bit host compiler), <tt>cd</tt> to the directory where you've unpacked the sources and run -the following commands. This builds a static library <tt>luajit20.lib</tt>, -which can be linked against your game, just like the Lua library. +the following commands: </p> <pre class="code"> cd src diff --git a/luajit/doc/luajit.html b/luajit/doc/luajit.html index 43af69c..ddbc016 100644 --- a/luajit/doc/luajit.html +++ b/luajit/doc/luajit.html @@ -38,6 +38,9 @@ table.os1 td { table.os2 td { color: #ffa040; } +table.os3 td { + color: #40ffff; +} table.compiler td { color: #2080ff; background: #62bf41; @@ -158,7 +161,10 @@ LuaJIT is Copyright © 2005-2014 Mike Pall, released under the <tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr> </table> <table class="feature os os2"> -<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td><td>PS4</td><td>Xbox 360</td></tr> +<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr> +</table> +<table class="feature os os3"> +<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td></tr> </table> <table class="feature compiler"> <tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr> diff --git a/luajit/doc/running.html b/luajit/doc/running.html index bbbe8be..c01c52d 100644 --- a/luajit/doc/running.html +++ b/luajit/doc/running.html @@ -186,7 +186,7 @@ itself. For a description of their options and output format, please read the comment block at the start of their source. They can be found in the <tt>lib</tt> directory of the source distribution or installed under the <tt>jit</tt> directory. By default -this is <tt>/usr/local/share/luajit-2.0.2/jit</tt> on POSIX +this is <tt>/usr/local/share/luajit-2.0.3/jit</tt> on POSIX systems. </p> diff --git a/luajit/dynasm/dasm_x86.lua b/luajit/dynasm/dasm_x86.lua index f3859e3..5f82f4f 100644 --- a/luajit/dynasm/dasm_x86.lua +++ b/luajit/dynasm/dasm_x86.lua @@ -1081,6 +1081,9 @@ local map_op = { btr_2 = "mrqdw:0FB3Rm|miqdw:0FBA6mU", bts_2 = "mrqdw:0FABRm|miqdw:0FBA5mU", + shld_3 = "mriqdw:0FA4RmU|mrCqdw:0FA5Rm", + shrd_3 = "mriqdw:0FACRmU|mrCqdw:0FADRm", + rdtsc_0 = "0F31", -- P1+ cpuid_0 = "0FA2", -- P1+ @@ -1114,6 +1117,9 @@ local map_op = { fucompp_0 = "DAE9", fcompp_0 = "DED9", + fldenv_1 = "x.:D94m", + fnstenv_1 = "x.:D96m", + fstenv_1 = "x.:9BD96m", fldcw_1 = "xw:nD95m", fstcw_1 = "xw:n9BD97m", fnstcw_1 = "xw:nD97m", @@ -1189,6 +1195,8 @@ local map_op = { cvttps2dq_2 = "rmo:F30F5BrM", cvttsd2si_2 = "rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:", cvttss2si_2 = "rr/do:F30F2CrM|rr/qo:|rxd:|rx/qd:", + fxsave_1 = "x.:0FAE0m", + fxrstor_1 = "x.:0FAE1m", ldmxcsr_1 = "xd:0FAE2m", lfence_0 = "0FAEE8", maskmovdqu_2 = "rro:660FF7rM", diff --git a/luajit/etc/luajit.pc b/luajit/etc/luajit.pc index 4823396..d3f0cf3 100644 --- a/luajit/etc/luajit.pc +++ b/luajit/etc/luajit.pc @@ -1,7 +1,7 @@ # Package information for LuaJIT to be used by pkg-config. majver=2 minver=0 -relver=2 +relver=3 version=${majver}.${minver}.${relver} abiver=5.1 diff --git a/luajit/src/Makefile b/luajit/src/Makefile index 72bc912..c558003 100644 --- a/luajit/src/Makefile +++ b/luajit/src/Makefile @@ -12,7 +12,7 @@ MAJVER= 2 MINVER= 0 -RELVER= 2 +RELVER= 3 ABIVER= 5.1 NODOTABIVER= 51 @@ -122,8 +122,10 @@ XCFLAGS= # # Use the system provided memory allocator (realloc) instead of the # bundled memory allocator. This is slower, but sometimes helpful for -# debugging. It's helpful for Valgrind's memcheck tool, too. This option -# cannot be enabled on x64, since the built-in allocator is mandatory. +# debugging. This option cannot be enabled on x64, since realloc usually +# doesn't return addresses in the right address range. +# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and +# the only way to get useful results from it for all other architectures. #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC # # This define is required to run LuaJIT under Valgrind. The Valgrind diff --git a/luajit/src/Makefile.dep b/luajit/src/Makefile.dep index 8ca3315..9e14d61 100644 --- a/luajit/src/Makefile.dep +++ b/luajit/src/Makefile.dep @@ -90,7 +90,7 @@ lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_state.h lj_frame.h \ - lj_bc.h lj_jit.h lj_ir.h + lj_bc.h lj_vm.h lj_jit.h lj_ir.h lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_err.h lj_errmsg.h lj_func.h lj_str.h lj_tab.h lj_meta.h lj_debug.h \ lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h lj_jit.h lj_ir.h \ diff --git a/luajit/src/host/buildvm_asm.c b/luajit/src/host/buildvm_asm.c index 9b28b3b..079e9a8 100644 --- a/luajit/src/host/buildvm_asm.c +++ b/luajit/src/host/buildvm_asm.c @@ -286,7 +286,7 @@ void emit_asm(BuildCtx *ctx) fprintf(ctx->fp, "\n"); switch (ctx->mode) { case BUILD_elfasm: -#if !LJ_TARGET_PS3 +#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA) fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n"); #endif #if LJ_TARGET_PPCSPE diff --git a/luajit/src/jit/bc.lua b/luajit/src/jit/bc.lua index 9192cb9..9df19c7 100644 --- a/luajit/src/jit/bc.lua +++ b/luajit/src/jit/bc.lua @@ -41,7 +41,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20002, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") local jutil = require("jit.util") local vmdef = require("jit.vmdef") local bit = require("bit") diff --git a/luajit/src/jit/bcsave.lua b/luajit/src/jit/bcsave.lua index 13b79db..122bb24 100644 --- a/luajit/src/jit/bcsave.lua +++ b/luajit/src/jit/bcsave.lua @@ -11,7 +11,7 @@ ------------------------------------------------------------------------------ local jit = require("jit") -assert(jit.version_num == 20002, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") local bit = require("bit") -- Symbol name prefix for LuaJIT bytecode. @@ -69,7 +69,7 @@ local map_arch = { local map_os = { linux = true, windows = true, osx = true, freebsd = true, netbsd = true, - openbsd = true, solaris = true, + openbsd = true, dragonfly = true, solaris = true, } local function checkarg(str, map, err) diff --git a/luajit/src/jit/dump.lua b/luajit/src/jit/dump.lua index 6a77f92..556ce88 100644 --- a/luajit/src/jit/dump.lua +++ b/luajit/src/jit/dump.lua @@ -55,7 +55,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20002, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") local jutil = require("jit.util") local vmdef = require("jit.vmdef") local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc diff --git a/luajit/src/jit/v.lua b/luajit/src/jit/v.lua index b9e0eb5..197e67c 100644 --- a/luajit/src/jit/v.lua +++ b/luajit/src/jit/v.lua @@ -59,7 +59,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20002, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") local jutil = require("jit.util") local vmdef = require("jit.vmdef") local funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo diff --git a/luajit/src/lib_aux.c b/luajit/src/lib_aux.c index 1b01fe0..e88dc7c 100644 --- a/luajit/src/lib_aux.c +++ b/luajit/src/lib_aux.c @@ -302,7 +302,7 @@ static int panic(lua_State *L) #ifdef LUAJIT_USE_SYSMALLOC -#if LJ_64 +#if LJ_64 && !defined(LUAJIT_USE_VALGRIND) #error "Must use builtin allocator for 64 bit target" #endif diff --git a/luajit/src/lib_ffi.c b/luajit/src/lib_ffi.c index e789ad6..2549678 100644 --- a/luajit/src/lib_ffi.c +++ b/luajit/src/lib_ffi.c @@ -136,6 +136,7 @@ static int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm) return 0; } } + copyTV(L, base, L->top); tv = L->top-1; } return lj_meta_tailcall(L, tv); diff --git a/luajit/src/lib_io.c b/luajit/src/lib_io.c index 04f0f73..90f310b 100644 --- a/luajit/src/lib_io.c +++ b/luajit/src/lib_io.c @@ -426,7 +426,7 @@ LJLIB_CF(io_popen) LJLIB_CF(io_tmpfile) { IOFileUD *iof = io_file_new(L); -#if LJ_TARGET_PS3 || LJ_TARGET_PS4 +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA iof->fp = NULL; errno = ENOSYS; #else iof->fp = tmpfile(); diff --git a/luajit/src/lib_os.c b/luajit/src/lib_os.c index f62e8c8..713ec93 100644 --- a/luajit/src/lib_os.c +++ b/luajit/src/lib_os.c @@ -7,7 +7,6 @@ */ #include <errno.h> -#include <locale.h> #include <time.h> #define lib_os_c @@ -27,6 +26,10 @@ #include <stdio.h> #endif +#if !LJ_TARGET_PSVITA +#include <locale.h> +#endif + /* ------------------------------------------------------------------------ */ #define LJLIB_MODULE_os @@ -70,7 +73,7 @@ LJLIB_CF(os_rename) LJLIB_CF(os_tmpname) { -#if LJ_TARGET_PS3 || LJ_TARGET_PS4 +#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA lj_err_caller(L, LJ_ERR_OSUNIQF); return 0; #else @@ -254,6 +257,9 @@ LJLIB_CF(os_difftime) LJLIB_CF(os_setlocale) { +#if LJ_TARGET_PSVITA + lua_pushliteral(L, "C"); +#else GCstr *s = lj_lib_optstr(L, 1); const char *str = s ? strdata(s) : NULL; int opt = lj_lib_checkopt(L, 2, 6, @@ -265,6 +271,7 @@ LJLIB_CF(os_setlocale) else if (opt == 4) opt = LC_MONETARY; else if (opt == 6) opt = LC_ALL; lua_pushstring(L, setlocale(opt, str)); +#endif return 1; } diff --git a/luajit/src/lj_alloc.c b/luajit/src/lj_alloc.c index f856a7a..7c7ec67 100644 --- a/luajit/src/lj_alloc.c +++ b/luajit/src/lj_alloc.c @@ -179,23 +179,29 @@ static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size) #if defined(MAP_32BIT) +#if defined(__sun__) +#define MMAP_REGION_START ((uintptr_t)0x1000) +#else /* Actually this only gives us max. 1GB in current Linux kernels. */ +#define MMAP_REGION_START ((uintptr_t)0) +#endif + static LJ_AINLINE void *CALL_MMAP(size_t size) { int olderr = errno; - void *ptr = mmap(NULL, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0); + void *ptr = mmap((void *)MMAP_REGION_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0); errno = olderr; return ptr; } -#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) +#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) /* OSX and FreeBSD mmap() use a naive first-fit linear search. ** That's perfect for us. Except that -pagezero_size must be set for OSX, ** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs ** to be reduced to 250MB on FreeBSD. */ -#if LJ_TARGET_OSX +#if LJ_TARGET_OSX || defined(__DragonFly__) #define MMAP_REGION_START ((uintptr_t)0x10000) #elif LJ_TARGET_PS4 #define MMAP_REGION_START ((uintptr_t)0x4000) @@ -232,7 +238,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) return p; } if (p != CMFAIL) munmap(p, size); -#ifdef __sun__ +#if defined(__sun__) || defined(__DragonFly__) alloc_hint += 0x1000000; /* Need near-exhaustive linear scan. */ if (alloc_hint + size < MMAP_REGION_END) continue; #endif diff --git a/luajit/src/lj_arch.h b/luajit/src/lj_arch.h index 0196eed..f1c6e5e 100644 --- a/luajit/src/lj_arch.h +++ b/luajit/src/lj_arch.h @@ -67,7 +67,8 @@ #elif defined(__MACH__) && defined(__APPLE__) #define LUAJIT_OS LUAJIT_OS_OSX #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__) + defined(__NetBSD__) || defined(__OpenBSD__) || \ + defined(__DragonFly__)) && !defined(__ORBIS__) #define LUAJIT_OS LUAJIT_OS_BSD #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__) #define LUAJIT_OS LUAJIT_OS_POSIX @@ -111,6 +112,11 @@ #define NULL ((void*)0) #endif +#ifdef __psp2__ +#define LJ_TARGET_PSVITA 1 +#define LJ_TARGET_CONSOLE 1 +#endif + #if _XBOX_VER >= 200 #define LJ_TARGET_XBOX360 1 #define LJ_TARGET_CONSOLE 1 diff --git a/luajit/src/lj_asm.c b/luajit/src/lj_asm.c index 264649a..2afa92d 100644 --- a/luajit/src/lj_asm.c +++ b/luajit/src/lj_asm.c @@ -353,6 +353,7 @@ static Reg ra_rematk(ASMState *as, IRRef ref) static int32_t ra_spill(ASMState *as, IRIns *ir) { int32_t slot = ir->s; + lua_assert(ir >= as->ir + REF_TRUE); if (!ra_hasspill(slot)) { if (irt_is64(ir->t)) { slot = as->evenspill; diff --git a/luajit/src/lj_asm_ppc.h b/luajit/src/lj_asm_ppc.h index e1a496a..0a3d35e 100644 --- a/luajit/src/lj_asm_ppc.h +++ b/luajit/src/lj_asm_ppc.h @@ -49,6 +49,8 @@ static void asm_exitstub_setup(ASMState *as, ExitNo nexits) { ExitNo i; MCode *mxp = as->mctop; + if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim) + asm_mclimit(as); /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */ for (i = nexits-1; (int32_t)i >= 0; i--) *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2); diff --git a/luajit/src/lj_asm_x86.h b/luajit/src/lj_asm_x86.h index fda911e..04b7964 100644 --- a/luajit/src/lj_asm_x86.h +++ b/luajit/src/lj_asm_x86.h @@ -325,6 +325,14 @@ static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow) as->mrm.base = as->mrm.idx = RID_NONE; return RID_MRM; } + } else if (ir->o == IR_KINT64) { + RegSet avail = as->freeset & ~as->modset & RSET_GPR; + lua_assert(allow != RSET_EMPTY); + if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */ + as->mrm.ofs = ptr2addr(ir_kint64(ir)); + as->mrm.base = as->mrm.idx = RID_NONE; + return RID_MRM; + } } else if (mayfuse(as, ref)) { RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR; if (ir->o == IR_SLOAD) { @@ -361,7 +369,7 @@ static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow) return RID_MRM; } } - if (!(as->freeset & allow) && + if (!(as->freeset & allow) && !irref_isk(ref) && (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref))) goto fusespill; return ra_allocref(as, ref, allow); @@ -571,7 +579,7 @@ static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) lua_assert(!irt_ispri(ir->t)); ra_destreg(as, ir, RID_RET); } - } else if (LJ_32 && irt_isfp(ir->t)) { + } else if (LJ_32 && irt_isfp(ir->t) && !(ci->flags & CCI_CASTU64)) { emit_x87op(as, XI_FPOP); /* Pop unused result from x87 st0. */ } } diff --git a/luajit/src/lj_carith.c b/luajit/src/lj_carith.c index 9f94091..9a451b2 100644 --- a/luajit/src/lj_carith.c +++ b/luajit/src/lj_carith.c @@ -62,7 +62,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) TValue *o2 = i == 0 ? o+1 : o-1; CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid); ca->ct[i] = NULL; - ca->p[i] = NULL; + ca->p[i] = (uint8_t *)strVdata(o); ok = 0; if (ctype_isenum(ct->info)) { CTSize ofs; @@ -79,7 +79,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) } } else { ca->ct[i] = NULL; - ca->p[i] = NULL; + ca->p[i] = (void *)(intptr_t)1; /* To make it unequal. */ ok = 0; } } @@ -234,7 +234,9 @@ static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm) const char *repr[2]; int i, isenum = -1, isstr = -1; if (mm == MM_eq) { /* Equality checks never raise an error. */ - setboolV(L->top-1, 0); + int eq = ca->p[0] == ca->p[1]; + setboolV(L->top-1, eq); + setboolV(&G(L)->tmptv2, eq); /* Remember for trace recorder. */ return 1; } for (i = 0; i < 2; i++) { diff --git a/luajit/src/lj_cconv.c b/luajit/src/lj_cconv.c index de4938e..90cd36e 100644 --- a/luajit/src/lj_cconv.c +++ b/luajit/src/lj_cconv.c @@ -702,6 +702,7 @@ static void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp, } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) { cconv_substruct_init(cts, ctype_rawchild(cts, df), dp+df->size, o, len, ip); + if ((d->info & CTF_UNION)) break; } /* Ignore all other entries in the chain. */ } } diff --git a/luajit/src/lj_crecord.c b/luajit/src/lj_crecord.c index da9013f..fe08b93 100644 --- a/luajit/src/lj_crecord.c +++ b/luajit/src/lj_crecord.c @@ -794,7 +794,7 @@ again: } } else if (tref_isstr(idx)) { GCstr *name = strV(&rd->argv[1]); - if (cd->ctypeid == CTID_CTYPEID) + if (cd && cd->ctypeid == CTID_CTYPEID) ct = ctype_raw(cts, crec_constructor(J, cd, ptr)); if (ctype_isstruct(ct->info)) { CTSize fofs; @@ -835,6 +835,7 @@ again: CType *cct = ctype_rawchild(cts, ct); if (ctype_isstruct(cct->info)) { ct = cct; + cd = NULL; if (tref_isstr(idx)) goto again; } } @@ -847,8 +848,11 @@ again: /* Resolve reference for field. */ ct = ctype_get(cts, sid); - if (ctype_isref(ct->info)) + if (ctype_isref(ct->info)) { ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0); + sid = ctype_cid(ct->info); + ct = ctype_get(cts, sid); + } while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct); /* Skip attributes. */ @@ -1317,7 +1321,8 @@ static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm) } /* Record ctype arithmetic metamethods. */ -static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd) +static TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts, + RecordFFData *rd) { cTValue *tv = NULL; if (J->base[0]) { @@ -1338,13 +1343,20 @@ static void crec_arith_meta(jit_State *J, CTState *cts, RecordFFData *rd) if (tvisfunc(tv)) { J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME; rd->nres = -1; /* Pending tailcall. */ - return; + return 0; } /* NYI: non-function metamethods. */ - } else if ((MMS)rd->data == MM_eq) { - J->base[0] = TREF_FALSE; - return; + } else if ((MMS)rd->data == MM_eq) { /* Fallback cdata pointer comparison. */ + if (sp[0] && sp[1] && ctype_isnum(s[0]->info) == ctype_isnum(s[1]->info)) { + /* Assume true comparison. Fixup and emit pending guard later. */ + lj_ir_set(J, IRTG(IR_EQ, IRT_PTR), sp[0], sp[1]); + J->postproc = LJ_POST_FIXGUARD; + return TREF_TRUE; + } else { + return TREF_FALSE; + } } lj_trace_err(J, LJ_TRERR_BADTYPE); + return 0; } void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) @@ -1357,7 +1369,7 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) TRef tr = J->base[i]; CType *ct = ctype_get(cts, CTID_DOUBLE); if (!tr) { - goto trymeta; + lj_trace_err(J, LJ_TRERR_BADTYPE); } else if (tref_iscdata(tr)) { CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid; IRType t; @@ -1387,11 +1399,12 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) } if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); if (ctype_isnum(ct->info)) { - if (t == IRT_CDATA) goto trymeta; - if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); - tr = emitir(IRT(IR_XLOAD, t), tr, 0); - } else if (!(ctype_isptr(ct->info) || ctype_isrefarray(ct->info))) { - goto trymeta; + if (t == IRT_CDATA) { + tr = 0; + } else { + if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); + tr = emitir(IRT(IR_XLOAD, t), tr, 0); + } } } else if (tref_isnil(tr)) { tr = lj_ir_kptr(J, NULL); @@ -1411,10 +1424,17 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str)); ct = ctype_child(cts, cct); tr = lj_ir_kint(J, (int32_t)ofs); - } /* else: interpreter will throw. */ - } /* else: interpreter will throw. */ + } else { /* Interpreter will throw or return false. */ + ct = ctype_get(cts, CTID_P_VOID); + } + } else if (ctype_isptr(ct->info)) { + tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr))); + } else { + ct = ctype_get(cts, CTID_P_VOID); + } } else if (!tref_isnum(tr)) { - goto trymeta; + tr = 0; + ct = ctype_get(cts, CTID_P_VOID); } ok: s[i] = ct; @@ -1422,22 +1442,20 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) } { TRef tr; - if ((tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) || - (tr = crec_arith_ptr(J, sp, s, (MMS)rd->data))) { - J->base[0] = tr; - /* Fixup cdata comparisons, too. Avoids some cdata escapes. */ - if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) && - !irt_isguard(J->guardemit)) { - const BCIns *pc = frame_contpc(J->L->base-1) - 1; - if (bc_op(*pc) <= BC_ISNEP) { - setframe_pc(&J2G(J)->tmptv, pc); - J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1); - J->postproc = LJ_POST_FIXCOMP; - } + if (!(tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) && + !(tr = crec_arith_ptr(J, sp, s, (MMS)rd->data)) && + !(tr = crec_arith_meta(J, sp, s, cts, rd))) + return; + J->base[0] = tr; + /* Fixup cdata comparisons, too. Avoids some cdata escapes. */ + if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) && + !irt_isguard(J->guardemit)) { + const BCIns *pc = frame_contpc(J->L->base-1) - 1; + if (bc_op(*pc) <= BC_ISNEP) { + setframe_pc(&J2G(J)->tmptv, pc); + J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1); + J->postproc = LJ_POST_FIXCOMP; } - } else { - trymeta: - crec_arith_meta(J, cts, rd); } } } diff --git a/luajit/src/lj_debug.c b/luajit/src/lj_debug.c index 4653a4e..e4ab9c1 100644 --- a/luajit/src/lj_debug.c +++ b/luajit/src/lj_debug.c @@ -14,6 +14,7 @@ #include "lj_state.h" #include "lj_frame.h" #include "lj_bc.h" +#include "lj_vm.h" #if LJ_HASJIT #include "lj_jit.h" #endif @@ -86,7 +87,8 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) if (frame_islua(f)) { f = frame_prevl(f); } else { - if (frame_isc(f)) + if (frame_isc(f) || (LJ_HASFFI && frame_iscont(f) && + (f-1)->u32.lo == LJ_CONT_FFI_CALLBACK)) cf = cframe_raw(cframe_prev(cf)); f = frame_prevd(f); } @@ -463,7 +465,7 @@ int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext) lj_debug_shortname(ar->short_src, name); ar->linedefined = (int)firstline; ar->lastlinedefined = (int)(firstline + pt->numline); - ar->what = firstline ? "Lua" : "main"; + ar->what = (firstline || !pt->numline) ? "Lua" : "main"; } else { ar->source = "=[C]"; ar->short_src[0] = '['; diff --git a/luajit/src/lj_def.h b/luajit/src/lj_def.h index 3c43be7..8624aed 100644 --- a/luajit/src/lj_def.h +++ b/luajit/src/lj_def.h @@ -111,7 +111,7 @@ typedef uintptr_t BloomFilter; #define bloomset(b, x) ((b) |= bloombit((x))) #define bloomtest(b, x) ((b) & bloombit((x))) -#if defined(__GNUC__) +#if defined(__GNUC__) || defined(__psp2__) #define LJ_NORET __attribute__((noreturn)) #define LJ_ALIGN(n) __attribute__((aligned(n))) @@ -119,7 +119,7 @@ typedef uintptr_t BloomFilter; #define LJ_AINLINE inline __attribute__((always_inline)) #define LJ_NOINLINE __attribute__((noinline)) -#if defined(__ELF__) || defined(__MACH__) +#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__) #if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__)) #define LJ_NOAPI extern __attribute__((visibility("hidden"))) #endif @@ -150,6 +150,9 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x) #if defined(__arm__) static LJ_AINLINE uint32_t lj_bswap(uint32_t x) { +#if defined(__psp2__) + return __builtin_rev(x); +#else uint32_t r; #if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\ __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ @@ -163,6 +166,7 @@ static LJ_AINLINE uint32_t lj_bswap(uint32_t x) #endif return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8); #endif +#endif } static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) diff --git a/luajit/src/lj_err.c b/luajit/src/lj_err.c index db18267..3097795 100644 --- a/luajit/src/lj_err.c +++ b/luajit/src/lj_err.c @@ -378,7 +378,7 @@ typedef struct UndocumentedDispatcherContext { ULONG64 EstablisherFrame; ULONG64 TargetIp; PCONTEXT ContextRecord; - PEXCEPTION_ROUTINE LanguageHandler; + void (*LanguageHandler)(void); PVOID HandlerData; PUNWIND_HISTORY_TABLE HistoryTable; ULONG ScopeIndex; @@ -518,12 +518,14 @@ static ptrdiff_t finderrfunc(lua_State *L) case FRAME_C: cf = cframe_prev(cf); /* fallthrough */ + case FRAME_VARG: + frame = frame_prevd(frame); + break; case FRAME_CONT: #if LJ_HASFFI if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) cf = cframe_prev(cf); #endif - case FRAME_VARG: frame = frame_prevd(frame); break; case FRAME_CP: diff --git a/luajit/src/lj_gc.c b/luajit/src/lj_gc.c index c2bc397..c856df4 100644 --- a/luajit/src/lj_gc.c +++ b/luajit/src/lj_gc.c @@ -631,6 +631,8 @@ static size_t gc_onestep(lua_State *L) case GCSsweep: { MSize old = g->gc.total; setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { gc_shrink(g, L); if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ @@ -643,8 +645,6 @@ static size_t gc_onestep(lua_State *L) g->gc.debt = 0; } } - lua_assert(old >= g->gc.total); - g->gc.estimate -= old - g->gc.total; return GCSWEEPMAX*GCSWEEPCOST; } case GCSfinalize: diff --git a/luajit/src/lj_gdbjit.c b/luajit/src/lj_gdbjit.c index 5e7fca1..d999986 100644 --- a/luajit/src/lj_gdbjit.c +++ b/luajit/src/lj_gdbjit.c @@ -356,6 +356,8 @@ static const ELFheader elfhdr_template = { .eosabi = 2, #elif defined(__OpenBSD__) .eosabi = 12, +#elif defined(__DragonFly__) + .eosabi = 0, #elif (defined(__sun__) && defined(__svr4__)) .eosabi = 6, #else diff --git a/luajit/src/lj_ircall.h b/luajit/src/lj_ircall.h index af30ba8..92d61df 100644 --- a/luajit/src/lj_ircall.h +++ b/luajit/src/lj_ircall.h @@ -86,6 +86,12 @@ typedef struct CCallInfo { #define IRCALLCOND_FFI32(x) NULL #endif +#if LJ_TARGET_X86 +#define CCI_RANDFPR 0 /* Clang on OSX/x86 is overzealous. */ +#else +#define CCI_RANDFPR CCI_NOFPRCLOBBER +#endif + #if LJ_SOFTFP #define ARG1_FP 2 /* Treat as 2 32 bit arguments. */ #else @@ -112,7 +118,7 @@ typedef struct CCallInfo { _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \ _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \ _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \ - _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \ + _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_RANDFPR)\ _(ANY, lj_vm_modi, 2, FN, INT, 0) \ _(ANY, sinh, ARG1_FP, N, NUM, 0) \ _(ANY, cosh, ARG1_FP, N, NUM, 0) \ diff --git a/luajit/src/lj_jit.h b/luajit/src/lj_jit.h index b69e4f4..ecd79de 100644 --- a/luajit/src/lj_jit.h +++ b/luajit/src/lj_jit.h @@ -279,6 +279,7 @@ typedef struct BPropEntry { /* Scalar evolution analysis cache. */ typedef struct ScEvEntry { + MRef pc; /* Bytecode PC of FORI. */ IRRef1 idx; /* Index reference. */ IRRef1 start; /* Constant start reference. */ IRRef1 stop; /* Constant stop reference. */ diff --git a/luajit/src/lj_opt_dce.c b/luajit/src/lj_opt_dce.c index be80189..fdfe934 100644 --- a/luajit/src/lj_opt_dce.c +++ b/luajit/src/lj_opt_dce.c @@ -69,6 +69,7 @@ void lj_opt_dce(jit_State *J) if ((J->flags & JIT_F_OPT_DCE)) { dce_marksnap(J); dce_propagate(J); + memset(J->bpropcache, 0, sizeof(J->bpropcache)); /* Invalidate cache. */ } } diff --git a/luajit/src/lj_opt_fold.c b/luajit/src/lj_opt_fold.c index 8a5b41c..a15f927 100644 --- a/luajit/src/lj_opt_fold.c +++ b/luajit/src/lj_opt_fold.c @@ -505,13 +505,14 @@ LJFOLDF(kfold_strref_snew) } else { /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */ IRIns *ir = IR(fleft->op1); - IRRef1 str = ir->op1; /* IRIns * is not valid across emitir. */ - lua_assert(ir->o == IR_STRREF); - PHIBARRIER(ir); - fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */ - fins->op1 = str; - fins->ot = IRT(IR_STRREF, IRT_P32); - return RETRYFOLD; + if (ir->o == IR_STRREF) { + IRRef1 str = ir->op1; /* IRIns * is not valid across emitir. */ + PHIBARRIER(ir); + fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */ + fins->op1 = str; + fins->ot = IRT(IR_STRREF, IRT_P32); + return RETRYFOLD; + } } return NEXTFOLD; } @@ -1825,7 +1826,8 @@ LJFOLDF(merge_eqne_snew_kgc) if (len <= FOLD_SNEW_MAX_LEN) { IROp op = (IROp)fins->o; IRRef strref = fleft->op1; - lua_assert(IR(strref)->o == IR_STRREF); + if (IR(strref)->o != IR_STRREF) + return NEXTFOLD; if (op == IR_EQ) { emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len)); /* Caveat: fins/fleft/fright is no longer valid after emitir. */ diff --git a/luajit/src/lj_opt_mem.c b/luajit/src/lj_opt_mem.c index c8cdc3e..d5f5290 100644 --- a/luajit/src/lj_opt_mem.c +++ b/luajit/src/lj_opt_mem.c @@ -740,21 +740,19 @@ retry: case ALIAS_MUST: /* Emit conversion if the loaded type doesn't match the forwarded type. */ if (!irt_sametype(fins->t, IR(store->op2)->t)) { - IRType st = irt_type(fins->t); - if (st == IRT_I8 || st == IRT_I16) { /* Trunc + sign-extend. */ - st |= IRCONV_SEXT; - } else if (st == IRT_U8 || st == IRT_U16) { /* Trunc + zero-extend. */ - } else if (st == IRT_INT) { - st = irt_type(IR(store->op2)->t); /* Needs dummy CONV.int.*. */ - } else { /* I64/U64 are boxed, U32 is hidden behind a CONV.num.u32. */ - goto store_fwd; + IRType dt = irt_type(fins->t), st = irt_type(IR(store->op2)->t); + if (dt == IRT_I8 || dt == IRT_I16) { /* Trunc + sign-extend. */ + st = dt | IRCONV_SEXT; + dt = IRT_INT; + } else if (dt == IRT_U8 || dt == IRT_U16) { /* Trunc + zero-extend. */ + st = dt; + dt = IRT_INT; } - fins->ot = IRTI(IR_CONV); + fins->ot = IRT(IR_CONV, dt); fins->op1 = store->op2; - fins->op2 = (IRT_INT<<5)|st; + fins->op2 = (dt<<5)|st; return RETRYFOLD; } - store_fwd: return store->op2; /* Store forwarding. */ } ref = store->prev; diff --git a/luajit/src/lj_record.c b/luajit/src/lj_record.c index c6848fc..12b76bb 100644 --- a/luajit/src/lj_record.c +++ b/luajit/src/lj_record.c @@ -421,6 +421,7 @@ static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev, J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); J->base[ra+FORL_EXT] = idx; scev->idx = tref_ref(idx); + setmref(scev->pc, fori); J->maxslot = ra+FORL_EXT+1; } @@ -436,7 +437,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) IRType t; if (isforl) { /* Handle FORL/JFORL opcodes. */ TRef idx = tr[FORL_IDX]; - if (tref_ref(idx) == J->scev.idx) { + if (mref(J->scev.pc, const BCIns) == fori && tref_ref(idx) == J->scev.idx) { t = J->scev.t.irt; stop = J->scev.stop; idx = emitir(IRT(IR_ADD, t), idx, J->scev.step); @@ -1059,7 +1060,7 @@ static void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize) lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD); stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]); /* Runtime value for stop of loop is within bounds? */ - if ((int64_t)stop + ofs < (int64_t)asize) { + if ((uint64_t)stop + ofs < (uint64_t)asize) { /* Emit invariant bounds check for stop. */ emitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop : emitir(IRTI(IR_ADD), J->scev.stop, ofsref)); @@ -2153,6 +2154,7 @@ void lj_record_setup(jit_State *J) memset(J->chain, 0, sizeof(J->chain)); memset(J->bpropcache, 0, sizeof(J->bpropcache)); J->scev.idx = REF_NIL; + setmref(J->scev.pc, NULL); J->baseslot = 1; /* Invoking function is at base[-1]. */ J->base = J->slot + J->baseslot; diff --git a/luajit/src/lj_snap.c b/luajit/src/lj_snap.c index 1c978c2..803533c 100644 --- a/luajit/src/lj_snap.c +++ b/luajit/src/lj_snap.c @@ -104,8 +104,6 @@ static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map) if (frame_islua(frame)) { map[f++] = SNAP_MKPC(frame_pc(frame)); frame = frame_prevl(frame); - if (frame + funcproto(frame_func(frame))->framesize > ftop) - ftop = frame + funcproto(frame_func(frame))->framesize; } else if (frame_iscont(frame)) { map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); map[f++] = SNAP_MKPC(frame_contpc(frame)); @@ -114,7 +112,10 @@ static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map) lua_assert(!frame_isc(frame)); map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); frame = frame_prevd(frame); + continue; } + if (frame + funcproto(frame_func(frame))->framesize > ftop) + ftop = frame + funcproto(frame_func(frame))->framesize; } lua_assert(f == (MSize)(1 + J->framedepth)); return (BCReg)(ftop - lim); diff --git a/luajit/src/lj_state.c b/luajit/src/lj_state.c index f972fdc..b9eaef4 100644 --- a/luajit/src/lj_state.c +++ b/luajit/src/lj_state.c @@ -175,7 +175,7 @@ static void close_state(lua_State *L) g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); } -#if LJ_64 +#if LJ_64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC)) lua_State *lj_state_newstate(lua_Alloc f, void *ud) #else LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) diff --git a/luajit/src/lj_trace.c b/luajit/src/lj_trace.c index 9e5e400..0f48809 100644 --- a/luajit/src/lj_trace.c +++ b/luajit/src/lj_trace.c @@ -607,6 +607,7 @@ static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud) } lj_opt_split(J); lj_opt_sink(J); + if (!J->loopref) J->cur.snap[J->cur.nsnap-1].count = SNAPCOUNT_DONE; J->state = LJ_TRACE_ASM; break; diff --git a/luajit/src/luaconf.h b/luajit/src/luaconf.h index d884a7e..736c0e2 100644 --- a/luajit/src/luaconf.h +++ b/luajit/src/luaconf.h @@ -37,7 +37,7 @@ #endif #define LUA_LROOT "/usr/local" #define LUA_LUADIR "/lua/5.1/" -#define LUA_LJDIR "/luajit-2.0.2/" +#define LUA_LJDIR "/luajit-2.0.3/" #ifdef LUA_ROOT #define LUA_JROOT LUA_ROOT diff --git a/luajit/src/luajit.c b/luajit/src/luajit.c index 3be170f..4e85908 100644 --- a/luajit/src/luajit.c +++ b/luajit/src/luajit.c @@ -592,17 +592,17 @@ static int loadjitmodule(lua_State *L) lua_concat(L, 2); if (lua_pcall(L, 1, 1, 0)) { const char *msg = lua_tostring(L, -1); - if (msg && !strncmp(msg, "module ", 7)) { - err: - l_message(progname, - "unknown luaJIT command or jit.* modules not installed"); - return 1; - } else { - return report(L, 1); - } + if (msg && !strncmp(msg, "module ", 7)) + goto nomodule; + return report(L, 1); } lua_getfield(L, -1, "start"); - if (lua_isnil(L, -1)) goto err; + if (lua_isnil(L, -1)) { + nomodule: + l_message(progname, + "unknown luaJIT command or jit.* modules not installed"); + return 1; + } lua_remove(L, -2); /* Drop module table. */ return 0; } diff --git a/luajit/src/luajit.h b/luajit/src/luajit.h index 7bb9317..be721cf 100644 --- a/luajit/src/luajit.h +++ b/luajit/src/luajit.h @@ -30,9 +30,9 @@ #include "lua.h" -#define LUAJIT_VERSION "LuaJIT 2.0.2" -#define LUAJIT_VERSION_NUM 20002 /* Version 2.0.2 = 02.00.02. */ -#define LUAJIT_VERSION_SYM luaJIT_version_2_0_2 +#define LUAJIT_VERSION "LuaJIT 2.0.3" +#define LUAJIT_VERSION_NUM 20003 /* Version 2.0.3 = 02.00.03. */ +#define LUAJIT_VERSION_SYM luaJIT_version_2_0_3 #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2014 Mike Pall" #define LUAJIT_URL "http://luajit.org/" diff --git a/luajit/src/psvitabuild.bat b/luajit/src/psvitabuild.bat new file mode 100644 index 0000000..3991dc6 --- /dev/null +++ b/luajit/src/psvitabuild.bat @@ -0,0 +1,93 @@ +@rem Script to build LuaJIT with the PS Vita SDK.
+@rem Donated to the public domain.
+@rem
+@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler)
+@rem Then cd to this directory and run this script.
+
+@if not defined INCLUDE goto :FAIL
+@if not defined SCE_PSP2_SDK_DIR goto :FAIL
+
+@setlocal
+@rem ---- Host compiler ----
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
+@set LJLINK=link /nologo
+@set LJMT=mt /nologo
+@set DASMDIR=..\dynasm
+@set DASM=%DASMDIR%\dynasm.lua
+@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
+
+%LJCOMPILE% host\minilua.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:minilua.exe minilua.obj
+@if errorlevel 1 goto :BAD
+if exist minilua.exe.manifest^
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
+
+@rem Check for 32 bit host compiler.
+@minilua
+@if errorlevel 8 goto :FAIL
+
+@set DASMFLAGS=-D FPU -D HFABI
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_arm.dasc
+@if errorlevel 1 goto :BAD
+
+%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLJ_TARGET_PSVITA=1 host\buildvm*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:buildvm.exe buildvm*.obj
+@if errorlevel 1 goto :BAD
+if exist buildvm.exe.manifest^
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
+
+buildvm -m elfasm -o lj_vm.s
+@if errorlevel 1 goto :BAD
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+@if errorlevel 1 goto :BAD
+
+@rem ---- Cross compiler ----
+@set LJCOMPILE="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2snc" -c -w -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC
+@set LJLIB="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2ld32" -r --output=
+@set INCLUDE=""
+
+"%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2as" -o lj_vm.o lj_vm.s
+
+@if "%1" neq "debug" goto :NODEBUG
+@shift
+@set LJCOMPILE=%LJCOMPILE% -g -O0
+@set TARGETLIB=libluajitD.a
+goto :BUILD
+:NODEBUG
+@set LJCOMPILE=%LJCOMPILE% -O2
+@set TARGETLIB=libluajit.a
+:BUILD
+del %TARGETLIB%
+
+%LJCOMPILE% ljamalg.c
+@if errorlevel 1 goto :BAD
+%LJLIB%%TARGETLIB% ljamalg.o lj_vm.o
+@if errorlevel 1 goto :BAD
+
+@del *.o *.obj *.manifest minilua.exe buildvm.exe
+@echo.
+@echo === Successfully built LuaJIT for PS Vita ===
+
+@goto :END
+:BAD
+@echo.
+@echo *******************************************************
+@echo *** Build FAILED -- Please check the error messages ***
+@echo *******************************************************
+@goto :END
+:FAIL
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"
+@echo (32 bit host compiler). The PS Vita SDK must be installed, too.
+:END
diff --git a/luajit/src/vm_ppc.dasc b/luajit/src/vm_ppc.dasc index da75f55..7ae40ec 100644 --- a/luajit/src/vm_ppc.dasc +++ b/luajit/src/vm_ppc.dasc @@ -75,6 +75,29 @@ |.endif |.endmacro | +|.macro clrso, reg +|.if PPE +| li reg, 0 +| mtxer reg +|.else +| mcrxr cr0 +|.endif +|.endmacro +| +|.macro checkov, reg, noov +|.if PPE +| mfxer reg +| add reg, reg, reg +| cmpwi reg, 0 +| li reg, 0 +| mtxer reg +| bgey noov +|.else +| mcrxr cr0 +| bley noov +|.endif +|.endmacro +| |//----------------------------------------------------------------------- | |// Fixed register assignments for the interpreter. @@ -2587,7 +2610,7 @@ static void build_subroutines(BuildCtx *ctx) | stw CARG2, DISPATCH_GL(vmstate)(DISPATCH) | savex_ 0,1,2,3 | stw CARG1, 0(sp) // Store extended stack chain. - | mcrxr cr0 // Clear SO flag. + | clrso TMP1 | savex_ 4,5,6,7 | addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp. | savex_ 8,9,10,11 @@ -2706,7 +2729,7 @@ static void build_subroutines(BuildCtx *ctx) | cmpwi CARG2, 0 | li CARG1, 0 | beqlr - | mcrxr cr0 // Clear SO for -2147483648 % -1 and return 0. + | clrso TMP0 // Clear SO for -2147483648 % -1 and return 0. | blr | |//----------------------------------------------------------------------- @@ -3309,7 +3332,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) |4: |.if not GPR64 | // Potential overflow. - | mcrxr cr0; bley <1 // Ignore unrelated overflow. + | checkov TMP1, <1 // Ignore unrelated overflow. |.endif | lus TMP1, 0x41e0 // 2^31. | li TMP0, 0 @@ -3494,7 +3517,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) |2: | ins_next2 |4: // Overflow. - | mcrxr cr0; bley <1 // Ignore unrelated overflow. + | checkov TMP0, <1 // Ignore unrelated overflow. | ins_arithfallback b |5: // FP variant. ||if (vk == 1) { @@ -4692,7 +4715,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | b <1 if (vk) { |6: // Potential overflow. - | mcrxr cr0; bley <4 // Ignore unrelated overflow. + | checkov TMP0, <4 // Ignore unrelated overflow. | b <2 } |.endif @@ -4832,7 +4855,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | // Traces on PPC don't store the trace number, so use 0. | stw ZERO, DISPATCH_GL(vmstate)(DISPATCH) | lwzx TRACE:TMP2, TMP1, RD - | mcrxr cr0 // Clear SO flag. + | clrso TMP1 | lp TMP2, TRACE:TMP2->mcode | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) | mtctr TMP2 diff --git a/luajit/src/vm_x86.dasc b/luajit/src/vm_x86.dasc index 8a9b536..bd7056f 100644 --- a/luajit/src/vm_x86.dasc +++ b/luajit/src/vm_x86.dasc @@ -2198,7 +2198,7 @@ static void build_subroutines(BuildCtx *ctx) |.endif | |.ffunc_nnr math_fmod - |1: ; fprem; fnstsw ax; sahf; jp <1 + |1: ; fprem; fnstsw ax; and ax, 0x400; jnz <1 | fpop1 | jmp ->fff_resn | |