aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2023-08-13 02:25:12 +0200
committerMike Pall <mike>2023-08-13 02:25:12 +0200
commit119fd1fab0ebf235669456fbb57ee872fb05fc73 (patch)
tree2445387dda68d8559bf3fc584e4889bc48230116 /src
parent27af72e66f6a285298d1a9be370779aae945eb14 (diff)
downloadluajit-119fd1fab0ebf235669456fbb57ee872fb05fc73.tar.gz
luajit-119fd1fab0ebf235669456fbb57ee872fb05fc73.tar.bz2
luajit-119fd1fab0ebf235669456fbb57ee872fb05fc73.zip
Ensure forward progress on trace exit to BC_ITERN.
Also use a safer way to force a static dispatch for BC_RET*. Reported by Bartel Eerdekens. Analyzed by Peter Cawley. #1000 #1045
Diffstat (limited to 'src')
-rw-r--r--src/lj_trace.c37
-rw-r--r--src/vm_arm.dasc17
-rw-r--r--src/vm_arm64.dasc21
-rw-r--r--src/vm_mips.dasc27
-rw-r--r--src/vm_mips64.dasc27
-rw-r--r--src/vm_ppc.dasc22
-rw-r--r--src/vm_x64.dasc13
-rw-r--r--src/vm_x86.dasc17
8 files changed, 146 insertions, 35 deletions
diff --git a/src/lj_trace.c b/src/lj_trace.c
index 03c8d1d0..e019a79f 100644
--- a/src/lj_trace.c
+++ b/src/lj_trace.c
@@ -431,6 +431,12 @@ static void trace_start(jit_State *J)
431 return; 431 return;
432 } 432 }
433 433
434 /* Ensuring forward progress for BC_ITERN can trigger hotcount again. */
435 if (!J->parent && bc_op(*J->pc) == BC_JLOOP) { /* Already compiled. */
436 J->state = LJ_TRACE_IDLE; /* Silently ignored. */
437 return;
438 }
439
434 /* Get a new trace number. */ 440 /* Get a new trace number. */
435 traceno = trace_findfree(J); 441 traceno = trace_findfree(J);
436 if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */ 442 if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */
@@ -867,7 +873,7 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
867 ExitDataCP exd; 873 ExitDataCP exd;
868 int errcode, exitcode = J->exitcode; 874 int errcode, exitcode = J->exitcode;
869 TValue exiterr; 875 TValue exiterr;
870 const BCIns *pc; 876 const BCIns *pc, *retpc;
871 void *cf; 877 void *cf;
872 GCtrace *T; 878 GCtrace *T;
873 879
@@ -919,22 +925,7 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
919 } else { 925 } else {
920 trace_hotside(J, pc); 926 trace_hotside(J, pc);
921 } 927 }
922 if (bc_op(*pc) == BC_JLOOP) { 928 /* Return MULTRES or 0 or -17. */
923 BCIns *retpc = &traceref(J, bc_d(*pc))->startins;
924 int isret = bc_isret(bc_op(*retpc));
925 if (isret || bc_op(*retpc) == BC_ITERN) {
926 if (J->state == LJ_TRACE_RECORD) {
927 J->patchins = *pc;
928 J->patchpc = (BCIns *)pc;
929 *J->patchpc = *retpc;
930 J->bcskip = 1;
931 } else if (isret) {
932 pc = retpc;
933 setcframe_pc(cf, pc);
934 }
935 }
936 }
937 /* Return MULTRES or 0. */
938 ERRNO_RESTORE 929 ERRNO_RESTORE
939 switch (bc_op(*pc)) { 930 switch (bc_op(*pc)) {
940 case BC_CALLM: case BC_CALLMT: 931 case BC_CALLM: case BC_CALLMT:
@@ -943,6 +934,18 @@ int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
943 return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc)); 934 return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc));
944 case BC_TSETM: 935 case BC_TSETM:
945 return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc)); 936 return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc));
937 case BC_JLOOP:
938 retpc = &traceref(J, bc_d(*pc))->startins;
939 if (bc_isret(bc_op(*retpc)) || bc_op(*retpc) == BC_ITERN) {
940 /* Dispatch to original ins to ensure forward progress. */
941 if (J->state != LJ_TRACE_RECORD) return -17;
942 /* Unpatch bytecode when recording. */
943 J->patchins = *pc;
944 J->patchpc = (BCIns *)pc;
945 *J->patchpc = *retpc;
946 J->bcskip = 1;
947 }
948 return 0;
946 default: 949 default:
947 if (bc_op(*pc) >= BC_FUNCF) 950 if (bc_op(*pc) >= BC_FUNCF)
948 return (int)((BCReg)(L->top - L->base) + 1); 951 return (int)((BCReg)(L->top - L->base) + 1);
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index 770c1602..4df4b488 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -2196,8 +2196,8 @@ static void build_subroutines(BuildCtx *ctx)
2196 |.if JIT 2196 |.if JIT
2197 | ldr L, SAVE_L 2197 | ldr L, SAVE_L
2198 |1: 2198 |1:
2199 | cmp CARG1, #0 2199 | cmn CARG1, #LUA_ERRERR
2200 | blt >9 // Check for error from exit. 2200 | bhs >9 // Check for error from exit.
2201 | lsl RC, CARG1, #3 2201 | lsl RC, CARG1, #3
2202 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] 2202 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
2203 | str RC, SAVE_MULTRES 2203 | str RC, SAVE_MULTRES
@@ -2213,6 +2213,8 @@ static void build_subroutines(BuildCtx *ctx)
2213 | ldr INS, [PC], #4 2213 | ldr INS, [PC], #4
2214 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8. 2214 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2215 | st_vmstate CARG4 2215 | st_vmstate CARG4
2216 | cmn CARG1, #17 // Static dispatch?
2217 | beq >5
2216 | cmp OP, #BC_FUNCC+2 // Fast function? 2218 | cmp OP, #BC_FUNCC+2 // Fast function?
2217 | bhs >4 2219 | bhs >4
2218 |2: 2220 |2:
@@ -2238,6 +2240,17 @@ static void build_subroutines(BuildCtx *ctx)
2238 | ldr KBASE, [CARG3, #PC2PROTO(k)] 2240 | ldr KBASE, [CARG3, #PC2PROTO(k)]
2239 | b <2 2241 | b <2
2240 | 2242 |
2243 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2244 | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
2245 | decode_RD RC, INS
2246 | ldr TRACE:CARG1, [CARG1, RC, lsl #2]
2247 | ldr INS, TRACE:CARG1->startins
2248 | decode_OP OP, INS
2249 | decode_RA8 RA, INS
2250 | add OP, DISPATCH, OP, lsl #2
2251 | decode_RD RC, INS
2252 | ldr pc, [OP, #GG_DISP2STATIC]
2253 |
2241 |9: // Rethrow error from the right C frame. 2254 |9: // Rethrow error from the right C frame.
2242 | rsb CARG2, CARG1, #0 2255 | rsb CARG2, CARG1, #0
2243 | mov CARG1, L 2256 | mov CARG1, L
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index d45cc86b..effb8d91 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -2005,8 +2005,8 @@ static void build_subroutines(BuildCtx *ctx)
2005 |.if JIT 2005 |.if JIT
2006 | ldr L, SAVE_L 2006 | ldr L, SAVE_L
2007 |1: 2007 |1:
2008 | cmp CARG1w, #0 2008 | cmn CARG1w, #LUA_ERRERR
2009 | blt >9 // Check for error from exit. 2009 | bhs >9 // Check for error from exit.
2010 | lsl RC, CARG1, #3 2010 | lsl RC, CARG1, #3
2011 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC] 2011 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
2012 | movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48 2012 | movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48
@@ -2023,6 +2023,8 @@ static void build_subroutines(BuildCtx *ctx)
2023 | ldrb RBw, [PC, # OFS_OP] 2023 | ldrb RBw, [PC, # OFS_OP]
2024 | ldr INSw, [PC], #4 2024 | ldr INSw, [PC], #4
2025 | st_vmstate CARG4w 2025 | st_vmstate CARG4w
2026 | cmn CARG1w, #17 // Static dispatch?
2027 | beq >5
2026 | cmp RBw, #BC_FUNCC+2 // Fast function? 2028 | cmp RBw, #BC_FUNCC+2 // Fast function?
2027 | add TMP1, GL, INS, uxtb #3 2029 | add TMP1, GL, INS, uxtb #3
2028 | bhs >4 2030 | bhs >4
@@ -2033,12 +2035,12 @@ static void build_subroutines(BuildCtx *ctx)
2033 | decode_RA RA, INS 2035 | decode_RA RA, INS
2034 | lsr TMP0, INS, #16 2036 | lsr TMP0, INS, #16
2035 | csel RC, TMP0, RC, lo 2037 | csel RC, TMP0, RC, lo
2036 | blo >5 2038 | blo >3
2037 | ldr CARG3, [BASE, FRAME_FUNC] 2039 | ldr CARG3, [BASE, FRAME_FUNC]
2038 | sub RC, RC, #8 2040 | sub RC, RC, #8
2039 | add RA, BASE, RA, lsl #3 // Yes: RA = BASE+framesize*8, RC = nargs*8 2041 | add RA, BASE, RA, lsl #3 // Yes: RA = BASE+framesize*8, RC = nargs*8
2040 | and LFUNC:CARG3, CARG3, #LJ_GCVMASK 2042 | and LFUNC:CARG3, CARG3, #LJ_GCVMASK
2041 |5: 2043 |3:
2042 | br_auth RB 2044 | br_auth RB
2043 | 2045 |
2044 |4: // Check frame below fast function. 2046 |4: // Check frame below fast function.
@@ -2055,6 +2057,17 @@ static void build_subroutines(BuildCtx *ctx)
2055 | ldr KBASE, [CARG3, #PC2PROTO(k)] 2057 | ldr KBASE, [CARG3, #PC2PROTO(k)]
2056 | b <2 2058 | b <2
2057 | 2059 |
2060 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2061 | ldr RA, [GL, #GL_J(trace)]
2062 | decode_RD RC, INS
2063 | ldr TRACE:RA, [RA, RC, lsl #3]
2064 | ldr INSw, TRACE:RA->startins
2065 | add TMP0, GL, INS, uxtb #3
2066 | decode_RA RA, INS
2067 | ldr RB, [TMP0, #GG_G2DISP+GG_DISP2STATIC]
2068 | decode_RD RC, INS
2069 | br_auth RB
2070 |
2058 |9: // Rethrow error from the right C frame. 2071 |9: // Rethrow error from the right C frame.
2059 | neg CARG2w, CARG1w 2072 | neg CARG2w, CARG1w
2060 | mov CARG1, L 2073 | mov CARG1, L
diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc
index 34645bf1..bfdcfc1e 100644
--- a/src/vm_mips.dasc
+++ b/src/vm_mips.dasc
@@ -2466,7 +2466,8 @@ static void build_subroutines(BuildCtx *ctx)
2466 | addiu DISPATCH, JGL, -GG_DISP2G-32768 2466 | addiu DISPATCH, JGL, -GG_DISP2G-32768
2467 | sw BASE, L->base 2467 | sw BASE, L->base
2468 |1: 2468 |1:
2469 | bltz CRET1, >9 // Check for error from exit. 2469 | sltiu TMP0, CRET1, -LUA_ERRERR // Check for error from exit.
2470 | beqz TMP0, >9
2470 |. lw LFUNC:RB, FRAME_FUNC(BASE) 2471 |. lw LFUNC:RB, FRAME_FUNC(BASE)
2471 | .FPU lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). 2472 | .FPU lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
2472 | sll MULTRES, CRET1, 3 2473 | sll MULTRES, CRET1, 3
@@ -2480,14 +2481,16 @@ static void build_subroutines(BuildCtx *ctx)
2480 | .FPU cvt.d.s TOBIT, TOBIT 2481 | .FPU cvt.d.s TOBIT, TOBIT
2481 | // Modified copy of ins_next which handles function header dispatch, too. 2482 | // Modified copy of ins_next which handles function header dispatch, too.
2482 | lw INS, 0(PC) 2483 | lw INS, 0(PC)
2483 | addiu PC, PC, 4 2484 | addiu CRET1, CRET1, 17 // Static dispatch?
2484 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1 2485 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1
2485 | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) 2486 | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
2487 | decode_RD8a RD, INS
2488 | beqz CRET1, >5
2489 |. addiu PC, PC, 4
2486 | decode_OP4a TMP1, INS 2490 | decode_OP4a TMP1, INS
2487 | decode_OP4b TMP1 2491 | decode_OP4b TMP1
2488 | sltiu TMP2, TMP1, BC_FUNCF*4
2489 | addu TMP0, DISPATCH, TMP1 2492 | addu TMP0, DISPATCH, TMP1
2490 | decode_RD8a RD, INS 2493 | sltiu TMP2, TMP1, BC_FUNCF*4
2491 | lw AT, 0(TMP0) 2494 | lw AT, 0(TMP0)
2492 | decode_RA8a RA, INS 2495 | decode_RA8a RA, INS
2493 | beqz TMP2, >2 2496 | beqz TMP2, >2
@@ -2515,6 +2518,22 @@ static void build_subroutines(BuildCtx *ctx)
2515 | jr AT 2518 | jr AT
2516 |. addu RA, RA, BASE 2519 |. addu RA, RA, BASE
2517 | 2520 |
2521 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2522 | lw TMP0, DISPATCH_J(trace)(DISPATCH)
2523 | decode_RD4b RD
2524 | addu TMP0, TMP0, RD
2525 | lw TRACE:TMP2, 0(TMP0)
2526 | lw INS, TRACE:TMP2->startins
2527 | decode_OP4a TMP1, INS
2528 | decode_OP4b TMP1
2529 | addu TMP0, DISPATCH, TMP1
2530 | decode_RD8a RD, INS
2531 | lw AT, GG_DISP2STATIC(TMP0)
2532 | decode_RA8a RA, INS
2533 | decode_RD8b RD
2534 | jr AT
2535 |. decode_RA8b RA
2536 |
2518 |9: // Rethrow error from the right C frame. 2537 |9: // Rethrow error from the right C frame.
2519 | load_got lj_err_trace 2538 | load_got lj_err_trace
2520 | sub CARG2, r0, CRET1 2539 | sub CARG2, r0, CRET1
diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc
index 651bc42e..801087b3 100644
--- a/src/vm_mips64.dasc
+++ b/src/vm_mips64.dasc
@@ -2571,7 +2571,8 @@ static void build_subroutines(BuildCtx *ctx)
2571 | daddiu DISPATCH, JGL, -GG_DISP2G-32768 2571 | daddiu DISPATCH, JGL, -GG_DISP2G-32768
2572 | sd BASE, L->base 2572 | sd BASE, L->base
2573 |1: 2573 |1:
2574 | bltz CRET1, >9 // Check for error from exit. 2574 | sltiu TMP0, CRET1, -LUA_ERRERR // Check for error from exit.
2575 | beqz TMP0, >9
2575 |. ld LFUNC:RB, FRAME_FUNC(BASE) 2576 |. ld LFUNC:RB, FRAME_FUNC(BASE)
2576 | .FPU lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float). 2577 | .FPU lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
2577 | dsll MULTRES, CRET1, 3 2578 | dsll MULTRES, CRET1, 3
@@ -2586,14 +2587,16 @@ static void build_subroutines(BuildCtx *ctx)
2586 | .FPU cvt.d.s TOBIT, TOBIT 2587 | .FPU cvt.d.s TOBIT, TOBIT
2587 | // Modified copy of ins_next which handles function header dispatch, too. 2588 | // Modified copy of ins_next which handles function header dispatch, too.
2588 | lw INS, 0(PC) 2589 | lw INS, 0(PC)
2589 | daddiu PC, PC, 4 2590 | addiu CRET1, CRET1, 17 // Static dispatch?
2590 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1 2591 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1
2591 | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) 2592 | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
2593 | decode_RD8a RD, INS
2594 | beqz CRET1, >5
2595 |. daddiu PC, PC, 4
2592 | decode_OP8a TMP1, INS 2596 | decode_OP8a TMP1, INS
2593 | decode_OP8b TMP1 2597 | decode_OP8b TMP1
2594 | sltiu TMP2, TMP1, BC_FUNCF*8
2595 | daddu TMP0, DISPATCH, TMP1 2598 | daddu TMP0, DISPATCH, TMP1
2596 | decode_RD8a RD, INS 2599 | sltiu TMP2, TMP1, BC_FUNCF*8
2597 | ld AT, 0(TMP0) 2600 | ld AT, 0(TMP0)
2598 | decode_RA8a RA, INS 2601 | decode_RA8a RA, INS
2599 | beqz TMP2, >2 2602 | beqz TMP2, >2
@@ -2622,6 +2625,22 @@ static void build_subroutines(BuildCtx *ctx)
2622 | jr AT 2625 | jr AT
2623 |. daddu RA, RA, BASE 2626 |. daddu RA, RA, BASE
2624 | 2627 |
2628 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2629 | ld TMP0, DISPATCH_J(trace)(DISPATCH)
2630 | decode_RD8b RD
2631 | daddu TMP0, TMP0, RD
2632 | ld TRACE:TMP2, 0(TMP0)
2633 | lw INS, TRACE:TMP2->startins
2634 | decode_OP8a TMP1, INS
2635 | decode_OP8b TMP1
2636 | daddu TMP0, DISPATCH, TMP1
2637 | decode_RD8a RD, INS
2638 | ld AT, GG_DISP2STATIC(TMP0)
2639 | decode_RA8a RA, INS
2640 | decode_RD8b RD
2641 | jr AT
2642 |. decode_RA8b RA
2643 |
2625 |9: // Rethrow error from the right C frame. 2644 |9: // Rethrow error from the right C frame.
2626 | load_got lj_err_trace 2645 | load_got lj_err_trace
2627 | sub CARG2, r0, CRET1 2646 | sub CARG2, r0, CRET1
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
index 3cad37d2..73d60ae4 100644
--- a/src/vm_ppc.dasc
+++ b/src/vm_ppc.dasc
@@ -3015,8 +3015,9 @@ static void build_subroutines(BuildCtx *ctx)
3015 | addi DISPATCH, JGL, -GG_DISP2G-32768 3015 | addi DISPATCH, JGL, -GG_DISP2G-32768
3016 | stp BASE, L->base 3016 | stp BASE, L->base
3017 |1: 3017 |1:
3018 | cmpwi CARG1, 0 3018 | li TMP2, -LUA_ERRERR
3019 | blt >9 // Check for error from exit. 3019 | cmplw CARG1, TMP2
3020 | bge >9 // Check for error from exit.
3020 | lwz LFUNC:RB, FRAME_FUNC(BASE) 3021 | lwz LFUNC:RB, FRAME_FUNC(BASE)
3021 | slwi MULTRES, CARG1, 3 3022 | slwi MULTRES, CARG1, 3
3022 | li TMP2, 0 3023 | li TMP2, 0
@@ -3041,6 +3042,8 @@ static void build_subroutines(BuildCtx *ctx)
3041 | addi PC, PC, 4 3042 | addi PC, PC, 4
3042 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1. 3043 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1.
3043 | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH) 3044 | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
3045 | cmpwi CARG1, -17 // Static dispatch?
3046 | beq >5
3044 | decode_OPP TMP1, INS 3047 | decode_OPP TMP1, INS
3045 | decode_RA8 RA, INS 3048 | decode_RA8 RA, INS
3046 | lpx TMP0, DISPATCH, TMP1 3049 | lpx TMP0, DISPATCH, TMP1
@@ -3070,6 +3073,21 @@ static void build_subroutines(BuildCtx *ctx)
3070 | add RA, RA, BASE 3073 | add RA, RA, BASE
3071 | bctr 3074 | bctr
3072 | 3075 |
3076 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
3077 | lwz TMP1, DISPATCH_J(trace)(DISPATCH)
3078 | decode_RD4 RD, INS
3079 | lwzx TRACE:TMP1, TMP1, RD
3080 | lwz INS, TRACE:TMP1->startins
3081 | decode_OPP TMP1, INS
3082 | addi TMP1, TMP1, GG_DISP2STATIC
3083 | lpx TMP0, DISPATCH, TMP1
3084 | mtctr TMP0
3085 | decode_RB8 RB, INS
3086 | decode_RD8 RD, INS
3087 | decode_RA8 RA, INS
3088 | decode_RC8 RC, INS
3089 | bctr
3090 |
3073 |9: // Rethrow error from the right C frame. 3091 |9: // Rethrow error from the right C frame.
3074 | neg CARG2, CARG1 3092 | neg CARG2, CARG1
3075 | mr CARG1, L 3093 | mr CARG1, L
diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc
index 03d96557..5983eeed 100644
--- a/src/vm_x64.dasc
+++ b/src/vm_x64.dasc
@@ -2453,7 +2453,7 @@ static void build_subroutines(BuildCtx *ctx)
2453 | mov r12, [RA] 2453 | mov r12, [RA]
2454 | mov rsp, RA // Reposition stack to C frame. 2454 | mov rsp, RA // Reposition stack to C frame.
2455 |.endif 2455 |.endif
2456 | test RDd, RDd; js >9 // Check for error from exit. 2456 | cmp RDd, -LUA_ERRERR; jae >9 // Check for error from exit.
2457 | mov L:RB, SAVE_L 2457 | mov L:RB, SAVE_L
2458 | mov MULTRES, RDd 2458 | mov MULTRES, RDd
2459 | mov LFUNC:KBASE, [BASE-16] 2459 | mov LFUNC:KBASE, [BASE-16]
@@ -2469,6 +2469,8 @@ static void build_subroutines(BuildCtx *ctx)
2469 | movzx OP, RCL 2469 | movzx OP, RCL
2470 | add PC, 4 2470 | add PC, 4
2471 | shr RCd, 16 2471 | shr RCd, 16
2472 | cmp MULTRES, -17 // Static dispatch?
2473 | je >5
2472 | cmp OP, BC_FUNCF // Function header? 2474 | cmp OP, BC_FUNCF // Function header?
2473 | jb >3 2475 | jb >3
2474 | cmp OP, BC_FUNCC+2 // Fast function? 2476 | cmp OP, BC_FUNCC+2 // Fast function?
@@ -2491,6 +2493,15 @@ static void build_subroutines(BuildCtx *ctx)
2491 | mov KBASE, [KBASE+PC2PROTO(k)] 2493 | mov KBASE, [KBASE+PC2PROTO(k)]
2492 | jmp <2 2494 | jmp <2
2493 | 2495 |
2496 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2497 | mov RA, [DISPATCH+DISPATCH_J(trace)]
2498 | mov TRACE:RA, [RA+RD*8]
2499 | mov RCd, TRACE:RA->startins
2500 | movzx RAd, RCH
2501 | movzx OP, RCL
2502 | shr RCd, 16
2503 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]
2504 |
2494 |9: // Rethrow error from the right C frame. 2505 |9: // Rethrow error from the right C frame.
2495 | mov CARG2d, RDd 2506 | mov CARG2d, RDd
2496 | mov CARG1, L:RB 2507 | mov CARG1, L:RB
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index 18ca87b5..f7847762 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -2902,7 +2902,7 @@ static void build_subroutines(BuildCtx *ctx)
2902 | mov r13, TMPa 2902 | mov r13, TMPa
2903 | mov r12, TMPQ 2903 | mov r12, TMPQ
2904 |.endif 2904 |.endif
2905 | test RD, RD; js >9 // Check for error from exit. 2905 | cmp RD, -LUA_ERRERR; jae >9 // Check for error from exit.
2906 | mov L:RB, SAVE_L 2906 | mov L:RB, SAVE_L
2907 | mov MULTRES, RD 2907 | mov MULTRES, RD
2908 | mov LFUNC:KBASE, [BASE-8] 2908 | mov LFUNC:KBASE, [BASE-8]
@@ -2917,6 +2917,8 @@ static void build_subroutines(BuildCtx *ctx)
2917 | movzx OP, RCL 2917 | movzx OP, RCL
2918 | add PC, 4 2918 | add PC, 4
2919 | shr RC, 16 2919 | shr RC, 16
2920 | cmp MULTRES, -17 // Static dispatch?
2921 | je >5
2920 | cmp OP, BC_FUNCF // Function header? 2922 | cmp OP, BC_FUNCF // Function header?
2921 | jb >3 2923 | jb >3
2922 | cmp OP, BC_FUNCC+2 // Fast function? 2924 | cmp OP, BC_FUNCC+2 // Fast function?
@@ -2942,6 +2944,19 @@ static void build_subroutines(BuildCtx *ctx)
2942 | mov KBASE, [KBASE+PC2PROTO(k)] 2944 | mov KBASE, [KBASE+PC2PROTO(k)]
2943 | jmp <2 2945 | jmp <2
2944 | 2946 |
2947 |5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
2948 | mov RA, [DISPATCH+DISPATCH_J(trace)]
2949 | mov TRACE:RA, [RA+RD*4]
2950 | mov RC, TRACE:RA->startins
2951 | movzx RA, RCH
2952 | movzx OP, RCL
2953 | shr RC, 16
2954 |.if X64
2955 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]
2956 |.else
2957 | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC]
2958 |.endif
2959 |
2945 |9: // Rethrow error from the right C frame. 2960 |9: // Rethrow error from the right C frame.
2946 | mov FCARG2, RD 2961 | mov FCARG2, RD
2947 | mov FCARG1, L:RB 2962 | mov FCARG1, L:RB