From fd63b05253f11d7e436c3685827fce9b64725da6 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 9 Sep 2010 12:01:29 +0200 Subject: [PATCH] Use biased integer constant for TSETM array index. --- lib/bc.lua | 4 +++- src/buildvm_x86.dasc | 12 ++---------- src/lj_parse.c | 3 ++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/bc.lua b/lib/bc.lua index 51fc1bd0..78b342f2 100644 --- a/lib/bc.lua +++ b/lib/bc.lua @@ -70,8 +70,9 @@ local function bcline(func, pc, prefix) local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128) local a = band(shr(ins, 8), 0xff) local oidx = 6*band(ins, 0xff) + local op = sub(bcnames, oidx+1, oidx+6) local s = format("%04d %s %-6s %3s ", - pc, prefix or " ", sub(bcnames, oidx+1, oidx+6), ma == 0 and "" or a) + pc, prefix or " ", op, ma == 0 and "" or a) local d = shr(ins, 16) if mc == 13*128 then -- BCMjump return format("%s=> %04d\n", s, pc+d-0x7fff) @@ -87,6 +88,7 @@ local function bcline(func, pc, prefix) kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub)) elseif mc == 9*128 then -- BCMnum kc = funck(func, d) + if op == "TSETM " then kc = kc - 2^52 end elseif mc == 12*128 then -- BCMfunc local fi = funcinfo(funck(func, -d-1)) if fi.ffid then diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index bc128457..d7c36d90 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc @@ -4288,15 +4288,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) case BC_TSETM: | ins_AD // RA = base (table at base-1), RD = num const (start index) | mov TMP1, KBASE // Need one more free register. - if (sse) { - | cvtsd2si KBASE, qword [KBASE+RD*8] - } else { - |.if not X64 - | fld qword [KBASE+RD*8] - | fistp ARG4 // Const is guaranteed to be an int. - | mov KBASE, ARG4 - |.endif - } + | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word. |1: | lea RA, [BASE+RA*8] | mov TAB:RB, [RA-8] // Guaranteed to be a table. @@ -4308,7 +4300,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | jz >4 // Nothing to copy? | add RD, KBASE // Compute needed size. | cmp RD, TAB:RB->asize - | jae >5 // Does not fit into array part? + | jae >5 // Doesn't fit into array part? | sub RD, KBASE | shl KBASE, 3 | add KBASE, TAB:RB->array diff --git a/src/lj_parse.c b/src/lj_parse.c index f5f59d03..e1ca2ff7 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -1369,7 +1369,8 @@ static void expr_table(LexState *ls, ExpDesc *e) lua_assert(bc_a(ilp->ins) == freg && bc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB)); expr_init(&en, VKNUM, 0); - setintV(&en.u.nval, narr-1); + en.u.nval.u32.lo = narr-1; + en.u.nval.u32.hi = 0x43300000; /* Biased integer to avoid denormals. */ if (narr > 256) { fs->pc--; ilp--; } ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en)); setbc_b(&ilp[-1].ins, 0);