From f587c9d0a8750d59d9272efb534994b24572e6c8 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Mon, 30 Jan 2023 20:58:40 +0800 Subject: [PATCH] Update LuaJIT to LuaJIT/LuaJIT@d0e8893 --- CMakeLists.txt | 2 +- libs/LuaJIT/doc/contact.html | 9 +++++++-- libs/LuaJIT/doc/ext_buffer.html | 2 -- libs/LuaJIT/doc/ext_c_api.html | 2 -- libs/LuaJIT/doc/ext_ffi.html | 2 -- libs/LuaJIT/doc/ext_ffi_api.html | 2 -- libs/LuaJIT/doc/ext_ffi_semantics.html | 2 -- libs/LuaJIT/doc/ext_ffi_tutorial.html | 2 -- libs/LuaJIT/doc/ext_jit.html | 2 -- libs/LuaJIT/doc/ext_profiler.html | 2 -- libs/LuaJIT/doc/extensions.html | 2 -- libs/LuaJIT/doc/faq.html | 4 ---- libs/LuaJIT/doc/install.html | 2 -- libs/LuaJIT/doc/luajit.html | 2 -- libs/LuaJIT/doc/running.html | 10 ++++++++-- libs/LuaJIT/doc/status.html | 2 -- libs/LuaJIT/src/lib_base.c | 2 +- libs/LuaJIT/src/lib_bit.c | 3 ++- libs/LuaJIT/src/lib_buffer.c | 8 ++++---- libs/LuaJIT/src/lj_arch.h | 9 +++++++++ libs/LuaJIT/src/lj_asm_arm.h | 6 +++++- libs/LuaJIT/src/lj_asm_arm64.h | 5 +++-- libs/LuaJIT/src/lj_asm_mips.h | 2 +- libs/LuaJIT/src/lj_asm_ppc.h | 3 ++- libs/LuaJIT/src/lj_carith.c | 2 +- libs/LuaJIT/src/lj_cparse.c | 2 +- libs/LuaJIT/src/lj_crecord.c | 7 ++++++- libs/LuaJIT/src/lj_ctype.c | 14 +++++++++++++- libs/LuaJIT/src/lj_debug.c | 9 ++++++--- libs/LuaJIT/src/lj_emit_arm.h | 2 +- libs/LuaJIT/src/lj_emit_arm64.h | 9 +++++---- libs/LuaJIT/src/lj_err.c | 5 +++-- libs/LuaJIT/src/lj_ffrecord.c | 4 ++-- libs/LuaJIT/src/lj_jit.h | 4 +++- libs/LuaJIT/src/lj_obj.h | 2 +- libs/LuaJIT/src/lj_opt_fold.c | 6 +++--- libs/LuaJIT/src/lj_parse.c | 12 ++++++------ libs/LuaJIT/src/lj_prng.c | 2 +- libs/LuaJIT/src/lj_profile.c | 4 ++++ libs/LuaJIT/src/lj_record.c | 9 +++++---- libs/LuaJIT/src/lj_strfmt.c | 4 ++-- libs/LuaJIT/src/lj_strscan.c | 26 +++++++++++++------------- libs/LuaJIT/src/lj_vmmath.c | 19 +++++++++++++++---- libs/LuaJIT/src/nxbuild.bat | 1 + libs/LuaJIT/src/ps4build.bat | 4 ++-- libs/LuaJIT/src/ps5build.bat | 4 ++-- libs/LuaJIT/src/vm_arm64.dasc | 4 +++- 47 files changed, 142 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 534d8696..e01cfd42 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,7 +167,7 @@ endif() set(MEGA_ZLIB_VER "1.2.12") set(MEGA_LUA51_VER "5.1.5") -set(MEGA_LUAJIT_VER "2.1.0-7306ba7") +set(MEGA_LUAJIT_VER "2.1.0-d0e8893") set(MEGA_LIBOGG_VER "1.3.2") set(MEGA_LIBVORBIS_VER "1.3.5") set(MEGA_LIBTHEORA_VER "1.1.1") diff --git a/libs/LuaJIT/doc/contact.html b/libs/LuaJIT/doc/contact.html index 89c1af95..6d609286 100644 --- a/libs/LuaJIT/doc/contact.html +++ b/libs/LuaJIT/doc/contact.html @@ -50,8 +50,6 @@
  • FAQ
  • -Wiki » -
  • Mailing List »
  • @@ -86,6 +84,13 @@ xD("fyZKB8xv\"FJytmz8.KAB0u52D")

    +

    +Note: I cannot reply to GMail, Google Workplace, Outlook or Office365 +mail addresses, since they prefer to mindlessly filter out mails sent +from small domains using independent mail servers, such as mine. If you +don't like that, please complain to Google or Microsoft, not me. +

    +

    Copyright

    All documentation is diff --git a/libs/LuaJIT/doc/ext_buffer.html b/libs/LuaJIT/doc/ext_buffer.html index 192110a7..2a82aa97 100644 --- a/libs/LuaJIT/doc/ext_buffer.html +++ b/libs/LuaJIT/doc/ext_buffer.html @@ -61,8 +61,6 @@

  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_c_api.html b/libs/LuaJIT/doc/ext_c_api.html index 21dc1310..151d20b5 100644 --- a/libs/LuaJIT/doc/ext_c_api.html +++ b/libs/LuaJIT/doc/ext_c_api.html @@ -50,8 +50,6 @@
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_ffi.html b/libs/LuaJIT/doc/ext_ffi.html index b39ae314..5f1e2d7c 100644 --- a/libs/LuaJIT/doc/ext_ffi.html +++ b/libs/LuaJIT/doc/ext_ffi.html @@ -50,8 +50,6 @@
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_ffi_api.html b/libs/LuaJIT/doc/ext_ffi_api.html index b8da1c95..89ddb0d9 100644 --- a/libs/LuaJIT/doc/ext_ffi_api.html +++ b/libs/LuaJIT/doc/ext_ffi_api.html @@ -55,8 +55,6 @@ td.abiparam { font-weight: bold; width: 6em; }
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_ffi_semantics.html b/libs/LuaJIT/doc/ext_ffi_semantics.html index 22f7f17c..603f9950 100644 --- a/libs/LuaJIT/doc/ext_ffi_semantics.html +++ b/libs/LuaJIT/doc/ext_ffi_semantics.html @@ -55,8 +55,6 @@ td.convop { font-style: italic; width: 40%; }
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_ffi_tutorial.html b/libs/LuaJIT/doc/ext_ffi_tutorial.html index e0bf9040..ff0c3a9a 100644 --- a/libs/LuaJIT/doc/ext_ffi_tutorial.html +++ b/libs/LuaJIT/doc/ext_ffi_tutorial.html @@ -57,8 +57,6 @@ td.idiomlua b { font-weight: normal; color: #2142bf; }
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_jit.html b/libs/LuaJIT/doc/ext_jit.html index b8a25967..3ff5c05e 100644 --- a/libs/LuaJIT/doc/ext_jit.html +++ b/libs/LuaJIT/doc/ext_jit.html @@ -50,8 +50,6 @@
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/ext_profiler.html b/libs/LuaJIT/doc/ext_profiler.html index b645a204..d6e26efd 100644 --- a/libs/LuaJIT/doc/ext_profiler.html +++ b/libs/LuaJIT/doc/ext_profiler.html @@ -50,8 +50,6 @@
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/extensions.html b/libs/LuaJIT/doc/extensions.html index 040fc588..f006a6db 100644 --- a/libs/LuaJIT/doc/extensions.html +++ b/libs/LuaJIT/doc/extensions.html @@ -67,8 +67,6 @@ td.excinterop {
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/faq.html b/libs/LuaJIT/doc/faq.html index 9effeb16..c07fd248 100644 --- a/libs/LuaJIT/doc/faq.html +++ b/libs/LuaJIT/doc/faq.html @@ -53,8 +53,6 @@ dd { margin-left: 1.5em; }
  • FAQ
  • -Wiki » -
  • Mailing List »
  • @@ -65,8 +63,6 @@ dd { margin-left: 1.5em; } diff --git a/libs/LuaJIT/doc/luajit.html b/libs/LuaJIT/doc/luajit.html index 03a29528..e3a5478d 100644 --- a/libs/LuaJIT/doc/luajit.html +++ b/libs/LuaJIT/doc/luajit.html @@ -135,8 +135,6 @@ table.feature small {
  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/doc/running.html b/libs/LuaJIT/doc/running.html index 91a719f9..edc049fb 100644 --- a/libs/LuaJIT/doc/running.html +++ b/libs/LuaJIT/doc/running.html @@ -72,8 +72,6 @@ td.param_default {
  • FAQ
  • -Wiki » -
  • Mailing List »
  • @@ -222,6 +220,12 @@ mix the three forms, but note that setting an optimization level overrides all earlier flags.

    +Note that -Ofma is not enabled by default at any level, +because it affects floating-point result accuracy. Only enable this, +if you fully understand the trade-offs of FMA for performance (higher), +determinism (lower) and numerical accuracy (higher). +

    +

    Here are the available flags and at what optimization levels they are enabled:

    @@ -253,6 +257,8 @@ are enabled: sink  •Allocation/Store Sinking fuse  •Fusion of operands into instructions + +fma    Fused multiply-add

    Here are the parameters and their default settings: diff --git a/libs/LuaJIT/doc/status.html b/libs/LuaJIT/doc/status.html index 1c86c103..efb1e064 100644 --- a/libs/LuaJIT/doc/status.html +++ b/libs/LuaJIT/doc/status.html @@ -53,8 +53,6 @@ ul li { padding-bottom: 0.3em; }

  • FAQ
  • -Wiki » -
  • Mailing List »
  • diff --git a/libs/LuaJIT/src/lib_base.c b/libs/LuaJIT/src/lib_base.c index 98ec67c7..c59d54a2 100644 --- a/libs/LuaJIT/src/lib_base.c +++ b/libs/LuaJIT/src/lib_base.c @@ -303,7 +303,7 @@ LJLIB_ASM(tonumber) LJLIB_REC(.) while (lj_char_isspace((unsigned char)(*ep))) ep++; if (*ep == '\0') { if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u+neg)) { - if (neg) ul = (unsigned long)-(long)ul; + if (neg) ul = ~ul+1u; setintV(L->base-1-LJ_FR2, (int32_t)ul); } else { lua_Number n = (lua_Number)ul; diff --git a/libs/LuaJIT/src/lib_bit.c b/libs/LuaJIT/src/lib_bit.c index 38c0f578..e08cd883 100644 --- a/libs/LuaJIT/src/lib_bit.c +++ b/libs/LuaJIT/src/lib_bit.c @@ -155,7 +155,8 @@ LJLIB_CF(bit_tohex) LJLIB_REC(.) #endif SBuf *sb = lj_buf_tmp_(L); SFormat sf = (STRFMT_UINT|STRFMT_T_HEX); - if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; } + if (n < 0) { n = (int32_t)(~(uint32_t)n+1u); sf |= STRFMT_F_UPPER; } + if ((uint32_t)n > 254) n = 254; sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC); #if LJ_HASFFI if (n < 16) b &= ((uint64_t)1 << 4*n)-1; diff --git a/libs/LuaJIT/src/lib_buffer.c b/libs/LuaJIT/src/lib_buffer.c index aad8e7eb..d6ff1346 100644 --- a/libs/LuaJIT/src/lib_buffer.c +++ b/libs/LuaJIT/src/lib_buffer.c @@ -128,7 +128,7 @@ LJLIB_CF(buffer_method_put) LJLIB_REC(.) lj_strfmt_putfnum((SBuf *)sbx, STRFMT_G14, numV(o)); } else if (tvisbuf(o)) { SBufExt *sbx2 = bufV(o); - if (sbx2 == sbx) lj_err_arg(L, arg+1, LJ_ERR_BUFFER_SELF); + if (sbx2 == sbx) lj_err_arg(L, (int)(arg+1), LJ_ERR_BUFFER_SELF); lj_buf_putmem((SBuf *)sbx, sbx2->r, sbufxlen(sbx2)); } else if (!mo && !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { /* Call __tostring metamethod inline. */ @@ -140,7 +140,7 @@ LJLIB_CF(buffer_method_put) LJLIB_REC(.) L->top = L->base + narg; goto retry; /* Retry with the result. */ } else { - lj_err_argtype(L, arg+1, "string/number/__tostring"); + lj_err_argtype(L, (int)(arg+1), "string/number/__tostring"); } /* Probably not useful to inline other __tostring MMs, e.g. FFI numbers. */ } @@ -169,7 +169,7 @@ LJLIB_CF(buffer_method_get) LJLIB_REC(.) for (arg = 1; arg < narg; arg++) { TValue *o = &L->base[arg]; MSize n = tvisnil(o) ? LJ_MAX_BUF : - (MSize) lj_lib_checkintrange(L, arg+1, 0, LJ_MAX_BUF); + (MSize) lj_lib_checkintrange(L, (int)(arg+1), 0, LJ_MAX_BUF); MSize len = sbufxlen(sbx); if (n > len) n = len; setstrV(L, o, lj_str_new(L, sbx->r, n)); @@ -177,7 +177,7 @@ LJLIB_CF(buffer_method_get) LJLIB_REC(.) } if (sbx->r == sbx->w && !sbufiscow(sbx)) sbx->r = sbx->w = sbx->b; lj_gc_check(L); - return narg-1; + return (int)(narg-1); } #if LJ_HASFFI diff --git a/libs/LuaJIT/src/lj_arch.h b/libs/LuaJIT/src/lj_arch.h index 882c99cb..bddd757d 100644 --- a/libs/LuaJIT/src/lj_arch.h +++ b/libs/LuaJIT/src/lj_arch.h @@ -93,6 +93,9 @@ #elif defined(__CYGWIN__) #define LJ_TARGET_CYGWIN 1 #define LUAJIT_OS LUAJIT_OS_POSIX +#elif defined(__QNX__) +#define LJ_TARGET_QNX 1 +#define LUAJIT_OS LUAJIT_OS_POSIX #else #define LUAJIT_OS LUAJIT_OS_OTHER #endif @@ -463,11 +466,17 @@ #endif #endif #elif !LJ_TARGET_PS3 +#if __clang__ +#if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)) +#error "Need at least Clang 3.5 or newer" +#endif +#else #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3) #error "Need at least GCC 4.3 or newer" #endif #endif #endif +#endif /* Check target-specific constraints. */ #ifndef _BUILDVM_H diff --git a/libs/LuaJIT/src/lj_asm_arm.h b/libs/LuaJIT/src/lj_asm_arm.h index 326330f4..ba6267ec 100644 --- a/libs/LuaJIT/src/lj_asm_arm.h +++ b/libs/LuaJIT/src/lj_asm_arm.h @@ -313,7 +313,11 @@ static void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref, } #if !LJ_SOFTFP -/* Fuse to multiply-add/sub instruction. */ +/* +** Fuse to multiply-add/sub instruction. +** VMLA rounds twice (UMA, not FMA) -- no need to check for JIT_F_OPT_FMA. +** VFMA needs VFPv4, which is uncommon on the remaining ARM32 targets. +*/ static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air) { IRRef lref = ir->op1, rref = ir->op2; diff --git a/libs/LuaJIT/src/lj_asm_arm64.h b/libs/LuaJIT/src/lj_asm_arm64.h index 1f44d023..805ea54b 100644 --- a/libs/LuaJIT/src/lj_asm_arm64.h +++ b/libs/LuaJIT/src/lj_asm_arm64.h @@ -337,7 +337,8 @@ static int asm_fusemadd(ASMState *as, IRIns *ir, A64Ins ai, A64Ins air) { IRRef lref = ir->op1, rref = ir->op2; IRIns *irm; - if (lref != rref && + if ((as->flags & JIT_F_OPT_FMA) && + lref != rref && ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && ra_noreg(irm->r)) || (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && @@ -1201,7 +1202,7 @@ dotypecheck: tmp = ra_scratch(as, allow); rset_clear(allow, tmp); } - if (irt_isnum(t) && !(ir->op2 & IRSLOAD_CONVERT)) + if (ra_hasreg(dest) && tmp != dest) emit_dn(as, A64I_FMOV_D_R, (dest & 31), tmp); /* Need type check, even if the load result is unused. */ asm_guardcc(as, irt_isnum(t) ? CC_LS : CC_NE); diff --git a/libs/LuaJIT/src/lj_asm_mips.h b/libs/LuaJIT/src/lj_asm_mips.h index 1686b40f..ac2d2662 100644 --- a/libs/LuaJIT/src/lj_asm_mips.h +++ b/libs/LuaJIT/src/lj_asm_mips.h @@ -1894,7 +1894,7 @@ static void asm_arithov(ASMState *as, IRIns *ir) lj_assertA(!irt_is64(ir->t), "bad usage"); if (irref_isk(ir->op2)) { int k = IR(ir->op2)->i; - if (ir->o == IR_SUBOV) k = -k; + if (ir->o == IR_SUBOV) k = (int)(~(unsigned int)k+1u); if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */ left = ra_alloc1(as, ir->op1, RSET_GPR); asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); diff --git a/libs/LuaJIT/src/lj_asm_ppc.h b/libs/LuaJIT/src/lj_asm_ppc.h index 546b8e5d..aa818745 100644 --- a/libs/LuaJIT/src/lj_asm_ppc.h +++ b/libs/LuaJIT/src/lj_asm_ppc.h @@ -235,7 +235,8 @@ static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir) { IRRef lref = ir->op1, rref = ir->op2; IRIns *irm; - if (lref != rref && + if ((as->flags & JIT_F_OPT_FMA) && + lref != rref && ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) && ra_noreg(irm->r)) || (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) && diff --git a/libs/LuaJIT/src/lj_carith.c b/libs/LuaJIT/src/lj_carith.c index 1a2a058f..2e8504a9 100644 --- a/libs/LuaJIT/src/lj_carith.c +++ b/libs/LuaJIT/src/lj_carith.c @@ -207,7 +207,7 @@ static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm) else *up = lj_carith_powu64(u0, u1); break; - case MM_unm: *up = (uint64_t)-(int64_t)u0; break; + case MM_unm: *up = ~u0+1u; break; default: lj_assertL(0, "bad metamethod %d", mm); break; diff --git a/libs/LuaJIT/src/lj_cparse.c b/libs/LuaJIT/src/lj_cparse.c index 7fd83997..126032d5 100644 --- a/libs/LuaJIT/src/lj_cparse.c +++ b/libs/LuaJIT/src/lj_cparse.c @@ -488,7 +488,7 @@ static void cp_expr_prefix(CPState *cp, CPValue *k) } else if (cp_opt(cp, '+')) { cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */ } else if (cp_opt(cp, '-')) { - cp_expr_unary(cp, k); k->i32 = -k->i32; + cp_expr_unary(cp, k); k->i32 = (int32_t)(~(uint32_t)k->i32+1); } else if (cp_opt(cp, '~')) { cp_expr_unary(cp, k); k->i32 = ~k->i32; } else if (cp_opt(cp, '!')) { diff --git a/libs/LuaJIT/src/lj_crecord.c b/libs/LuaJIT/src/lj_crecord.c index bc21d859..9c9b6ccb 100644 --- a/libs/LuaJIT/src/lj_crecord.c +++ b/libs/LuaJIT/src/lj_crecord.c @@ -1504,9 +1504,13 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct); goto ok; } else if (ctype_isfunc(ct->info)) { + CTypeID id0 = i ? ctype_typeid(cts, s[0]) : 0; tr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR); ct = ctype_get(cts, lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR)); + if (i) { + s[0] = ctype_get(cts, id0); /* cts->tab may have been reallocated. */ + } goto ok; } else { tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata))); @@ -1875,7 +1879,8 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr) } else { n = id ? 16 : 8; } - if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; } + if (n < 0) { n = (int32_t)(~n+1u); sf |= STRFMT_F_UPPER; } + if ((uint32_t)n > 254) n = 254; sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC); if (id) { tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]); diff --git a/libs/LuaJIT/src/lj_ctype.c b/libs/LuaJIT/src/lj_ctype.c index 204be034..73481e63 100644 --- a/libs/LuaJIT/src/lj_ctype.c +++ b/libs/LuaJIT/src/lj_ctype.c @@ -191,8 +191,20 @@ CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size) } id = cts->top; if (LJ_UNLIKELY(id >= cts->sizetab)) { +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR + CType *ct; +#endif if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV); +#ifdef LUAJIT_CTYPE_CHECK_ANCHOR + ct = lj_mem_newvec(cts->L, id+1, CType); + memcpy(ct, cts->tab, id*sizeof(CType)); + memset(cts->tab, 0, id*sizeof(CType)); + lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType); + cts->tab = ct; + cts->sizetab = id+1; +#else lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType); +#endif } cts->top = id+1; cts->tab[id].info = info; @@ -570,7 +582,7 @@ GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned) if (isunsigned) { *--p = 'U'; } else if ((int64_t)n < 0) { - n = (uint64_t)-(int64_t)n; + n = ~n+1u; sign = 1; } do { *--p = (char)('0' + n % 10); } while (n /= 10); diff --git a/libs/LuaJIT/src/lj_debug.c b/libs/LuaJIT/src/lj_debug.c index 112f5358..ca893153 100644 --- a/libs/LuaJIT/src/lj_debug.c +++ b/libs/LuaJIT/src/lj_debug.c @@ -101,9 +101,12 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) pos = proto_bcpos(pt, ins) - 1; #if LJ_HASJIT if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */ - GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); - lj_assertL(bc_isret(bc_op(ins[-1])), "return bytecode expected"); - pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + if (bc_isret(bc_op(ins[-1]))) { + GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); + pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); + } else { + pos = NO_BCPOS; /* Punt in case of stack overflow for stitched trace. */ + } } #endif return pos; diff --git a/libs/LuaJIT/src/lj_emit_arm.h b/libs/LuaJIT/src/lj_emit_arm.h index cfb174f4..0fd2aa05 100644 --- a/libs/LuaJIT/src/lj_emit_arm.h +++ b/libs/LuaJIT/src/lj_emit_arm.h @@ -157,7 +157,7 @@ static int emit_kdelta2(ASMState *as, Reg rd, int32_t i) if (other) { int32_t delta = i - other; uint32_t sh, inv = 0, k2, k; - if (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; } + if (delta < 0) { delta = (int32_t)(~(uint32_t)delta+1u); inv = ARMI_ADD^ARMI_SUB; } sh = lj_ffs(delta) & ~1; k2 = emit_isk12(0, delta & (255 << sh)); k = emit_isk12(0, delta & ~(255 << sh)); diff --git a/libs/LuaJIT/src/lj_emit_arm64.h b/libs/LuaJIT/src/lj_emit_arm64.h index c4b4c147..0ddba4a3 100644 --- a/libs/LuaJIT/src/lj_emit_arm64.h +++ b/libs/LuaJIT/src/lj_emit_arm64.h @@ -27,8 +27,8 @@ static uint64_t get_k64val(ASMState *as, IRRef ref) /* Encode constant in K12 format for data processing instructions. */ static uint32_t emit_isk12(int64_t n) { - uint64_t k = (n < 0) ? -n : n; - uint32_t m = (n < 0) ? 0x40000000 : 0; + uint64_t k = n < 0 ? ~(uint64_t)n+1u : (uint64_t)n; + uint32_t m = n < 0 ? 0x40000000 : 0; if (k < 0x1000) { return A64I_K12|m|A64F_U12(k); } else if ((k & 0xfff000) == k) { @@ -177,7 +177,7 @@ static int emit_kdelta(ASMState *as, Reg rd, uint64_t k, int lim) emit_dm(as, A64I_MOVx, rd, r); return 1; } else { - uint32_t k12 = emit_isk12(delta < 0 ? -delta : delta); + uint32_t k12 = emit_isk12(delta < 0 ? (int64_t)(~(uint64_t)delta+1u) : delta); if (k12) { emit_dn(as, (delta < 0 ? A64I_SUBx : A64I_ADDx)^k12, rd, r); return 1; @@ -417,7 +417,8 @@ static void emit_addptr(ASMState *as, Reg r, int32_t ofs) { if (ofs) emit_opk(as, ofs < 0 ? A64I_SUBx : A64I_ADDx, r, r, - ofs < 0 ? -ofs : ofs, rset_exclude(RSET_GPR, r)); + ofs < 0 ? (int32_t)(~(uint32_t)ofs+1u) : ofs, + rset_exclude(RSET_GPR, r)); } #define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs)) diff --git a/libs/LuaJIT/src/lj_err.c b/libs/LuaJIT/src/lj_err.c index 563c7706..a497ab11 100644 --- a/libs/LuaJIT/src/lj_err.c +++ b/libs/LuaJIT/src/lj_err.c @@ -329,12 +329,12 @@ static void err_unwind_win_jit(global_State *g, int errcode) memset(&hist, 0, sizeof(hist)); RtlCaptureContext(&ctx); while (1) { - uintptr_t frame, base, addr = ctx.CONTEXT_REG_PC; + DWORD64 frame, base, addr = ctx.CONTEXT_REG_PC; void *hdata; PRUNTIME_FUNCTION func = RtlLookupFunctionEntry(addr, &base, &hist); if (!func) { /* Found frame without .pdata: must be JIT-compiled code. */ ExitNo exitno; - uintptr_t stub = lj_trace_unwind(G2J(g), addr - sizeof(MCode), &exitno); + uintptr_t stub = lj_trace_unwind(G2J(g), (uintptr_t)(addr - sizeof(MCode)), &exitno); if (stub) { /* Jump to side exit to unwind the trace. */ ctx.CONTEXT_REG_PC = stub; G2J(g)->exitcode = errcode; @@ -777,6 +777,7 @@ LJ_NOINLINE void lj_err_mem(lua_State *L) { if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ lj_vm_unwind_c(L->cframe, LUA_ERRMEM); + if (curr_funcisL(L)) L->top = curr_topL(L); setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); lj_err_throw(L, LUA_ERRMEM); } diff --git a/libs/LuaJIT/src/lj_ffrecord.c b/libs/LuaJIT/src/lj_ffrecord.c index 60c1d84f..022de1aa 100644 --- a/libs/LuaJIT/src/lj_ffrecord.c +++ b/libs/LuaJIT/src/lj_ffrecord.c @@ -1117,7 +1117,7 @@ static LJ_AINLINE TRef recff_sbufx_len(jit_State *J, TRef trr, TRef trw) } /* Emit typecheck for string buffer. */ -static TRef recff_sbufx_check(jit_State *J, RecordFFData *rd, int arg) +static TRef recff_sbufx_check(jit_State *J, RecordFFData *rd, ptrdiff_t arg) { TRef trtype, ud = J->base[arg]; if (!tvisbuf(&rd->argv[arg])) lj_trace_err(J, LJ_TRERR_BADTYPE); @@ -1135,7 +1135,7 @@ static TRef recff_sbufx_write(jit_State *J, TRef ud) } /* Check for integer in range for the buffer API. */ -static TRef recff_sbufx_checkint(jit_State *J, RecordFFData *rd, int arg) +static TRef recff_sbufx_checkint(jit_State *J, RecordFFData *rd, ptrdiff_t arg) { TRef tr = J->base[arg]; TRef trlim = lj_ir_kint(J, LJ_MAX_BUF); diff --git a/libs/LuaJIT/src/lj_jit.h b/libs/LuaJIT/src/lj_jit.h index 32b3861a..7f081730 100644 --- a/libs/LuaJIT/src/lj_jit.h +++ b/libs/LuaJIT/src/lj_jit.h @@ -87,10 +87,11 @@ #define JIT_F_OPT_ABC (JIT_F_OPT << 7) #define JIT_F_OPT_SINK (JIT_F_OPT << 8) #define JIT_F_OPT_FUSE (JIT_F_OPT << 9) +#define JIT_F_OPT_FMA (JIT_F_OPT << 10) /* Optimizations names for -O. Must match the order above. */ #define JIT_F_OPTSTRING \ - "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse" + "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse\3fma" /* Optimization levels set a fixed combination of flags. */ #define JIT_F_OPT_0 0 @@ -99,6 +100,7 @@ #define JIT_F_OPT_3 (JIT_F_OPT_2|\ JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE) #define JIT_F_OPT_DEFAULT JIT_F_OPT_3 +/* Note: FMA is not set by default. */ /* -- JIT engine parameters ----------------------------------------------- */ diff --git a/libs/LuaJIT/src/lj_obj.h b/libs/LuaJIT/src/lj_obj.h index 67e41181..e541387f 100644 --- a/libs/LuaJIT/src/lj_obj.h +++ b/libs/LuaJIT/src/lj_obj.h @@ -413,7 +413,7 @@ typedef struct GCproto { #define PROTO_UV_IMMUTABLE 0x4000 /* Immutable upvalue. */ #define proto_kgc(pt, idx) \ - check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \ + check_exp((uintptr_t)(intptr_t)(idx) >= ~(uintptr_t)(pt)->sizekgc+1u, \ gcref(mref((pt)->k, GCRef)[(idx)])) #define proto_knumtv(pt, idx) \ check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)]) diff --git a/libs/LuaJIT/src/lj_opt_fold.c b/libs/LuaJIT/src/lj_opt_fold.c index 7ef09a1f..c8f5397d 100644 --- a/libs/LuaJIT/src/lj_opt_fold.c +++ b/libs/LuaJIT/src/lj_opt_fold.c @@ -267,7 +267,7 @@ static int32_t kfold_intop(int32_t k1, int32_t k2, IROp op) case IR_SUB: k1 -= k2; break; case IR_MUL: k1 *= k2; break; case IR_MOD: k1 = lj_vm_modi(k1, k2); break; - case IR_NEG: k1 = -k1; break; + case IR_NEG: k1 = (int32_t)(~(uint32_t)k1+1u); break; case IR_BAND: k1 &= k2; break; case IR_BOR: k1 |= k2; break; case IR_BXOR: k1 ^= k2; break; @@ -1366,7 +1366,7 @@ LJFOLDF(simplify_intsub_k) if (fright->i == 0) /* i - 0 ==> i */ return LEFTFOLD; fins->o = IR_ADD; /* i - k ==> i + (-k) */ - fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i); /* Overflow for -2^31 ok. */ + fins->op2 = (IRRef1)lj_ir_kint(J, (int32_t)(~(uint32_t)fright->i+1u)); /* Overflow for -2^31 ok. */ return RETRYFOLD; } @@ -1397,7 +1397,7 @@ LJFOLDF(simplify_intsub_k64) if (k == 0) /* i - 0 ==> i */ return LEFTFOLD; fins->o = IR_ADD; /* i - k ==> i + (-k) */ - fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k); + fins->op2 = (IRRef1)lj_ir_kint64(J, ~k+1u); return RETRYFOLD; } diff --git a/libs/LuaJIT/src/lj_parse.c b/libs/LuaJIT/src/lj_parse.c index 9ddf60ed..64ae2c16 100644 --- a/libs/LuaJIT/src/lj_parse.c +++ b/libs/LuaJIT/src/lj_parse.c @@ -964,22 +964,22 @@ static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e) #if LJ_HASFFI if (e->k == VKCDATA) { /* Fold in-place since cdata is not interned. */ GCcdata *cd = cdataV(&e->u.nval); - int64_t *p = (int64_t *)cdataptr(cd); + uint64_t *p = (uint64_t *)cdataptr(cd); if (cd->ctypeid == CTID_COMPLEX_DOUBLE) - p[1] ^= (int64_t)U64x(80000000,00000000); + p[1] ^= U64x(80000000,00000000); else - *p = -*p; + *p = ~*p+1u; return; } else #endif if (expr_isnumk(e) && !expr_numiszero(e)) { /* Avoid folding to -0. */ TValue *o = expr_numtv(e); if (tvisint(o)) { - int32_t k = intV(o); - if (k == -k) + int32_t k = intV(o), negk = (int32_t)(~(uint32_t)k+1u); + if (k == negk) setnumV(o, -(lua_Number)k); else - setintV(o, -k); + setintV(o, negk); return; } else { o->u64 ^= U64x(80000000,00000000); diff --git a/libs/LuaJIT/src/lj_prng.c b/libs/LuaJIT/src/lj_prng.c index 9e57505e..01935e57 100644 --- a/libs/LuaJIT/src/lj_prng.c +++ b/libs/LuaJIT/src/lj_prng.c @@ -125,7 +125,7 @@ static PRGR libfunc_rgr; #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 #define LJ_TARGET_HAS_GETENTROPY 1 #endif -#elif (LJ_TARGET_BSD && !defined(__NetBSD__)) || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN +#elif (LJ_TARGET_BSD && !defined(__NetBSD__)) || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN || LJ_TARGET_QNX #define LJ_TARGET_HAS_GETENTROPY 1 #endif diff --git a/libs/LuaJIT/src/lj_profile.c b/libs/LuaJIT/src/lj_profile.c index f0af91cb..4a13537d 100644 --- a/libs/LuaJIT/src/lj_profile.c +++ b/libs/LuaJIT/src/lj_profile.c @@ -185,7 +185,11 @@ static void profile_timer_start(ProfileState *ps) tm.it_value.tv_sec = tm.it_interval.tv_sec = interval / 1000; tm.it_value.tv_usec = tm.it_interval.tv_usec = (interval % 1000) * 1000; setitimer(ITIMER_PROF, &tm, NULL); +#if LJ_TARGET_QNX + sa.sa_flags = 0; +#else sa.sa_flags = SA_RESTART; +#endif sa.sa_handler = profile_signal; sigemptyset(&sa.sa_mask); sigaction(SIGPROF, &sa, &ps->oldsa); diff --git a/libs/LuaJIT/src/lj_record.c b/libs/LuaJIT/src/lj_record.c index 92bdbfc9..79ee6172 100644 --- a/libs/LuaJIT/src/lj_record.c +++ b/libs/LuaJIT/src/lj_record.c @@ -1945,6 +1945,8 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) } else if (dst + nresults > J->maxslot) { J->maxslot = dst + (BCReg)nresults; } + if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS) + lj_trace_err(J, LJ_TRERR_STACKOV); for (i = 0; i < nresults; i++) J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1 - LJ_FR2) : TREF_NIL; } else { /* Unknown number of varargs passed to trace. */ @@ -1964,7 +1966,7 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) vbase = emitir(IRT(IR_ADD, IRT_PGC), vbase, lj_ir_kint(J, frofs-8*(1+LJ_FR2))); for (i = 0; i < nload; i++) { IRType t = itype2irt(&J->L->base[i-1-LJ_FR2-nvararg]); - J->base[dst+i] = lj_record_vload(J, vbase, i, t); + J->base[dst+i] = lj_record_vload(J, vbase, (MSize)i, t); } } else { emitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs)); @@ -2022,8 +2024,6 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults) lj_trace_err_info(J, LJ_TRERR_NYIBC); } } - if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS) - lj_trace_err(J, LJ_TRERR_STACKOV); } /* -- Record allocations -------------------------------------------------- */ @@ -2572,7 +2572,8 @@ void lj_record_ins(jit_State *J) break; case BC_JLOOP: rec_loop_jit(J, rc, rec_loop(J, ra, - !bc_isret(bc_op(traceref(J, rc)->startins)))); + !bc_isret(bc_op(traceref(J, rc)->startins)) && + bc_op(traceref(J, rc)->startins) != BC_ITERN)); break; case BC_IFORL: diff --git a/libs/LuaJIT/src/lj_strfmt.c b/libs/LuaJIT/src/lj_strfmt.c index 5c808290..71ee9f62 100644 --- a/libs/LuaJIT/src/lj_strfmt.c +++ b/libs/LuaJIT/src/lj_strfmt.c @@ -102,7 +102,7 @@ retlit: char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k) { uint32_t u = (uint32_t)k; - if (k < 0) { u = (uint32_t)-k; *p++ = '-'; } + if (k < 0) { u = ~u+1u; *p++ = '-'; } if (u < 10000) { if (u < 10) goto dig1; if (u < 100) goto dig2; @@ -287,7 +287,7 @@ SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k) /* Figure out signed prefixes. */ if (STRFMT_TYPE(sf) == STRFMT_INT) { if ((int64_t)k < 0) { - k = (uint64_t)-(int64_t)k; + k = ~k+1u; prefix = 256 + '-'; } else if ((sf & STRFMT_F_PLUS)) { prefix = 256 + '+'; diff --git a/libs/LuaJIT/src/lj_strscan.c b/libs/LuaJIT/src/lj_strscan.c index 1d1c1c74..4ca848ec 100644 --- a/libs/LuaJIT/src/lj_strscan.c +++ b/libs/LuaJIT/src/lj_strscan.c @@ -124,19 +124,19 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, case STRSCAN_INT: if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && !(x == 0 && neg)) { - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_INT; /* Fast path for 32 bit integers. */ } if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } /* fallthrough */ case STRSCAN_U32: if (dig > 8) return STRSCAN_ERROR; - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_U32; case STRSCAN_I64: case STRSCAN_U64: if (dig > 16) return STRSCAN_ERROR; - o->u64 = neg ? (uint64_t)-(int64_t)x : x; + o->u64 = neg ? ~x+1u : x; return fmt; default: break; @@ -168,12 +168,12 @@ static StrScanFmt strscan_oct(const uint8_t *p, TValue *o, /* fallthrough */ case STRSCAN_U32: if ((x >> 32)) return STRSCAN_ERROR; - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~(uint32_t)x+1u) : (int32_t)x; break; default: case STRSCAN_I64: case STRSCAN_U64: - o->u64 = neg ? (uint64_t)-(int64_t)x : x; + o->u64 = neg ? ~x+1u : x; break; } return fmt; @@ -229,18 +229,18 @@ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o, switch (fmt) { case STRSCAN_INT: if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_INT; /* Fast path for 32 bit integers. */ } if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; } /* fallthrough */ case STRSCAN_U32: if ((x >> 32) != 0) return STRSCAN_ERROR; - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_U32; case STRSCAN_I64: case STRSCAN_U64: - o->u64 = neg ? (uint64_t)-(int64_t)x : x; + o->u64 = neg ? ~x+1u : x; return fmt; default: plainnumber: /* Fast path for plain numbers < 2^63. */ @@ -348,18 +348,18 @@ static StrScanFmt strscan_bin(const uint8_t *p, TValue *o, switch (fmt) { case STRSCAN_INT: if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_INT; /* Fast path for 32 bit integers. */ } if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } /* fallthrough */ case STRSCAN_U32: if (dig > 32) return STRSCAN_ERROR; - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_U32; case STRSCAN_I64: case STRSCAN_U64: - o->u64 = neg ? (uint64_t)-(int64_t)x : x; + o->u64 = neg ? ~x+1u : x; return fmt; default: break; @@ -468,7 +468,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; p++; } - ex += negx ? -(int32_t)xx : (int32_t)xx; + ex += negx ? (int32_t)(~xx+1u) : (int32_t)xx; } /* Parse suffix. */ @@ -507,7 +507,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, o->n = -0.0; return STRSCAN_NUM; } else { - o->i = neg ? -(int32_t)x : (int32_t)x; + o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; return STRSCAN_INT; } } diff --git a/libs/LuaJIT/src/lj_vmmath.c b/libs/LuaJIT/src/lj_vmmath.c index b6cc60ba..4fa79ae4 100644 --- a/libs/LuaJIT/src/lj_vmmath.c +++ b/libs/LuaJIT/src/lj_vmmath.c @@ -36,6 +36,17 @@ LJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); } /* -- Helper functions ---------------------------------------------------- */ +/* Required to prevent the C compiler from applying FMA optimizations. +** +** Yes, there's -ffp-contract and the FP_CONTRACT pragma ... in theory. +** But the current state of C compilers is a mess in this regard. +** Also, this function is not performance sensitive at all. +*/ +LJ_NOINLINE static double lj_vm_floormul(double x, double y) +{ + return lj_vm_floor(x / y) * y; +} + double lj_vm_foldarith(double x, double y, int op) { switch (op) { @@ -43,7 +54,7 @@ double lj_vm_foldarith(double x, double y, int op) case IR_SUB - IR_ADD: return x-y; break; case IR_MUL - IR_ADD: return x*y; break; case IR_DIV - IR_ADD: return x/y; break; - case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break; + case IR_MOD - IR_ADD: return x-lj_vm_floormul(x, y); break; case IR_POW - IR_ADD: return pow(x, y); break; case IR_NEG - IR_ADD: return -x; break; case IR_ABS - IR_ADD: return fabs(x); break; @@ -64,11 +75,11 @@ int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b) uint32_t y, ua, ub; /* This must be checked before using this function. */ lj_assertX(b != 0, "modulo with zero divisor"); - ua = a < 0 ? (uint32_t)-a : (uint32_t)a; - ub = b < 0 ? (uint32_t)-b : (uint32_t)b; + ua = a < 0 ? ~(uint32_t)a+1u : (uint32_t)a; + ub = b < 0 ? ~(uint32_t)b+1u : (uint32_t)b; y = ua % ub; if (y != 0 && (a^b) < 0) y = y - ub; - if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y; + if (((int32_t)y^b) < 0) y = ~y+1u; return (int32_t)y; } #endif diff --git a/libs/LuaJIT/src/nxbuild.bat b/libs/LuaJIT/src/nxbuild.bat index c4a21f05..5c7088ee 100644 --- a/libs/LuaJIT/src/nxbuild.bat +++ b/libs/LuaJIT/src/nxbuild.bat @@ -121,6 +121,7 @@ goto :BUILD @set TARGETLIB=libluajit_%TARGETLIB_SUFFIX%.a :BUILD del %TARGETLIB% +@set LJCOMPILE=%LJCOMPILE% -fPIC @if "%1" neq "noamalg" goto :AMALG for %%f in (lj_*.c lib_*.c) do ( %LJCOMPILE% %%f diff --git a/libs/LuaJIT/src/ps4build.bat b/libs/LuaJIT/src/ps4build.bat index fdd09d81..034e2c87 100644 --- a/libs/LuaJIT/src/ps4build.bat +++ b/libs/LuaJIT/src/ps4build.bat @@ -51,7 +51,7 @@ if exist minilua.exe.manifest^ minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC% @if errorlevel 1 goto :BAD -%LJCOMPILE% /I "." /I %DASMDIR% %GC64% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c +%LJCOMPILE% /I "." /I %DASMDIR% %GC64% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -DLUAJIT_NO_UNWIND host\buildvm*.c @if errorlevel 1 goto :BAD %LJLINK% /out:buildvm.exe buildvm*.obj @if errorlevel 1 goto :BAD @@ -78,7 +78,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c @set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus @set INCLUDE="" -orbis-as -o lj_vm.o lj_vm.s +"%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-as" -o lj_vm.o lj_vm.s @if "%1" neq "debug" goto :NODEBUG @shift diff --git a/libs/LuaJIT/src/ps5build.bat b/libs/LuaJIT/src/ps5build.bat index 0b1ebd5b..56818c2e 100644 --- a/libs/LuaJIT/src/ps5build.bat +++ b/libs/LuaJIT/src/ps5build.bat @@ -74,11 +74,11 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c @if errorlevel 1 goto :BAD @rem ---- Cross compiler ---- -@set LJCOMPILE="%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-clang" -c -Wall -DLUAJIT_DISABLE_FFI %GC64% +@set LJCOMPILE="%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-clang" -c -Wall -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC %GC64% @set LJLIB="%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-llvm-ar" rcus @set INCLUDE="" -%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-llvm-as -o lj_vm.o lj_vm.s +"%SCE_PROSPERO_SDK_DIR%\host_tools\bin\prospero-clang" -c -o lj_vm.o lj_vm.s @if "%1" neq "debug" goto :NODEBUG @shift diff --git a/libs/LuaJIT/src/vm_arm64.dasc b/libs/LuaJIT/src/vm_arm64.dasc index 3448d0d2..36a036ae 100644 --- a/libs/LuaJIT/src/vm_arm64.dasc +++ b/libs/LuaJIT/src/vm_arm64.dasc @@ -2636,7 +2636,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) |.macro ins_arithmod, res, reg1, reg2 | fdiv d2, reg1, reg2 | frintm d2, d2 - | fmsub res, d2, reg2, reg1 + | // Cannot use fmsub, because FMA is not enabled by default. + | fmul d2, d2, reg2 + | fsub res, reg1, d2 |.endmacro | |.macro ins_arithdn, intins, fpins