diff options
Diffstat (limited to 'src/lj_ir.c')
-rw-r--r-- | src/lj_ir.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c index acb39463..124d5791 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -91,7 +91,7 @@ static void lj_ir_growbot(jit_State *J) | |||
91 | IRIns *baseir = J->irbuf + J->irbotlim; | 91 | IRIns *baseir = J->irbuf + J->irbotlim; |
92 | MSize szins = J->irtoplim - J->irbotlim; | 92 | MSize szins = J->irtoplim - J->irbotlim; |
93 | lua_assert(szins != 0); | 93 | lua_assert(szins != 0); |
94 | lua_assert(J->cur.nk == J->irbotlim); | 94 | lua_assert(J->cur.nk == J->irbotlim || J->cur.nk-1 == J->irbotlim); |
95 | if (J->cur.nins + (szins >> 1) < J->irtoplim) { | 95 | if (J->cur.nins + (szins >> 1) < J->irtoplim) { |
96 | /* More than half of the buffer is free on top: shift up by a quarter. */ | 96 | /* More than half of the buffer is free on top: shift up by a quarter. */ |
97 | MSize ofs = szins >> 2; | 97 | MSize ofs = szins >> 2; |
@@ -173,6 +173,18 @@ static LJ_AINLINE IRRef ir_nextk(jit_State *J) | |||
173 | return ref; | 173 | return ref; |
174 | } | 174 | } |
175 | 175 | ||
176 | /* Get ref of next 64 bit IR constant and optionally grow IR. | ||
177 | ** Note: this may invalidate all IRIns *! | ||
178 | */ | ||
179 | static LJ_AINLINE IRRef ir_nextk64(jit_State *J) | ||
180 | { | ||
181 | IRRef ref = J->cur.nk - 2; | ||
182 | lua_assert(J->state != LJ_TRACE_ASM); | ||
183 | if (LJ_UNLIKELY(ref < J->irbotlim)) lj_ir_growbot(J); | ||
184 | J->cur.nk = ref; | ||
185 | return ref; | ||
186 | } | ||
187 | |||
176 | /* Intern int32_t constant. */ | 188 | /* Intern int32_t constant. */ |
177 | TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k) | 189 | TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k) |
178 | { | 190 | { |
@@ -266,19 +278,18 @@ TValue *lj_ir_k64_reserve(jit_State *J) | |||
266 | return ir_k64_add(J, kp, 0); /* Set to 0. Final value is set later. */ | 278 | return ir_k64_add(J, kp, 0); /* Set to 0. Final value is set later. */ |
267 | } | 279 | } |
268 | 280 | ||
269 | /* Intern 64 bit constant, given by its address. */ | 281 | /* Intern 64 bit constant, given by its 64 bit pattern. */ |
270 | TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) | 282 | TRef lj_ir_k64(jit_State *J, IROp op, uint64_t u64) |
271 | { | 283 | { |
272 | IRIns *ir, *cir = J->cur.ir; | 284 | IRIns *ir, *cir = J->cur.ir; |
273 | IRRef ref; | 285 | IRRef ref; |
274 | IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64; | 286 | IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64; |
275 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) | 287 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) |
276 | if (ir_k64(&cir[ref]) == tv) | 288 | if (ir_k64(&cir[ref])->u64 == u64) |
277 | goto found; | 289 | goto found; |
278 | ref = ir_nextk(J); | 290 | ref = ir_nextk64(J); |
279 | ir = IR(ref); | 291 | ir = IR(ref); |
280 | lua_assert(checkptrGC(tv)); | 292 | ir[1].tv.u64 = u64; |
281 | setmref(ir->ptr, tv); | ||
282 | ir->t.irt = t; | 293 | ir->t.irt = t; |
283 | ir->o = op; | 294 | ir->o = op; |
284 | ir->prev = J->chain[op]; | 295 | ir->prev = J->chain[op]; |
@@ -290,13 +301,13 @@ found: | |||
290 | /* Intern FP constant, given by its 64 bit pattern. */ | 301 | /* Intern FP constant, given by its 64 bit pattern. */ |
291 | TRef lj_ir_knum_u64(jit_State *J, uint64_t u64) | 302 | TRef lj_ir_knum_u64(jit_State *J, uint64_t u64) |
292 | { | 303 | { |
293 | return lj_ir_k64(J, IR_KNUM, lj_ir_k64_find(J, u64)); | 304 | return lj_ir_k64(J, IR_KNUM, u64); |
294 | } | 305 | } |
295 | 306 | ||
296 | /* Intern 64 bit integer constant. */ | 307 | /* Intern 64 bit integer constant. */ |
297 | TRef lj_ir_kint64(jit_State *J, uint64_t u64) | 308 | TRef lj_ir_kint64(jit_State *J, uint64_t u64) |
298 | { | 309 | { |
299 | return lj_ir_k64(J, IR_KINT64, lj_ir_k64_find(J, u64)); | 310 | return lj_ir_k64(J, IR_KINT64, u64); |
300 | } | 311 | } |
301 | 312 | ||
302 | /* Check whether a number is int and return it. -0 is NOT considered an int. */ | 313 | /* Check whether a number is int and return it. -0 is NOT considered an int. */ |
@@ -367,7 +378,7 @@ TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) | |||
367 | IRRef ref; | 378 | IRRef ref; |
368 | lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr); | 379 | lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr); |
369 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) | 380 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) |
370 | if (mref(cir[ref].ptr, void) == ptr) | 381 | if (ir_kptr(&cir[ref]) == ptr) |
371 | goto found; | 382 | goto found; |
372 | ref = ir_nextk(J); | 383 | ref = ir_nextk(J); |
373 | ir = IR(ref); | 384 | ir = IR(ref); |
@@ -432,9 +443,8 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir) | |||
432 | case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break; | 443 | case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break; |
433 | case IR_KINT: setintV(tv, ir->i); break; | 444 | case IR_KINT: setintV(tv, ir->i); break; |
434 | case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; | 445 | case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; |
435 | case IR_KPTR: case IR_KKPTR: case IR_KNULL: | 446 | case IR_KPTR: case IR_KKPTR: setlightudV(tv, ir_kptr(ir)); break; |
436 | setlightudV(tv, mref(ir->ptr, void)); | 447 | case IR_KNULL: setlightudV(tv, NULL); break; |
437 | break; | ||
438 | case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; | 448 | case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; |
439 | #if LJ_HASFFI | 449 | #if LJ_HASFFI |
440 | case IR_KINT64: { | 450 | case IR_KINT64: { |