Use biased integer constant for TSETM array index.

This commit is contained in:
Mike Pall
2010-09-09 12:01:29 +02:00
parent 8a1af8cf89
commit fd63b05253
3 changed files with 7 additions and 12 deletions

View File

@@ -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

View File

@@ -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);