From 1ca794e0b071416afdf3f351e0a953029f59eff7 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 24 Mar 2014 09:41:33 +0100 Subject: [PATCH 001/165] Fix compiler warnings. --- src/luajit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/luajit.c b/src/luajit.c index 4cccf04e..e0343439 100644 --- a/src/luajit.c +++ b/src/luajit.c @@ -301,17 +301,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; } From c03be1210c5334e58958d95ea0412c20c3eb0128 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 27 Mar 2014 11:38:07 +0100 Subject: [PATCH 002/165] x86/x64: Avoid use of SAHF instruction. --- src/vm_x86.dasc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 8a9b536d..bd7056f8 100644 --- a/src/vm_x86.dasc +++ b/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 | From 095344ce7ca1f8eb30987086a2b4dc78b9d813e6 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 27 Mar 2014 23:29:30 +0100 Subject: [PATCH 003/165] Fix check for reuse of SCEV results in FORL. --- src/lj_jit.h | 1 + src/lj_record.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lj_jit.h b/src/lj_jit.h index b69e4f4e..ecd79de5 100644 --- a/src/lj_jit.h +++ b/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/src/lj_record.c b/src/lj_record.c index c6848fc0..95957d31 100644 --- a/src/lj_record.c +++ b/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) { t = J->scev.t.irt; stop = J->scev.stop; idx = emitir(IRT(IR_ADD, t), idx, J->scev.step); @@ -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; From c735293921724b3d660d2353c08f2ce15887b71d Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 28 Mar 2014 19:09:45 +0100 Subject: [PATCH 004/165] FFI: Fix pseudo type conversions for type punning. --- src/lj_opt_mem.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lj_opt_mem.c b/src/lj_opt_mem.c index c8cdc3e5..d5f5290c 100644 --- a/src/lj_opt_mem.c +++ b/src/lj_opt_mem.c @@ -740,21 +740,19 @@ TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J) 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; From 19b69f21d409375ad8362c04186b246c1749fc8e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 1 Apr 2014 00:30:22 +0200 Subject: [PATCH 005/165] FFI: Allow non-scalar cdata to be compared for equality by address. --- src/lj_carith.c | 6 +++-- src/lj_crecord.c | 61 +++++++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/lj_carith.c b/src/lj_carith.c index 9f94091d..92fe5597 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -73,7 +73,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) ok = 1; } else { ca->ct[1-i] = ct; /* Use enum to improve error message. */ - ca->p[1-i] = NULL; + ca->p[1-i] = (void *)(intptr_t)1; /* To make it unequal. */ break; } } @@ -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/src/lj_crecord.c b/src/lj_crecord.c index da9013f0..71f3d069 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1317,7 +1317,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, CTState *cts, + RecordFFData *rd) { cTValue *tv = NULL; if (J->base[0]) { @@ -1338,13 +1339,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]) { + /* 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 +1365,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 +1395,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); @@ -1414,7 +1423,7 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) } /* else: interpreter will throw. */ } /* else: interpreter will throw. */ } else if (!tref_isnum(tr)) { - goto trymeta; + tr = 0; } ok: s[i] = ct; @@ -1422,22 +1431,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, 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); } } } From b293063eb823160d3f87c1d56f98a742ee8ee58e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 1 Apr 2014 10:07:15 +0200 Subject: [PATCH 006/165] Correct fix for reuse of SCEV results in FORL. --- src/lj_record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_record.c b/src/lj_record.c index 95957d31..47d7115b 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -437,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 (mref(J->scev.pc, const BCIns) == fori) { + 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); From 111b2e8711366b40161b4530f5f0a4fd08dc3420 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 3 Apr 2014 21:45:57 +0200 Subject: [PATCH 007/165] Fix top slot calculation for snapshots with continuations. --- src/lj_snap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lj_snap.c b/src/lj_snap.c index 1c978c26..803533cd 100644 --- a/src/lj_snap.c +++ b/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); From 4ed3ee1f046618c5251baae3013f125b4cc7ca9c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 8 Apr 2014 12:10:51 +0200 Subject: [PATCH 008/165] FFI: Fix cdata equality comparison against strings. --- src/lj_carith.c | 4 ++-- src/lj_crecord.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lj_carith.c b/src/lj_carith.c index 92fe5597..36d7abb1 100644 --- a/src/lj_carith.c +++ b/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; @@ -73,7 +73,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) ok = 1; } else { ca->ct[1-i] = ct; /* Use enum to improve error message. */ - ca->p[1-i] = (void *)(intptr_t)1; /* To make it unequal. */ + ca->p[1-i] = NULL; break; } } diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 71f3d069..8612f005 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1421,7 +1421,9 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) ct = ctype_child(cts, cct); tr = lj_ir_kint(J, (int32_t)ofs); } /* else: interpreter will throw. */ - } /* else: interpreter will throw. */ + } else { + tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr))); + } } else if (!tref_isnum(tr)) { tr = 0; } From cc5075e845368538e239a64a34a68c702fbf529d Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 8 Apr 2014 16:53:41 +0200 Subject: [PATCH 009/165] FFI: Fix cdata equality comparison against other Lua types. --- src/lj_carith.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_carith.c b/src/lj_carith.c index 36d7abb1..9a451b24 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -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; } } From 65626eac23633bfb511513b55b2b4dec5d50e4d3 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 17 Apr 2014 10:30:35 +0200 Subject: [PATCH 010/165] PPC: Don't use mcrxr on PPE. --- src/vm_ppc.dasc | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index da75f556..7ae40ecd 100644 --- a/src/vm_ppc.dasc +++ b/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 From f3374b526619671fe576d593dcdc6bd048bf5603 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 21 Apr 2014 22:26:46 +0200 Subject: [PATCH 011/165] x64: Allow building with LUAJIT_USE_SYSMALLOC and LUAJIT_USE_VALGRIND. Valgrind 3.9 killed MAP_32BIT support. Ugh. So now we have to rely on undocumented behavior where Valgrind always allocates from the bottom of memory. Alas, such a binary won't run properly without Valgrind. --- src/Makefile | 6 ++++-- src/lib_aux.c | 2 +- src/lj_state.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index 9551781a..c558003c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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/src/lib_aux.c b/src/lib_aux.c index 1b01fe07..e88dc7c2 100644 --- a/src/lib_aux.c +++ b/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/src/lj_state.c b/src/lj_state.c index f972fdce..b9eaef46 100644 --- a/src/lj_state.c +++ b/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) From 18309b0a25babe1a7d601d2ee92ce1dba1859ef9 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 22 Apr 2014 09:57:39 +0200 Subject: [PATCH 012/165] Prevent adding side traces for stack checks. --- src/lj_trace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lj_trace.c b/src/lj_trace.c index 9e5e400f..0f48809d 100644 --- a/src/lj_trace.c +++ b/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; From 2715fe3aee7c8202b4b5d04748d1c5faa6d8fd9c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 22 Apr 2014 11:26:52 +0200 Subject: [PATCH 013/165] Prevent GC estimate miscalculation due to buffer growth. --- src/lj_gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lj_gc.c b/src/lj_gc.c index c2bc397d..c856df4d 100644 --- a/src/lj_gc.c +++ b/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: From 7a39be0ac45d8cd19c13bab38d4dda31ea599760 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 27 Apr 2014 00:09:45 +0200 Subject: [PATCH 014/165] Add PS Vita port. Thanks to Anton Stenmark. --- doc/install.html | 57 ++++++++++++++++---------- doc/luajit.html | 8 +++- src/host/buildvm_asm.c | 2 +- src/lib_io.c | 2 +- src/lib_os.c | 11 ++++- src/lj_arch.h | 5 +++ src/lj_def.h | 8 +++- src/psvitabuild.bat | 93 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+), 28 deletions(-) create mode 100644 src/psvitabuild.bat diff --git a/doc/install.html b/doc/install.html index 2388ff33..f8163153 100644 --- a/doc/install.html +++ b/doc/install.html @@ -127,7 +127,7 @@

Installation

ARMv5+
ARM9E+
GCC 4.2+ -GCC 4.2+ +GCC 4.2+
PSP2 (PS VITA) GCC 4.2+   @@ -458,41 +458,56 @@

Cross-compiling LuaJIT

make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \ TARGET_SYS=iOS + +

Cross-compiling for consoles

-You can cross-compile for PS3 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.

-
-make HOST_CC="gcc -m32" CROSS=ppu-lv2-
-

-You can cross-compile for PS4 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.

-Open a "Visual Studio .NET Command Prompt" (64 bit host compiler), -cd to the directory where you've unpacked the sources and run -the following commands. This builds a static library libluajit.a, +The following commands build a static library libluajit.a, which can be linked against your game, just like the Lua library.

+

+To cross-compile for PS3 from a Linux host (requires +32 bit GCC, i.e. multilib Linux/x64) or a Windows host (requires +32 bit MinGW), run this command: +

+
+make HOST_CC="gcc -m32" CROSS=ppu-lv2-
+
+

+To cross-compile for PS4 from a Windows host, +open a "Visual Studio .NET Command Prompt" (64 bit host compiler), +cd to the directory where you've unpacked the sources and +run the following commands: +

 cd src
 ps4build
 

-You can cross-compile for Xbox 360 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 PS Vita from a Windows host, +open a "Visual Studio .NET Command Prompt" (32 bit host compiler), +cd to the directory where you've unpacked the sources and +run the following commands:

+
+cd src
+psvitabuild
+

-Open a "Visual Studio .NET Command Prompt" (32 bit host compiler), +To cross-compile for Xbox 360 from a Windows host, +open a "Visual Studio .NET Command Prompt" (32 bit host compiler), cd to the directory where you've unpacked the sources and run -the following commands. This builds a static library luajit20.lib, -which can be linked against your game, just like the Lua library. +the following commands:

 cd src
diff --git a/doc/luajit.html b/doc/luajit.html
index 43af69c9..ddbc0164 100644
--- a/doc/luajit.html
+++ b/doc/luajit.html
@@ -38,6 +38,9 @@
 table.os2 td {
   color: #ffa040;
 }
+table.os3 td {
+  color: #40ffff;
+}
 table.compiler td {
   color: #2080ff;
   background: #62bf41;
@@ -158,7 +161,10 @@ 

Compatibility

WindowsLinuxBSDOSXPOSIX - + +
EmbeddedAndroidiOSPS3PS4Xbox 360
EmbeddedAndroidiOS
+ +
PS3PS4PS VitaXbox 360
diff --git a/src/host/buildvm_asm.c b/src/host/buildvm_asm.c index 9b28b3b3..079e9a80 100644 --- a/src/host/buildvm_asm.c +++ b/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/src/lib_io.c b/src/lib_io.c index 04f0f739..90f310bb 100644 --- a/src/lib_io.c +++ b/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/src/lib_os.c b/src/lib_os.c index f62e8c8b..713ec935 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -7,7 +7,6 @@ */ #include -#include #include #define lib_os_c @@ -27,6 +26,10 @@ #include #endif +#if !LJ_TARGET_PSVITA +#include +#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/src/lj_arch.h b/src/lj_arch.h index 0196eedc..f04da3bf 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -111,6 +111,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/src/lj_def.h b/src/lj_def.h index 3c43be78..8624aed2 100644 --- a/src/lj_def.h +++ b/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/src/psvitabuild.bat b/src/psvitabuild.bat new file mode 100644 index 00000000..3991dc65 --- /dev/null +++ b/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 From ef82bb014a639142a95b077188c5b18b9cd377e5 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 6 May 2014 14:31:31 +0200 Subject: [PATCH 015/165] FFI: Another fix for cdata equality comparisons. --- src/lj_crecord.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 8612f005..69b21f88 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1317,7 +1317,7 @@ static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm) } /* Record ctype arithmetic metamethods. */ -static TRef crec_arith_meta(jit_State *J, TRef *sp, CTState *cts, +static TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts, RecordFFData *rd) { cTValue *tv = NULL; @@ -1342,7 +1342,7 @@ static TRef crec_arith_meta(jit_State *J, TRef *sp, CTState *cts, return 0; } /* NYI: non-function metamethods. */ } else if ((MMS)rd->data == MM_eq) { /* Fallback cdata pointer comparison. */ - if (sp[0] && sp[1]) { + 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; @@ -1420,9 +1420,13 @@ 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 { + } 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)) { tr = 0; @@ -1435,7 +1439,7 @@ 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)) && - !(tr = crec_arith_meta(J, sp, cts, rd))) + !(tr = crec_arith_meta(J, sp, s, cts, rd))) return; J->base[0] = tr; /* Fixup cdata comparisons, too. Avoids some cdata escapes. */ From 29172880192471b12e699718a906ff1b9a270fe4 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 6 May 2014 14:47:37 +0200 Subject: [PATCH 016/165] x64: Workaround for MSVC build issue. --- src/lj_err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_err.c b/src/lj_err.c index db182673..dc970840 100644 --- a/src/lj_err.c +++ b/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; From 624260f8318e0a64f4a128f0111a974230d5cb48 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 12 May 2014 14:35:30 +0200 Subject: [PATCH 017/165] Fix frame traversal while searching for error function. --- src/lj_err.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lj_err.c b/src/lj_err.c index dc970840..3097795c 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -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: From 8a38af2f99685eac412d862dd379036ad65cbb6e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 15 May 2014 17:03:28 +0200 Subject: [PATCH 018/165] Fix FOLD rule for STRREF of SNEW. --- src/lj_opt_fold.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 8a5b41cc..409549c9 100644 --- a/src/lj_opt_fold.c +++ b/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; } From fe288e7b836deb21fedf489c590d2e2a6ad6816b Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 15 May 2014 17:28:08 +0200 Subject: [PATCH 019/165] FFI: Fix recording of indexing a struct pointer ctype object itself. --- src/lj_crecord.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 69b21f88..d4b9ddee 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -794,7 +794,7 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) } } 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 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) CType *cct = ctype_rawchild(cts, ct); if (ctype_isstruct(cct->info)) { ct = cct; + cd = NULL; if (tref_isstr(idx)) goto again; } } From e15765186c9e6a02cea1479e91ca6b02a23d8677 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 20 May 2014 11:41:32 +0200 Subject: [PATCH 020/165] Fix FOLD rule for string.sub(s, ...) == k. --- src/lj_opt_fold.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 409549c9..a15f927c 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c @@ -1826,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. */ From fc76d540a076e44bd95af939e0675b0a44acf3c0 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 27 May 2014 15:25:34 +0200 Subject: [PATCH 021/165] x86: Fix code generation for unused result of math.random(). --- src/lj_asm_x86.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index fda911e5..40f95636 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -571,7 +571,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. */ } } From 49d3157e146bc33b5b7c3a82ce00a8f824f6fa49 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 27 May 2014 15:58:04 +0200 Subject: [PATCH 022/165] PPC: Fix red zone overflow in machine code generation. --- src/lj_asm_ppc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h index e1a496a7..0a3d35e9 100644 --- a/src/lj_asm_ppc.h +++ b/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); From 7fb503dc8682c97f3922f88494b0e4e5c9b9398e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 28 May 2014 15:46:26 +0200 Subject: [PATCH 023/165] Fix compatibility issues with Illumos. Thanks to Theo Schlossnagle. --- src/lj_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lj_alloc.c b/src/lj_alloc.c index f856a7a0..facccee5 100644 --- a/src/lj_alloc.c +++ b/src/lj_alloc.c @@ -179,11 +179,17 @@ 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; } From e7c6a1afa2b62888ff78679a7a48b4e303b4a8a6 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 11 Jun 2014 10:19:53 +0200 Subject: [PATCH 024/165] Fix debug info for main chunk of stripped bytecode. --- src/lj_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_debug.c b/src/lj_debug.c index 4653a4ec..effb4841 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c @@ -463,7 +463,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] = '['; From 7dc9e5ade487ff2cd81c0c644f4f0953166b1375 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 11 Jun 2014 22:44:08 +0200 Subject: [PATCH 025/165] x86: lj_math_random_step() clobbers XMM regs on OSX Clang. --- src/lj_ircall.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lj_ircall.h b/src/lj_ircall.h index af30ba8f..92d61dfa 100644 --- a/src/lj_ircall.h +++ b/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) \ From 5e7b9bb8ed5bd8d7fa5263acc19e0869adc87d4c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 12 Jun 2014 10:58:22 +0200 Subject: [PATCH 026/165] FFI: Fix frame traversal for backtraces with FFI callbacks. --- src/Makefile.dep | 2 +- src/lj_debug.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Makefile.dep b/src/Makefile.dep index 8ca33151..9e14d617 100644 --- a/src/Makefile.dep +++ b/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/src/lj_debug.c b/src/lj_debug.c index effb4841..e4ab9c12 100644 --- a/src/lj_debug.c +++ b/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); } From bb5dfbb034a75e8a38ba918deb09db07b5989b73 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 13 Jun 2014 11:16:39 +0200 Subject: [PATCH 027/165] Typo. --- doc/ext_ffi_tutorial.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ext_ffi_tutorial.html b/doc/ext_ffi_tutorial.html index 01fb8992..8e4eaf72 100644 --- a/doc/ext_ffi_tutorial.html +++ b/doc/ext_ffi_tutorial.html @@ -564,7 +564,7 @@

To Cache or Not to Cache

individual C functions like this:

-local funca, funcb = ffi.C.funcb, ffi.C.funcb -- Not helpful!
+local funca, funcb = ffi.C.funca, ffi.C.funcb -- Not helpful!
 local function foo(x, n)
   for i=1,n do funcb(funca(x, i), 1) end
 end

From a6c34b85f776d8c83b0c01cbdc50550e613d1fda Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Tue, 1 Jul 2014 17:53:40 +0200
Subject: [PATCH 028/165] Fix ABC elimination.

---
 src/lj_record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lj_record.c b/src/lj_record.c
index 47d7115b..12b76bba 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1060,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));

From f948fe0c2797bb75ed2147ef86795b082712c96b Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Fri, 4 Jul 2014 18:17:32 +0200
Subject: [PATCH 029/165] FFI: Fix compilation of reference field access.

---
 src/lj_crecord.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index d4b9ddee..2b83f3a1 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -848,8 +848,11 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
 
   /* 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. */

From 59d290656a31f66d490e79c3a2d669a036194a75 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Thu, 24 Jul 2014 13:08:02 +0200
Subject: [PATCH 030/165] Invalidate backpropagation cache after DCE.

---
 src/lj_opt_dce.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/lj_opt_dce.c b/src/lj_opt_dce.c
index be801894..fdfe9343 100644
--- a/src/lj_opt_dce.c
+++ b/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. */
   }
 }
 

From 66515a054c0826cee4f0abc5e532f35b421e9c81 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Tue, 5 Aug 2014 20:15:52 +0200
Subject: [PATCH 031/165] FFI: Fix __index/__newindex metamethod resolution for
 ctypes.

---
 src/lib_ffi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index e789ad6c..25496780 100644
--- a/src/lib_ffi.c
+++ b/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);

From 247ead6718767d4b83ca5e94ebb4b31331630551 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 8 Sep 2014 23:28:02 +0200
Subject: [PATCH 032/165] FFI: Fix for cdata vs. non-cdata arithmetic and
 comparisons.

Thanks to Roman Tsisyk.
---
 src/lj_crecord.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 2b83f3a1..fe08b935 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -1434,6 +1434,7 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)
       }
     } else if (!tref_isnum(tr)) {
       tr = 0;
+      ct = ctype_get(cts, CTID_P_VOID);
     }
   ok:
     s[i] = ct;

From 41156fe1cdd6b60a5e8d9855c57699e89ccfbf97 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 8 Sep 2014 23:37:22 +0200
Subject: [PATCH 033/165] FFI: Fix initialization of unions of subtypes.

Thanks to Peter Colberg.
---
 src/lj_cconv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/lj_cconv.c b/src/lj_cconv.c
index de4938e4..90cd36e3 100644
--- a/src/lj_cconv.c
+++ b/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. */
   }
 }

From ae7d4d5ad6a843ee1b9a3eea0aff72253b0fa9cb Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sun, 21 Sep 2014 18:03:47 +0200
Subject: [PATCH 034/165] DynASM/x86: Add shld/shrd opcodes.

Thanks to Peter Cawley.
---
 dynasm/dasm_x86.lua | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua
index f3859e3e..4de5b478 100644
--- a/dynasm/dasm_x86.lua
+++ b/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+
 

From cb886b58176dc5cd969f512d1a633f06d7120941 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 22 Sep 2014 13:44:28 +0200
Subject: [PATCH 035/165] DynASM/x86: Add fldenv, f[n]stenv, fxsave, fxrstor
 opcodes.

Thanks to Cosmin Apreutesei.
---
 dynasm/dasm_x86.lua | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua
index 4de5b478..5f82f4f3 100644
--- a/dynasm/dasm_x86.lua
+++ b/dynasm/dasm_x86.lua
@@ -1117,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",
@@ -1192,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",

From 4846a714a9b8e01bac8f9fc1de0eb2a5f00ea79b Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Tue, 7 Oct 2014 16:17:29 +0200
Subject: [PATCH 036/165] Fix DragonFly build (unsupported).

Thanks to Robin Hahling, Alex Hornung and Joris Giovannangeli.
---
 src/jit/bcsave.lua | 2 +-
 src/lj_alloc.c     | 6 +++---
 src/lj_arch.h      | 3 ++-
 src/lj_gdbjit.c    | 2 ++
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua
index f55bda97..122bb24b 100644
--- a/src/jit/bcsave.lua
+++ b/src/jit/bcsave.lua
@@ -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/src/lj_alloc.c b/src/lj_alloc.c
index facccee5..7c7ec678 100644
--- a/src/lj_alloc.c
+++ b/src/lj_alloc.c
@@ -194,14 +194,14 @@ static LJ_AINLINE void *CALL_MMAP(size_t size)
   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)
@@ -238,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/src/lj_arch.h b/src/lj_arch.h
index f04da3bf..f1c6e5e0 100644
--- a/src/lj_arch.h
+++ b/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
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c
index 5e7fca1c..d999986e 100644
--- a/src/lj_gdbjit.c
+++ b/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

From 6d0654d3eca7654c9c4f8a9923907d06b177a8a1 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Wed, 8 Oct 2014 22:04:51 +0200
Subject: [PATCH 037/165] Fix fused constant loads under high register
 pressure.

---
 src/lj_asm.c     |  1 +
 src/lj_asm_x86.h | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/lj_asm.c b/src/lj_asm.c
index 264649ae..2afa92d0 100644
--- a/src/lj_asm.c
+++ b/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/src/lj_asm_x86.h b/src/lj_asm_x86.h
index 40f95636..04b79649 100644
--- a/src/lj_asm_x86.h
+++ b/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);

From a31c317fb59964be6ab4414fbaea4abebef1c0f5 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 3 Nov 2014 21:34:24 +0100
Subject: [PATCH 038/165] FFI: No meta fallback when indexing pointer to
 incomplete struct.

---
 src/lj_cdata.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/lj_cdata.c b/src/lj_cdata.c
index 590ddf10..ebaea6d2 100644
--- a/src/lj_cdata.c
+++ b/src/lj_cdata.c
@@ -127,16 +127,16 @@ CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,
   integer_key:
     if (ctype_ispointer(ct->info)) {
       CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info));  /* Element size. */
-      if (sz != CTSIZE_INVALID) {
-	if (ctype_isptr(ct->info)) {
-	  p = (uint8_t *)cdata_getptr(p, ct->size);
-	} else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
-	  if ((ct->info & CTF_COMPLEX)) idx &= 1;
-	  *qual |= CTF_CONST;  /* Valarray elements are constant. */
-	}
-	*pp = p + idx*(int32_t)sz;
-	return ct;
+      if (sz == CTSIZE_INVALID)
+	lj_err_caller(cts->L, LJ_ERR_FFI_INVSIZE);
+      if (ctype_isptr(ct->info)) {
+	p = (uint8_t *)cdata_getptr(p, ct->size);
+      } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
+	if ((ct->info & CTF_COMPLEX)) idx &= 1;
+	*qual |= CTF_CONST;  /* Valarray elements are constant. */
       }
+      *pp = p + idx*(int32_t)sz;
+      return ct;
     }
   } else if (tviscdata(key)) {  /* Integer cdata key. */
     GCcdata *cdk = cdataV(key);

From c75c62b489ebd0b4f9eb35af3b7d5a071939721e Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Fri, 28 Nov 2014 20:20:12 +0100
Subject: [PATCH 039/165] Fix snapshot #0 handling for traces with a stack
 check on entry.

---
 src/lj_asm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/lj_asm.c b/src/lj_asm.c
index 2afa92d0..f15458b9 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1373,6 +1373,11 @@ static void asm_head_side(ASMState *as)
   int pass3 = 0;
   IRRef i;
 
+  if (as->snapno && as->topslot > as->parent->topslot) {
+    /* Force snap #0 alloc to prevent register overwrite in stack check. */
+    as->snapno = 0;
+    asm_snap_alloc(as);
+  }
   allow = asm_head_side_base(as, irp, allow);
 
   /* Scan all parent SLOADs and collect register dependencies. */

From 3f2e4ec69946fa2c37b6a571948ee0909f6ddbea Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Wed, 3 Dec 2014 14:09:17 +0100
Subject: [PATCH 040/165] DynASM/ARM: Fix description shown for multi-element
 templates.

---
 dynasm/dasm_arm.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dynasm/dasm_arm.lua b/dynasm/dasm_arm.lua
index b3a8827e..3aa8dead 100644
--- a/dynasm/dasm_arm.lua
+++ b/dynasm/dasm_arm.lua
@@ -923,7 +923,7 @@ local function parse_template(params, template, nparams, pos)
 end
 
 map_op[".template__"] = function(params, template, nparams)
-  if not params then return sub(template, 9) end
+  if not params then return template:gsub("%x%x%x%x%x%x%x%x", "") end
 
   -- Limit number of section buffer positions used by a single dasm_put().
   -- A single opcode needs a maximum of 3 positions.

From 6fddb9bc2e9e85a89aa229538103f1bd80d6b5be Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 8 Dec 2014 02:07:05 +0100
Subject: [PATCH 041/165] Avoid error messages when building with Clang.

---
 src/Makefile | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index c558003c..541abb90 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -290,15 +290,15 @@ ifeq (Windows,$(TARGET_SYS))
   TARGET_XSHLDFLAGS= -shared
   TARGET_DYNXLDOPTS=
 else
+ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
+  TARGET_XCFLAGS+= -fno-stack-protector
+endif
 ifeq (Darwin,$(TARGET_SYS))
   ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
     export MACOSX_DEPLOYMENT_TARGET=10.4
   endif
   TARGET_STRIP+= -x
   TARGET_AR+= 2>/dev/null
-  ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
-    TARGET_XCFLAGS+= -fno-stack-protector
-  endif
   TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
   TARGET_DYNXLDOPTS=
   TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
@@ -310,14 +310,10 @@ else
 ifeq (iOS,$(TARGET_SYS))
   TARGET_STRIP+= -x
   TARGET_AR+= 2>/dev/null
-  TARGET_XCFLAGS+= -fno-stack-protector
   TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
   TARGET_DYNXLDOPTS=
   TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
 else
-  ifneq (,$(findstring stack-protector,$(shell $(TARGET_CC) -dumpspecs)))
-    TARGET_XCFLAGS+= -fno-stack-protector
-  endif
   ifneq (SunOS,$(TARGET_SYS))
     ifneq (PS3,$(TARGET_SYS))
       TARGET_XLDFLAGS+= -Wl,-E

From c6e69249ddc69523eaa0c88f68c6f816a30b537c Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Mon, 15 Dec 2014 01:55:45 +0100
Subject: [PATCH 042/165] Gracefully handle lua_error() for a suspended
 coroutine.

Thanks to Sergei Zhirikov.
---
 src/lj_err.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/lj_err.c b/src/lj_err.c
index 3097795c..8010221f 100644
--- a/src/lj_err.c
+++ b/src/lj_err.c
@@ -499,8 +499,7 @@ static ptrdiff_t finderrfunc(lua_State *L)
 {
   cTValue *frame = L->base-1, *bot = tvref(L->stack);
   void *cf = L->cframe;
-  while (frame > bot) {
-    lua_assert(cf != NULL);
+  while (frame > bot && cf) {
     while (cframe_nres(cframe_raw(cf)) < 0) {  /* cframe without frame? */
       if (frame >= restorestack(L, -cframe_nres(cf)))
 	break;

From 10caad02619c81bf4bf9ee453bee51d2b4473916 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 20 Dec 2014 01:05:06 +0100
Subject: [PATCH 043/165] x86: Fix argument checks for ipairs() iterator.

---
 src/vm_x86.dasc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index bd7056f8..3e59d95b 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -1617,7 +1617,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  mov RD, 1+3
   |  jmp ->fff_res
   |
-  |.ffunc_1 ipairs_aux
+  |.ffunc_2 ipairs_aux
   |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback
   |  cmp dword [BASE+12], LJ_TISNUM
   |.if DUALNUM

From 1b774d9da38686532c1da623819fedf7b261f607 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 05:46:51 +0100
Subject: [PATCH 044/165] Fix corner case in string to number conversion.

---
 src/lj_strscan.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/lj_strscan.c b/src/lj_strscan.c
index a21c414a..0fddd43b 100644
--- a/src/lj_strscan.c
+++ b/src/lj_strscan.c
@@ -289,14 +289,15 @@ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o,
 
     /* Scale down until no more than 17 or 18 integer part digits remain. */
     while (idig > 9) {
-      uint32_t i, cy = 0;
+      uint32_t i = hi, cy = 0;
       ex2 += 6;
-      for (i = hi; i != lo; i = DNEXT(i)) {
+      do {
 	cy += xi[i];
 	xi[i] = (cy >> 6);
 	cy = 100 * (cy & 0x3f);
 	if (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--;
-      }
+	i = DNEXT(i);
+      } while (i != lo);
       while (cy) {
 	if (hi == lo) { xi[DPREV(lo)] |= 1; break; }
 	xi[lo] = (cy >> 6); lo = DNEXT(lo);

From 54826563b2f5e1f41c234bd021b3144efedcdc6f Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 05:59:16 +0100
Subject: [PATCH 045/165] ARM: Fix excess stack growth in interpreter.

---
 src/vm_arm.dasc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index 82cba909..0865d016 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -335,7 +335,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  // - The GC shrinks the stack in between.
   |  // - A return back from a lua_call() with (high) nresults adjustment.
   |  str BASE, L->top			// Save current top held in BASE (yes).
-  |  mov CARG2, KBASE
+  |  lsr CARG2, KBASE, #3
   |  mov CARG1, L
   |  bl extern lj_state_growstack	// (lua_State *L, int n)
   |  ldr BASE, L->top			// Need the (realloced) L->top in BASE.
@@ -389,7 +389,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  str BASE, L->base
   |   add PC, PC, #4			// Must point after first instruction.
   |  str RC, L->top
-  |   lsr CARG3, RA, #3
+  |   lsr CARG2, RA, #3
   |2:
   |  // L->base = new base, L->top = top
   |  str PC, SAVE_PC

From 16f910b4a8144d7a0b9aa5b6bf3cd0226e8e764e Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 06:03:06 +0100
Subject: [PATCH 046/165] ARM: Fix write barrier check in BC_USETS.

---
 src/vm_arm.dasc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index 0865d016..2d600d22 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -3241,10 +3241,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
     |    mvn RC, RC
     |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
     |    ldr STR:CARG3, [KBASE, RC, lsl #2]
-    |    mvn CARG4, #~LJ_TSTR
     |  ldrb RB, UPVAL:CARG2->marked
-    |   ldr CARG2, UPVAL:CARG2->v
     |     ldrb RC, UPVAL:CARG2->closed
+    |   ldr CARG2, UPVAL:CARG2->v
+    |    mvn CARG4, #~LJ_TSTR
     |  tst RB, #LJ_GC_BLACK		// isblack(uv)
     |    ldrb RB, STR:CARG3->marked
     |   strd CARG34, [CARG2]

From 6319e0312dd77ff0f59399a26ef96bfccacdf302 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 06:05:50 +0100
Subject: [PATCH 047/165] PPC: Fix excess stack growth in interpreter.

---
 src/vm_ppc.dasc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
index 7ae40ecd..30e4c663 100644
--- a/src/vm_ppc.dasc
+++ b/src/vm_ppc.dasc
@@ -586,7 +586,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  // - A return back from a lua_call() with (high) nresults adjustment.
   |  stp BASE, L->top			// Save current top held in BASE (yes).
   |   mr SAVE0, RD
-  |  mr CARG2, TMP2
+  |  srwi CARG2, TMP2, 3
   |  mr CARG1, L
   |  bl extern lj_state_growstack	// (lua_State *L, int n)
   |    lwz TMP2, SAVE_NRES

From f45d11e2fea7a56dcf699e72dee40b475590128c Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 06:06:07 +0100
Subject: [PATCH 048/165] MIPS: Fix excess stack growth in interpreter.

---
 src/vm_mips.dasc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc
index 0ec13e60..96f20659 100644
--- a/src/vm_mips.dasc
+++ b/src/vm_mips.dasc
@@ -398,7 +398,7 @@ static void build_subroutines(BuildCtx *ctx)
   |  // - A return back from a lua_call() with (high) nresults adjustment.
   |  load_got lj_state_growstack
   |   move MULTRES, RD
-  |  move CARG2, TMP2
+  |  srl CARG2, TMP2, 3
   |  call_intern lj_state_growstack	// (lua_State *L, int n)
   |.  move CARG1, L
   |    lw TMP2, SAVE_NRES

From db7cb5ab0ebf15f60e7b23e8edce95707fc451b1 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sat, 27 Dec 2014 06:08:36 +0100
Subject: [PATCH 049/165] DynASM/ARM: Fix rollback for variant templates.

---
 dynasm/dasm_arm.lua | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/dynasm/dasm_arm.lua b/dynasm/dasm_arm.lua
index 3aa8dead..d5078f7e 100644
--- a/dynasm/dasm_arm.lua
+++ b/dynasm/dasm_arm.lua
@@ -929,13 +929,16 @@ map_op[".template__"] = function(params, template, nparams)
   -- A single opcode needs a maximum of 3 positions.
   if secpos+3 > maxsecpos then wflush() end
   local pos = wpos()
-  local apos, spos = #actargs, secpos
+  local lpos, apos, spos = #actlist, #actargs, secpos
 
   local ok, err
   for t in gmatch(template, "[^|]+") do
     ok, err = pcall(parse_template, params, t, nparams, pos)
     if ok then return end
     secpos = spos
+    actlist[lpos+1] = nil
+    actlist[lpos+2] = nil
+    actlist[lpos+3] = nil
     actargs[apos+1] = nil
     actargs[apos+2] = nil
     actargs[apos+3] = nil

From 9caaf6595fce4204fb55d73a6e3bb34b43cd85a6 Mon Sep 17 00:00:00 2001
From: Mike Pall 
Date: Sun, 4 Jan 2015 22:58:11 +0100
Subject: [PATCH 050/165] Fix docs.

---
 doc/ext_jit.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/ext_jit.html b/doc/ext_jit.html
index 098be5e0..434e41ba 100644
--- a/doc/ext_jit.html
+++ b/doc/ext_jit.html
@@ -151,7 +151,7 @@ 

jit.os

jit.arch

Contains the target architecture name: -"x86", "x64" or "ppcspe". +"x86", "x64", "arm", "ppc", "ppcspe", or "mips".

jit.opt.* — JIT compiler optimization control

From 31e66838d81d958b22fcac02d7bca2093feeac34 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 5 Jan 2015 00:04:40 +0100 Subject: [PATCH 051/165] x86: Minor interpreter optimization. --- src/vm_x86.dasc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 3e59d95b..f86ee4de 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -5320,8 +5320,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | jnz <4 | movzx RA, PC_RA | not RAa - | lea RA, [BASE+RA*8] - | mov LFUNC:KBASE, [RA-8] // Need to prepare KBASE. + | mov LFUNC:KBASE, [BASE+RA*8-8] // Need to prepare KBASE. | mov KBASE, LFUNC:KBASE->pc | mov KBASE, [KBASE+PC2PROTO(k)] | jmp <4 From 4d9e8e245a96b2ef30c9ec34ab1c98bca3dcccb8 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 5 Jan 2015 00:05:38 +0100 Subject: [PATCH 052/165] ARM: Minor interpreter optimization. --- src/vm_arm.dasc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc index 2d600d22..62579eab 100644 --- a/src/vm_arm.dasc +++ b/src/vm_arm.dasc @@ -539,9 +539,8 @@ static void build_subroutines(BuildCtx *ctx) |1: | beq ->cont_ffi_callback // cont = 1: return from FFI callback. | // cont = 0: tailcall from C function. - | ldr CARG3, [BASE, FRAME_FUNC] - | sub CARG4, CARG4, #16 - | sub RC, CARG4, BASE + | sub CARG4, CARG4, #16 + | sub RC, CARG4, BASE | b ->vm_call_tail |.endif | From 999f57de83180c4edd928eb9051e58602ba7e20a Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 5 Jan 2015 23:39:37 +0100 Subject: [PATCH 053/165] Fix BC_UCLO/BC_JMP join optimization in Lua parser. --- src/lj_parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lj_parse.c b/src/lj_parse.c index e8aafba2..5ced1dd8 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -685,10 +685,12 @@ static BCPos bcemit_jmp(FuncState *fs) BCPos j = fs->pc - 1; BCIns *ip = &fs->bcbase[j].ins; fs->jpc = NO_JMP; - if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) + if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) { setbc_j(ip, NO_JMP); - else + fs->lasttarget = j+1; + } else { j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP); + } jmp_append(fs, &j, jpc); return j; } From 86913b9bbf75c78a5dcfa2bf6071db8db7df7c51 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 5 Jan 2015 23:59:31 +0100 Subject: [PATCH 054/165] Bump copyright date to 2015. --- COPYRIGHT | 2 +- Makefile | 2 +- README | 2 +- doc/bluequad-print.css | 2 +- doc/bluequad.css | 2 +- doc/changes.html | 4 ++-- doc/contact.html | 6 +++--- doc/ext_c_api.html | 4 ++-- doc/ext_ffi.html | 4 ++-- doc/ext_ffi_api.html | 4 ++-- doc/ext_ffi_semantics.html | 4 ++-- doc/ext_ffi_tutorial.html | 4 ++-- doc/ext_jit.html | 4 ++-- doc/extensions.html | 4 ++-- doc/faq.html | 4 ++-- doc/install.html | 4 ++-- doc/luajit.html | 6 +++--- doc/running.html | 4 ++-- doc/status.html | 4 ++-- dynasm/dasm_arm.h | 2 +- dynasm/dasm_arm.lua | 2 +- dynasm/dasm_mips.h | 2 +- dynasm/dasm_mips.lua | 2 +- dynasm/dasm_ppc.h | 2 +- dynasm/dasm_ppc.lua | 2 +- dynasm/dasm_proto.h | 2 +- dynasm/dasm_x64.lua | 2 +- dynasm/dasm_x86.h | 2 +- dynasm/dasm_x86.lua | 2 +- dynasm/dynasm.lua | 4 ++-- etc/luajit.1 | 2 +- src/Makefile | 2 +- src/host/buildvm.c | 2 +- src/host/buildvm.h | 2 +- src/host/buildvm_asm.c | 2 +- src/host/buildvm_fold.c | 2 +- src/host/buildvm_lib.c | 2 +- src/host/buildvm_peobj.c | 2 +- src/host/genminilua.lua | 2 +- src/jit/bc.lua | 2 +- src/jit/bcsave.lua | 2 +- src/jit/dis_arm.lua | 2 +- src/jit/dis_mips.lua | 2 +- src/jit/dis_mipsel.lua | 2 +- src/jit/dis_ppc.lua | 2 +- src/jit/dis_x64.lua | 2 +- src/jit/dis_x86.lua | 2 +- src/jit/dump.lua | 2 +- src/jit/v.lua | 2 +- src/lib_aux.c | 2 +- src/lib_base.c | 2 +- src/lib_bit.c | 2 +- src/lib_debug.c | 2 +- src/lib_ffi.c | 2 +- src/lib_init.c | 2 +- src/lib_io.c | 2 +- src/lib_jit.c | 2 +- src/lib_math.c | 2 +- src/lib_os.c | 2 +- src/lib_package.c | 2 +- src/lib_string.c | 2 +- src/lib_table.c | 2 +- src/lj_api.c | 2 +- src/lj_arch.h | 2 +- src/lj_asm.c | 2 +- src/lj_asm.h | 2 +- src/lj_asm_arm.h | 2 +- src/lj_asm_mips.h | 2 +- src/lj_asm_ppc.h | 2 +- src/lj_asm_x86.h | 2 +- src/lj_bc.c | 2 +- src/lj_bc.h | 2 +- src/lj_bcdump.h | 2 +- src/lj_bcread.c | 2 +- src/lj_bcwrite.c | 2 +- src/lj_carith.c | 2 +- src/lj_carith.h | 2 +- src/lj_ccall.c | 2 +- src/lj_ccall.h | 2 +- src/lj_ccallback.c | 2 +- src/lj_ccallback.h | 2 +- src/lj_cconv.c | 2 +- src/lj_cconv.h | 2 +- src/lj_cdata.c | 2 +- src/lj_cdata.h | 2 +- src/lj_clib.c | 2 +- src/lj_clib.h | 2 +- src/lj_cparse.c | 2 +- src/lj_cparse.h | 2 +- src/lj_crecord.c | 2 +- src/lj_crecord.h | 2 +- src/lj_ctype.c | 2 +- src/lj_ctype.h | 2 +- src/lj_debug.c | 2 +- src/lj_debug.h | 2 +- src/lj_def.h | 2 +- src/lj_dispatch.c | 2 +- src/lj_dispatch.h | 2 +- src/lj_emit_arm.h | 2 +- src/lj_emit_mips.h | 2 +- src/lj_emit_ppc.h | 2 +- src/lj_emit_x86.h | 2 +- src/lj_err.c | 2 +- src/lj_err.h | 2 +- src/lj_errmsg.h | 2 +- src/lj_ff.h | 2 +- src/lj_ffrecord.c | 2 +- src/lj_ffrecord.h | 2 +- src/lj_frame.h | 2 +- src/lj_func.c | 2 +- src/lj_func.h | 2 +- src/lj_gc.c | 2 +- src/lj_gc.h | 2 +- src/lj_gdbjit.c | 2 +- src/lj_gdbjit.h | 2 +- src/lj_ir.c | 2 +- src/lj_ir.h | 2 +- src/lj_ircall.h | 2 +- src/lj_iropt.h | 2 +- src/lj_jit.h | 2 +- src/lj_lex.c | 2 +- src/lj_lex.h | 2 +- src/lj_lib.c | 2 +- src/lj_lib.h | 2 +- src/lj_load.c | 2 +- src/lj_mcode.c | 2 +- src/lj_mcode.h | 2 +- src/lj_meta.c | 2 +- src/lj_meta.h | 2 +- src/lj_obj.c | 2 +- src/lj_obj.h | 2 +- src/lj_opt_dce.c | 2 +- src/lj_opt_fold.c | 2 +- src/lj_opt_loop.c | 2 +- src/lj_opt_mem.c | 2 +- src/lj_opt_narrow.c | 2 +- src/lj_opt_sink.c | 2 +- src/lj_opt_split.c | 2 +- src/lj_parse.c | 2 +- src/lj_parse.h | 2 +- src/lj_record.c | 2 +- src/lj_record.h | 2 +- src/lj_snap.c | 2 +- src/lj_snap.h | 2 +- src/lj_state.c | 2 +- src/lj_state.h | 2 +- src/lj_str.c | 2 +- src/lj_str.h | 2 +- src/lj_strscan.c | 2 +- src/lj_strscan.h | 2 +- src/lj_tab.c | 2 +- src/lj_tab.h | 2 +- src/lj_target.h | 2 +- src/lj_target_arm.h | 2 +- src/lj_target_mips.h | 2 +- src/lj_target_ppc.h | 2 +- src/lj_target_x86.h | 2 +- src/lj_trace.c | 2 +- src/lj_trace.h | 2 +- src/lj_traceerr.h | 2 +- src/lj_udata.c | 2 +- src/lj_udata.h | 2 +- src/lj_vm.h | 2 +- src/lj_vmevent.c | 2 +- src/lj_vmevent.h | 2 +- src/lj_vmmath.c | 2 +- src/ljamalg.c | 2 +- src/luaconf.h | 2 +- src/luajit.c | 2 +- src/luajit.h | 4 ++-- src/lualib.h | 2 +- src/msvcbuild.bat | 2 +- src/vm_arm.dasc | 2 +- src/vm_mips.dasc | 2 +- src/vm_ppc.dasc | 2 +- src/vm_ppcspe.dasc | 2 +- src/vm_x86.dasc | 2 +- 177 files changed, 195 insertions(+), 195 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 08936dfb..1ef7df62 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,7 +1,7 @@ =============================================================================== LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ -Copyright (C) 2005-2014 Mike Pall. All rights reserved. +Copyright (C) 2005-2015 Mike Pall. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index b23b6481..0891b713 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # For MSVC, please follow the instructions given in src/msvcbuild.bat. # For MinGW and Cygwin, cd to src and run make with the Makefile there. # -# Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h +# Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h ############################################################################## MAJVER= 2 diff --git a/README b/README index 902a6d2e..d151bb7b 100644 --- a/README +++ b/README @@ -5,7 +5,7 @@ LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. Project Homepage: http://luajit.org/ -LuaJIT is Copyright (C) 2005-2014 Mike Pall. +LuaJIT is Copyright (C) 2005-2015 Mike Pall. LuaJIT is free software, released under the MIT license. See full Copyright Notice in the COPYRIGHT file or in luajit.h. diff --git a/doc/bluequad-print.css b/doc/bluequad-print.css index 21da8688..07f5c84a 100644 --- a/doc/bluequad-print.css +++ b/doc/bluequad-print.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2014 Mike Pall. +/* Copyright (C) 2004-2015 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/doc/bluequad.css b/doc/bluequad.css index 05b092e4..ae531430 100644 --- a/doc/bluequad.css +++ b/doc/bluequad.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2014 Mike Pall. +/* Copyright (C) 2004-2015 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/doc/changes.html b/doc/changes.html index 98412293..3d8f5dbb 100644 --- a/doc/changes.html +++ b/doc/changes.html @@ -4,7 +4,7 @@ LuaJIT Change History - + @@ -918,7 +918,7 @@

LuaJIT 1.0.0 — 2005-08-29

Building LuaJIT

The supplied Makefiles try to auto-detect the settings needed for your diff --git a/doc/running.html b/doc/running.html index c2ec5113..c6e1c296 100644 --- a/doc/running.html +++ b/doc/running.html @@ -186,7 +186,7 @@

-j cmd[=arg[,arg...]]

read the comment block at the start of their source. They can be found in the lib directory of the source distribution or installed under the jit directory. By default -this is /usr/local/share/luajit-2.0.3/jit on POSIX +this is /usr/local/share/luajit-2.0.4/jit on POSIX systems.

diff --git a/etc/luajit.pc b/etc/luajit.pc index d3f0cf30..a652b40d 100644 --- a/etc/luajit.pc +++ b/etc/luajit.pc @@ -1,7 +1,7 @@ # Package information for LuaJIT to be used by pkg-config. majver=2 minver=0 -relver=3 +relver=4 version=${majver}.${minver}.${relver} abiver=5.1 diff --git a/src/Makefile b/src/Makefile index 33b0a43b..1d38fa25 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ MAJVER= 2 MINVER= 0 -RELVER= 3 +RELVER= 4 ABIVER= 5.1 NODOTABIVER= 51 diff --git a/src/jit/bc.lua b/src/jit/bc.lua index a179d50e..46a40892 100644 --- a/src/jit/bc.lua +++ b/src/jit/bc.lua @@ -41,7 +41,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20004, "LuaJIT core/library version mismatch") local jutil = require("jit.util") local vmdef = require("jit.vmdef") local bit = require("bit") diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua index 2ba234d0..0319b3d2 100644 --- a/src/jit/bcsave.lua +++ b/src/jit/bcsave.lua @@ -11,7 +11,7 @@ ------------------------------------------------------------------------------ local jit = require("jit") -assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20004, "LuaJIT core/library version mismatch") local bit = require("bit") -- Symbol name prefix for LuaJIT bytecode. diff --git a/src/jit/dump.lua b/src/jit/dump.lua index 589543f1..d15c528e 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua @@ -55,7 +55,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20004, "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/src/jit/v.lua b/src/jit/v.lua index c622443d..32666fd1 100644 --- a/src/jit/v.lua +++ b/src/jit/v.lua @@ -59,7 +59,7 @@ -- Cache some library functions and objects. local jit = require("jit") -assert(jit.version_num == 20003, "LuaJIT core/library version mismatch") +assert(jit.version_num == 20004, "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/src/luaconf.h b/src/luaconf.h index 7f57bae1..84fa6418 100644 --- a/src/luaconf.h +++ b/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.3/" +#define LUA_LJDIR "/luajit-2.0.4/" #ifdef LUA_ROOT #define LUA_JROOT LUA_ROOT diff --git a/src/luajit.h b/src/luajit.h index 901807ab..9ced18eb 100644 --- a/src/luajit.h +++ b/src/luajit.h @@ -30,9 +30,9 @@ #include "lua.h" -#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_VERSION "LuaJIT 2.0.4" +#define LUAJIT_VERSION_NUM 20004 /* Version 2.0.4 = 02.00.04. */ +#define LUAJIT_VERSION_SYM luaJIT_version_2_0_4 #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2015 Mike Pall" #define LUAJIT_URL "http://luajit.org/" From 72347895edbdc8730c1e758bfee4264fd60164ac Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 9 Jun 2015 21:56:58 +0200 Subject: [PATCH 070/165] x64: Allow building without external unwinder. Required for PS4 SDK 2.5. Thanks to James Park. --- src/Makefile | 7 ++++--- src/lj_arch.h | 2 +- src/lj_err.c | 4 ++-- src/lj_frame.h | 4 ++++ src/ps4build.bat | 4 ++-- src/vm_x86.dasc | 24 ++++++++++++++++++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 1d38fa25..5021e479 100644 --- a/src/Makefile +++ b/src/Makefile @@ -243,9 +243,6 @@ ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) TARGET_ARCH+= -D__CELLOS_LV2__ TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC endif -ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) - TARGET_ARCH+= -DLUAJIT_NO_UNWIND -endif TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH)) TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH)) @@ -397,6 +394,10 @@ ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH))) else TARGET_ARCH+= -DLJ_ABI_SOFTFP=1 endif +ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) + DASM_AFLAGS+= -D NO_UNWIND + TARGET_ARCH+= -DLUAJIT_NO_UNWIND +endif DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH)))) ifeq (Windows,$(TARGET_SYS)) DASM_AFLAGS+= -D WIN diff --git a/src/lj_arch.h b/src/lj_arch.h index d3a9d57d..d89d1169 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -423,7 +423,7 @@ #define LUAJIT_NO_EXP2 #endif -#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 +#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 #define LJ_NO_UNWIND 1 #endif diff --git a/src/lj_err.c b/src/lj_err.c index 081bfde4..11b07b56 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -57,10 +57,10 @@ ** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH. ** EXT is mandatory on WIN64 since the calling convention has an abundance ** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15). -** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. +** The POSIX/x64 interpreter only saves r12/r13 for INT (e.g. PS4). */ -#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) +#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND #define LJ_UNWIND_EXT 1 #elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS #define LJ_UNWIND_EXT 1 diff --git a/src/lj_frame.h b/src/lj_frame.h index cd57be22..f9810984 100644 --- a/src/lj_frame.h +++ b/src/lj_frame.h @@ -86,7 +86,11 @@ enum { #define CFRAME_OFS_ERRF (5*4) #define CFRAME_OFS_NRES (4*4) #define CFRAME_OFS_MULTRES (1*4) +#if LJ_NO_UNWIND +#define CFRAME_SIZE (12*8) +#else #define CFRAME_SIZE (10*8) +#endif #define CFRAME_SIZE_JIT (CFRAME_SIZE + 16) #define CFRAME_SHIFT_MULTRES 0 #endif diff --git a/src/ps4build.bat b/src/ps4build.bat index 42fc9a64..337a44fa 100644 --- a/src/ps4build.bat +++ b/src/ps4build.bat @@ -27,11 +27,11 @@ if exist minilua.exe.manifest^ @minilua @if not errorlevel 8 goto :FAIL -@set DASMFLAGS=-D P64 +@set DASMFLAGS=-D P64 -D NO_UNWIND minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc @if errorlevel 1 goto :BAD -%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c +%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c @if errorlevel 1 goto :BAD %LJLINK% /out:buildvm.exe buildvm*.obj @if errorlevel 1 goto :BAD diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 6cdb8cbd..129ab000 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -222,6 +222,9 @@ |.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). |.macro saveregs_ | push rbx; push r15; push r14 +|.if NO_UNWIND +| push r13; push r12 +|.endif | sub rsp, CFRAME_SPACE |.endmacro |.macro saveregs @@ -229,15 +232,28 @@ |.endmacro |.macro restoreregs | add rsp, CFRAME_SPACE +|.if NO_UNWIND +| pop r12; pop r13 +|.endif | pop r14; pop r15; pop rbx; pop rbp |.endmacro | |//----- 16 byte aligned, +|.if NO_UNWIND +|.define SAVE_RET, aword [rsp+aword*11] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*10] +|.define SAVE_R3, aword [rsp+aword*9] +|.define SAVE_R2, aword [rsp+aword*8] +|.define SAVE_R1, aword [rsp+aword*7] +|.define SAVE_RU2, aword [rsp+aword*6] +|.define SAVE_RU1, aword [rsp+aword*5] //<-- rsp after register saves. +|.else |.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. |.define SAVE_R4, aword [rsp+aword*8] |.define SAVE_R3, aword [rsp+aword*7] |.define SAVE_R2, aword [rsp+aword*6] |.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.endif |.define SAVE_CFRAME, aword [rsp+aword*4] |.define SAVE_PC, dword [rsp+dword*7] |.define SAVE_L, dword [rsp+dword*6] @@ -6119,6 +6135,10 @@ static void emit_asm_debug(BuildCtx *ctx) "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ +#if LJ_NO_UNWIND + "\t.byte 0x8d\n\t.uleb128 0x6\n" /* offset r13 */ + "\t.byte 0x8c\n\t.uleb128 0x7\n" /* offset r12 */ +#endif #else "\t.long .Lbegin\n" "\t.long %d\n" @@ -6154,6 +6174,7 @@ static void emit_asm_debug(BuildCtx *ctx) "\t.align " SZPTR "\n" ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); #endif +#if !LJ_NO_UNWIND #if (defined(__sun__) && defined(__svr4__)) #if LJ_64 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n"); @@ -6241,8 +6262,10 @@ static void emit_asm_debug(BuildCtx *ctx) #endif "\t.align " SZPTR "\n" ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); +#endif #endif break; +#if !LJ_NO_UNWIND /* Mental note: never let Apple design an assembler. ** Or a linker. Or a plastic case. But I digress. */ @@ -6370,6 +6393,7 @@ static void emit_asm_debug(BuildCtx *ctx) #endif } break; +#endif default: /* Difficult for other modes. */ break; } From 7f454aed82ef364245ae73a16a04b21e2245e342 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 10 Jun 2015 16:14:41 +0200 Subject: [PATCH 071/165] Fix narrowing of TOBIT. --- src/lj_opt_narrow.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lj_opt_narrow.c b/src/lj_opt_narrow.c index 58b3763d..fb647189 100644 --- a/src/lj_opt_narrow.c +++ b/src/lj_opt_narrow.c @@ -205,7 +205,6 @@ typedef struct NarrowConv { jit_State *J; /* JIT compiler state. */ NarrowIns *sp; /* Current stack pointer. */ NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */ - int lim; /* Limit on the number of emitted conversions. */ IRRef mode; /* Conversion mode (IRCONV_*). */ IRType t; /* Destination type: IRT_INT or IRT_I64. */ NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */ @@ -342,7 +341,7 @@ static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth) NarrowIns *savesp = nc->sp; int count = narrow_conv_backprop(nc, ir->op1, depth); count += narrow_conv_backprop(nc, ir->op2, depth); - if (count <= nc->lim) { /* Limit total number of conversions. */ + if (count <= 1) { /* Limit total number of conversions. */ *nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref); return count; } @@ -414,12 +413,10 @@ TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J) nc.t = irt_type(fins->t); if (fins->o == IR_TOBIT) { nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */ - nc.lim = 2; /* TOBIT can use a more optimistic rule. */ } else { nc.mode = fins->op2; - nc.lim = 1; } - if (narrow_conv_backprop(&nc, fins->op1, 0) <= nc.lim) + if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1) return narrow_conv_emit(J, &nc); } return NEXTFOLD; From 575bfe50286cd8f7645d571177a2e84b5c307d71 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 10 Jul 2015 03:42:51 +0200 Subject: [PATCH 072/165] Limit number of arguments given to io.lines() and fp:lines(). --- src/lib_io.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib_io.c b/src/lib_io.c index 037aa28e..a502dd52 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -278,6 +278,15 @@ static int io_file_iter(lua_State *L) return n; } +static int io_file_lines(lua_State *L) +{ + int n = (int)(L->top - L->base); + if (n > LJ_MAX_UPVAL) + lj_err_caller(L, LJ_ERR_UNPACK); + lua_pushcclosure(L, io_file_iter, n); + return 1; +} + /* -- I/O file methods ---------------------------------------------------- */ #define LJLIB_MODULE_io_method @@ -361,8 +370,7 @@ LJLIB_CF(io_method_setvbuf) LJLIB_CF(io_method_lines) { io_tofile(L); - lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); - return 1; + return io_file_lines(L); } LJLIB_CF(io_method___gc) @@ -492,8 +500,7 @@ LJLIB_CF(io_lines) } else { /* io.lines() iterates over stdin. */ setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); } - lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); - return 1; + return io_file_lines(L); } LJLIB_CF(io_type) From a5b1c4d98eeb97a950774ae032f51f820dfbfc4c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 17 Jul 2015 23:14:21 +0200 Subject: [PATCH 073/165] FFI: Don't propagate qualifiers into subtypes of complex. --- src/lj_cparse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lj_cparse.c b/src/lj_cparse.c index b9df88d7..9e213610 100644 --- a/src/lj_cparse.c +++ b/src/lj_cparse.c @@ -798,6 +798,10 @@ static void cp_push_type(CPDecl *decl, CTypeID id) cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ break; case CT_ARRAY: + if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) { + info |= (decl->attr & CTF_QUAL); + decl->attr &= ~CTF_QUAL; + } cp_push_type(decl, ctype_cid(info)); /* Unroll. */ cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */ decl->stack[decl->pos].sib = 1; /* Mark as already checked and sized. */ From 424940ffc3fbc0b158cb95875a70accd49c04d30 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 20 Aug 2015 00:49:20 +0200 Subject: [PATCH 074/165] Fix NYICF error message. Thanks to Vyacheslav Egorov. --- src/lj_traceerr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_traceerr.h b/src/lj_traceerr.h index 9bef117a..150ac2db 100644 --- a/src/lj_traceerr.h +++ b/src/lj_traceerr.h @@ -23,7 +23,7 @@ TREDEF(BADTYPE, "bad argument type") TREDEF(CJITOFF, "JIT compilation disabled for function") TREDEF(CUNROLL, "call unroll limit reached") TREDEF(DOWNREC, "down-recursion, restarting") -TREDEF(NYICF, "NYI: C function %p") +TREDEF(NYICF, "NYI: C function %s") TREDEF(NYIFF, "NYI: FastFunc %s") TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s") TREDEF(NYIRETL, "NYI: return to lower frame") From 8715ae65c1f70f2402b89a004b88ab04ca103625 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 20 Aug 2015 01:10:30 +0200 Subject: [PATCH 075/165] Properly handle OOM in trace_save(). Thanks to Vyacheslav Egorov. --- src/lj_trace.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lj_trace.c b/src/lj_trace.c index e51ec546..7d1b0936 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -117,15 +117,22 @@ static void perftools_addtrace(GCtrace *T) } #endif -/* Save current trace by copying and compacting it. */ -static void trace_save(jit_State *J) +/* Allocate space for copy of trace. */ +static GCtrace *trace_save_alloc(jit_State *J) { size_t sztr = ((sizeof(GCtrace)+7)&~7); size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns); size_t sz = sztr + szins + J->cur.nsnap*sizeof(SnapShot) + J->cur.nsnapmap*sizeof(SnapEntry); - GCtrace *T = lj_mem_newt(J->L, (MSize)sz, GCtrace); + return lj_mem_newt(J->L, (MSize)sz, GCtrace); +} + +/* Save current trace by copying and compacting it. */ +static void trace_save(jit_State *J, GCtrace *T) +{ + size_t sztr = ((sizeof(GCtrace)+7)&~7); + size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns); char *p = (char *)T + sztr; memcpy(T, &J->cur, sizeof(GCtrace)); setgcrefr(T->nextgc, J2G(J)->gc.root); @@ -417,6 +424,7 @@ static void trace_stop(jit_State *J) BCOp op = bc_op(J->cur.startins); GCproto *pt = &gcref(J->cur.startpt)->pt; TraceNo traceno = J->cur.traceno; + GCtrace *T = trace_save_alloc(J); /* Do this first. May throw OOM. */ lua_State *L; switch (op) { @@ -461,7 +469,7 @@ static void trace_stop(jit_State *J) /* Commit new mcode only after all patching is done. */ lj_mcode_commit(J, J->cur.mcode); J->postproc = LJ_POST_NONE; - trace_save(J); + trace_save(J, T); L = J->L; lj_vmevent_send(L, TRACE, From 076d625dc6046c5f05d55a95d3b9afd5637d5a5a Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 20 Sep 2015 19:17:02 +0200 Subject: [PATCH 076/165] Fix Cygwin support. Note: this is not a supported target. Contributed by Yaakov Selkowitz. --- src/lj_alloc.c | 2 +- src/lj_arch.h | 6 +++++- src/lj_err.c | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lj_alloc.c b/src/lj_alloc.c index 7c7ec678..9218c440 100644 --- a/src/lj_alloc.c +++ b/src/lj_alloc.c @@ -194,7 +194,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) return ptr; } -#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) +#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__CYGWIN__) /* 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, diff --git a/src/lj_arch.h b/src/lj_arch.h index d89d1169..9a6d4305 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -151,7 +151,11 @@ #define LJ_ARCH_NAME "x64" #define LJ_ARCH_BITS 64 #define LJ_ARCH_ENDIAN LUAJIT_LE -#define LJ_ABI_WIN LJ_TARGET_WINDOWS +#if LJ_TARGET_WINDOWS || __CYGWIN__ +#define LJ_ABI_WIN 1 +#else +#define LJ_ABI_WIN 0 +#endif #define LJ_TARGET_X64 1 #define LJ_TARGET_X86ORX64 1 #define LJ_TARGET_EHRETREG 0 diff --git a/src/lj_err.c b/src/lj_err.c index 11b07b56..6d8519bb 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -186,7 +186,7 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode) /* -- External frame unwinding -------------------------------------------- */ -#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_TARGET_WINDOWS +#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_ABI_WIN /* ** We have to use our own definitions instead of the mandatory (!) unwind.h, @@ -352,7 +352,7 @@ LJ_FUNCA int lj_err_unwind_arm(int state, void *ucb, _Unwind_Context *ctx) #endif -#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS +#elif LJ_TARGET_X64 && LJ_ABI_WIN /* ** Someone in Redmond owes me several days of my life. A lot of this is @@ -417,7 +417,9 @@ LJ_FUNCA EXCEPTION_DISPOSITION lj_err_unwind_win64(EXCEPTION_RECORD *rec, if (cf2) { /* We catch it, so start unwinding the upper frames. */ if (rec->ExceptionCode == LJ_MSVC_EXCODE || rec->ExceptionCode == LJ_GCC_EXCODE) { +#if LJ_TARGET_WINDOWS __DestructExceptionObject(rec, 1); +#endif setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP)); } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) { /* Don't catch access violations etc. */ From ef087aa6782d72af61dcf1b5801ce43818ecf003 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 1 Oct 2015 16:12:48 +0200 Subject: [PATCH 077/165] Fix unsinking check. Reported by Elias Hogstvedt. Debugged and fixed by Vyacheslav Egorov. --- src/lj_snap.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lj_snap.c b/src/lj_snap.c index 5c870baf..ea46b831 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -26,9 +26,6 @@ #include "lj_cdata.h" #endif -/* Some local macros to save typing. Undef'd at the end. */ -#define IR(ref) (&J->cur.ir[(ref)]) - /* Pass IR on to next optimization in chain (FOLD). */ #define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) @@ -73,7 +70,7 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) IRRef ref = tref_ref(tr); if (ref) { SnapEntry sn = SNAP_TR(s, tr); - IRIns *ir = IR(ref); + IRIns *ir = &J->cur.ir[ref]; if (!(sn & (SNAP_CONT|SNAP_FRAME)) && ir->o == IR_SLOAD && ir->op1 == s && ref > retf) { /* No need to snapshot unmodified non-inherited slots. */ @@ -404,24 +401,24 @@ static TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax, } /* Check whether a sunk store corresponds to an allocation. Slow path. */ -static int snap_sunk_store2(jit_State *J, IRIns *ira, IRIns *irs) +static int snap_sunk_store2(GCtrace *T, IRIns *ira, IRIns *irs) { if (irs->o == IR_ASTORE || irs->o == IR_HSTORE || irs->o == IR_FSTORE || irs->o == IR_XSTORE) { - IRIns *irk = IR(irs->op1); + IRIns *irk = &T->ir[irs->op1]; if (irk->o == IR_AREF || irk->o == IR_HREFK) - irk = IR(irk->op1); - return (IR(irk->op1) == ira); + irk = &T->ir[irk->op1]; + return (&T->ir[irk->op1] == ira); } return 0; } /* Check whether a sunk store corresponds to an allocation. Fast path. */ -static LJ_AINLINE int snap_sunk_store(jit_State *J, IRIns *ira, IRIns *irs) +static LJ_AINLINE int snap_sunk_store(GCtrace *T, IRIns *ira, IRIns *irs) { if (irs->s != 255) return (ira + irs->s == irs); /* Fast check. */ - return snap_sunk_store2(J, ira, irs); + return snap_sunk_store2(T, ira, irs); } /* Replay snapshot state to setup side trace. */ @@ -484,7 +481,7 @@ void lj_snap_replay(jit_State *J, GCtrace *T) } else { IRIns *irs; for (irs = ir+1; irs < irlast; irs++) - if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { if (snap_pref(J, T, map, nent, seen, irs->op2) == 0) snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1); else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && @@ -524,7 +521,7 @@ void lj_snap_replay(jit_State *J, GCtrace *T) TRef tr = emitir(ir->ot, op1, op2); J->slot[snap_slot(sn)] = tr; for (irs = ir+1; irs < irlast; irs++) - if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { IRIns *irr = &T->ir[irs->op1]; TRef val, key = irr->op2, tmp = tr; if (irr->o != IR_FREF) { @@ -726,7 +723,7 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, } else { IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref]; for (irs = ir+1; irs < irlast; irs++) - if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { IRIns *iro = &T->ir[T->ir[irs->op1].op2]; uint8_t *p = (uint8_t *)cd; CTSize szs; @@ -759,7 +756,7 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, settabV(J->L, o, t); irlast = &T->ir[T->snap[snapno].ref]; for (irs = ir+1; irs < irlast; irs++) - if (irs->r == RID_SINK && snap_sunk_store(J, ir, irs)) { + if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { IRIns *irk = &T->ir[irs->op1]; TValue tmp, *val; lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE || @@ -859,7 +856,6 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) return pc; } -#undef IR #undef emitir_raw #undef emitir From 2e85af8836931f10aaaaae8c10f9b394219187a5 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 1 Oct 2015 16:32:30 +0200 Subject: [PATCH 078/165] Flush symbol tables in jit.dump on trace flush. --- src/jit/dump.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jit/dump.lua b/src/jit/dump.lua index d15c528e..e6ea18a8 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua @@ -564,6 +564,7 @@ local function dump_trace(what, tr, func, pc, otr, oex) end if dumpmode.H then out:write("\n\n") else out:write("\n") end else + if what == "flush" then symtab, nexitsym = {}, 0 end out:write("---- TRACE ", what, "\n\n") end out:flush() From 4808e62a9a05fef36854a05e09f791148de1ad74 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 15 Oct 2015 02:28:04 +0200 Subject: [PATCH 079/165] Drop marks from replayed instructions when sinking. Reported by Vyacheslav Egorov. --- src/lj_snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_snap.c b/src/lj_snap.c index ea46b831..50412bc4 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -515,7 +515,7 @@ void lj_snap_replay(jit_State *J, GCtrace *T) op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2, snap_pref(J, T, map, nent, seen, (ir+1)->op2)); } - J->slot[snap_slot(sn)] = emitir(ir->ot, op1, op2); + J->slot[snap_slot(sn)] = emitir(ir->ot & ~(IRT_MARK|IRT_ISPHI), op1, op2); } else { IRIns *irs; TRef tr = emitir(ir->ot, op1, op2); From e5f4cb1ccb3bfef5d40a2329d6aa36c1ba74a709 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 17:59:44 +0200 Subject: [PATCH 080/165] FFI: Fix ipairs() recording. Thanks to Vyacheslav Egorov. --- src/lj_ffrecord.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 69f71ab2..30832251 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -366,11 +366,12 @@ static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd) static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd) { - if (!(LJ_52 && recff_metacall(J, rd, MM_ipairs))) { - TRef tab = J->base[0]; - if (tref_istab(tab)) { + TRef tr = J->base[0]; + if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) && + recff_metacall(J, rd, MM_ipairs))) { + if (tref_istab(tr)) { J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0])); - J->base[1] = tab; + J->base[1] = tr; J->base[2] = lj_ir_kint(J, 0); rd->nres = 3; } /* else: Interpreter will throw. */ From 9dc785e0af2d25fc56dda69b69742e45ed0694ef Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 18:12:40 +0200 Subject: [PATCH 081/165] DynASM/x86: Fix some SSE instruction templates. Thanks to Peter Cawley. --- dynasm/dasm_x86.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua index 7ca061d2..0b1668f5 100644 --- a/dynasm/dasm_x86.lua +++ b/dynasm/dasm_x86.lua @@ -1190,7 +1190,7 @@ local map_op = { cvtsi2sd_2 = "rm/od:F20F2ArM|rm/oq:F20F2ArXM", cvtsi2ss_2 = "rm/od:F30F2ArM|rm/oq:F30F2ArXM", cvtss2sd_2 = "rro:F30F5ArM|rx/od:", - cvtss2si_2 = "rr/do:F20F2CrM|rr/qo:|rxd:|rx/qd:", + cvtss2si_2 = "rr/do:F30F2DrM|rr/qo:|rxd:|rx/qd:", cvttpd2dq_2 = "rmo:660FE6rM", cvttps2dq_2 = "rmo:F30F5BrM", cvttsd2si_2 = "rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:", @@ -1247,7 +1247,7 @@ local map_op = { pcmpgtb_2 = "rmo:660F64rM", pcmpgtd_2 = "rmo:660F66rM", pcmpgtw_2 = "rmo:660F65rM", - pextrw_3 = "rri/do:660FC5rMU|xri/wo:660F3A15nrMU", -- Mem op: SSE4.1 only. + pextrw_3 = "rri/do:660FC5rMU|xri/wo:660F3A15nRmU", -- Mem op: SSE4.1 only. pinsrw_3 = "rri/od:660FC4rMU|rxi/ow:", pmaddwd_2 = "rmo:660FF5rM", pmaxsw_2 = "rmo:660FEErM", @@ -1352,7 +1352,7 @@ local map_op = { dpps_3 = "rmio:660F3A40rMU", extractps_3 = "mri/do:660F3A17RmU|rri/qo:660F3A17RXmU", insertps_3 = "rrio:660F3A41rMU|rxi/od:", - movntdqa_2 = "rmo:660F382ArM", + movntdqa_2 = "rxo:660F382ArM", mpsadbw_3 = "rmio:660F3A42rMU", packusdw_2 = "rmo:660F382BrM", pblendvb_3 = "rmRo:660F3810rM", From 7579b161af49b379f3ac071d309bcde69aba7810 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 18:15:44 +0200 Subject: [PATCH 082/165] DynASM/x86: Restrict shld/shrd to operands with same width. Thanks to Peter Cawley. --- dynasm/dasm_x86.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua index 0b1668f5..8f4228d4 100644 --- a/dynasm/dasm_x86.lua +++ b/dynasm/dasm_x86.lua @@ -1081,8 +1081,8 @@ 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", + shld_3 = "mriqdw:0FA4RmU|mrC/qq:0FA5Rm|mrC/dd:|mrC/ww:", + shrd_3 = "mriqdw:0FACRmU|mrC/qq:0FADRm|mrC/dd:|mrC/ww:", rdtsc_0 = "0F31", -- P1+ cpuid_0 = "0FA2", -- P1+ From 3639ff41420610969f44eceebac11253ff7c8025 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 19:02:15 +0200 Subject: [PATCH 083/165] iOS: Disable os.execute() when building for iOS >= 8.0. Thanks to Vyacheslav Egorov. --- src/lib_os.c | 2 +- src/lj_arch.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib_os.c b/src/lib_os.c index bb5a141e..762bb591 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -36,7 +36,7 @@ LJLIB_CF(os_execute) { -#if LJ_TARGET_CONSOLE +#if LJ_NO_SYSTEM #if LJ_52 errno = ENOSYS; return luaL_fileresult(L, 0, NULL); diff --git a/src/lj_arch.h b/src/lj_arch.h index 9a6d4305..f1a1160f 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -426,6 +426,9 @@ #if defined(__symbian__) #define LUAJIT_NO_EXP2 #endif +#if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0) +#define LJ_NO_SYSTEM 1 +#endif #if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 #define LJ_NO_UNWIND 1 From f416cf6a6439782e4ae7c4b29387d4564bb765db Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 19:10:40 +0200 Subject: [PATCH 084/165] OSX: Switch to Clang as the default compiler. --- src/Makefile | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5021e479..9c95c4ce 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,11 +24,13 @@ NODOTABIVER= 51 # removing the '#' in front of them. Make sure you force a full recompile # with "make clean", followed by "make" if you change any options. # +DEFAULT_CC = gcc +# # LuaJIT builds as a native 32 or 64 bit binary by default. -CC= gcc +CC= $(DEFAULT_CC) # # Use this if you want to force a 32 bit build on a 64 bit multilib OS. -#CC= gcc -m32 +#CC= $(DEFAULT_CC) -m32 # # Since the assembler part does NOT maintain a frame pointer, it's pointless # to slow down the C part by not omitting it. Debugging, tracebacks and @@ -150,6 +152,29 @@ XCFLAGS= # You probably don't need to change anything below this line! ############################################################################## +############################################################################## +# Host system detection. +############################################################################## + +ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM)) + HOST_SYS= Windows + HOST_RM= del +else + HOST_SYS:= $(shell uname -s) + ifneq (,$(findstring MINGW,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= mingw + endif + ifneq (,$(findstring CYGWIN,$(HOST_SYS))) + HOST_SYS= Windows + HOST_MSYS= cygwin + endif + # Use Clang for OSX host. + ifeq (Darwin,$(HOST_SYS)) + DEFAULT_CC= clang + endif +endif + ############################################################################## # Flags and options for host and target. ############################################################################## @@ -263,24 +288,9 @@ ifneq (,$(LMULTILIB)) endif ############################################################################## -# System detection. +# Target system detection. ############################################################################## -ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM)) - HOST_SYS= Windows - HOST_RM= del -else - HOST_SYS:= $(shell uname -s) - ifneq (,$(findstring MINGW,$(HOST_SYS))) - HOST_SYS= Windows - HOST_MSYS= mingw - endif - ifneq (,$(findstring CYGWIN,$(HOST_SYS))) - HOST_SYS= Windows - HOST_MSYS= cygwin - endif -endif - TARGET_SYS?= $(HOST_SYS) ifeq (Windows,$(TARGET_SYS)) TARGET_STRIP+= --strip-unneeded From 1393b2f681df3a71cb381b958e8e3221d2dd427d Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 24 Oct 2015 19:20:33 +0200 Subject: [PATCH 085/165] Update build instructions. --- doc/install.html | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/doc/install.html b/doc/install.html index 7a878b1c..5dc1289e 100644 --- a/doc/install.html +++ b/doc/install.html @@ -112,23 +112,23 @@

Installation

- - - + + + - + - + - + @@ -439,8 +439,7 @@

Cross-compiling LuaJIT

make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"

-You can cross-compile for iOS 3.0+ (iPhone/iPad) using the » iOS SDK. -The environment variables need to match the iOS SDK version: +You can cross-compile for iOS 3.0+ (iPhone/iPad) using the » iOS SDK:

Note: the JIT compiler is disabled for iOS, because regular iOS Apps @@ -450,13 +449,11 @@

Cross-compiling LuaJIT

Or use Android. :-p

-IXCODE=`xcode-select -print-path`
-ISDK=$IXCODE/Platforms/iPhoneOS.platform/Developer
-ISDKVER=iPhoneOS6.0.sdk
-ISDKP=$ISDK/usr/bin/
-ISDKF="-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER"
-make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \
-     TARGET_SYS=iOS
+ISDKP=$(xcrun --sdk iphoneos --show-sdk-path)
+ICC=$(xcrun --sdk iphoneos --find clang)
+ISDKF="-arch armv7 -isysroot $ISDKP"
+make HOST_CC="clang -m32 -arch i386" CROSS="$(dirname $ICC)/" \
+     TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS
 

Cross-compiling for consoles

From 7991a669ddf90636f4d768f312e7b73646a65182 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 4 Nov 2015 14:01:37 +0100 Subject: [PATCH 086/165] Extend Valgrind suppressions for non-inlined C code. Thanks to Dennis Schridde. --- src/lj.supp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lj.supp b/src/lj.supp index 411f2617..acb9e789 100644 --- a/src/lj.supp +++ b/src/lj.supp @@ -24,3 +24,18 @@ Memcheck:Cond fun:lj_str_new } +{ + Optimized string compare + Memcheck:Addr4 + fun:lj_str_fastcmp +} +{ + Optimized string compare + Memcheck:Addr1 + fun:lj_str_fastcmp +} +{ + Optimized string compare + Memcheck:Cond + fun:lj_str_fastcmp +} From 367cba29ea03aa758eb041c3a0c5f1c7616f9a0a Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 4 Nov 2015 14:04:19 +0100 Subject: [PATCH 087/165] DynASM/x86: Add rdpmc instruction. Thanks to Cosmin Apreutesei. --- dynasm/dasm_x86.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua index 8f4228d4..3a535f2f 100644 --- a/dynasm/dasm_x86.lua +++ b/dynasm/dasm_x86.lua @@ -1085,6 +1085,7 @@ local map_op = { shrd_3 = "mriqdw:0FACRmU|mrC/qq:0FADRm|mrC/dd:|mrC/ww:", rdtsc_0 = "0F31", -- P1+ + rdpmc_0 = "0F33", -- P6+ cpuid_0 = "0FA2", -- P1+ -- floating point ops From 3d4c9f96391b38fc02536bd4147545f08ae7c1e9 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 26 Nov 2015 22:25:13 +0100 Subject: [PATCH 088/165] FFI: Fix SPLIT pass for CONV i64.u64. Thanks to Vyacheslav Egorov. --- src/lj_opt_split.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c index 1cee5093..4a1b0a6e 100644 --- a/src/lj_opt_split.c +++ b/src/lj_opt_split.c @@ -471,7 +471,8 @@ static void split_ir(jit_State *J) } #endif else if (st == IRT_I64 || st == IRT_U64) { /* 64/64 bit cast. */ - /* Drop cast, since assembler doesn't care. */ + /* Drop cast, since assembler doesn't care. But fwd both parts. */ + hi = hiref; goto fwdlo; } else if ((ir->op2 & IRCONV_SEXT)) { /* Sign-extend to 64 bit. */ IRRef k31 = lj_ir_kint(J, 31); From a44388967763d0f7f5f78dfd71703437afa69fc0 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 10 Feb 2016 18:51:02 +0100 Subject: [PATCH 089/165] Don't allocate unused 2nd result register in JIT compiler backend. --- src/lj_asm_arm.h | 2 +- src/lj_asm_mips.h | 2 +- src/lj_asm_ppc.h | 2 +- src/lj_asm_x86.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h index 9e4cf436..ba65f45b 100644 --- a/src/lj_asm_arm.h +++ b/src/lj_asm_arm.h @@ -426,7 +426,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) { RegSet drop = RSET_SCRATCH; - int hiop = ((ir+1)->o == IR_HIOP); + int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t)); if (ra_hasreg(ir->r)) rset_clear(drop, ir->r); /* Dest reg handled below. */ if (hiop && ra_hasreg((ir+1)->r)) diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h index 78bd26d5..8cdd913b 100644 --- a/src/lj_asm_mips.h +++ b/src/lj_asm_mips.h @@ -291,7 +291,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) { RegSet drop = RSET_SCRATCH; - int hiop = ((ir+1)->o == IR_HIOP); + int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t)); if ((ci->flags & CCI_NOFPRCLOBBER)) drop &= ~RSET_FPR; if (ra_hasreg(ir->r)) diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h index 2c5d74a8..e6129032 100644 --- a/src/lj_asm_ppc.h +++ b/src/lj_asm_ppc.h @@ -298,7 +298,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) { RegSet drop = RSET_SCRATCH; - int hiop = ((ir+1)->o == IR_HIOP); + int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t)); if ((ci->flags & CCI_NOFPRCLOBBER)) drop &= ~RSET_FPR; if (ra_hasreg(ir->r)) diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index 0b6b2d4a..a79be4e6 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -531,7 +531,7 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci) { RegSet drop = RSET_SCRATCH; - int hiop = (LJ_32 && (ir+1)->o == IR_HIOP); + int hiop = (LJ_32 && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t)); if ((ci->flags & CCI_NOFPRCLOBBER)) drop &= ~RSET_FPR; if (ra_hasreg(ir->r)) From db1b399af134e715b8ba9a0e4ad9cbafbe06ecb1 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 3 Mar 2016 12:02:22 +0100 Subject: [PATCH 090/165] Bump copyright date to 2016. --- COPYRIGHT | 2 +- Makefile | 2 +- README | 2 +- doc/bluequad-print.css | 2 +- doc/bluequad.css | 2 +- doc/changes.html | 4 ++-- doc/contact.html | 6 +++--- doc/ext_c_api.html | 4 ++-- doc/ext_ffi.html | 4 ++-- doc/ext_ffi_api.html | 4 ++-- doc/ext_ffi_semantics.html | 4 ++-- doc/ext_ffi_tutorial.html | 4 ++-- doc/ext_jit.html | 4 ++-- doc/extensions.html | 4 ++-- doc/faq.html | 4 ++-- doc/install.html | 4 ++-- doc/luajit.html | 6 +++--- doc/running.html | 4 ++-- doc/status.html | 4 ++-- dynasm/dasm_arm.h | 2 +- dynasm/dasm_arm.lua | 2 +- dynasm/dasm_mips.h | 2 +- dynasm/dasm_mips.lua | 2 +- dynasm/dasm_ppc.h | 2 +- dynasm/dasm_ppc.lua | 2 +- dynasm/dasm_proto.h | 2 +- dynasm/dasm_x64.lua | 2 +- dynasm/dasm_x86.h | 2 +- dynasm/dasm_x86.lua | 2 +- dynasm/dynasm.lua | 4 ++-- etc/luajit.1 | 2 +- src/Makefile | 2 +- src/host/buildvm.c | 2 +- src/host/buildvm.h | 2 +- src/host/buildvm_asm.c | 2 +- src/host/buildvm_fold.c | 2 +- src/host/buildvm_lib.c | 2 +- src/host/buildvm_peobj.c | 2 +- src/host/genminilua.lua | 2 +- src/jit/bc.lua | 2 +- src/jit/bcsave.lua | 2 +- src/jit/dis_arm.lua | 2 +- src/jit/dis_mips.lua | 2 +- src/jit/dis_mipsel.lua | 2 +- src/jit/dis_ppc.lua | 2 +- src/jit/dis_x64.lua | 2 +- src/jit/dis_x86.lua | 2 +- src/jit/dump.lua | 2 +- src/jit/v.lua | 2 +- src/lib_aux.c | 2 +- src/lib_base.c | 2 +- src/lib_bit.c | 2 +- src/lib_debug.c | 2 +- src/lib_ffi.c | 2 +- src/lib_init.c | 2 +- src/lib_io.c | 2 +- src/lib_jit.c | 2 +- src/lib_math.c | 2 +- src/lib_os.c | 2 +- src/lib_package.c | 2 +- src/lib_string.c | 2 +- src/lib_table.c | 2 +- src/lj_api.c | 2 +- src/lj_arch.h | 2 +- src/lj_asm.c | 2 +- src/lj_asm.h | 2 +- src/lj_asm_arm.h | 2 +- src/lj_asm_mips.h | 2 +- src/lj_asm_ppc.h | 2 +- src/lj_asm_x86.h | 2 +- src/lj_bc.c | 2 +- src/lj_bc.h | 2 +- src/lj_bcdump.h | 2 +- src/lj_bcread.c | 2 +- src/lj_bcwrite.c | 2 +- src/lj_carith.c | 2 +- src/lj_carith.h | 2 +- src/lj_ccall.c | 2 +- src/lj_ccall.h | 2 +- src/lj_ccallback.c | 2 +- src/lj_ccallback.h | 2 +- src/lj_cconv.c | 2 +- src/lj_cconv.h | 2 +- src/lj_cdata.c | 2 +- src/lj_cdata.h | 2 +- src/lj_clib.c | 2 +- src/lj_clib.h | 2 +- src/lj_cparse.c | 2 +- src/lj_cparse.h | 2 +- src/lj_crecord.c | 2 +- src/lj_crecord.h | 2 +- src/lj_ctype.c | 2 +- src/lj_ctype.h | 2 +- src/lj_debug.c | 2 +- src/lj_debug.h | 2 +- src/lj_def.h | 2 +- src/lj_dispatch.c | 2 +- src/lj_dispatch.h | 2 +- src/lj_emit_arm.h | 2 +- src/lj_emit_mips.h | 2 +- src/lj_emit_ppc.h | 2 +- src/lj_emit_x86.h | 2 +- src/lj_err.c | 2 +- src/lj_err.h | 2 +- src/lj_errmsg.h | 2 +- src/lj_ff.h | 2 +- src/lj_ffrecord.c | 2 +- src/lj_ffrecord.h | 2 +- src/lj_frame.h | 2 +- src/lj_func.c | 2 +- src/lj_func.h | 2 +- src/lj_gc.c | 2 +- src/lj_gc.h | 2 +- src/lj_gdbjit.c | 2 +- src/lj_gdbjit.h | 2 +- src/lj_ir.c | 2 +- src/lj_ir.h | 2 +- src/lj_ircall.h | 2 +- src/lj_iropt.h | 2 +- src/lj_jit.h | 2 +- src/lj_lex.c | 2 +- src/lj_lex.h | 2 +- src/lj_lib.c | 2 +- src/lj_lib.h | 2 +- src/lj_load.c | 2 +- src/lj_mcode.c | 2 +- src/lj_mcode.h | 2 +- src/lj_meta.c | 2 +- src/lj_meta.h | 2 +- src/lj_obj.c | 2 +- src/lj_obj.h | 2 +- src/lj_opt_dce.c | 2 +- src/lj_opt_fold.c | 2 +- src/lj_opt_loop.c | 2 +- src/lj_opt_mem.c | 2 +- src/lj_opt_narrow.c | 5 ++--- src/lj_opt_sink.c | 2 +- src/lj_opt_split.c | 2 +- src/lj_parse.c | 2 +- src/lj_parse.h | 2 +- src/lj_record.c | 2 +- src/lj_record.h | 2 +- src/lj_snap.c | 2 +- src/lj_snap.h | 2 +- src/lj_state.c | 2 +- src/lj_state.h | 2 +- src/lj_str.c | 2 +- src/lj_str.h | 2 +- src/lj_strscan.c | 2 +- src/lj_strscan.h | 2 +- src/lj_tab.c | 2 +- src/lj_tab.h | 2 +- src/lj_target.h | 2 +- src/lj_target_arm.h | 2 +- src/lj_target_mips.h | 2 +- src/lj_target_ppc.h | 2 +- src/lj_target_x86.h | 2 +- src/lj_trace.c | 2 +- src/lj_trace.h | 2 +- src/lj_traceerr.h | 2 +- src/lj_udata.c | 2 +- src/lj_udata.h | 2 +- src/lj_vm.h | 2 +- src/lj_vmevent.c | 2 +- src/lj_vmevent.h | 2 +- src/lj_vmmath.c | 2 +- src/ljamalg.c | 2 +- src/luaconf.h | 2 +- src/luajit.c | 2 +- src/luajit.h | 4 ++-- src/lualib.h | 2 +- src/msvcbuild.bat | 2 +- src/vm_arm.dasc | 2 +- src/vm_mips.dasc | 2 +- src/vm_ppc.dasc | 2 +- src/vm_ppcspe.dasc | 2 +- src/vm_x86.dasc | 2 +- 177 files changed, 196 insertions(+), 197 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 1ef7df62..b614d3eb 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,7 +1,7 @@ =============================================================================== LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ -Copyright (C) 2005-2015 Mike Pall. All rights reserved. +Copyright (C) 2005-2016 Mike Pall. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 0cbe741a..d5b7d723 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # For MSVC, please follow the instructions given in src/msvcbuild.bat. # For MinGW and Cygwin, cd to src and run make with the Makefile there. # -# Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h +# Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h ############################################################################## MAJVER= 2 diff --git a/README b/README index 44366af5..e5bb1c62 100644 --- a/README +++ b/README @@ -5,7 +5,7 @@ LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. Project Homepage: http://luajit.org/ -LuaJIT is Copyright (C) 2005-2015 Mike Pall. +LuaJIT is Copyright (C) 2005-2016 Mike Pall. LuaJIT is free software, released under the MIT license. See full Copyright Notice in the COPYRIGHT file or in luajit.h. diff --git a/doc/bluequad-print.css b/doc/bluequad-print.css index 07f5c84a..975a55bf 100644 --- a/doc/bluequad-print.css +++ b/doc/bluequad-print.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2015 Mike Pall. +/* Copyright (C) 2004-2016 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/doc/bluequad.css b/doc/bluequad.css index ae531430..5dca9064 100644 --- a/doc/bluequad.css +++ b/doc/bluequad.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2015 Mike Pall. +/* Copyright (C) 2004-2016 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/doc/changes.html b/doc/changes.html index d7b83ce6..96eef660 100644 --- a/doc/changes.html +++ b/doc/changes.html @@ -4,7 +4,7 @@ LuaJIT Change History - + @@ -968,7 +968,7 @@

LuaJIT 1.0.0 — 2005-08-29

GCCCLANG
LLVM
MSVC
x86 (32 bit)GCC 4.x
GCC 3.4
GCC 4.x
GCC 3.4
GCC 4.x
GCC 3.4
GCC 4.x+
GCC 3.4
GCC 4.x+
GCC 3.4
XCode 5.0+
Clang
MSVC, MSVC/EE
WinSDK
MinGW, Cygwin
x64 (64 bit)GCC 4.xGCC 4.x+ ORBIS (PS4)GCC 4.xXCode 5.0+
Clang
MSVC + SDK v7.0
WinSDK v7.0
ARMv5+
ARM9E+
GCC 4.2+ GCC 4.2+
PSP2 (PS VITA)
GCC 4.2+XCode 5.0+
Clang