Skip to content

Commit

Permalink
Merge commit 'ae0e60ad387c118ac75a079208d52a443bed4502' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Nov 13, 2024
2 parents 234c743 + ae0e60a commit d107dd4
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/deps/src/luajit/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ ifeq (Darwin,$(TARGET_SYS))
endif
TARGET_STRIP+= -x
TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
TARGET_XSHLDFLAGS= -dynamiclib -undefined dynamic_lookup -fPIC
TARGET_DYNXLDOPTS=
TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
else
ifeq (iOS,$(TARGET_SYS))
TARGET_STRIP+= -x
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
TARGET_XSHLDFLAGS= -dynamiclib -undefined dynamic_lookup -fPIC
TARGET_DYNXLDOPTS=
TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
ifeq (arm64,$(TARGET_LJARCH))
Expand Down
2 changes: 1 addition & 1 deletion src/deps/src/luajit/src/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \
lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \
lj_crecord.h lj_strfmt.h
lj_crecord.h lj_strfmt.h lj_strscan.h
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_strfmt.h lj_ctype.h \
lj_ccallback.h lj_buf.h
Expand Down
4 changes: 4 additions & 0 deletions src/deps/src/luajit/src/host/buildvm_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ void emit_asm(BuildCtx *ctx)
fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident);
break;
case BUILD_machasm:
#if defined(__apple_build_version__) && __apple_build_version__ >= 15000000 && __apple_build_version__ < 15000300
/* Workaround for XCode 15.0 - 15.2. */
fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#endif
fprintf(ctx->fp,
"\t.cstring\n"
"\t.ascii \"%s\\0\"\n", ctx->dasm_ident);
Expand Down
2 changes: 1 addition & 1 deletion src/deps/src/luajit/src/lib_bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL)
x = lj_carith_shift64(x, sh, curr_func(L)->c.ffid - (int)FF_bit_lshift);
return bit_result64(L, id, x);
}
if (id2) setintV(L->base+1, sh);
setintV(L->base+1, sh);
return FFH_RETRY;
#else
lj_lib_checknumber(L, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/deps/src/luajit/src/lj_asm_mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static void asm_retf(ASMState *as, IRIns *ir)
emit_addptr(as, base, -8*delta);
asm_guard(as, MIPSI_BNE, RID_TMP,
ra_allock(as, igcptr(pc), rset_exclude(RSET_GPR, base)));
emit_tsi(as, MIPSI_AL, RID_TMP, base, -8);
emit_tsi(as, MIPSI_AL, RID_TMP, base, (LJ_BE || LJ_FR2) ? -8 : -4);
}

/* -- Buffer operations --------------------------------------------------- */
Expand Down
4 changes: 1 addition & 3 deletions src/deps/src/luajit/src/lj_carith.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,7 @@ uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id)
if (LJ_LIKELY(tvisint(o))) {
return (uint32_t)intV(o);
} else {
int32_t i = lj_num2bit(numV(o));
if (LJ_DUALNUM) setintV(o, i);
return (uint32_t)i;
return (uint32_t)lj_num2bit(numV(o));
}
}

Expand Down
31 changes: 21 additions & 10 deletions src/deps/src/luajit/src/lj_crecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "lj_crecord.h"
#include "lj_dispatch.h"
#include "lj_strfmt.h"
#include "lj_strscan.h"

/* Some local macros to save typing. Undef'd at the end. */
#define IR(ref) (&J->cur.ir[(ref)])
Expand Down Expand Up @@ -1807,11 +1808,21 @@ static CTypeID crec_bit64_type(CTState *cts, cTValue *tv)
return 0; /* Use regular 32 bit ops. */
}

static TRef crec_bit64_arg(jit_State *J, CType *d, TRef sp, TValue *sval)
{
if (LJ_UNLIKELY(tref_isstr(sp))) {
if (lj_strscan_num(strV(sval), sval)) {
sp = emitir(IRTG(IR_STRTO, IRT_NUM), sp, 0);
} /* else: interpreter will throw. */
}
return crec_ct_tv(J, d, 0, sp, sval);
}

void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef tr = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,
J->base[0], &rd->argv[0]);
TRef tr = crec_bit64_arg(J, ctype_get(cts, CTID_INT64),
J->base[0], &rd->argv[0]);
if (!tref_isinteger(tr))
tr = emitconv(tr, IRT_INT, tref_type(tr), 0);
J->base[0] = tr;
Expand All @@ -1822,7 +1833,7 @@ int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)
CTState *cts = ctype_ctsG(J2G(J));
CTypeID id = crec_bit64_type(cts, &rd->argv[0]);
if (id) {
TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);
TRef tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
tr = emitir(IRT(rd->data, id-CTID_INT64+IRT_I64), tr, 0);
J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
return 1;
Expand All @@ -1842,9 +1853,9 @@ int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)
if (id) {
CType *ct = ctype_get(cts, id);
uint32_t ot = IRT(rd->data, id-CTID_INT64+IRT_I64);
TRef tr = crec_ct_tv(J, ct, 0, J->base[0], &rd->argv[0]);
TRef tr = crec_bit64_arg(J, ct, J->base[0], &rd->argv[0]);
for (i = 1; J->base[i] != 0; i++) {
TRef tr2 = crec_ct_tv(J, ct, 0, J->base[i], &rd->argv[i]);
TRef tr2 = crec_bit64_arg(J, ct, J->base[i], &rd->argv[i]);
tr = emitir(ot, tr, tr2);
}
J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
Expand All @@ -1859,15 +1870,15 @@ int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)
CTypeID id;
TRef tsh = 0;
if (J->base[0] && tref_iscdata(J->base[1])) {
tsh = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,
J->base[1], &rd->argv[1]);
tsh = crec_bit64_arg(J, ctype_get(cts, CTID_INT64),
J->base[1], &rd->argv[1]);
if (!tref_isinteger(tsh))
tsh = emitconv(tsh, IRT_INT, tref_type(tsh), 0);
J->base[1] = tsh;
}
id = crec_bit64_type(cts, &rd->argv[0]);
if (id) {
TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);
TRef tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
uint32_t op = rd->data;
if (!tsh) tsh = lj_opt_narrow_tobit(J, J->base[1]);
if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&
Expand Down Expand Up @@ -1897,7 +1908,7 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
CTypeID id2 = 0;
n = (int32_t)lj_carith_check64(J->L, 2, &id2);
if (id2)
trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]);
trsf = crec_bit64_arg(J, ctype_get(cts, CTID_INT32), trsf, &rd->argv[1]);
else
trsf = lj_opt_narrow_tobit(J, trsf);
emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n)); /* Specialize to n. */
Expand All @@ -1908,7 +1919,7 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
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]);
tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
if (n < 16)
tr = emitir(IRT(IR_BAND, IRT_U64), tr,
lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));
Expand Down
17 changes: 11 additions & 6 deletions src/deps/src/luajit/src/lj_emit_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ static void emit_d(ASMState *as, A64Ins ai, Reg rd)
*--as->mcp = ai | A64F_D(rd);
}

static void emit_dl(ASMState *as, A64Ins ai, Reg rd, uint32_t l)
{
*--as->mcp = ai | A64F_D(rd) | A64F_S19(l >> 2);
}

static void emit_n(ASMState *as, A64Ins ai, Reg rn)
{
*--as->mcp = ai | A64F_N(rn);
Expand Down Expand Up @@ -226,7 +231,7 @@ static int emit_kadrp(ASMState *as, Reg rd, uint64_t k)
emit_dn(as, (A64I_ADDx^A64I_K12)|A64F_U12(k - kpage), rd, rd);
ai = A64I_ADRP;
}
emit_d(as, ai|(((uint32_t)ofs&3)<<29)|A64F_S19(ofs>>2), rd);
emit_dl(as, ai|(((uint32_t)ofs&3)<<29), rd, ofs);
return 1;
}

Expand Down Expand Up @@ -291,7 +296,7 @@ static void emit_lsptr(ASMState *as, A64Ins ai, Reg r, void *p)
/* GL + offset, might subsequently fuse to LDP/STP. */
} else if (ai == A64I_LDRx && checkmcpofs(as, p)) {
/* IP + offset is cheaper than allock, but address must be in range. */
emit_d(as, A64I_LDRLx | A64F_S19(mcpofs(as, p)>>2), r);
emit_dl(as, A64I_LDRLx, r, mcpofs(as, p));
return;
} else { /* Split up into base reg + offset. */
int64_t i64 = i64ptr(p);
Expand Down Expand Up @@ -320,15 +325,15 @@ static void emit_loadk64(ASMState *as, Reg r, IRIns *ir)
if (emit_checkofs(A64I_LDRx, ofs)) {
emit_lso(as, r >= RID_MAX_GPR ? A64I_LDRd : A64I_LDRx,
(r & 31), RID_GL, ofs);
} else if (checkmcpofs(as, k)) {
emit_dl(as, r >= RID_MAX_GPR ? A64I_LDRLd : A64I_LDRLx,
(r & 31), mcpofs(as, k));
} else {
if (r >= RID_MAX_GPR) {
emit_dn(as, A64I_FMOV_D_R, (r & 31), RID_TMP);
r = RID_TMP;
}
if (checkmcpofs(as, k))
emit_d(as, A64I_LDRLx | A64F_S19(mcpofs(as, k)>>2), r);
else
emit_loadu64(as, r, *k);
emit_loadu64(as, r, *k);
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/deps/src/luajit/src/lj_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ typedef struct UndocumentedDispatcherContext {
/* Another wild guess. */
extern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow);

#if LJ_TARGET_X64 && defined(MINGW_SDK_INIT)
/* Workaround for broken MinGW64 declaration. */
VOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm("RtlUnwindEx");
#define RtlUnwindEx RtlUnwindEx_FIXED
#endif

#define LJ_MSVC_EXCODE ((DWORD)0xe06d7363)
#define LJ_GCC_EXCODE ((DWORD)0x20474343)

Expand Down
2 changes: 1 addition & 1 deletion src/deps/src/luajit/src/lj_ffrecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd)
mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt;
emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref);
if (!tref_isnil(mt))
emitir(IRT(IR_TBAR, IRT_TAB), tr, 0);
emitir(IRT(IR_TBAR, IRT_NIL), tr, 0);
J->base[0] = tr;
J->needsnap = 1;
} /* else: Interpreter will throw. */
Expand Down
12 changes: 2 additions & 10 deletions src/deps/src/luajit/src/lj_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ static void gc_finalize(lua_State *L)
setcdataV(L, &tmp, gco2cd(o));
tv = lj_tab_set(L, tabref(g->gcroot[GCROOT_FFI_FIN]), &tmp);
if (!tvisnil(tv)) {
g->gc.nocdatafin = 0;
copyTV(L, &tmp, tv);
setnilV(tv); /* Clear entry in finalizer table. */
gc_call_finalizer(g, L, &tmp, o);
Expand Down Expand Up @@ -604,12 +603,11 @@ void lj_gc_finalize_cdata(lua_State *L)
/* Free all remaining GC objects. */
void lj_gc_freeall(global_State *g)
{
MSize i, strmask;
MSize i;
/* Free everything, except super-fixed objects (the main thread). */
g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED;
gc_fullsweep(g, &g->gc.root);
strmask = g->str.mask;
for (i = 0; i <= strmask; i++) /* Free all string hash chains. */
for (i = g->str.mask; i != ~(MSize)0; i--) /* Free all string hash chains. */
gc_sweepstr(g, &g->str.tab[i]);
}

Expand Down Expand Up @@ -690,9 +688,6 @@ static size_t gc_onestep(lua_State *L)
lj_str_resize(L, g->str.mask >> 1); /* Shrink string table. */
if (gcref(g->gc.mmudata)) { /* Need any finalizations? */
g->gc.state = GCSfinalize;
#if LJ_HASFFI
g->gc.nocdatafin = 1;
#endif
} else { /* Otherwise skip this phase to help the JIT. */
g->gc.state = GCSpause; /* End of GC cycle. */
g->gc.debt = 0;
Expand All @@ -712,9 +707,6 @@ static size_t gc_onestep(lua_State *L)
g->gc.estimate -= GCFINALIZECOST;
return GCFINALIZECOST;
}
#if LJ_HASFFI
if (!g->gc.nocdatafin) lj_tab_rehash(L, tabref(g->gcroot[GCROOT_FFI_FIN]));
#endif
g->gc.state = GCSpause; /* End of GC cycle. */
g->gc.debt = 0;
return 0;
Expand Down
19 changes: 10 additions & 9 deletions src/deps/src/luajit/src/lj_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,30 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
FileReaderCtx ctx;
int status;
const char *chunkname;
int err = 0;
if (filename) {
chunkname = lua_pushfstring(L, "@%s", filename);
ctx.fp = fopen(filename, "rb");
if (ctx.fp == NULL) {
L->top--;
lua_pushfstring(L, "cannot open %s: %s", filename, strerror(errno));
return LUA_ERRFILE;
}
chunkname = lua_pushfstring(L, "@%s", filename);
} else {
ctx.fp = stdin;
chunkname = "=stdin";
}
status = lua_loadx(L, reader_file, &ctx, chunkname, mode);
if (ferror(ctx.fp)) {
L->top -= filename ? 2 : 1;
lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno));
if (filename)
fclose(ctx.fp);
return LUA_ERRFILE;
}
if (ferror(ctx.fp)) err = errno;
if (filename) {
fclose(ctx.fp);
L->top--;
copyTV(L, L->top-1, L->top);
fclose(ctx.fp);
}
if (err) {
L->top--;
lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(err));
return LUA_ERRFILE;
}
return status;
}
Expand Down
2 changes: 1 addition & 1 deletion src/deps/src/luajit/src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ typedef struct GCState {
GCSize threshold; /* Memory threshold. */
uint8_t currentwhite; /* Current white color. */
uint8_t state; /* GC state. */
uint8_t nocdatafin; /* No cdata finalizer called. */
uint8_t unused0;
#if LJ_64
uint8_t lightudnum; /* Number of lightuserdata segments - 1. */
#else
Expand Down
3 changes: 2 additions & 1 deletion src/deps/src/luajit/src/lj_opt_narrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ 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 <= 1) { /* Limit total number of conversions. */
/* Limit total number of conversions. */
if (count <= 1 && nc->sp < nc->maxsp) {
*nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);
return count;
}
Expand Down
6 changes: 3 additions & 3 deletions src/deps/src/luajit/src/lj_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
} else if (tref_isudata(ix->tab)) {
int udtype = udataV(&ix->tabv)->udtype;
mt = tabref(udataV(&ix->tabv)->metatable);
mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META);
/* The metatables of special userdata objects are treated as immutable. */
if (udtype != UDTYPE_USERDATA) {
cTValue *mo;
Expand All @@ -1087,18 +1088,17 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
}
immutable_mt:
mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm));
ix->mt = mix.tab;
ix->mtv = mt;
if (!mo || tvisnil(mo))
return 0; /* No metamethod. */
/* Treat metamethod or index table as immutable, too. */
if (!(tvisfunc(mo) || tvistab(mo)))
lj_trace_err(J, LJ_TRERR_BADTYPE);
copyTV(J->L, &ix->mobjv, mo);
ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB);
ix->mtv = mt;
ix->mt = TREF_NIL; /* Dummy value for comparison semantics. */
return 1; /* Got metamethod or index table. */
}
mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META);
} else {
/* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */
mt = tabref(basemt_obj(J2G(J), &ix->tabv));
Expand Down
7 changes: 0 additions & 7 deletions src/deps/src/luajit/src/lj_tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,6 @@ static void rehashtab(lua_State *L, GCtab *t, cTValue *ek)
lj_tab_resize(L, t, asize, hsize2hbits(total));
}

#if LJ_HASFFI
void lj_tab_rehash(lua_State *L, GCtab *t)
{
rehashtab(L, t, niltv(L));
}
#endif

void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize)
{
lj_tab_resize(L, t, nasize+1, t->hmask > 0 ? lj_fls(t->hmask)+1 : 0);
Expand Down
3 changes: 0 additions & 3 deletions src/deps/src/luajit/src/lj_tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);
LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);
LJ_FUNC void LJ_FASTCALL lj_tab_clear(GCtab *t);
LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);
#if LJ_HASFFI
LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);
#endif
LJ_FUNC void lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits);
LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);

Expand Down
1 change: 1 addition & 0 deletions src/deps/src/luajit/src/lj_target_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ typedef enum A64Ins {
A64I_FSQRTd = 0x1e61c000,
A64I_LDRs = 0xbd400000,
A64I_LDRd = 0xfd400000,
A64I_LDRLd = 0x5c000000,
A64I_STRs = 0xbd000000,
A64I_STRd = 0xfd000000,
A64I_LDPs = 0x2d400000,
Expand Down
Loading

0 comments on commit d107dd4

Please sign in to comment.