aboutsummaryrefslogtreecommitdiff
path: root/src/lj_ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_ir.c')
-rw-r--r--src/lj_ir.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c
index 5e555fc3..63c98254 100644
--- a/src/lj_ir.c
+++ b/src/lj_ir.c
@@ -15,6 +15,7 @@
15#if LJ_HASJIT 15#if LJ_HASJIT
16 16
17#include "lj_gc.h" 17#include "lj_gc.h"
18#include "lj_buf.h"
18#include "lj_str.h" 19#include "lj_str.h"
19#include "lj_tab.h" 20#include "lj_tab.h"
20#include "lj_ir.h" 21#include "lj_ir.h"
@@ -29,6 +30,7 @@
29#endif 30#endif
30#include "lj_vm.h" 31#include "lj_vm.h"
31#include "lj_strscan.h" 32#include "lj_strscan.h"
33#include "lj_strfmt.h"
32#include "lj_lib.h" 34#include "lj_lib.h"
33 35
34/* Some local macros to save typing. Undef'd at the end. */ 36/* Some local macros to save typing. Undef'd at the end. */
@@ -207,24 +209,13 @@ void lj_ir_k64_freeall(jit_State *J)
207 lj_mem_free(J2G(J), k, sizeof(K64Array)); 209 lj_mem_free(J2G(J), k, sizeof(K64Array));
208 k = next; 210 k = next;
209 } 211 }
212 setmref(J->k64, NULL);
210} 213}
211 214
212/* Find 64 bit constant in chained array or add it. */ 215/* Get new 64 bit constant slot. */
213cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64) 216static TValue *ir_k64_add(jit_State *J, K64Array *kp, uint64_t u64)
214{ 217{
215 K64Array *k, *kp = NULL;
216 TValue *ntv; 218 TValue *ntv;
217 MSize idx;
218 /* Search for the constant in the whole chain of arrays. */
219 for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) {
220 kp = k; /* Remember previous element in list. */
221 for (idx = 0; idx < k->numk; idx++) { /* Search one array. */
222 TValue *tv = &k->k[idx];
223 if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */
224 return tv;
225 }
226 }
227 /* Constant was not found, need to add it. */
228 if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */ 219 if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */
229 K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array); 220 K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array);
230 setmref(kn->next, NULL); 221 setmref(kn->next, NULL);
@@ -240,6 +231,33 @@ cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64)
240 return ntv; 231 return ntv;
241} 232}
242 233
234/* Find 64 bit constant in chained array or add it. */
235cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64)
236{
237 K64Array *k, *kp = NULL;
238 MSize idx;
239 /* Search for the constant in the whole chain of arrays. */
240 for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) {
241 kp = k; /* Remember previous element in list. */
242 for (idx = 0; idx < k->numk; idx++) { /* Search one array. */
243 TValue *tv = &k->k[idx];
244 if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */
245 return tv;
246 }
247 }
248 /* Otherwise add a new constant. */
249 return ir_k64_add(J, kp, u64);
250}
251
252TValue *lj_ir_k64_reserve(jit_State *J)
253{
254 K64Array *k, *kp = NULL;
255 lj_ir_k64_find(J, 0); /* Intern dummy 0 to protect the reserved slot. */
256 /* Find last K64Array, if any. */
257 for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) kp = k;
258 return ir_k64_add(J, kp, 0); /* Set to 0. Final value is set later. */
259}
260
243/* Intern 64 bit constant, given by its address. */ 261/* Intern 64 bit constant, given by its address. */
244TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv) 262TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv)
245{ 263{
@@ -251,7 +269,7 @@ TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv)
251 goto found; 269 goto found;
252 ref = ir_nextk(J); 270 ref = ir_nextk(J);
253 ir = IR(ref); 271 ir = IR(ref);
254 lua_assert(checkptr32(tv)); 272 lua_assert(checkptrGC(tv));
255 setmref(ir->ptr, tv); 273 setmref(ir->ptr, tv);
256 ir->t.irt = t; 274 ir->t.irt = t;
257 ir->o = op; 275 ir->o = op;
@@ -305,6 +323,7 @@ TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)
305{ 323{
306 IRIns *ir, *cir = J->cur.ir; 324 IRIns *ir, *cir = J->cur.ir;
307 IRRef ref; 325 IRRef ref;
326 lua_assert(!LJ_GC64); /* TODO_GC64: major changes required. */
308 lua_assert(!isdead(J2G(J), o)); 327 lua_assert(!isdead(J2G(J), o));
309 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev) 328 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)
310 if (ir_kgc(&cir[ref]) == o) 329 if (ir_kgc(&cir[ref]) == o)
@@ -390,7 +409,7 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
390 UNUSED(L); 409 UNUSED(L);
391 lua_assert(ir->o != IR_KSLOT); /* Common mistake. */ 410 lua_assert(ir->o != IR_KSLOT); /* Common mistake. */
392 switch (ir->o) { 411 switch (ir->o) {
393 case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break; 412 case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break;
394 case IR_KINT: setintV(tv, ir->i); break; 413 case IR_KINT: setintV(tv, ir->i); break;
395 case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; 414 case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;
396 case IR_KPTR: case IR_KKPTR: case IR_KNULL: 415 case IR_KPTR: case IR_KKPTR: case IR_KNULL:
@@ -443,7 +462,8 @@ TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr)
443 if (!tref_isstr(tr)) { 462 if (!tref_isstr(tr)) {
444 if (!tref_isnumber(tr)) 463 if (!tref_isnumber(tr))
445 lj_trace_err(J, LJ_TRERR_BADTYPE); 464 lj_trace_err(J, LJ_TRERR_BADTYPE);
446 tr = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0); 465 tr = emitir(IRT(IR_TOSTR, IRT_STR), tr,
466 tref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT);
447 } 467 }
448 return tr; 468 return tr;
449} 469}