aboutsummaryrefslogtreecommitdiff
path: root/src/vm_arm64.dasc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/vm_arm64.dasc69
1 files changed, 46 insertions, 23 deletions
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index bb2496ab..cfbc61a1 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -151,6 +151,21 @@
151|.define FRAME_FUNC, #-16 151|.define FRAME_FUNC, #-16
152|.define FRAME_PC, #-8 152|.define FRAME_PC, #-8
153| 153|
154|// Endian-specific defines.
155|.if ENDIAN_LE
156|.define LO, 0
157|.define OFS_RD, 2
158|.define OFS_RB, 3
159|.define OFS_RA, 1
160|.define OFS_OP, 0
161|.else
162|.define LO, 4
163|.define OFS_RD, 0
164|.define OFS_RB, 0
165|.define OFS_RA, 2
166|.define OFS_OP, 3
167|.endif
168|
154|.macro decode_RA, dst, ins; ubfx dst, ins, #8, #8; .endmacro 169|.macro decode_RA, dst, ins; ubfx dst, ins, #8, #8; .endmacro
155|.macro decode_RB, dst, ins; ubfx dst, ins, #24, #8; .endmacro 170|.macro decode_RB, dst, ins; ubfx dst, ins, #24, #8; .endmacro
156|.macro decode_RC, dst, ins; ubfx dst, ins, #16, #8; .endmacro 171|.macro decode_RC, dst, ins; ubfx dst, ins, #16, #8; .endmacro
@@ -717,7 +732,7 @@ static void build_subroutines(BuildCtx *ctx)
717 | cmp CRET1, #1 732 | cmp CRET1, #1
718 | bhi ->vmeta_binop 733 | bhi ->vmeta_binop
719 |4: 734 |4:
720 | ldrh RBw, [PC, #2] 735 | ldrh RBw, [PC, # OFS_RD]
721 | add PC, PC, #4 736 | add PC, PC, #4
722 | add RB, PC, RB, lsl #2 737 | add RB, PC, RB, lsl #2
723 | sub RB, RB, #0x20000 738 | sub RB, RB, #0x20000
@@ -1500,7 +1515,12 @@ static void build_subroutines(BuildCtx *ctx)
1500 | bne ->fff_fallback 1515 | bne ->fff_fallback
1501 | checkint CARG1, ->fff_fallback 1516 | checkint CARG1, ->fff_fallback
1502 | mov CARG3, #1 1517 | mov CARG3, #1
1503 | mov CARG2, BASE // Points to stack. Little-endian. 1518 | // Point to the char inside the integer in the stack slot.
1519 |.if ENDIAN_LE
1520 | mov CARG2, BASE
1521 |.else
1522 | add CARG2, BASE, #7
1523 |.endif
1504 |->fff_newstr: 1524 |->fff_newstr:
1505 | // CARG2 = str, CARG3 = len. 1525 | // CARG2 = str, CARG3 = len.
1506 | str BASE, L->base 1526 | str BASE, L->base
@@ -1703,7 +1723,7 @@ static void build_subroutines(BuildCtx *ctx)
1703 | ands TMP0, PC, #FRAME_TYPE 1723 | ands TMP0, PC, #FRAME_TYPE
1704 | and TMP1, PC, #~FRAME_TYPEP 1724 | and TMP1, PC, #~FRAME_TYPEP
1705 | bne >3 1725 | bne >3
1706 | ldrb RAw, [PC, #-3] 1726 | ldrb RAw, [PC, #-4+OFS_RA]
1707 | lsl RA, RA, #3 1727 | lsl RA, RA, #3
1708 | add TMP1, RA, #16 1728 | add TMP1, RA, #16
1709 |3: 1729 |3:
@@ -1838,7 +1858,7 @@ static void build_subroutines(BuildCtx *ctx)
1838 |->cont_stitch: // Trace stitching. 1858 |->cont_stitch: // Trace stitching.
1839 |.if JIT 1859 |.if JIT
1840 | // RA = resultptr, CARG4 = meta base 1860 | // RA = resultptr, CARG4 = meta base
1841 | ldr RB, SAVE_MULTRES 1861 | ldr RBw, SAVE_MULTRES
1842 | ldr INSw, [PC, #-4] 1862 | ldr INSw, [PC, #-4]
1843 | ldr TRACE:CARG3, [CARG4, #-40] // Save previous trace. 1863 | ldr TRACE:CARG3, [CARG4, #-40] // Save previous trace.
1844 | subs RB, RB, #8 1864 | subs RB, RB, #8
@@ -1869,7 +1889,7 @@ static void build_subroutines(BuildCtx *ctx)
1869 | 1889 |
1870 | // Stitch a new trace to the previous trace. 1890 | // Stitch a new trace to the previous trace.
1871 | mov CARG1, #GL_J(exitno) 1891 | mov CARG1, #GL_J(exitno)
1872 | str RA, [GL, CARG1] 1892 | str RAw, [GL, CARG1]
1873 | mov CARG1, #GL_J(L) 1893 | mov CARG1, #GL_J(L)
1874 | str L, [GL, CARG1] 1894 | str L, [GL, CARG1]
1875 | str BASE, L->base 1895 | str BASE, L->base
@@ -1936,6 +1956,9 @@ static void build_subroutines(BuildCtx *ctx)
1936 | sub CARG1, CARG1, #2 1956 | sub CARG1, CARG1, #2
1937 | ldr CARG2w, [lr] // Load trace number. 1957 | ldr CARG2w, [lr] // Load trace number.
1938 | st_vmstate CARG4 1958 | st_vmstate CARG4
1959 |.if ENDIAN_BE
1960 | rev32 CARG2, CARG2
1961 |.endif
1939 | str BASE, L->base 1962 | str BASE, L->base
1940 | ubfx CARG2w, CARG2w, #5, #16 1963 | ubfx CARG2w, CARG2w, #5, #16
1941 | str CARG1w, [GL, #GL_J(exitno)] 1964 | str CARG1w, [GL, #GL_J(exitno)]
@@ -1967,14 +1990,14 @@ static void build_subroutines(BuildCtx *ctx)
1967 | movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16 1990 | movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16
1968 | movn TISNIL, #0 1991 | movn TISNIL, #0
1969 | and LFUNC:CARG2, CARG2, #LJ_GCVMASK 1992 | and LFUNC:CARG2, CARG2, #LJ_GCVMASK
1970 | str RC, SAVE_MULTRES 1993 | str RCw, SAVE_MULTRES
1971 | str BASE, L->base 1994 | str BASE, L->base
1972 | ldr CARG2, LFUNC:CARG2->pc 1995 | ldr CARG2, LFUNC:CARG2->pc
1973 | str xzr, GL->jit_base 1996 | str xzr, GL->jit_base
1974 | mv_vmstate CARG4, INTERP 1997 | mv_vmstate CARG4, INTERP
1975 | ldr KBASE, [CARG2, #PC2PROTO(k)] 1998 | ldr KBASE, [CARG2, #PC2PROTO(k)]
1976 | // Modified copy of ins_next which handles function header dispatch, too. 1999 | // Modified copy of ins_next which handles function header dispatch, too.
1977 | ldrb RBw, [PC] 2000 | ldrb RBw, [PC, # OFS_OP]
1978 | ldr INSw, [PC], #4 2001 | ldr INSw, [PC], #4
1979 | st_vmstate CARG4 2002 | st_vmstate CARG4
1980 | cmp RBw, #BC_FUNCC+2 // Fast function? 2003 | cmp RBw, #BC_FUNCC+2 // Fast function?
@@ -2000,7 +2023,7 @@ static void build_subroutines(BuildCtx *ctx)
2000 | ands CARG2, CARG1, #FRAME_TYPE 2023 | ands CARG2, CARG1, #FRAME_TYPE
2001 | bne <2 // Trace stitching continuation? 2024 | bne <2 // Trace stitching continuation?
2002 | // Otherwise set KBASE for Lua function below fast function. 2025 | // Otherwise set KBASE for Lua function below fast function.
2003 | ldr CARG3, [CARG1, #-4] 2026 | ldr CARG3w, [CARG1, #-4]
2004 | decode_RA CARG1, CARG3 2027 | decode_RA CARG1, CARG3
2005 | sub CARG2, BASE, CARG1, lsl #3 2028 | sub CARG2, BASE, CARG1, lsl #3
2006 | ldr LFUNC:CARG3, [CARG2, #-32] 2029 | ldr LFUNC:CARG3, [CARG2, #-32]
@@ -2153,7 +2176,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2153 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT: 2176 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
2154 | // RA = src1, RC = src2, JMP with RC = target 2177 | // RA = src1, RC = src2, JMP with RC = target
2155 | ldr CARG1, [BASE, RA, lsl #3] 2178 | ldr CARG1, [BASE, RA, lsl #3]
2156 | ldrh RBw, [PC, #2] 2179 | ldrh RBw, [PC, # OFS_RD]
2157 | ldr CARG2, [BASE, RC, lsl #3] 2180 | ldr CARG2, [BASE, RC, lsl #3]
2158 | add PC, PC, #4 2181 | add PC, PC, #4
2159 | add RB, PC, RB, lsl #2 2182 | add RB, PC, RB, lsl #2
@@ -2210,7 +2233,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2210 | // RA = src1, RC = src2, JMP with RC = target 2233 | // RA = src1, RC = src2, JMP with RC = target
2211 | ldr CARG1, [BASE, RA, lsl #3] 2234 | ldr CARG1, [BASE, RA, lsl #3]
2212 | add RC, BASE, RC, lsl #3 2235 | add RC, BASE, RC, lsl #3
2213 | ldrh RBw, [PC, #2] 2236 | ldrh RBw, [PC, # OFS_RD]
2214 | ldr CARG3, [RC] 2237 | ldr CARG3, [RC]
2215 | add PC, PC, #4 2238 | add PC, PC, #4
2216 | add RB, PC, RB, lsl #2 2239 | add RB, PC, RB, lsl #2
@@ -2271,7 +2294,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2271 | // RA = src, RC = str_const (~), JMP with RC = target 2294 | // RA = src, RC = str_const (~), JMP with RC = target
2272 | ldr CARG1, [BASE, RA, lsl #3] 2295 | ldr CARG1, [BASE, RA, lsl #3]
2273 | mvn RC, RC 2296 | mvn RC, RC
2274 | ldrh RBw, [PC, #2] 2297 | ldrh RBw, [PC, # OFS_RD]
2275 | ldr CARG2, [KBASE, RC, lsl #3] 2298 | ldr CARG2, [KBASE, RC, lsl #3]
2276 | add PC, PC, #4 2299 | add PC, PC, #4
2277 | movn TMP0, #~LJ_TSTR 2300 | movn TMP0, #~LJ_TSTR
@@ -2299,7 +2322,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2299 | // RA = src, RC = num_const (~), JMP with RC = target 2322 | // RA = src, RC = num_const (~), JMP with RC = target
2300 | ldr CARG1, [BASE, RA, lsl #3] 2323 | ldr CARG1, [BASE, RA, lsl #3]
2301 | add RC, KBASE, RC, lsl #3 2324 | add RC, KBASE, RC, lsl #3
2302 | ldrh RBw, [PC, #2] 2325 | ldrh RBw, [PC, # OFS_RD]
2303 | ldr CARG3, [RC] 2326 | ldr CARG3, [RC]
2304 | add PC, PC, #4 2327 | add PC, PC, #4
2305 | add RB, PC, RB, lsl #2 2328 | add RB, PC, RB, lsl #2
@@ -2359,7 +2382,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2359 vk = op == BC_ISEQP; 2382 vk = op == BC_ISEQP;
2360 | // RA = src, RC = primitive_type (~), JMP with RC = target 2383 | // RA = src, RC = primitive_type (~), JMP with RC = target
2361 | ldr TMP0, [BASE, RA, lsl #3] 2384 | ldr TMP0, [BASE, RA, lsl #3]
2362 | ldrh RBw, [PC, #2] 2385 | ldrh RBw, [PC, # OFS_RD]
2363 | add PC, PC, #4 2386 | add PC, PC, #4
2364 | add RC, RC, #1 2387 | add RC, RC, #1
2365 | add RB, PC, RB, lsl #2 2388 | add RB, PC, RB, lsl #2
@@ -2384,7 +2407,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2384 2407
2385 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF: 2408 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
2386 | // RA = dst or unused, RC = src, JMP with RC = target 2409 | // RA = dst or unused, RC = src, JMP with RC = target
2387 | ldrh RBw, [PC, #2] 2410 | ldrh RBw, [PC, # OFS_RD]
2388 | ldr TMP0, [BASE, RC, lsl #3] 2411 | ldr TMP0, [BASE, RC, lsl #3]
2389 | add PC, PC, #4 2412 | add PC, PC, #4
2390 | mov_false TMP1 2413 | mov_false TMP1
@@ -2631,7 +2654,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2631 | str PC, SAVE_PC 2654 | str PC, SAVE_PC
2632 | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left) 2655 | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
2633 | // Returns NULL (finished) or TValue * (metamethod). 2656 | // Returns NULL (finished) or TValue * (metamethod).
2634 | ldrb RBw, [PC, #-1] 2657 | ldrb RBw, [PC, #-4+OFS_RB]
2635 | ldr BASE, L->base 2658 | ldr BASE, L->base
2636 | cbnz CRET1, ->vmeta_binop 2659 | cbnz CRET1, ->vmeta_binop
2637 | ldr TMP0, [BASE, RB, lsl #3] 2660 | ldr TMP0, [BASE, RB, lsl #3]
@@ -3262,7 +3285,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3262 | ins_callt 3285 | ins_callt
3263 | 3286 |
3264 |5: // Tailcall to a fast function with a Lua frame below. 3287 |5: // Tailcall to a fast function with a Lua frame below.
3265 | ldrb RAw, [PC, #-3] 3288 | ldrb RAw, [PC, #-4+OFS_RA]
3266 | sub CARG1, BASE, RA, lsl #3 3289 | sub CARG1, BASE, RA, lsl #3
3267 | ldr LFUNC:CARG1, [CARG1, #-32] 3290 | ldr LFUNC:CARG1, [CARG1, #-32]
3268 | and LFUNC:CARG1, CARG1, #LJ_GCVMASK 3291 | and LFUNC:CARG1, CARG1, #LJ_GCVMASK
@@ -3303,8 +3326,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3303 |.endif 3326 |.endif
3304 | add RA, BASE, RA, lsl #3 3327 | add RA, BASE, RA, lsl #3
3305 | ldr TAB:RB, [RA, #-16] 3328 | ldr TAB:RB, [RA, #-16]
3306 | ldrh TMP3w, [PC, #2] 3329 | ldrh TMP3w, [PC, # OFS_RD]
3307 | ldr CARG1w, [RA, #-8] // Get index from control var. 3330 | ldr CARG1w, [RA, #-8+LO] // Get index from control var.
3308 | add PC, PC, #4 3331 | add PC, PC, #4
3309 | add TMP3, PC, TMP3, lsl #2 3332 | add TMP3, PC, TMP3, lsl #2
3310 | and TAB:RB, RB, #LJ_GCVMASK 3333 | and TAB:RB, RB, #LJ_GCVMASK
@@ -3323,7 +3346,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3323 | stp CARG1, TMP0, [RA] 3346 | stp CARG1, TMP0, [RA]
3324 | add CARG1, CARG1, #1 3347 | add CARG1, CARG1, #1
3325 |3: 3348 |3:
3326 | str CARG1w, [RA, #-8] // Update control var. 3349 | str CARG1w, [RA, #-8+LO] // Update control var.
3327 | mov PC, TMP3 3350 | mov PC, TMP3
3328 |4: 3351 |4:
3329 | ins_next 3352 | ins_next
@@ -3369,8 +3392,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3369 |5: // Despecialize bytecode if any of the checks fail. 3392 |5: // Despecialize bytecode if any of the checks fail.
3370 | mov TMP0, #BC_JMP 3393 | mov TMP0, #BC_JMP
3371 | mov TMP1, #BC_ITERC 3394 | mov TMP1, #BC_ITERC
3372 | strb TMP0w, [PC, #-4] 3395 | strb TMP0w, [PC, #-4+OFS_OP]
3373 | strb TMP1w, [RC] 3396 | strb TMP1w, [RC, # OFS_OP]
3374 | b <1 3397 | b <1
3375 break; 3398 break;
3376 3399
@@ -3576,7 +3599,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3576 | csel PC, RC, PC, gt 3599 | csel PC, RC, PC, gt
3577 } else if (op == BC_JFORI) { 3600 } else if (op == BC_JFORI) {
3578 | mov PC, RC 3601 | mov PC, RC
3579 | ldrh RCw, [RC, #-2] 3602 | ldrh RCw, [RC, #-4+OFS_RD]
3580 } else if (op == BC_IFORL) { 3603 } else if (op == BC_IFORL) {
3581 | csel PC, RC, PC, le 3604 | csel PC, RC, PC, le
3582 } 3605 }
@@ -3617,7 +3640,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3617 if (op == BC_FORI) { 3640 if (op == BC_FORI) {
3618 | csel PC, RC, PC, hi 3641 | csel PC, RC, PC, hi
3619 } else if (op == BC_JFORI) { 3642 } else if (op == BC_JFORI) {
3620 | ldrh RCw, [RC, #-2] 3643 | ldrh RCw, [RC, #-4+OFS_RD]
3621 | bls =>BC_JLOOP 3644 | bls =>BC_JLOOP
3622 } else if (op == BC_IFORL) { 3645 } else if (op == BC_IFORL) {
3623 | csel PC, RC, PC, ls 3646 | csel PC, RC, PC, ls