diff options
Diffstat (limited to 'src/vm_ppc.dasc')
-rw-r--r-- | src/vm_ppc.dasc | 365 |
1 files changed, 232 insertions, 133 deletions
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index da75f556..4eef1eab 100644 --- a/src/vm_ppc.dasc +++ b/src/vm_ppc.dasc | |||
@@ -293,6 +293,7 @@ | |||
293 | |.type NODE, Node | 293 | |.type NODE, Node |
294 | |.type NARGS8, int | 294 | |.type NARGS8, int |
295 | |.type TRACE, GCtrace | 295 | |.type TRACE, GCtrace |
296 | |.type SBUF, SBuf | ||
296 | | | 297 | | |
297 | |//----------------------------------------------------------------------- | 298 | |//----------------------------------------------------------------------- |
298 | | | 299 | | |
@@ -661,12 +662,13 @@ static void build_subroutines(BuildCtx *ctx) | |||
661 | | stw CARG3, SAVE_NRES | 662 | | stw CARG3, SAVE_NRES |
662 | | cmplwi TMP1, 0 | 663 | | cmplwi TMP1, 0 |
663 | | stw CARG3, SAVE_ERRF | 664 | | stw CARG3, SAVE_ERRF |
664 | | stp TMP0, L->cframe | ||
665 | | stp CARG3, SAVE_CFRAME | 665 | | stp CARG3, SAVE_CFRAME |
666 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. | 666 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. |
667 | | stp TMP0, L->cframe | ||
667 | | beq >3 | 668 | | beq >3 |
668 | | | 669 | | |
669 | | // Resume after yield (like a return). | 670 | | // Resume after yield (like a return). |
671 | | stw L, DISPATCH_GL(cur_L)(DISPATCH) | ||
670 | | mr RA, BASE | 672 | | mr RA, BASE |
671 | | lp BASE, L->base | 673 | | lp BASE, L->base |
672 | | li TISNUM, LJ_TISNUM // Setup type comparison constants. | 674 | | li TISNUM, LJ_TISNUM // Setup type comparison constants. |
@@ -706,17 +708,18 @@ static void build_subroutines(BuildCtx *ctx) | |||
706 | | | 708 | | |
707 | |1: // Entry point for vm_pcall above (PC = ftype). | 709 | |1: // Entry point for vm_pcall above (PC = ftype). |
708 | | lp TMP1, L:CARG1->cframe | 710 | | lp TMP1, L:CARG1->cframe |
709 | | stw CARG3, SAVE_NRES | ||
710 | | mr L, CARG1 | 711 | | mr L, CARG1 |
711 | | stw CARG1, SAVE_L | 712 | | stw CARG3, SAVE_NRES |
712 | | mr BASE, CARG2 | ||
713 | | stp sp, L->cframe // Add our C frame to cframe chain. | ||
714 | | lwz DISPATCH, L->glref // Setup pointer to dispatch table. | 713 | | lwz DISPATCH, L->glref // Setup pointer to dispatch table. |
714 | | stw CARG1, SAVE_L | ||
715 | | mr BASE, CARG2 | ||
716 | | addi DISPATCH, DISPATCH, GG_G2DISP | ||
715 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. | 717 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. |
716 | | stp TMP1, SAVE_CFRAME | 718 | | stp TMP1, SAVE_CFRAME |
717 | | addi DISPATCH, DISPATCH, GG_G2DISP | 719 | | stp sp, L->cframe // Add our C frame to cframe chain. |
718 | | | 720 | | |
719 | |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). | 721 | |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). |
722 | | stw L, DISPATCH_GL(cur_L)(DISPATCH) | ||
720 | | lp TMP2, L->base // TMP2 = old base (used in vmeta_call). | 723 | | lp TMP2, L->base // TMP2 = old base (used in vmeta_call). |
721 | | li TISNUM, LJ_TISNUM // Setup type comparison constants. | 724 | | li TISNUM, LJ_TISNUM // Setup type comparison constants. |
722 | | lp TMP1, L->top | 725 | | lp TMP1, L->top |
@@ -753,15 +756,18 @@ static void build_subroutines(BuildCtx *ctx) | |||
753 | | lwz TMP0, L:CARG1->stack | 756 | | lwz TMP0, L:CARG1->stack |
754 | | stw CARG1, SAVE_L | 757 | | stw CARG1, SAVE_L |
755 | | lp TMP1, L->top | 758 | | lp TMP1, L->top |
759 | | lwz DISPATCH, L->glref // Setup pointer to dispatch table. | ||
756 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. | 760 | | stw CARG1, SAVE_PC // Any value outside of bytecode is ok. |
757 | | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). | 761 | | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top). |
758 | | lp TMP1, L->cframe | 762 | | lp TMP1, L->cframe |
759 | | stp sp, L->cframe // Add our C frame to cframe chain. | 763 | | addi DISPATCH, DISPATCH, GG_G2DISP |
760 | | .toc lp CARG4, 0(CARG4) | 764 | | .toc lp CARG4, 0(CARG4) |
761 | | li TMP2, 0 | 765 | | li TMP2, 0 |
762 | | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. | 766 | | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame. |
763 | | stw TMP2, SAVE_ERRF // No error function. | 767 | | stw TMP2, SAVE_ERRF // No error function. |
764 | | stp TMP1, SAVE_CFRAME | 768 | | stp TMP1, SAVE_CFRAME |
769 | | stp sp, L->cframe // Add our C frame to cframe chain. | ||
770 | | stw L, DISPATCH_GL(cur_L)(DISPATCH) | ||
765 | | mtctr CARG4 | 771 | | mtctr CARG4 |
766 | | bctrl // (lua_State *L, lua_CFunction func, void *ud) | 772 | | bctrl // (lua_State *L, lua_CFunction func, void *ud) |
767 | |.if PPE | 773 | |.if PPE |
@@ -770,9 +776,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
770 | |.else | 776 | |.else |
771 | | mr. BASE, CRET1 | 777 | | mr. BASE, CRET1 |
772 | |.endif | 778 | |.endif |
773 | | lwz DISPATCH, L->glref // Setup pointer to dispatch table. | 779 | | li PC, FRAME_CP |
774 | | li PC, FRAME_CP | ||
775 | | addi DISPATCH, DISPATCH, GG_G2DISP | ||
776 | | bne <3 // Else continue with the call. | 780 | | bne <3 // Else continue with the call. |
777 | | b ->vm_leave_cp // No base? Just remove C frame. | 781 | | b ->vm_leave_cp // No base? Just remove C frame. |
778 | | | 782 | | |
@@ -895,6 +899,17 @@ static void build_subroutines(BuildCtx *ctx) | |||
895 | | li NARGS8:RC, 16 // 2 args for func(t, k). | 899 | | li NARGS8:RC, 16 // 2 args for func(t, k). |
896 | | b ->vm_call_dispatch_f | 900 | | b ->vm_call_dispatch_f |
897 | | | 901 | | |
902 | |->vmeta_tgetr: | ||
903 | | bl extern lj_tab_getinth // (GCtab *t, int32_t key) | ||
904 | | // Returns cTValue * or NULL. | ||
905 | | cmplwi CRET1, 0 | ||
906 | | beq >1 | ||
907 | | lfd f14, 0(CRET1) | ||
908 | | b ->BC_TGETR_Z | ||
909 | |1: | ||
910 | | stwx TISNIL, BASE, RA | ||
911 | | b ->cont_nop | ||
912 | | | ||
898 | |//----------------------------------------------------------------------- | 913 | |//----------------------------------------------------------------------- |
899 | | | 914 | | |
900 | |->vmeta_tsets1: | 915 | |->vmeta_tsets1: |
@@ -962,6 +977,14 @@ static void build_subroutines(BuildCtx *ctx) | |||
962 | | stfd f0, 16(BASE) // Copy value to third argument. | 977 | | stfd f0, 16(BASE) // Copy value to third argument. |
963 | | b ->vm_call_dispatch_f | 978 | | b ->vm_call_dispatch_f |
964 | | | 979 | | |
980 | |->vmeta_tsetr: | ||
981 | | stp BASE, L->base | ||
982 | | stw PC, SAVE_PC | ||
983 | | bl extern lj_tab_setinth // (lua_State *L, GCtab *t, int32_t key) | ||
984 | | // Returns TValue *. | ||
985 | | stfd f14, 0(CRET1) | ||
986 | | b ->cont_nop | ||
987 | | | ||
965 | |//-- Comparison metamethods --------------------------------------------- | 988 | |//-- Comparison metamethods --------------------------------------------- |
966 | | | 989 | | |
967 | |->vmeta_comp: | 990 | |->vmeta_comp: |
@@ -1040,6 +1063,16 @@ static void build_subroutines(BuildCtx *ctx) | |||
1040 | | b <3 | 1063 | | b <3 |
1041 | |.endif | 1064 | |.endif |
1042 | | | 1065 | | |
1066 | |->vmeta_istype: | ||
1067 | | subi PC, PC, 4 | ||
1068 | | stp BASE, L->base | ||
1069 | | srwi CARG2, RA, 3 | ||
1070 | | mr CARG1, L | ||
1071 | | srwi CARG3, RD, 3 | ||
1072 | | stw PC, SAVE_PC | ||
1073 | | bl extern lj_meta_istype // (lua_State *L, BCReg ra, BCReg tp) | ||
1074 | | b ->cont_nop | ||
1075 | | | ||
1043 | |//-- Arithmetic metamethods --------------------------------------------- | 1076 | |//-- Arithmetic metamethods --------------------------------------------- |
1044 | | | 1077 | | |
1045 | |->vmeta_arith_nv: | 1078 | |->vmeta_arith_nv: |
@@ -1364,9 +1397,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
1364 | | mr CARG1, L | 1397 | | mr CARG1, L |
1365 | | mr CARG2, BASE | 1398 | | mr CARG2, BASE |
1366 | |.if DUALNUM | 1399 | |.if DUALNUM |
1367 | | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o) | 1400 | | bl extern lj_strfmt_number // (lua_State *L, cTValue *o) |
1368 | |.else | 1401 | |.else |
1369 | | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np) | 1402 | | bl extern lj_strfmt_num // (lua_State *L, lua_Number *np) |
1370 | |.endif | 1403 | |.endif |
1371 | | // Returns GCstr *. | 1404 | | // Returns GCstr *. |
1372 | | li CARG3, LJ_TSTR | 1405 | | li CARG3, LJ_TSTR |
@@ -1599,6 +1632,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
1599 | | lp TMP3, L:SAVE0->top | 1632 | | lp TMP3, L:SAVE0->top |
1600 | | li_vmstate INTERP | 1633 | | li_vmstate INTERP |
1601 | | lp BASE, L->base | 1634 | | lp BASE, L->base |
1635 | | stw L, DISPATCH_GL(cur_L)(DISPATCH) | ||
1602 | | st_vmstate | 1636 | | st_vmstate |
1603 | | bgt >8 | 1637 | | bgt >8 |
1604 | | sub RD, TMP3, TMP2 | 1638 | | sub RD, TMP3, TMP2 |
@@ -1870,12 +1904,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
1870 | | math_extern2 atan2 | 1904 | | math_extern2 atan2 |
1871 | | math_extern2 fmod | 1905 | | math_extern2 fmod |
1872 | | | 1906 | | |
1873 | |->ff_math_deg: | ||
1874 | |.ffunc_n math_rad | ||
1875 | | lfd FARG2, CFUNC:RB->upvalue[0] | ||
1876 | | fmul FARG1, FARG1, FARG2 | ||
1877 | | b ->fff_resn | ||
1878 | | | ||
1879 | |.if DUALNUM | 1907 | |.if DUALNUM |
1880 | |.ffunc math_ldexp | 1908 | |.ffunc math_ldexp |
1881 | | cmplwi NARGS8:RC, 16 | 1909 | | cmplwi NARGS8:RC, 16 |
@@ -2021,11 +2049,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
2021 | | | 2049 | | |
2022 | |//-- String library ----------------------------------------------------- | 2050 | |//-- String library ----------------------------------------------------- |
2023 | | | 2051 | | |
2024 | |.ffunc_1 string_len | ||
2025 | | checkstr CARG3; bne ->fff_fallback | ||
2026 | | lwz CRET1, STR:CARG1->len | ||
2027 | | b ->fff_resi | ||
2028 | | | ||
2029 | |.ffunc string_byte // Only handle the 1-arg case here. | 2052 | |.ffunc string_byte // Only handle the 1-arg case here. |
2030 | | cmplwi NARGS8:RC, 8 | 2053 | | cmplwi NARGS8:RC, 8 |
2031 | | lwz CARG3, 0(BASE) | 2054 | | lwz CARG3, 0(BASE) |
@@ -2080,6 +2103,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
2080 | | stp BASE, L->base | 2103 | | stp BASE, L->base |
2081 | | stw PC, SAVE_PC | 2104 | | stw PC, SAVE_PC |
2082 | | bl extern lj_str_new // (lua_State *L, char *str, size_t l) | 2105 | | bl extern lj_str_new // (lua_State *L, char *str, size_t l) |
2106 | |->fff_resstr: | ||
2083 | | // Returns GCstr *. | 2107 | | // Returns GCstr *. |
2084 | | lp BASE, L->base | 2108 | | lp BASE, L->base |
2085 | | li CARG3, LJ_TSTR | 2109 | | li CARG3, LJ_TSTR |
@@ -2157,114 +2181,29 @@ static void build_subroutines(BuildCtx *ctx) | |||
2157 | | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) | 2181 | | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0) |
2158 | | b <3 | 2182 | | b <3 |
2159 | | | 2183 | | |
2160 | |.ffunc string_rep // Only handle the 1-char case inline. | 2184 | |.macro ffstring_op, name |
2161 | | ffgccheck | 2185 | | .ffunc string_ .. name |
2162 | | cmplwi NARGS8:RC, 16 | ||
2163 | | lwz TMP0, 0(BASE) | ||
2164 | | lwz STR:CARG1, 4(BASE) | ||
2165 | | lwz CARG4, 8(BASE) | ||
2166 | |.if DUALNUM | ||
2167 | | lwz CARG3, 12(BASE) | ||
2168 | |.else | ||
2169 | | lfd FARG2, 8(BASE) | ||
2170 | |.endif | ||
2171 | | bne ->fff_fallback // Exactly 2 arguments. | ||
2172 | | checkstr TMP0; bne ->fff_fallback | ||
2173 | |.if DUALNUM | ||
2174 | | checknum CARG4; bne ->fff_fallback | ||
2175 | |.else | ||
2176 | | checknum CARG4; bge ->fff_fallback | ||
2177 | | toint CARG3, FARG2 | ||
2178 | |.endif | ||
2179 | | lwz TMP0, STR:CARG1->len | ||
2180 | | cmpwi CARG3, 0 | ||
2181 | | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) | ||
2182 | | ble >2 // Count <= 0? (or non-int) | ||
2183 | | cmplwi TMP0, 1 | ||
2184 | | subi TMP2, CARG3, 1 | ||
2185 | | blt >2 // Zero length string? | ||
2186 | | cmplw cr1, TMP1, CARG3 | ||
2187 | | bne ->fff_fallback // Fallback for > 1-char strings. | ||
2188 | | lbz TMP0, STR:CARG1[1] | ||
2189 | | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) | ||
2190 | | blt cr1, ->fff_fallback | ||
2191 | |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?). | ||
2192 | | cmplwi TMP2, 0 | ||
2193 | | stbx TMP0, CARG2, TMP2 | ||
2194 | | subi TMP2, TMP2, 1 | ||
2195 | | bne <1 | ||
2196 | | b ->fff_newstr | ||
2197 | |2: // Return empty string. | ||
2198 | | la STR:CARG1, DISPATCH_GL(strempty)(DISPATCH) | ||
2199 | | li CARG3, LJ_TSTR | ||
2200 | | b ->fff_restv | ||
2201 | | | ||
2202 | |.ffunc string_reverse | ||
2203 | | ffgccheck | 2186 | | ffgccheck |
2204 | | cmplwi NARGS8:RC, 8 | 2187 | | cmplwi NARGS8:RC, 8 |
2205 | | lwz CARG3, 0(BASE) | 2188 | | lwz CARG3, 0(BASE) |
2206 | | lwz STR:CARG1, 4(BASE) | 2189 | | lwz STR:CARG2, 4(BASE) |
2207 | | blt ->fff_fallback | 2190 | | blt ->fff_fallback |
2208 | | checkstr CARG3 | 2191 | | checkstr CARG3 |
2209 | | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) | 2192 | | la SBUF:CARG1, DISPATCH_GL(tmpbuf)(DISPATCH) |
2210 | | bne ->fff_fallback | 2193 | | bne ->fff_fallback |
2211 | | lwz CARG3, STR:CARG1->len | 2194 | | lwz TMP0, SBUF:CARG1->b |
2212 | | la CARG1, #STR(STR:CARG1) | 2195 | | stw L, SBUF:CARG1->L |
2213 | | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) | 2196 | | stp BASE, L->base |
2214 | | li TMP2, 0 | 2197 | | stw PC, SAVE_PC |
2215 | | cmplw TMP1, CARG3 | 2198 | | stw TMP0, SBUF:CARG1->p |
2216 | | subi TMP3, CARG3, 1 | 2199 | | bl extern lj_buf_putstr_ .. name |
2217 | | blt ->fff_fallback | 2200 | | bl extern lj_buf_tostr |
2218 | |1: // Reverse string copy. | 2201 | | b ->fff_resstr |
2219 | | cmpwi TMP3, 0 | ||
2220 | | lbzx TMP1, CARG1, TMP2 | ||
2221 | | blty ->fff_newstr | ||
2222 | | stbx TMP1, CARG2, TMP3 | ||
2223 | | subi TMP3, TMP3, 1 | ||
2224 | | addi TMP2, TMP2, 1 | ||
2225 | | b <1 | ||
2226 | | | ||
2227 | |.macro ffstring_case, name, lo | ||
2228 | | .ffunc name | ||
2229 | | ffgccheck | ||
2230 | | cmplwi NARGS8:RC, 8 | ||
2231 | | lwz CARG3, 0(BASE) | ||
2232 | | lwz STR:CARG1, 4(BASE) | ||
2233 | | blt ->fff_fallback | ||
2234 | | checkstr CARG3 | ||
2235 | | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH) | ||
2236 | | bne ->fff_fallback | ||
2237 | | lwz CARG3, STR:CARG1->len | ||
2238 | | la CARG1, #STR(STR:CARG1) | ||
2239 | | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH) | ||
2240 | | cmplw TMP1, CARG3 | ||
2241 | | li TMP2, 0 | ||
2242 | | blt ->fff_fallback | ||
2243 | |1: // ASCII case conversion. | ||
2244 | | cmplw TMP2, CARG3 | ||
2245 | | lbzx TMP1, CARG1, TMP2 | ||
2246 | | bgey ->fff_newstr | ||
2247 | | subi TMP0, TMP1, lo | ||
2248 | | xori TMP3, TMP1, 0x20 | ||
2249 | | addic TMP0, TMP0, -26 | ||
2250 | | subfe TMP3, TMP3, TMP3 | ||
2251 | | rlwinm TMP3, TMP3, 0, 26, 26 // x &= 0x20. | ||
2252 | | xor TMP1, TMP1, TMP3 | ||
2253 | | stbx TMP1, CARG2, TMP2 | ||
2254 | | addi TMP2, TMP2, 1 | ||
2255 | | b <1 | ||
2256 | |.endmacro | 2202 | |.endmacro |
2257 | | | 2203 | | |
2258 | |ffstring_case string_lower, 65 | 2204 | |ffstring_op reverse |
2259 | |ffstring_case string_upper, 97 | 2205 | |ffstring_op lower |
2260 | | | 2206 | |ffstring_op upper |
2261 | |//-- Table library ------------------------------------------------------ | ||
2262 | | | ||
2263 | |.ffunc_1 table_getn | ||
2264 | | checktab CARG3; bne ->fff_fallback | ||
2265 | | bl extern lj_tab_len // (GCtab *t) | ||
2266 | | // Returns uint32_t (but less than 2^31). | ||
2267 | | b ->fff_resi | ||
2268 | | | 2207 | | |
2269 | |//-- Bit library -------------------------------------------------------- | 2208 | |//-- Bit library -------------------------------------------------------- |
2270 | | | 2209 | | |
@@ -2566,6 +2505,70 @@ static void build_subroutines(BuildCtx *ctx) | |||
2566 | | mtctr CRET1 | 2505 | | mtctr CRET1 |
2567 | | bctr | 2506 | | bctr |
2568 | | | 2507 | | |
2508 | |->cont_stitch: // Trace stitching. | ||
2509 | |.if JIT | ||
2510 | | // RA = resultptr, RB = meta base | ||
2511 | | lwz INS, -4(PC) | ||
2512 | | lwz TMP3, -20(RB) // Save previous trace number. | ||
2513 | | addic. TMP1, MULTRES, -8 | ||
2514 | | decode_RA8 RC, INS // Call base. | ||
2515 | | beq >2 | ||
2516 | |1: // Move results down. | ||
2517 | | lfd f0, 0(RA) | ||
2518 | | addic. TMP1, TMP1, -8 | ||
2519 | | addi RA, RA, 8 | ||
2520 | | stfdx f0, BASE, RC | ||
2521 | | addi RC, RC, 8 | ||
2522 | | bne <1 | ||
2523 | |2: | ||
2524 | | decode_RA8 RA, INS | ||
2525 | | decode_RB8 RB, INS | ||
2526 | | add RA, RA, RB | ||
2527 | | lwz TMP1, DISPATCH_J(trace)(DISPATCH) | ||
2528 | |3: | ||
2529 | | cmplw RA, RC | ||
2530 | | bgt >9 // More results wanted? | ||
2531 | | | ||
2532 | | slwi TMP2, TMP3, 2 | ||
2533 | | lwzx TRACE:TMP2, TMP1, TMP2 | ||
2534 | | cmpwi TRACE:TMP2, 0 | ||
2535 | | beq ->cont_nop | ||
2536 | | lhz RD, TRACE:TMP2->link | ||
2537 | | cmpw RD, TMP3 | ||
2538 | | cmpwi cr1, RD, 0 | ||
2539 | | beq ->cont_nop // Blacklisted. | ||
2540 | | slwi RD, RD, 3 | ||
2541 | | bne cr1, =>BC_JLOOP // Jump to stitched trace. | ||
2542 | | | ||
2543 | | // Stitch a new trace to the previous trace. | ||
2544 | | stw TMP3, DISPATCH_J(exitno)(DISPATCH) | ||
2545 | | stp L, DISPATCH_J(L)(DISPATCH) | ||
2546 | | stp BASE, L->base | ||
2547 | | addi CARG1, DISPATCH, GG_DISP2J | ||
2548 | | mr CARG2, PC | ||
2549 | | bl extern lj_dispatch_stitch // (jit_State *J, const BCIns *pc) | ||
2550 | | lp BASE, L->base | ||
2551 | | b ->cont_nop | ||
2552 | | | ||
2553 | |9: | ||
2554 | | stwx TISNIL, BASE, RC | ||
2555 | | addi RC, RC, 8 | ||
2556 | | b <3 | ||
2557 | |.endif | ||
2558 | | | ||
2559 | |->vm_profhook: // Dispatch target for profiler hook. | ||
2560 | #if LJ_HASPROFILE | ||
2561 | | mr CARG1, L | ||
2562 | | stw MULTRES, SAVE_MULTRES | ||
2563 | | mr CARG2, PC | ||
2564 | | stp BASE, L->base | ||
2565 | | bl extern lj_dispatch_profile // (lua_State *L, const BCIns *pc) | ||
2566 | | // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction. | ||
2567 | | lp BASE, L->base | ||
2568 | | subi PC, PC, 4 | ||
2569 | | b ->cont_nop | ||
2570 | #endif | ||
2571 | | | ||
2569 | |//----------------------------------------------------------------------- | 2572 | |//----------------------------------------------------------------------- |
2570 | |//-- Trace exit handler ------------------------------------------------- | 2573 | |//-- Trace exit handler ------------------------------------------------- |
2571 | |//----------------------------------------------------------------------- | 2574 | |//----------------------------------------------------------------------- |
@@ -2600,16 +2603,16 @@ static void build_subroutines(BuildCtx *ctx) | |||
2600 | | savex_ 20,21,22,23 | 2603 | | savex_ 20,21,22,23 |
2601 | | lhz CARG4, 2(CARG3) // Load trace number. | 2604 | | lhz CARG4, 2(CARG3) // Load trace number. |
2602 | | savex_ 24,25,26,27 | 2605 | | savex_ 24,25,26,27 |
2603 | | lwz L, DISPATCH_GL(jit_L)(DISPATCH) | 2606 | | lwz L, DISPATCH_GL(cur_L)(DISPATCH) |
2604 | | savex_ 28,29,30,31 | 2607 | | savex_ 28,29,30,31 |
2605 | | sub CARG3, TMP0, CARG3 // Compute exit number. | 2608 | | sub CARG3, TMP0, CARG3 // Compute exit number. |
2606 | | lp BASE, DISPATCH_GL(jit_base)(DISPATCH) | 2609 | | lp BASE, DISPATCH_GL(jit_base)(DISPATCH) |
2607 | | srwi CARG3, CARG3, 2 | 2610 | | srwi CARG3, CARG3, 2 |
2608 | | stw L, DISPATCH_J(L)(DISPATCH) | 2611 | | stp L, DISPATCH_J(L)(DISPATCH) |
2609 | | subi CARG3, CARG3, 2 | 2612 | | subi CARG3, CARG3, 2 |
2610 | | stw TMP1, DISPATCH_GL(jit_L)(DISPATCH) | ||
2611 | | stw CARG4, DISPATCH_J(parent)(DISPATCH) | ||
2612 | | stp BASE, L->base | 2613 | | stp BASE, L->base |
2614 | | stw CARG4, DISPATCH_J(parent)(DISPATCH) | ||
2615 | | stw TMP1, DISPATCH_GL(jit_base)(DISPATCH) | ||
2613 | | addi CARG1, DISPATCH, GG_DISP2J | 2616 | | addi CARG1, DISPATCH, GG_DISP2J |
2614 | | stw CARG3, DISPATCH_J(exitno)(DISPATCH) | 2617 | | stw CARG3, DISPATCH_J(exitno)(DISPATCH) |
2615 | | addi CARG2, sp, 16 | 2618 | | addi CARG2, sp, 16 |
@@ -2633,15 +2636,16 @@ static void build_subroutines(BuildCtx *ctx) | |||
2633 | | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set. | 2636 | | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set. |
2634 | | lwz L, SAVE_L | 2637 | | lwz L, SAVE_L |
2635 | | addi DISPATCH, JGL, -GG_DISP2G-32768 | 2638 | | addi DISPATCH, JGL, -GG_DISP2G-32768 |
2639 | | stp BASE, L->base | ||
2636 | |1: | 2640 | |1: |
2637 | | cmpwi CARG1, 0 | 2641 | | cmpwi CARG1, 0 |
2638 | | blt >3 // Check for error from exit. | 2642 | | blt >9 // Check for error from exit. |
2639 | | lwz LFUNC:TMP1, FRAME_FUNC(BASE) | 2643 | | lwz LFUNC:RB, FRAME_FUNC(BASE) |
2640 | | slwi MULTRES, CARG1, 3 | 2644 | | slwi MULTRES, CARG1, 3 |
2641 | | li TMP2, 0 | 2645 | | li TMP2, 0 |
2642 | | stw MULTRES, SAVE_MULTRES | 2646 | | stw MULTRES, SAVE_MULTRES |
2643 | | lwz TMP1, LFUNC:TMP1->pc | 2647 | | lwz TMP1, LFUNC:RB->pc |
2644 | | stw TMP2, DISPATCH_GL(jit_L)(DISPATCH) | 2648 | | stw TMP2, DISPATCH_GL(jit_base)(DISPATCH) |
2645 | | lwz KBASE, PC2PROTO(k)(TMP1) | 2649 | | lwz KBASE, PC2PROTO(k)(TMP1) |
2646 | | // Setup type comparison constants. | 2650 | | // Setup type comparison constants. |
2647 | | li TISNUM, LJ_TISNUM | 2651 | | li TISNUM, LJ_TISNUM |
@@ -2671,11 +2675,25 @@ static void build_subroutines(BuildCtx *ctx) | |||
2671 | | decode_RC8 RC, INS | 2675 | | decode_RC8 RC, INS |
2672 | | bctr | 2676 | | bctr |
2673 | |2: | 2677 | |2: |
2678 | | cmplwi TMP1, (BC_FUNCC+2)*4 // Fast function? | ||
2679 | | blt >3 | ||
2680 | | // Check frame below fast function. | ||
2681 | | lwz TMP1, FRAME_PC(BASE) | ||
2682 | | andix. TMP0, TMP1, FRAME_TYPE | ||
2683 | | bney >3 // Trace stitching continuation? | ||
2684 | | // Otherwise set KBASE for Lua function below fast function. | ||
2685 | | lwz TMP2, -4(TMP1) | ||
2686 | | decode_RA8 TMP0, TMP2 | ||
2687 | | sub TMP1, BASE, TMP0 | ||
2688 | | lwz LFUNC:TMP2, -12(TMP1) | ||
2689 | | lwz TMP1, LFUNC:TMP2->pc | ||
2690 | | lwz KBASE, PC2PROTO(k)(TMP1) | ||
2691 | |3: | ||
2674 | | subi RC, MULTRES, 8 | 2692 | | subi RC, MULTRES, 8 |
2675 | | add RA, RA, BASE | 2693 | | add RA, RA, BASE |
2676 | | bctr | 2694 | | bctr |
2677 | | | 2695 | | |
2678 | |3: // Rethrow error from the right C frame. | 2696 | |9: // Rethrow error from the right C frame. |
2679 | | neg CARG2, CARG1 | 2697 | | neg CARG2, CARG1 |
2680 | | mr CARG1, L | 2698 | | mr CARG1, L |
2681 | | bl extern lj_err_throw // (lua_State *L, int errcode) | 2699 | | bl extern lj_err_throw // (lua_State *L, int errcode) |
@@ -3265,6 +3283,29 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
3265 | | ins_next | 3283 | | ins_next |
3266 | break; | 3284 | break; |
3267 | 3285 | ||
3286 | case BC_ISTYPE: | ||
3287 | | // RA = src*8, RD = -type*8 | ||
3288 | | lwzx TMP0, BASE, RA | ||
3289 | | srwi TMP1, RD, 3 | ||
3290 | | ins_next1 | ||
3291 | |.if not PPE and not GPR64 | ||
3292 | | add. TMP0, TMP0, TMP1 | ||
3293 | |.else | ||
3294 | | neg TMP1, TMP1 | ||
3295 | | cmpw TMP0, TMP1 | ||
3296 | |.endif | ||
3297 | | bne ->vmeta_istype | ||
3298 | | ins_next2 | ||
3299 | break; | ||
3300 | case BC_ISNUM: | ||
3301 | | // RA = src*8, RD = -(TISNUM-1)*8 | ||
3302 | | lwzx TMP0, BASE, RA | ||
3303 | | ins_next1 | ||
3304 | | checknum TMP0 | ||
3305 | | bge ->vmeta_istype | ||
3306 | | ins_next2 | ||
3307 | break; | ||
3308 | |||
3268 | /* -- Unary ops --------------------------------------------------------- */ | 3309 | /* -- Unary ops --------------------------------------------------------- */ |
3269 | 3310 | ||
3270 | case BC_MOV: | 3311 | case BC_MOV: |
@@ -4016,6 +4057,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4016 | | bne <1 // 'no __index' flag set: done. | 4057 | | bne <1 // 'no __index' flag set: done. |
4017 | | b ->vmeta_tgetb // Caveat: preserve TMP0! | 4058 | | b ->vmeta_tgetb // Caveat: preserve TMP0! |
4018 | break; | 4059 | break; |
4060 | case BC_TGETR: | ||
4061 | | // RA = dst*8, RB = table*8, RC = key*8 | ||
4062 | | add RB, BASE, RB | ||
4063 | | lwz TAB:CARG1, 4(RB) | ||
4064 | |.if DUALNUM | ||
4065 | | add RC, BASE, RC | ||
4066 | | lwz TMP0, TAB:CARG1->asize | ||
4067 | | lwz CARG2, 4(RC) | ||
4068 | | lwz TMP1, TAB:CARG1->array | ||
4069 | |.else | ||
4070 | | lfdx f0, BASE, RC | ||
4071 | | lwz TMP0, TAB:CARG1->asize | ||
4072 | | toint CARG2, f0 | ||
4073 | | lwz TMP1, TAB:CARG1->array | ||
4074 | |.endif | ||
4075 | | cmplw TMP0, CARG2 | ||
4076 | | slwi TMP2, CARG2, 3 | ||
4077 | | ble ->vmeta_tgetr // In array part? | ||
4078 | | lfdx f14, TMP1, TMP2 | ||
4079 | |->BC_TGETR_Z: | ||
4080 | | ins_next1 | ||
4081 | | stfdx f14, BASE, RA | ||
4082 | | ins_next2 | ||
4083 | break; | ||
4019 | 4084 | ||
4020 | case BC_TSETV: | 4085 | case BC_TSETV: |
4021 | | // RA = src*8, RB = table*8, RC = key*8 | 4086 | | // RA = src*8, RB = table*8, RC = key*8 |
@@ -4195,6 +4260,39 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4195 | | barrierback TAB:RB, TMP3, TMP0 | 4260 | | barrierback TAB:RB, TMP3, TMP0 |
4196 | | b <2 | 4261 | | b <2 |
4197 | break; | 4262 | break; |
4263 | case BC_TSETR: | ||
4264 | | // RA = dst*8, RB = table*8, RC = key*8 | ||
4265 | | add RB, BASE, RB | ||
4266 | | lwz TAB:CARG2, 4(RB) | ||
4267 | |.if DUALNUM | ||
4268 | | add RC, BASE, RC | ||
4269 | | lbz TMP3, TAB:RB->marked | ||
4270 | | lwz TMP0, TAB:CARG2->asize | ||
4271 | | lwz CARG3, 4(RC) | ||
4272 | | lwz TMP1, TAB:CARG2->array | ||
4273 | |.else | ||
4274 | | lfdx f0, BASE, RC | ||
4275 | | lbz TMP3, TAB:RB->marked | ||
4276 | | lwz TMP0, TAB:CARG2->asize | ||
4277 | | toint CARG3, f0 | ||
4278 | | lwz TMP1, TAB:CARG2->array | ||
4279 | |.endif | ||
4280 | | andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table) | ||
4281 | | bne >7 | ||
4282 | |2: | ||
4283 | | cmplw TMP0, CARG3 | ||
4284 | | slwi TMP2, CARG3, 3 | ||
4285 | | lfdx f14, BASE, RA | ||
4286 | | ble ->vmeta_tsetr // In array part? | ||
4287 | | ins_next1 | ||
4288 | | stfdx f14, TMP1, TMP2 | ||
4289 | | ins_next2 | ||
4290 | | | ||
4291 | |7: // Possible table write barrier for the value. Skip valiswhite check. | ||
4292 | | barrierback TAB:CARG2, TMP3, TMP2 | ||
4293 | | b <2 | ||
4294 | break; | ||
4295 | |||
4198 | 4296 | ||
4199 | case BC_TSETM: | 4297 | case BC_TSETM: |
4200 | | // RA = base*8 (table at base-1), RD = num_const*8 (start index) | 4298 | | // RA = base*8 (table at base-1), RD = num_const*8 (start index) |
@@ -4836,8 +4934,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4836 | | lp TMP2, TRACE:TMP2->mcode | 4934 | | lp TMP2, TRACE:TMP2->mcode |
4837 | | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) | 4935 | | stw BASE, DISPATCH_GL(jit_base)(DISPATCH) |
4838 | | mtctr TMP2 | 4936 | | mtctr TMP2 |
4839 | | stw L, DISPATCH_GL(jit_L)(DISPATCH) | ||
4840 | | addi JGL, DISPATCH, GG_DISP2G+32768 | 4937 | | addi JGL, DISPATCH, GG_DISP2G+32768 |
4938 | | stw L, DISPATCH_GL(tmpbuf.L)(DISPATCH) | ||
4841 | | bctr | 4939 | | bctr |
4842 | |.endif | 4940 | |.endif |
4843 | break; | 4941 | break; |
@@ -4972,6 +5070,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
4972 | | lp TMP1, L->top | 5070 | | lp TMP1, L->top |
4973 | | li_vmstate INTERP | 5071 | | li_vmstate INTERP |
4974 | | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. | 5072 | | lwz PC, FRAME_PC(BASE) // Fetch PC of caller. |
5073 | | stw L, DISPATCH_GL(cur_L)(DISPATCH) | ||
4975 | | sub RA, TMP1, RD // RA = L->top - nresults*8 | 5074 | | sub RA, TMP1, RD // RA = L->top - nresults*8 |
4976 | | st_vmstate | 5075 | | st_vmstate |
4977 | | b ->vm_returnc | 5076 | | b ->vm_returnc |