aboutsummaryrefslogtreecommitdiff
path: root/src/buildvm_x86.dasc
diff options
context:
space:
mode:
authorMike Pall <mike>2009-12-08 20:35:29 +0100
committerMike Pall <mike>2009-12-08 20:35:29 +0100
commit3f1f9e11f4f699ae94182d4cba158092f434a7f6 (patch)
tree88fbb674a21a1d554d4b1ee9d4ef2c5fed6a1d88 /src/buildvm_x86.dasc
parent5287b9326479ea2b7dddd6f642673e58e5a7f354 (diff)
downloadluajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.tar.gz
luajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.tar.bz2
luajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.zip
Fast forward to sync public repo.
Compile math.sinh(), math.cosh(), math.tanh() and math.random(). Compile various io.*() functions. Drive the GC forward on string allocations in the parser. Improve KNUM fuse vs. load heuristics. Add abstract C call handling to IR.
Diffstat (limited to 'src/buildvm_x86.dasc')
-rw-r--r--src/buildvm_x86.dasc117
1 files changed, 58 insertions, 59 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc
index 09cfa6dc..e857a6be 100644
--- a/src/buildvm_x86.dasc
+++ b/src/buildvm_x86.dasc
@@ -30,6 +30,9 @@
30|.define RD, RC 30|.define RD, RC
31|.define RDL, RCL 31|.define RDL, RCL
32| 32|
33|.define FCARG1, ecx // Fastcall arguments.
34|.define FCARG2, edx
35|
33|// Type definitions. Some of these are only used for documentation. 36|// Type definitions. Some of these are only used for documentation.
34|.type L, lua_State 37|.type L, lua_State
35|.type GL, global_State 38|.type GL, global_State
@@ -1066,7 +1069,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
1066 | mov RB, LJ_TNUMX 1069 | mov RB, LJ_TNUMX
1067 |7: 1070 |7:
1068 | not RB 1071 | not RB
1069 | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(basemt)] 1072 | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]
1070 | jmp <2 1073 | jmp <2
1071 | 1074 |
1072 |.ffunc_2 setmetatable 1075 |.ffunc_2 setmetatable
@@ -1126,17 +1129,17 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
1126 | jmp ->fff_res1 1129 | jmp ->fff_res1
1127 |3: // Handle numbers inline, unless a number base metatable is present. 1130 |3: // Handle numbers inline, unless a number base metatable is present.
1128 | cmp dword [RA+4], LJ_TISNUM; ja ->fff_fallback 1131 | cmp dword [RA+4], LJ_TISNUM; ja ->fff_fallback
1129 | cmp dword [DISPATCH+DISPATCH_GL(basemt)+4*(~LJ_TNUMX)], 0 1132 | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0
1130 | jne ->fff_fallback 1133 | jne ->fff_fallback
1131 | ffgccheck // Caveat: uses label 1. 1134 | ffgccheck // Caveat: uses label 1.
1132 | mov L:RB, SAVE_L 1135 | mov L:RB, SAVE_L
1133 | mov ARG1, L:RB
1134 | mov ARG2, RA
1135 | mov L:RB->base, RA // Add frame since C call can throw. 1136 | mov L:RB->base, RA // Add frame since C call can throw.
1136 | mov [RA-4], PC 1137 | mov [RA-4], PC
1137 | mov SAVE_PC, PC // Redundant (but a defined value). 1138 | mov SAVE_PC, PC // Redundant (but a defined value).
1138 | mov ARG3, BASE // Save BASE. 1139 | mov ARG3, BASE // Save BASE.
1139 | call extern lj_str_fromnum // (lua_State *L, lua_Number *np) 1140 | mov FCARG2, RA // Caveat: FCARG2 == BASE
1141 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
1142 | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np)
1140 | // GCstr returned in eax (RC). 1143 | // GCstr returned in eax (RC).
1141 | mov RA, L:RB->base 1144 | mov RA, L:RB->base
1142 | mov BASE, ARG3 1145 | mov BASE, ARG3
@@ -1762,11 +1765,10 @@ static void build_subroutines(BuildCtx *ctx, int cmov)
1762 | 1765 |
1763 |.ffunc_1 table_getn 1766 |.ffunc_1 table_getn
1764 | cmp dword [RA+4], LJ_TTAB; jne ->fff_fallback 1767 | cmp dword [RA+4], LJ_TTAB; jne ->fff_fallback
1765 | mov TAB:RB, [RA] 1768 | mov ARG2, BASE // Save RA and BASE.
1766 | mov ARG1, TAB:RB 1769 | mov RB, RA
1767 | mov RB, RA // Save RA and BASE. 1770 | mov TAB:FCARG1, [RA] // Caveat: FCARG1 == RA
1768 | mov ARG2, BASE 1771 | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t)
1769 | call extern lj_tab_len // (GCtab *t)
1770 | // Length of table returned in eax (RC). 1772 | // Length of table returned in eax (RC).
1771 | mov ARG1, RC 1773 | mov ARG1, RC
1772 | mov RA, RB // Restore RA and BASE. 1774 | mov RA, RB // Restore RA and BASE.
@@ -2512,10 +2514,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov)
2512 | ins_next 2514 | ins_next
2513 |2: 2515 |2:
2514 | checktab RD, ->vmeta_len 2516 | checktab RD, ->vmeta_len
2515 | mov TAB:RD, [BASE+RD*8] 2517 | mov TAB:FCARG1, [BASE+RD*8]
2516 | mov ARG1, TAB:RD
2517 | mov RB, BASE // Save BASE. 2518 | mov RB, BASE // Save BASE.
2518 | call extern lj_tab_len // (GCtab *t) 2519 | call extern lj_tab_len@4 // (GCtab *t)
2519 | // Length of table returned in eax (RC). 2520 | // Length of table returned in eax (RC).
2520 | mov ARG1, RC 2521 | mov ARG1, RC
2521 | mov BASE, RB // Restore BASE. 2522 | mov BASE, RB // Restore BASE.
@@ -2665,66 +2666,63 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov)
2665 | ins_next 2666 | ins_next
2666 break; 2667 break;
2667 case BC_USETV: 2668 case BC_USETV:
2669#define TV2MARKOFS \
2670 ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
2668 | ins_AD // RA = upvalue #, RD = src 2671 | ins_AD // RA = upvalue #, RD = src
2669 | // Really ugly code due to the lack of a 4th free register.
2670 | mov LFUNC:RB, [BASE-8] 2672 | mov LFUNC:RB, [BASE-8]
2671 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] 2673 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
2672 | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv) 2674 | cmp byte UPVAL:RB->closed, 0
2673 | jnz >4
2674 |1:
2675 | mov RA, [BASE+RD*8]
2676 |2:
2677 | mov RB, UPVAL:RB->v 2675 | mov RB, UPVAL:RB->v
2676 | mov RA, [BASE+RD*8]
2678 | mov RD, [BASE+RD*8+4] 2677 | mov RD, [BASE+RD*8+4]
2679 | mov [RB], RA 2678 | mov [RB], RA
2680 | mov [RB+4], RD 2679 | mov [RB+4], RD
2681 |3: 2680 | jz >1
2681 | // Check barrier for closed upvalue.
2682 | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv)
2683 | jnz >2
2684 |1:
2682 | ins_next 2685 | ins_next
2683 | 2686 |
2684 |4: // Upvalue is black. Check if new value is collectable and white. 2687 |2: // Upvalue is black. Check if new value is collectable and white.
2685 | mov RA, [BASE+RD*8+4] 2688 | sub RD, LJ_TISGCV
2686 | sub RA, LJ_TISGCV 2689 | cmp RD, LJ_TISNUM - LJ_TISGCV // tvisgcv(v)
2687 | cmp RA, LJ_TISNUM - LJ_TISGCV // tvisgcv(v)
2688 | jbe <1 2690 | jbe <1
2689 | mov GCOBJ:RA, [BASE+RD*8]
2690 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v) 2691 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v)
2691 | jz <2 2692 | jz <1
2692 | // Crossed a write barrier. So move the barrier forward. 2693 | // Crossed a write barrier. Move the barrier forward.
2693 | mov ARG2, UPVAL:RB 2694 | xchg FCARG2, RB // Save BASE (FCARG2 == BASE).
2694 | mov ARG3, GCOBJ:RA 2695 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
2695 | mov RB, UPVAL:RB->v 2696 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
2696 | mov RD, [BASE+RD*8+4] 2697 | mov BASE, RB // Restore BASE.
2697 | mov [RB], GCOBJ:RA 2698 | jmp <1
2698 | mov [RB+4], RD
2699 |->BC_USETV_Z:
2700 | mov L:RB, SAVE_L
2701 | lea GL:RA, [DISPATCH+GG_DISP2G]
2702 | mov L:RB->base, BASE
2703 | mov ARG1, GL:RA
2704 | call extern lj_gc_barrieruv // (global_State *g, GCobj *o, GCobj *v)
2705 | mov BASE, L:RB->base
2706 | jmp <3
2707 break; 2699 break;
2700#undef TV2MARKOFS
2708 case BC_USETS: 2701 case BC_USETS:
2709 | ins_AND // RA = upvalue #, RD = str const (~) 2702 | ins_AND // RA = upvalue #, RD = str const (~)
2710 | mov LFUNC:RB, [BASE-8] 2703 | mov LFUNC:RB, [BASE-8]
2711 | mov GCOBJ:RD, [KBASE+RD*4]
2712 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)] 2704 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
2713 | mov RA, UPVAL:RB->v 2705 | mov GCOBJ:RA, [KBASE+RD*4]
2714 | mov dword [RA+4], LJ_TSTR 2706 | mov RD, UPVAL:RB->v
2715 | mov [RA], GCOBJ:RD 2707 | mov [RD], GCOBJ:RA
2708 | mov dword [RD+4], LJ_TSTR
2716 | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv) 2709 | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv)
2717 | jnz >2 2710 | jnz >2
2718 |1: 2711 |1:
2719 | ins_next 2712 | ins_next
2720 | 2713 |
2721 |2: // Upvalue is black. Check if string is white. 2714 |2: // Check if string is white and ensure upvalue is closed.
2722 | test byte GCOBJ:RD->gch.marked, LJ_GC_WHITES // iswhite(str) 2715 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str)
2723 | jz <1 2716 | jz <1
2724 | // Crossed a write barrier. So move the barrier forward. 2717 | cmp byte UPVAL:RB->closed, 0
2725 | mov ARG3, GCOBJ:RD 2718 | jz <1
2726 | mov ARG2, UPVAL:RB 2719 | // Crossed a write barrier. Move the barrier forward.
2727 | jmp ->BC_USETV_Z 2720 | mov RB, BASE // Save BASE (FCARG2 == BASE).
2721 | mov FCARG2, RD
2722 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
2723 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
2724 | mov BASE, RB // Restore BASE.
2725 | jmp <1
2728 break; 2726 break;
2729 case BC_USETN: 2727 case BC_USETN:
2730 | ins_AD // RA = upvalue #, RD = num const 2728 | ins_AD // RA = upvalue #, RD = num const
@@ -2808,23 +2806,22 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov)
2808 | mov dword [BASE+RA*8+4], LJ_TTAB 2806 | mov dword [BASE+RA*8+4], LJ_TTAB
2809 | ins_next 2807 | ins_next
2810 |2: 2808 |2:
2811 | call extern lj_gc_step_fixtop // (lua_State *L) 2809 | mov L:FCARG1, L:RB
2812 | mov ARG1, L:RB // Args owned by callee. Set it again. 2810 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
2813 | jmp <1 2811 | jmp <1
2814 break; 2812 break;
2815 case BC_TDUP: 2813 case BC_TDUP:
2816 | ins_AND // RA = dst, RD = table const (~) (holding template table) 2814 | ins_AND // RA = dst, RD = table const (~) (holding template table)
2817 | mov TAB:RD, [KBASE+RD*4]
2818 | mov L:RB, SAVE_L 2815 | mov L:RB, SAVE_L
2819 | mov ARG2, TAB:RD
2820 | mov ARG1, L:RB
2821 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] 2816 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
2822 | mov SAVE_PC, PC 2817 | mov SAVE_PC, PC
2823 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] 2818 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
2824 | mov L:RB->base, BASE 2819 | mov L:RB->base, BASE
2825 | jae >3 2820 | jae >3
2826 |2: 2821 |2:
2827 | call extern lj_tab_dup // (lua_State *L, Table *kt) 2822 | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE
2823 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
2824 | call extern lj_tab_dup@8 // (lua_State *L, Table *kt)
2828 | // Table * returned in eax (RC). 2825 | // Table * returned in eax (RC).
2829 | mov BASE, L:RB->base 2826 | mov BASE, L:RB->base
2830 | movzx RA, PC_RA 2827 | movzx RA, PC_RA
@@ -2832,8 +2829,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov)
2832 | mov dword [BASE+RA*8+4], LJ_TTAB 2829 | mov dword [BASE+RA*8+4], LJ_TTAB
2833 | ins_next 2830 | ins_next
2834 |3: 2831 |3:
2835 | call extern lj_gc_step_fixtop // (lua_State *L) 2832 | mov L:FCARG1, L:RB
2836 | mov ARG1, L:RB // Args owned by callee. Set it again. 2833 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
2834 | movzx RD, PC_RD // Need to reload RD.
2835 | not RD
2837 | jmp <2 2836 | jmp <2
2838 break; 2837 break;
2839 2838