diff options
Diffstat (limited to 'src/lj_snap.c')
-rw-r--r-- | src/lj_snap.c | 146 |
1 files changed, 100 insertions, 46 deletions
diff --git a/src/lj_snap.c b/src/lj_snap.c index de8068ac..a47c0e3e 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c | |||
@@ -68,10 +68,22 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) | |||
68 | for (s = 0; s < nslots; s++) { | 68 | for (s = 0; s < nslots; s++) { |
69 | TRef tr = J->slot[s]; | 69 | TRef tr = J->slot[s]; |
70 | IRRef ref = tref_ref(tr); | 70 | IRRef ref = tref_ref(tr); |
71 | #if LJ_FR2 | ||
72 | if (s == 1) { /* Ignore slot 1 in LJ_FR2 mode, except if tailcalled. */ | ||
73 | if ((tr & TREF_FRAME)) | ||
74 | map[n++] = SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL); | ||
75 | continue; | ||
76 | } | ||
77 | if ((tr & (TREF_FRAME | TREF_CONT)) && !ref) { | ||
78 | cTValue *base = J->L->base - J->baseslot; | ||
79 | tr = J->slot[s] = (tr & 0xff0000) | lj_ir_k64(J, IR_KNUM, base[s].u64); | ||
80 | ref = tref_ref(tr); | ||
81 | } | ||
82 | #endif | ||
71 | if (ref) { | 83 | if (ref) { |
72 | SnapEntry sn = SNAP_TR(s, tr); | 84 | SnapEntry sn = SNAP_TR(s, tr); |
73 | IRIns *ir = &J->cur.ir[ref]; | 85 | IRIns *ir = &J->cur.ir[ref]; |
74 | if (!(sn & (SNAP_CONT|SNAP_FRAME)) && | 86 | if ((LJ_FR2 || !(sn & (SNAP_CONT|SNAP_FRAME))) && |
75 | ir->o == IR_SLOAD && ir->op1 == s && ref > retf) { | 87 | ir->o == IR_SLOAD && ir->op1 == s && ref > retf) { |
76 | /* No need to snapshot unmodified non-inherited slots. */ | 88 | /* No need to snapshot unmodified non-inherited slots. */ |
77 | if (!(ir->op2 & IRSLOAD_INHERIT)) | 89 | if (!(ir->op2 & IRSLOAD_INHERIT)) |
@@ -81,7 +93,7 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) | |||
81 | (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT) | 93 | (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT) |
82 | sn |= SNAP_NORESTORE; | 94 | sn |= SNAP_NORESTORE; |
83 | } | 95 | } |
84 | if (LJ_SOFTFP && irt_isnum(ir->t)) | 96 | if (LJ_SOFTFP32 && irt_isnum(ir->t)) |
85 | sn |= SNAP_SOFTFPNUM; | 97 | sn |= SNAP_SOFTFPNUM; |
86 | map[n++] = sn; | 98 | map[n++] = sn; |
87 | } | 99 | } |
@@ -90,32 +102,51 @@ static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots) | |||
90 | } | 102 | } |
91 | 103 | ||
92 | /* Add frame links at the end of the snapshot. */ | 104 | /* Add frame links at the end of the snapshot. */ |
93 | static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map) | 105 | static MSize snapshot_framelinks(jit_State *J, SnapEntry *map, uint8_t *topslot) |
94 | { | 106 | { |
95 | cTValue *frame = J->L->base - 1; | 107 | cTValue *frame = J->L->base - 1; |
96 | cTValue *lim = J->L->base - J->baseslot; | 108 | cTValue *lim = J->L->base - J->baseslot + LJ_FR2; |
97 | cTValue *ftop = frame + funcproto(frame_func(frame))->framesize; | 109 | GCfunc *fn = frame_func(frame); |
110 | cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top; | ||
111 | #if LJ_FR2 | ||
112 | uint64_t pcbase = (u64ptr(J->pc) << 8) | (J->baseslot - 2); | ||
113 | lua_assert(2 <= J->baseslot && J->baseslot <= 257); | ||
114 | memcpy(map, &pcbase, sizeof(uint64_t)); | ||
115 | #else | ||
98 | MSize f = 0; | 116 | MSize f = 0; |
99 | map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */ | 117 | map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */ |
118 | #endif | ||
100 | while (frame > lim) { /* Backwards traversal of all frames above base. */ | 119 | while (frame > lim) { /* Backwards traversal of all frames above base. */ |
101 | if (frame_islua(frame)) { | 120 | if (frame_islua(frame)) { |
121 | #if !LJ_FR2 | ||
102 | map[f++] = SNAP_MKPC(frame_pc(frame)); | 122 | map[f++] = SNAP_MKPC(frame_pc(frame)); |
123 | #endif | ||
103 | frame = frame_prevl(frame); | 124 | frame = frame_prevl(frame); |
104 | } else if (frame_iscont(frame)) { | 125 | } else if (frame_iscont(frame)) { |
126 | #if !LJ_FR2 | ||
105 | map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); | 127 | map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); |
106 | map[f++] = SNAP_MKPC(frame_contpc(frame)); | 128 | map[f++] = SNAP_MKPC(frame_contpc(frame)); |
129 | #endif | ||
107 | frame = frame_prevd(frame); | 130 | frame = frame_prevd(frame); |
108 | } else { | 131 | } else { |
109 | lua_assert(!frame_isc(frame)); | 132 | lua_assert(!frame_isc(frame)); |
133 | #if !LJ_FR2 | ||
110 | map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); | 134 | map[f++] = SNAP_MKFTSZ(frame_ftsz(frame)); |
135 | #endif | ||
111 | frame = frame_prevd(frame); | 136 | frame = frame_prevd(frame); |
112 | continue; | 137 | continue; |
113 | } | 138 | } |
114 | if (frame + funcproto(frame_func(frame))->framesize > ftop) | 139 | if (frame + funcproto(frame_func(frame))->framesize > ftop) |
115 | ftop = frame + funcproto(frame_func(frame))->framesize; | 140 | ftop = frame + funcproto(frame_func(frame))->framesize; |
116 | } | 141 | } |
142 | *topslot = (uint8_t)(ftop - lim); | ||
143 | #if LJ_FR2 | ||
144 | lua_assert(sizeof(SnapEntry) * 2 == sizeof(uint64_t)); | ||
145 | return 2; | ||
146 | #else | ||
117 | lua_assert(f == (MSize)(1 + J->framedepth)); | 147 | lua_assert(f == (MSize)(1 + J->framedepth)); |
118 | return (BCReg)(ftop - lim); | 148 | return f; |
149 | #endif | ||
119 | } | 150 | } |
120 | 151 | ||
121 | /* Take a snapshot of the current stack. */ | 152 | /* Take a snapshot of the current stack. */ |
@@ -125,16 +156,16 @@ static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap) | |||
125 | MSize nent; | 156 | MSize nent; |
126 | SnapEntry *p; | 157 | SnapEntry *p; |
127 | /* Conservative estimate. */ | 158 | /* Conservative estimate. */ |
128 | lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1); | 159 | lj_snap_grow_map(J, nsnapmap + nslots + (MSize)(LJ_FR2?2:J->framedepth+1)); |
129 | p = &J->cur.snapmap[nsnapmap]; | 160 | p = &J->cur.snapmap[nsnapmap]; |
130 | nent = snapshot_slots(J, p, nslots); | 161 | nent = snapshot_slots(J, p, nslots); |
131 | snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent); | 162 | snap->nent = (uint8_t)nent; |
163 | nent += snapshot_framelinks(J, p + nent, &snap->topslot); | ||
132 | snap->mapofs = (uint32_t)nsnapmap; | 164 | snap->mapofs = (uint32_t)nsnapmap; |
133 | snap->ref = (IRRef1)J->cur.nins; | 165 | snap->ref = (IRRef1)J->cur.nins; |
134 | snap->nent = (uint8_t)nent; | ||
135 | snap->nslots = (uint8_t)nslots; | 166 | snap->nslots = (uint8_t)nslots; |
136 | snap->count = 0; | 167 | snap->count = 0; |
137 | J->cur.nsnapmap = (uint32_t)(nsnapmap + nent + 1 + J->framedepth); | 168 | J->cur.nsnapmap = (uint32_t)(nsnapmap + nent); |
138 | } | 169 | } |
139 | 170 | ||
140 | /* Add or merge a snapshot. */ | 171 | /* Add or merge a snapshot. */ |
@@ -143,8 +174,8 @@ void lj_snap_add(jit_State *J) | |||
143 | MSize nsnap = J->cur.nsnap; | 174 | MSize nsnap = J->cur.nsnap; |
144 | MSize nsnapmap = J->cur.nsnapmap; | 175 | MSize nsnapmap = J->cur.nsnapmap; |
145 | /* Merge if no ins. inbetween or if requested and no guard inbetween. */ | 176 | /* Merge if no ins. inbetween or if requested and no guard inbetween. */ |
146 | if (J->mergesnap ? !irt_isguard(J->guardemit) : | 177 | if ((nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins) || |
147 | (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) { | 178 | (J->mergesnap && !irt_isguard(J->guardemit))) { |
148 | if (nsnap == 1) { /* But preserve snap #0 PC. */ | 179 | if (nsnap == 1) { /* But preserve snap #0 PC. */ |
149 | emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); | 180 | emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0); |
150 | goto nomerge; | 181 | goto nomerge; |
@@ -237,7 +268,8 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf, | |||
237 | case BCMbase: | 268 | case BCMbase: |
238 | if (op >= BC_CALLM && op <= BC_VARG) { | 269 | if (op >= BC_CALLM && op <= BC_VARG) { |
239 | BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ? | 270 | BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ? |
240 | maxslot : (bc_a(ins) + bc_c(ins)); | 271 | maxslot : (bc_a(ins) + bc_c(ins)+LJ_FR2); |
272 | if (LJ_FR2) DEF_SLOT(bc_a(ins)+1); | ||
241 | s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0); | 273 | s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0); |
242 | for (; s < top; s++) USE_SLOT(s); | 274 | for (; s < top; s++) USE_SLOT(s); |
243 | for (; s < maxslot; s++) DEF_SLOT(s); | 275 | for (; s < maxslot; s++) DEF_SLOT(s); |
@@ -281,8 +313,8 @@ void lj_snap_shrink(jit_State *J) | |||
281 | MSize n, m, nlim, nent = snap->nent; | 313 | MSize n, m, nlim, nent = snap->nent; |
282 | uint8_t udf[SNAP_USEDEF_SLOTS]; | 314 | uint8_t udf[SNAP_USEDEF_SLOTS]; |
283 | BCReg maxslot = J->maxslot; | 315 | BCReg maxslot = J->maxslot; |
284 | BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot); | ||
285 | BCReg baseslot = J->baseslot; | 316 | BCReg baseslot = J->baseslot; |
317 | BCReg minslot = snap_usedef(J, udf, snap_pc(&map[nent]), maxslot); | ||
286 | maxslot += baseslot; | 318 | maxslot += baseslot; |
287 | minslot += baseslot; | 319 | minslot += baseslot; |
288 | snap->nslots = (uint8_t)maxslot; | 320 | snap->nslots = (uint8_t)maxslot; |
@@ -342,7 +374,7 @@ IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir) | |||
342 | break; | 374 | break; |
343 | } | 375 | } |
344 | } | 376 | } |
345 | } else if (LJ_SOFTFP && ir->o == IR_HIOP) { | 377 | } else if (LJ_SOFTFP32 && ir->o == IR_HIOP) { |
346 | ref++; | 378 | ref++; |
347 | } else if (ir->o == IR_PVAL) { | 379 | } else if (ir->o == IR_PVAL) { |
348 | ref = ir->op1 + REF_BIAS; | 380 | ref = ir->op1 + REF_BIAS; |
@@ -368,8 +400,8 @@ static TRef snap_replay_const(jit_State *J, IRIns *ir) | |||
368 | case IR_KPRI: return TREF_PRI(irt_type(ir->t)); | 400 | case IR_KPRI: return TREF_PRI(irt_type(ir->t)); |
369 | case IR_KINT: return lj_ir_kint(J, ir->i); | 401 | case IR_KINT: return lj_ir_kint(J, ir->i); |
370 | case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); | 402 | case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t)); |
371 | case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir)); | 403 | case IR_KNUM: case IR_KINT64: |
372 | case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir)); | 404 | return lj_ir_k64(J, (IROp)ir->o, ir_k64(ir)->u64); |
373 | case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ | 405 | case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ |
374 | default: lua_assert(0); return TREF_NIL; break; | 406 | default: lua_assert(0); return TREF_NIL; break; |
375 | } | 407 | } |
@@ -442,7 +474,11 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
442 | goto setslot; | 474 | goto setslot; |
443 | bloomset(seen, ref); | 475 | bloomset(seen, ref); |
444 | if (irref_isk(ref)) { | 476 | if (irref_isk(ref)) { |
445 | tr = snap_replay_const(J, ir); | 477 | /* See special treatment of LJ_FR2 slot 1 in snapshot_slots() above. */ |
478 | if (LJ_FR2 && (sn == SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL))) | ||
479 | tr = 0; | ||
480 | else | ||
481 | tr = snap_replay_const(J, ir); | ||
446 | } else if (!regsp_used(ir->prev)) { | 482 | } else if (!regsp_used(ir->prev)) { |
447 | pass23 = 1; | 483 | pass23 = 1; |
448 | lua_assert(s != 0); | 484 | lua_assert(s != 0); |
@@ -450,13 +486,13 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
450 | } else { | 486 | } else { |
451 | IRType t = irt_type(ir->t); | 487 | IRType t = irt_type(ir->t); |
452 | uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT; | 488 | uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT; |
453 | if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; | 489 | if (LJ_SOFTFP32 && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM; |
454 | if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY); | 490 | if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY); |
455 | tr = emitir_raw(IRT(IR_SLOAD, t), s, mode); | 491 | tr = emitir_raw(IRT(IR_SLOAD, t), s, mode); |
456 | } | 492 | } |
457 | setslot: | 493 | setslot: |
458 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ | 494 | J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */ |
459 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s); | 495 | J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && (s != LJ_FR2)); |
460 | if ((sn & SNAP_FRAME)) | 496 | if ((sn & SNAP_FRAME)) |
461 | J->baseslot = s+1; | 497 | J->baseslot = s+1; |
462 | } | 498 | } |
@@ -484,7 +520,7 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
484 | if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { | 520 | if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) { |
485 | if (snap_pref(J, T, map, nent, seen, irs->op2) == 0) | 521 | if (snap_pref(J, T, map, nent, seen, irs->op2) == 0) |
486 | snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1); | 522 | snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1); |
487 | else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && | 523 | else if ((LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)) && |
488 | irs+1 < irlast && (irs+1)->o == IR_HIOP) | 524 | irs+1 < irlast && (irs+1)->o == IR_HIOP) |
489 | snap_pref(J, T, map, nent, seen, (irs+1)->op2); | 525 | snap_pref(J, T, map, nent, seen, (irs+1)->op2); |
490 | } | 526 | } |
@@ -543,17 +579,16 @@ void lj_snap_replay(jit_State *J, GCtrace *T) | |||
543 | lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT); | 579 | lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT); |
544 | val = snap_pref(J, T, map, nent, seen, irc->op1); | 580 | val = snap_pref(J, T, map, nent, seen, irc->op1); |
545 | val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); | 581 | val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT); |
546 | } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) && | 582 | } else if ((LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)) && |
547 | irs+1 < irlast && (irs+1)->o == IR_HIOP) { | 583 | irs+1 < irlast && (irs+1)->o == IR_HIOP) { |
548 | IRType t = IRT_I64; | 584 | IRType t = IRT_I64; |
549 | if (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP) | 585 | if (LJ_SOFTFP32 && irt_type((irs+1)->t) == IRT_SOFTFP) |
550 | t = IRT_NUM; | 586 | t = IRT_NUM; |
551 | lj_needsplit(J); | 587 | lj_needsplit(J); |
552 | if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) { | 588 | if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) { |
553 | uint64_t k = (uint32_t)T->ir[irs->op2].i + | 589 | uint64_t k = (uint32_t)T->ir[irs->op2].i + |
554 | ((uint64_t)T->ir[(irs+1)->op2].i << 32); | 590 | ((uint64_t)T->ir[(irs+1)->op2].i << 32); |
555 | val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM, | 591 | val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM, k); |
556 | lj_ir_k64_find(J, k)); | ||
557 | } else { | 592 | } else { |
558 | val = emitir_raw(IRT(IR_HIOP, t), val, | 593 | val = emitir_raw(IRT(IR_HIOP, t), val, |
559 | snap_pref(J, T, map, nent, seen, (irs+1)->op2)); | 594 | snap_pref(J, T, map, nent, seen, (irs+1)->op2)); |
@@ -600,17 +635,18 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, | |||
600 | int32_t *sps = &ex->spill[regsp_spill(rs)]; | 635 | int32_t *sps = &ex->spill[regsp_spill(rs)]; |
601 | if (irt_isinteger(t)) { | 636 | if (irt_isinteger(t)) { |
602 | setintV(o, *sps); | 637 | setintV(o, *sps); |
603 | #if !LJ_SOFTFP | 638 | #if !LJ_SOFTFP32 |
604 | } else if (irt_isnum(t)) { | 639 | } else if (irt_isnum(t)) { |
605 | o->u64 = *(uint64_t *)sps; | 640 | o->u64 = *(uint64_t *)sps; |
606 | #endif | 641 | #endif |
607 | } else if (LJ_64 && irt_islightud(t)) { | 642 | #if LJ_64 && !LJ_GC64 |
643 | } else if (irt_islightud(t)) { | ||
608 | /* 64 bit lightuserdata which may escape already has the tag bits. */ | 644 | /* 64 bit lightuserdata which may escape already has the tag bits. */ |
609 | o->u64 = *(uint64_t *)sps; | 645 | o->u64 = *(uint64_t *)sps; |
646 | #endif | ||
610 | } else { | 647 | } else { |
611 | lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */ | 648 | lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */ |
612 | setgcrefi(o->gcr, *sps); | 649 | setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t)); |
613 | setitype(o, irt_toitype(t)); | ||
614 | } | 650 | } |
615 | } else { /* Restore from register. */ | 651 | } else { /* Restore from register. */ |
616 | Reg r = regsp_reg(rs); | 652 | Reg r = regsp_reg(rs); |
@@ -624,14 +660,19 @@ static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex, | |||
624 | #if !LJ_SOFTFP | 660 | #if !LJ_SOFTFP |
625 | } else if (irt_isnum(t)) { | 661 | } else if (irt_isnum(t)) { |
626 | setnumV(o, ex->fpr[r-RID_MIN_FPR]); | 662 | setnumV(o, ex->fpr[r-RID_MIN_FPR]); |
663 | #elif LJ_64 /* && LJ_SOFTFP */ | ||
664 | } else if (irt_isnum(t)) { | ||
665 | o->u64 = ex->gpr[r-RID_MIN_GPR]; | ||
627 | #endif | 666 | #endif |
628 | } else if (LJ_64 && irt_islightud(t)) { | 667 | #if LJ_64 && !LJ_GC64 |
629 | /* 64 bit lightuserdata which may escape already has the tag bits. */ | 668 | } else if (irt_is64(t)) { |
669 | /* 64 bit values that already have the tag bits. */ | ||
630 | o->u64 = ex->gpr[r-RID_MIN_GPR]; | 670 | o->u64 = ex->gpr[r-RID_MIN_GPR]; |
671 | #endif | ||
672 | } else if (irt_ispri(t)) { | ||
673 | setpriV(o, irt_toitype(t)); | ||
631 | } else { | 674 | } else { |
632 | if (!irt_ispri(t)) | 675 | setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t)); |
633 | setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]); | ||
634 | setitype(o, irt_toitype(t)); | ||
635 | } | 676 | } |
636 | } | 677 | } |
637 | } | 678 | } |
@@ -647,8 +688,8 @@ static void snap_restoredata(GCtrace *T, ExitState *ex, | |||
647 | int32_t *src; | 688 | int32_t *src; |
648 | uint64_t tmp; | 689 | uint64_t tmp; |
649 | if (irref_isk(ref)) { | 690 | if (irref_isk(ref)) { |
650 | if (ir->o == IR_KNUM || ir->o == IR_KINT64) { | 691 | if (ir_isk64(ir)) { |
651 | src = mref(ir->ptr, int32_t); | 692 | src = (int32_t *)&ir[1]; |
652 | } else if (sz == 8) { | 693 | } else if (sz == 8) { |
653 | tmp = (uint64_t)(uint32_t)ir->i; | 694 | tmp = (uint64_t)(uint32_t)ir->i; |
654 | src = (int32_t *)&tmp; | 695 | src = (int32_t *)&tmp; |
@@ -685,8 +726,9 @@ static void snap_restoredata(GCtrace *T, ExitState *ex, | |||
685 | #else | 726 | #else |
686 | if (LJ_BE && sz == 4) src++; | 727 | if (LJ_BE && sz == 4) src++; |
687 | #endif | 728 | #endif |
688 | } | 729 | } else |
689 | #endif | 730 | #endif |
731 | if (LJ_64 && LJ_BE && sz == 4) src++; | ||
690 | } | 732 | } |
691 | } | 733 | } |
692 | lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8); | 734 | lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8); |
@@ -708,8 +750,9 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, | |||
708 | if (ir->o == IR_CNEW || ir->o == IR_CNEWI) { | 750 | if (ir->o == IR_CNEW || ir->o == IR_CNEWI) { |
709 | CTState *cts = ctype_cts(J->L); | 751 | CTState *cts = ctype_cts(J->L); |
710 | CTypeID id = (CTypeID)T->ir[ir->op1].i; | 752 | CTypeID id = (CTypeID)T->ir[ir->op1].i; |
711 | CTSize sz = lj_ctype_size(cts, id); | 753 | CTSize sz; |
712 | GCcdata *cd = lj_cdata_new(cts, id, sz); | 754 | CTInfo info = lj_ctype_info(cts, id, &sz); |
755 | GCcdata *cd = lj_cdata_newx(cts, id, sz, info); | ||
713 | setcdataV(J->L, o, cd); | 756 | setcdataV(J->L, o, cd); |
714 | if (ir->o == IR_CNEWI) { | 757 | if (ir->o == IR_CNEWI) { |
715 | uint8_t *p = (uint8_t *)cdataptr(cd); | 758 | uint8_t *p = (uint8_t *)cdataptr(cd); |
@@ -773,7 +816,7 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, | |||
773 | val = lj_tab_set(J->L, t, &tmp); | 816 | val = lj_tab_set(J->L, t, &tmp); |
774 | /* NOBARRIER: The table is new (marked white). */ | 817 | /* NOBARRIER: The table is new (marked white). */ |
775 | snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val); | 818 | snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val); |
776 | if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { | 819 | if (LJ_SOFTFP32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) { |
777 | snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp); | 820 | snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp); |
778 | val->u32.hi = tmp.u32.lo; | 821 | val->u32.hi = tmp.u32.lo; |
779 | } | 822 | } |
@@ -791,11 +834,15 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
791 | SnapShot *snap = &T->snap[snapno]; | 834 | SnapShot *snap = &T->snap[snapno]; |
792 | MSize n, nent = snap->nent; | 835 | MSize n, nent = snap->nent; |
793 | SnapEntry *map = &T->snapmap[snap->mapofs]; | 836 | SnapEntry *map = &T->snapmap[snap->mapofs]; |
794 | SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1]; | 837 | #if !LJ_FR2 || defined(LUA_USE_ASSERT) |
795 | int32_t ftsz0; | 838 | SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1-LJ_FR2]; |
839 | #endif | ||
840 | #if !LJ_FR2 | ||
841 | ptrdiff_t ftsz0; | ||
842 | #endif | ||
796 | TValue *frame; | 843 | TValue *frame; |
797 | BloomFilter rfilt = snap_renamefilter(T, snapno); | 844 | BloomFilter rfilt = snap_renamefilter(T, snapno); |
798 | const BCIns *pc = snap_pc(map[nent]); | 845 | const BCIns *pc = snap_pc(&map[nent]); |
799 | lua_State *L = J->L; | 846 | lua_State *L = J->L; |
800 | 847 | ||
801 | /* Set interpreter PC to the next PC to get correct error messages. */ | 848 | /* Set interpreter PC to the next PC to get correct error messages. */ |
@@ -808,8 +855,10 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
808 | } | 855 | } |
809 | 856 | ||
810 | /* Fill stack slots with data from the registers and spill slots. */ | 857 | /* Fill stack slots with data from the registers and spill slots. */ |
811 | frame = L->base-1; | 858 | frame = L->base-1-LJ_FR2; |
859 | #if !LJ_FR2 | ||
812 | ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */ | 860 | ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */ |
861 | #endif | ||
813 | for (n = 0; n < nent; n++) { | 862 | for (n = 0; n < nent; n++) { |
814 | SnapEntry sn = map[n]; | 863 | SnapEntry sn = map[n]; |
815 | if (!(sn & SNAP_NORESTORE)) { | 864 | if (!(sn & SNAP_NORESTORE)) { |
@@ -828,17 +877,22 @@ const BCIns *lj_snap_restore(jit_State *J, void *exptr) | |||
828 | continue; | 877 | continue; |
829 | } | 878 | } |
830 | snap_restoreval(J, T, ex, snapno, rfilt, ref, o); | 879 | snap_restoreval(J, T, ex, snapno, rfilt, ref, o); |
831 | if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) { | 880 | if (LJ_SOFTFP32 && (sn & SNAP_SOFTFPNUM) && tvisint(o)) { |
832 | TValue tmp; | 881 | TValue tmp; |
833 | snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp); | 882 | snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp); |
834 | o->u32.hi = tmp.u32.lo; | 883 | o->u32.hi = tmp.u32.lo; |
884 | #if !LJ_FR2 | ||
835 | } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { | 885 | } else if ((sn & (SNAP_CONT|SNAP_FRAME))) { |
836 | /* Overwrite tag with frame link. */ | 886 | /* Overwrite tag with frame link. */ |
837 | o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0; | 887 | setframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0); |
838 | L->base = o+1; | 888 | L->base = o+1; |
889 | #endif | ||
839 | } | 890 | } |
840 | } | 891 | } |
841 | } | 892 | } |
893 | #if LJ_FR2 | ||
894 | L->base += (map[nent+LJ_BE] & 0xff); | ||
895 | #endif | ||
842 | lua_assert(map + nent == flinks); | 896 | lua_assert(map + nent == flinks); |
843 | 897 | ||
844 | /* Compute current stack top. */ | 898 | /* Compute current stack top. */ |