summaryrefslogtreecommitdiff
path: root/src/buildvm_arm.dasc
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildvm_arm.dasc')
-rw-r--r--src/buildvm_arm.dasc75
1 files changed, 69 insertions, 6 deletions
diff --git a/src/buildvm_arm.dasc b/src/buildvm_arm.dasc
index 9032c9c2..dadfc734 100644
--- a/src/buildvm_arm.dasc
+++ b/src/buildvm_arm.dasc
@@ -17,13 +17,15 @@
17| 17|
18|// Fixed register assignments for the interpreter. 18|// Fixed register assignments for the interpreter.
19| 19|
20|// The following must be C callee-save (but BASE is often refetched). 20|// The following must be C callee-save.
21|.define BASE, r4 // Base of current Lua stack frame. 21|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding.
22|.define KBASE, r5 // Constants of current Lua function. 22|.define KBASE, r5 // Constants of current Lua function.
23|.define PC, r6 // Next PC. 23|.define PC, r6 // Next PC.
24|.define DISPATCH, r7 // Opcode dispatch table. 24|.define DISPATCH, r7 // Opcode dispatch table.
25|.define LREG, r8 // Register holding lua_State (also in SAVE_L). 25|.define LREG, r8 // Register holding lua_State (also in SAVE_L).
26|.define MASKR8, r9 // 255*8 constant for fast bytecode decoding. 26|
27|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.
28|.define BASE, r9 // Base of current Lua stack frame.
27| 29|
28|// The following temporaries are not saved across C calls, except for RA/RC. 30|// The following temporaries are not saved across C calls, except for RA/RC.
29|.define RA, r10 // Callee-save. 31|.define RA, r10 // Callee-save.
@@ -204,6 +206,12 @@
204| str tmp, tab->gclist 206| str tmp, tab->gclist
205|.endmacro 207|.endmacro
206| 208|
209|.macro IOS, a, b
210||if (LJ_TARGET_OSX) {
211| a, b
212||}
213|.endmacro
214|
207|//----------------------------------------------------------------------- 215|//-----------------------------------------------------------------------
208 216
209#if !LJ_DUALNUM 217#if !LJ_DUALNUM
@@ -550,6 +558,7 @@ static void build_subroutines(BuildCtx *ctx)
550 | str PC, SAVE_PC 558 | str PC, SAVE_PC
551 | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k) 559 | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
552 | // Returns TValue * (finished) or NULL (metamethod). 560 | // Returns TValue * (finished) or NULL (metamethod).
561 | IOS ldr BASE, L->base
553 | cmp CRET1, #0 562 | cmp CRET1, #0
554 | beq >3 563 | beq >3
555 | ldrd CARG34, [CRET1] 564 | ldrd CARG34, [CRET1]
@@ -604,6 +613,7 @@ static void build_subroutines(BuildCtx *ctx)
604 | str PC, SAVE_PC 613 | str PC, SAVE_PC
605 | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k) 614 | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
606 | // Returns TValue * (finished) or NULL (metamethod). 615 | // Returns TValue * (finished) or NULL (metamethod).
616 | IOS ldr BASE, L->base
607 | cmp CRET1, #0 617 | cmp CRET1, #0
608 | ldrd CARG34, [BASE, RA] 618 | ldrd CARG34, [BASE, RA]
609 | beq >3 619 | beq >3
@@ -637,6 +647,7 @@ static void build_subroutines(BuildCtx *ctx)
637 | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op) 647 | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
638 | // Returns 0/1 or TValue * (metamethod). 648 | // Returns 0/1 or TValue * (metamethod).
639 |3: 649 |3:
650 | IOS ldr BASE, L->base
640 | cmp CRET1, #1 651 | cmp CRET1, #1
641 | bhi ->vmeta_binop 652 | bhi ->vmeta_binop
642 |4: 653 |4:
@@ -724,6 +735,7 @@ static void build_subroutines(BuildCtx *ctx)
724 | str OP, ARG5 735 | str OP, ARG5
725 | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op) 736 | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
726 | // Returns NULL (finished) or TValue * (metamethod). 737 | // Returns NULL (finished) or TValue * (metamethod).
738 | IOS ldr BASE, L->base
727 | cmp CRET1, #0 739 | cmp CRET1, #0
728 | beq ->cont_nop 740 | beq ->cont_nop
729 | 741 |
@@ -744,6 +756,7 @@ static void build_subroutines(BuildCtx *ctx)
744 | str PC, SAVE_PC 756 | str PC, SAVE_PC
745 | bl extern lj_meta_len // (lua_State *L, TValue *o) 757 | bl extern lj_meta_len // (lua_State *L, TValue *o)
746 | // Returns TValue * (metamethod base). 758 | // Returns TValue * (metamethod base).
759 | IOS ldr BASE, L->base
747 | b ->vmeta_binop // Binop call for compatibility. 760 | b ->vmeta_binop // Binop call for compatibility.
748 | 761 |
749 |//-- Call metamethod ---------------------------------------------------- 762 |//-- Call metamethod ----------------------------------------------------
@@ -755,7 +768,9 @@ static void build_subroutines(BuildCtx *ctx)
755 | sub CARG2, BASE, #8 768 | sub CARG2, BASE, #8
756 | str PC, SAVE_PC 769 | str PC, SAVE_PC
757 | add CARG3, BASE, NARGS8:RC 770 | add CARG3, BASE, NARGS8:RC
771 | IOS mov RA, BASE
758 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) 772 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
773 | IOS mov BASE, RA
759 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here. 774 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
760 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. 775 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
761 | ins_call 776 | ins_call
@@ -768,6 +783,7 @@ static void build_subroutines(BuildCtx *ctx)
768 | str PC, SAVE_PC 783 | str PC, SAVE_PC
769 | add CARG3, RA, NARGS8:RC 784 | add CARG3, RA, NARGS8:RC
770 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) 785 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
786 | IOS ldr BASE, L->base
771 | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here. 787 | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
772 | ldr PC, [BASE, FRAME_PC] 788 | ldr PC, [BASE, FRAME_PC]
773 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. 789 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
@@ -781,6 +797,7 @@ static void build_subroutines(BuildCtx *ctx)
781 | mov CARG2, RA 797 | mov CARG2, RA
782 | str PC, SAVE_PC 798 | str PC, SAVE_PC
783 | bl extern lj_meta_for // (lua_State *L, TValue *base) 799 | bl extern lj_meta_for // (lua_State *L, TValue *base)
800 | IOS ldr BASE, L->base
784#if LJ_HASJIT 801#if LJ_HASJIT
785 | ldrb OP, [PC, #-4] 802 | ldrb OP, [PC, #-4]
786#endif 803#endif
@@ -935,8 +952,10 @@ static void build_subroutines(BuildCtx *ctx)
935 | checktab CARG4, ->fff_fallback 952 | checktab CARG4, ->fff_fallback
936 | mov CARG1, L 953 | mov CARG1, L
937 | add CARG3, BASE, #8 954 | add CARG3, BASE, #8
955 | IOS mov RA, BASE
938 | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key) 956 | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
939 | // Returns cTValue *. 957 | // Returns cTValue *.
958 | IOS mov BASE, RA
940 | ldrd CARG12, [CRET1] 959 | ldrd CARG12, [CRET1]
941 | b ->fff_restv 960 | b ->fff_restv
942 | 961 |
@@ -984,6 +1003,7 @@ static void build_subroutines(BuildCtx *ctx)
984 | str PC, SAVE_PC 1003 | str PC, SAVE_PC
985 | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key) 1004 | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
986 | // Returns 0 at end of traversal. 1005 | // Returns 0 at end of traversal.
1006 | IOS ldr BASE, L->base
987 | cmp CRET1, #0 1007 | cmp CRET1, #0
988 | mvneq CRET2, #~LJ_TNIL 1008 | mvneq CRET2, #~LJ_TNIL
989 | beq ->fff_restv // End of traversal: return nil. 1009 | beq ->fff_restv // End of traversal: return nil.
@@ -1035,8 +1055,10 @@ static void build_subroutines(BuildCtx *ctx)
1035 | mov CARG2, CARG3 1055 | mov CARG2, CARG3
1036 | cmp RB, #0 1056 | cmp RB, #0
1037 | beq ->fff_res 1057 | beq ->fff_res
1058 | IOS mov RA, BASE
1038 | bl extern lj_tab_getinth // (GCtab *t, int32_t key) 1059 | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
1039 | // Returns cTValue * or NULL. 1060 | // Returns cTValue * or NULL.
1061 | IOS mov BASE, RA
1040 | cmp CRET1, #0 1062 | cmp CRET1, #0
1041 | beq ->fff_res 1063 | beq ->fff_res
1042 | ldrd CARG12, [CRET1] 1064 | ldrd CARG12, [CRET1]
@@ -1275,7 +1297,9 @@ static void build_subroutines(BuildCtx *ctx)
1275 | bmi <1 1297 | bmi <1
1276 |4: 1298 |4:
1277 | // NYI: Use internal implementation. 1299 | // NYI: Use internal implementation.
1300 | IOS mov RA, BASE
1278 | bl extern func 1301 | bl extern func
1302 | IOS mov BASE, RA
1279 | b ->fff_restv 1303 | b ->fff_restv
1280 |.endmacro 1304 |.endmacro
1281 | 1305 |
@@ -1330,13 +1354,17 @@ static void build_subroutines(BuildCtx *ctx)
1330 | 1354 |
1331 |.macro math_extern, func 1355 |.macro math_extern, func
1332 | .ffunc_n math_ .. func 1356 | .ffunc_n math_ .. func
1357 | IOS mov RA, BASE
1333 | bl extern func 1358 | bl extern func
1359 | IOS mov BASE, RA
1334 | b ->fff_restv 1360 | b ->fff_restv
1335 |.endmacro 1361 |.endmacro
1336 | 1362 |
1337 |.macro math_extern2, func 1363 |.macro math_extern2, func
1338 | .ffunc_nn math_ .. func 1364 | .ffunc_nn math_ .. func
1365 | IOS mov RA, BASE
1339 | bl extern func 1366 | bl extern func
1367 | IOS mov BASE, RA
1340 | b ->fff_restv 1368 | b ->fff_restv
1341 |.endmacro 1369 |.endmacro
1342 | 1370 |
@@ -1368,12 +1396,16 @@ static void build_subroutines(BuildCtx *ctx)
1368 | bhs ->fff_fallback 1396 | bhs ->fff_fallback
1369 | checktp CARG4, LJ_TISNUM 1397 | checktp CARG4, LJ_TISNUM
1370 | bne ->fff_fallback 1398 | bne ->fff_fallback
1399 | IOS mov RA, BASE
1371 | bl extern ldexp // (double x, int exp) 1400 | bl extern ldexp // (double x, int exp)
1401 | IOS mov BASE, RA
1372 | b ->fff_restv 1402 | b ->fff_restv
1373 | 1403 |
1374 |.ffunc_n math_frexp 1404 |.ffunc_n math_frexp
1375 | mov CARG3, sp 1405 | mov CARG3, sp
1406 | IOS mov RA, BASE
1376 | bl extern frexp 1407 | bl extern frexp
1408 | IOS mov BASE, RA
1377 | ldr CARG3, [sp] 1409 | ldr CARG3, [sp]
1378 | mvn CARG4, #~LJ_TISNUM 1410 | mvn CARG4, #~LJ_TISNUM
1379 | ldr PC, [BASE, FRAME_PC] 1411 | ldr PC, [BASE, FRAME_PC]
@@ -1385,7 +1417,9 @@ static void build_subroutines(BuildCtx *ctx)
1385 |.ffunc_n math_modf 1417 |.ffunc_n math_modf
1386 | sub CARG3, BASE, #8 1418 | sub CARG3, BASE, #8
1387 | ldr PC, [BASE, FRAME_PC] 1419 | ldr PC, [BASE, FRAME_PC]
1420 | IOS mov RA, BASE
1388 | bl extern modf 1421 | bl extern modf
1422 | IOS mov BASE, RA
1389 | mov RC, #(2+1)*8 1423 | mov RC, #(2+1)*8
1390 | strd CARG12, [BASE] 1424 | strd CARG12, [BASE]
1391 | b ->fff_res 1425 | b ->fff_res
@@ -1600,8 +1634,10 @@ static void build_subroutines(BuildCtx *ctx)
1600 | 1634 |
1601 |.ffunc_1 table_getn 1635 |.ffunc_1 table_getn
1602 | checktab CARG2, ->fff_fallback 1636 | checktab CARG2, ->fff_fallback
1637 | IOS mov RA, BASE
1603 | bl extern lj_tab_len // (GCtab *t) 1638 | bl extern lj_tab_len // (GCtab *t)
1604 | // Returns uint32_t (but less than 2^31). 1639 | // Returns uint32_t (but less than 2^31).
1640 | IOS mov BASE, RA
1605 | mvn CARG2, #~LJ_TISNUM 1641 | mvn CARG2, #~LJ_TISNUM
1606 | b ->fff_restv 1642 | b ->fff_restv
1607 | 1643 |
@@ -2347,8 +2383,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2347 | ins_next3 2383 | ins_next3
2348 |2: 2384 |2:
2349 | checktab CARG2, ->vmeta_len 2385 | checktab CARG2, ->vmeta_len
2386 | IOS mov RC, BASE
2350 | bl extern lj_tab_len // (GCtab *t) 2387 | bl extern lj_tab_len // (GCtab *t)
2351 | // Returns uint32_t (but less than 2^31). 2388 | // Returns uint32_t (but less than 2^31).
2389 | IOS mov BASE, RC
2352 | b <1 2390 | b <1
2353 break; 2391 break;
2354 2392
@@ -2434,8 +2472,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2434 | ins_next3 2472 | ins_next3
2435 |5: // FP variant. 2473 |5: // FP variant.
2436 | ins_arithfallback ins_arithcheck_num 2474 | ins_arithfallback ins_arithcheck_num
2475 |.if "intins" == "vm_modi"
2476 | IOS mov RC, BASE
2477 | bl fpcall
2478 | IOS mov BASE, RC // NYI: remove once we use internal impl. of floor.
2479 |.else
2437 | bl fpcall 2480 | bl fpcall
2438 |.if "intins" ~= "vm_modi"
2439 | ins_next1 2481 | ins_next1
2440 |.endif 2482 |.endif
2441 | b <4 2483 | b <4
@@ -2444,7 +2486,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2444 |.macro ins_arithfp, fpcall 2486 |.macro ins_arithfp, fpcall
2445 | ins_arithpre 2487 | ins_arithpre
2446 | ins_arithfallback ins_arithcheck_num 2488 | ins_arithfallback ins_arithcheck_num
2489 |.if "fpcall" == "extern pow"
2490 | IOS mov RC, BASE
2447 | bl fpcall 2491 | bl fpcall
2492 | IOS mov BASE, RC
2493 |.else
2494 | bl fpcall
2495 |.endif
2448 | ins_next1 2496 | ins_next1
2449 | ins_next2 2497 | ins_next2
2450 | strd CARG12, [BASE, RA] 2498 | strd CARG12, [BASE, RA]
@@ -2602,7 +2650,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2602 | sub CARG1, DISPATCH, #-GG_DISP2G 2650 | sub CARG1, DISPATCH, #-GG_DISP2G
2603 | tst RC, #LJ_GC_WHITES 2651 | tst RC, #LJ_GC_WHITES
2604 | // Crossed a write barrier. Move the barrier forward. 2652 | // Crossed a write barrier. Move the barrier forward.
2605 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) 2653 if (LJ_TARGET_OSX) {
2654 | beq <1
2655 | mov RC, BASE
2656 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
2657 | mov BASE, RC
2658 } else {
2659 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
2660 }
2606 | b <1 2661 | b <1
2607 break; 2662 break;
2608 case BC_USETS: 2663 case BC_USETS:
@@ -2629,7 +2684,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2629 | cmpne RC, #0 2684 | cmpne RC, #0
2630 | sub CARG1, DISPATCH, #-GG_DISP2G 2685 | sub CARG1, DISPATCH, #-GG_DISP2G
2631 | // Crossed a write barrier. Move the barrier forward. 2686 | // Crossed a write barrier. Move the barrier forward.
2632 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv) 2687 if (LJ_TARGET_OSX) {
2688 | beq <1
2689 | mov RC, BASE
2690 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
2691 | mov BASE, RC
2692 } else {
2693 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
2694 }
2633 | b <1 2695 | b <1
2634 break; 2696 break;
2635 case BC_USETN: 2697 case BC_USETN:
@@ -3072,6 +3134,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3072 | str PC, SAVE_PC 3134 | str PC, SAVE_PC
3073 | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) 3135 | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
3074 | // Must not reallocate the stack. 3136 | // Must not reallocate the stack.
3137 | IOS ldr BASE, L->base
3075 | b <1 3138 | b <1
3076 | 3139 |
3077 |7: // Possible table write barrier for any value. Skip valiswhite check. 3140 |7: // Possible table write barrier for any value. Skip valiswhite check.