From 1ac71f1fa8c0ad0c691ca7a2a96d74121b75ec9e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 16 May 2011 02:38:07 +0200 Subject: [PATCH] ARM: Add LJ_SOFTFP define. Add support for soft-float slot handling. --- lib/dump.lua | 4 ++++ src/lj_arch.h | 2 ++ src/lj_jit.h | 1 + src/lj_obj.h | 8 ++++---- src/lj_snap.c | 27 +++++++++++++++++++-------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/dump.lua b/lib/dump.lua index 652761ff..0f9f7b2b 100644 --- a/lib/dump.lua +++ b/lib/dump.lua @@ -320,6 +320,10 @@ local function printsnap(tr, snap) else local m, ot, op1, op2 = traceir(tr, ref) out:write(colorize(format("%04d", ref), band(ot, 31))) + if band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM + local m, ot, op1, op2 = traceir(tr, ref+1) + out:write(colorize(format("/%04d", ref+1), band(ot, 31))) + end end out:write(band(sn, 0x10000) == 0 and " " or "|") -- SNAP_FRAME else diff --git a/src/lj_arch.h b/src/lj_arch.h index b361e3dc..3c6d9e9c 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -232,6 +232,8 @@ #define LJ_HASFFI 1 #endif +#define LJ_SOFTFP (!LJ_ARCH_HASFPU) + #if LJ_ARCH_ENDIAN == LUAJIT_BE #define LJ_LE 0 #define LJ_BE 1 diff --git a/src/lj_jit.h b/src/lj_jit.h index 22f1d581..1cf63448 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h @@ -143,6 +143,7 @@ typedef uint32_t SnapEntry; #define SNAP_FRAME 0x010000 /* Frame slot. */ #define SNAP_CONT 0x020000 /* Continuation slot. */ #define SNAP_NORESTORE 0x040000 /* No need to restore slot. */ +#define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */ LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME); LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT); diff --git a/src/lj_obj.h b/src/lj_obj.h index c1bdb844..6d6782b4 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h @@ -786,18 +786,18 @@ static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2) /* -- Number to integer conversion ---------------------------------------- */ -#if !LJ_ARCH_HASFPU +#if LJ_SOFTFP LJ_ASMF int32_t lj_vm_tobit(double x); #endif static LJ_AINLINE int32_t lj_num2bit(lua_Number n) { -#if LJ_ARCH_HASFPU +#if LJ_SOFTFP + return lj_vm_tobit(n); +#else TValue o; o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */ return (int32_t)o.u32.lo; -#else - return lj_vm_tobit(n); #endif } diff --git a/src/lj_snap.c b/src/lj_snap.c index a3c081e1..e1791b51 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -72,6 +72,8 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT) sn |= SNAP_NORESTORE; } + if (LJ_SOFTFP && !irref_isk(ref) && irt_isnum(ir->t)) + sn |= SNAP_SOFTFPNUM; map[n++] = sn; } } @@ -386,9 +388,11 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) rs = snap_renameref(T, snapno, ref, rs); if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */ int32_t *sps = &ex->spill[regsp_spill(rs)]; - if (irt_isinteger(t)) { + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) { + o->u32.lo = (uint32_t)*sps; + } else if (irt_isinteger(t)) { setintV(o, *sps); - } else if (irt_isnum(t)) { + } else if (!LJ_SOFTFP && irt_isnum(t)) { o->u64 = *(uint64_t *)sps; #if LJ_64 } else if (irt_islightud(t)) { @@ -403,13 +407,12 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) } else { /* Restore from register. */ Reg r = regsp_reg(rs); lua_assert(ra_hasreg(r)); - if (irt_isinteger(t)) { + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) { + o->u32.lo = (uint32_t)ex->gpr[r-RID_MIN_GPR]; + } else if (irt_isinteger(t)) { setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]); - } else if (irt_isnum(t)) { - if (RID_NUM_FPR) - setnumV(o, ex->fpr[r-RID_MIN_FPR]); - else - setnumV(o, *(double *)&ex->gpr[r-RID_MIN_GPR]); + } else if (!LJ_SOFTFP && irt_isnum(t)) { + setnumV(o, ex->fpr[r-RID_MIN_FPR]); #if LJ_64 } else if (irt_islightud(t)) { /* 64 bit lightuserdata which may escape already has the tag bits. */ @@ -421,6 +424,14 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) setitype(o, irt_toitype(t)); } } + if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) { + rs = (ir+1)->prev; + if (LJ_UNLIKELY(bloomtest(rfilt, ref+1))) + rs = snap_renameref(T, snapno, ref+1, rs); + o->u32.hi = (ra_hasspill(regsp_spill(rs))) ? + (uint32_t)*&ex->spill[regsp_spill(rs)] : + (uint32_t)ex->gpr[regsp_reg(rs)-RID_MIN_GPR]; + } } } switch (bc_op(*pc)) {