1 |// Low-level VM code for ARM CPUs.
2 |// Bytecode interpreter, fast functions and helper functions.
3 |// Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
6 |.section code_op, code_sub
8 |.actionlist build_actionlist
10 |.globalnames globnames
11 |.externnames extnames
13 |// Note: The ragged indentation of the instructions is intentional.
14 |// The starting columns indicate data dependencies.
16 |//-----------------------------------------------------------------------
18 |// Fixed register assignments for the interpreter.
20 |// The following must be C callee-save.
21 |.define MASKR8, r4 // 255*8 constant for fast bytecode decoding.
22 |.define KBASE, r5 // Constants of current Lua function.
23 |.define PC, r6 // Next PC.
24 |.define DISPATCH, r7 // Opcode dispatch table.
25 |.define LREG, r8 // Register holding lua_State (also in SAVE_L).
27 |// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.
28 |.define BASE, r9 // Base of current Lua stack frame.
30 |// The following temporaries are not saved across C calls, except for RA/RC.
31 |.define RA, r10 // Callee-save.
32 |.define RC, r11 // Callee-save.
34 |.define OP, r12 // Overlaps RB, must not be lr.
37 |// Calling conventions. Also used as temporaries.
42 |.define CARG12, r0 // For 1st soft-fp double.
43 |.define CARG34, r2 // For 2nd soft-fp double.
48 |// Stack layout while in interpreter. Must match with lj_frame.h.
49 |.define SAVE_R4, [sp, #28]
50 |.define CFRAME_SPACE, #28
51 |.define SAVE_ERRF, [sp, #24]
52 |.define SAVE_NRES, [sp, #20]
53 |.define SAVE_CFRAME, [sp, #16]
54 |.define SAVE_L, [sp, #12]
55 |.define SAVE_PC, [sp, #8]
56 |.define SAVE_MULTRES, [sp, #4]
59 |.define TMPDhi, [sp, #4]
66 | push {r5, r6, r7, r8, r9, r10, r11, lr}
68 | sub sp, sp, CFRAME_SPACE+4
71 |.macro restoreregs_ret
73 | add sp, sp, CFRAME_SPACE+4
75 | pop {r5, r6, r7, r8, r9, r10, r11, pc}
79 | push {r4, r5, r6, r7, r8, r9, r10, r11, lr}
80 | sub sp, sp, CFRAME_SPACE
82 |.macro restoreregs_ret
83 | add sp, sp, CFRAME_SPACE
84 | pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
88 |// Type definitions. Some of these are only used for documentation.
89 |.type L, lua_State, LREG
90 |.type GL, global_State
101 |.type TRACE, GCtrace
104 |//-----------------------------------------------------------------------
106 |// Trap for not-yet-implemented parts.
107 |.macro NYI; ud; .endmacro
109 |//-----------------------------------------------------------------------
111 |// Access to frame relative to BASE.
112 |.define FRAME_FUNC, #-8
113 |.define FRAME_PC, #-4
115 |.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro
116 |.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro
117 |.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro
118 |.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro
119 |.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro
121 |// Instruction fetch.
128 |// Instruction decode+dispatch.
130 | ldr OP, [DISPATCH, OP, lsl #2]
141 |// Instruction footer.
143 | // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
144 | .define ins_next, ins_NEXT
145 | .define ins_next_, ins_NEXT
146 | .define ins_next1, ins_NEXT1
147 | .define ins_next2, ins_NEXT2
148 | .define ins_next3, ins_NEXT3
150 | // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
151 | // Affects only certain kinds of benchmarks (and only with -j off).
168 |// Avoid register name substitution for field name.
171 |// Call decode and dispatch.
173 | // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
174 | ldr PC, LFUNC:CARG3->field_pc
175 | ldrb OP, [PC] // STALL: load PC. early PC.
177 | ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP.
184 | // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
185 | str PC, [BASE, FRAME_PC]
186 | ins_callt // STALL: locked PC.
189 |//-----------------------------------------------------------------------
191 |// Macros to test operand types.
192 |.macro checktp, reg, tp; cmn reg, #-tp; .endmacro
193 |.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro
194 |.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro
195 |.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro
196 |.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro
197 |.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro
199 |// Assumes DISPATCH is relative to GL.
200 #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
201 #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
203 #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
205 |.macro hotcheck, delta
207 | and CARG1, CARG1, #126
208 | sub CARG1, CARG1, #-GG_DISP2HOT
209 | ldrh CARG2, [DISPATCH, CARG1]
210 | subs CARG2, CARG2, #delta
211 | strh CARG2, [DISPATCH, CARG1]
215 | hotcheck HOTCOUNT_LOOP
220 | hotcheck HOTCOUNT_CALL
224 |// Set current VM state.
225 |.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro
226 |.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro
228 |// Move table write barrier back. Overwrites mark and tmp.
229 |.macro barrierback, tab, mark, tmp
230 | ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
231 | bic mark, mark, #LJ_GC_BLACK // black2gray(tab)
232 | str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
233 | strb mark, tab->marked
234 | str tmp, tab->gclist
243 |//-----------------------------------------------------------------------
246 #error "Only dual-number mode supported for ARM target"
249 /* Generate subroutines used by opcodes and other parts of the VM. */
250 /* The .code_sub section should be last to help static branch prediction. */
251 static void build_subroutines(BuildCtx *ctx)
255 |//-----------------------------------------------------------------------
256 |//-- Return handling ----------------------------------------------------
257 |//-----------------------------------------------------------------------
260 | // See vm_return. Also: RB = previous base.
262 | beq ->cont_dispatch
264 | // Return from pcall or xpcall fast func.
265 | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame.
266 | mvn CARG2, #~LJ_TTRUE
268 | // Prepending may overwrite the pcall frame, so do it at the end.
269 | str CARG2, [RA, FRAME_PC] // Prepend true to results.
273 | adds RC, RC, #8 // RC = (nresults+1)*8.
274 | mov CRET1, #LUA_YIELD
275 | beq ->vm_unwind_c_eh
276 | str RC, SAVE_MULTRES
277 | ands CARG1, PC, #FRAME_TYPE
278 | beq ->BC_RET_Z // Handle regular return to Lua.
281 | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return
282 | // CARG1 = PC & FRAME_TYPE
283 | bic RB, PC, #FRAME_TYPEP
284 | cmp CARG1, #FRAME_C
285 | sub RB, BASE, RB // RB = previous base.
289 | ldr KBASE, SAVE_NRES
290 | mv_vmstate CARG4, C
293 | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8
297 | subs CARG3, CARG3, #8
298 | ldrd CARG12, [RA], #8
299 | strd CARG12, [BASE], #8
302 | cmp KBASE, RC // More/less results wanted?
305 | str BASE, L->top // Store new top.
308 | ldr RC, SAVE_CFRAME // Restore previous C frame.
309 | mov CRET1, #0 // Ok return status for vm_pcall.
316 | blt >7 // Less results wanted?
317 | // More results wanted. Check stack size and fill up results with nil.
318 | ldr CARG3, L->maxstack
319 | mvn CARG2, #~LJ_TNIL
322 | str CARG2, [BASE, #4]
327 |7: // Less results wanted.
328 | sub CARG1, RC, KBASE
329 | cmp KBASE, #0 // LUA_MULTRET+1 case?
330 | subne BASE, BASE, CARG1 // Either keep top or shrink it.
333 |8: // Corner case: need to grow stack for filling up results.
334 | // This can happen if:
335 | // - A C function grows the stack (a lot).
336 | // - The GC shrinks the stack in between.
337 | // - A return back from a lua_call() with (high) nresults adjustment.
338 | str BASE, L->top // Save current top held in BASE (yes).
339 | lsr CARG2, KBASE, #3
341 | bl extern lj_state_growstack // (lua_State *L, int n)
342 | ldr BASE, L->top // Need the (realloced) L->top in BASE.
345 |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
346 | // (void *cframe, int errcode)
349 |->vm_unwind_c_eh: // Landing pad for external unwinder.
351 | mv_vmstate CARG4, C
352 | ldr GL:CARG3, L->glref
353 | str CARG4, GL:CARG3->vmstate
356 |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
358 | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
360 |->vm_unwind_ff_eh: // Landing pad for external unwinder.
363 | mov RC, #16 // 2 results: false + error message.
364 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
366 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
367 | mvn CARG1, #~LJ_TFALSE
368 | sub RA, BASE, #8 // Results start at BASE-8.
369 | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame.
370 | add DISPATCH, DISPATCH, #GG_G2DISP
371 | mv_vmstate CARG2, INTERP
372 | str CARG1, [BASE, #-4] // Prepend false to error message.
376 |//-----------------------------------------------------------------------
377 |//-- Grow stack for calls -----------------------------------------------
378 |//-----------------------------------------------------------------------
380 |->vm_growstack_c: // Grow stack for C function.
382 | mov CARG2, #LUA_MINSTACK
385 |->vm_growstack_l: // Grow stack for Lua function.
386 | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
391 | add PC, PC, #4 // Must point after first instruction.
395 | // L->base = new base, L->top = top
397 | bl extern lj_state_growstack // (lua_State *L, int n)
400 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
401 | sub NARGS8:RC, RC, BASE
402 | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
403 | ins_callt // Just retry the call.
405 |//-----------------------------------------------------------------------
406 |//-- Entry points into the assembler VM ---------------------------------
407 |//-----------------------------------------------------------------------
409 |->vm_resume: // Setup C frame and resume thread.
410 | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
413 | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table.
415 | add DISPATCH, DISPATCH, #GG_G2DISP
418 | str CARG3, SAVE_NRES
419 | add CARG2, sp, #CFRAME_RESUME
420 | ldrb CARG1, L->status
421 | str CARG3, SAVE_ERRF
422 | str L, SAVE_PC // Any value outside of bytecode is ok.
423 | str CARG3, SAVE_CFRAME
425 | str CARG2, L->cframe
428 | // Resume after yield (like a return).
429 | str L, [DISPATCH, #DISPATCH_GL(cur_L)]
434 | strb CARG3, L->status
435 | sub RC, CARG1, BASE
436 | ldr PC, [BASE, FRAME_PC]
437 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
438 | mv_vmstate CARG2, INTERP
440 | ands CARG1, PC, #FRAME_TYPE
442 | str RC, SAVE_MULTRES
446 |->vm_pcall: // Setup protected C frame and enter VM.
447 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
450 | str CARG4, SAVE_ERRF
453 |->vm_call: // Setup C frame and enter VM.
454 | // (lua_State *L, TValue *base, int nres1)
458 |1: // Entry point for vm_pcall above (PC = ftype).
459 | ldr RC, L:CARG1->cframe
460 | str CARG3, SAVE_NRES
463 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
465 | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
466 | str RC, SAVE_CFRAME
467 | add DISPATCH, DISPATCH, #GG_G2DISP
468 | str sp, L->cframe // Add our C frame to cframe chain.
470 |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
471 | str L, [DISPATCH, #DISPATCH_GL(cur_L)]
472 | ldr RB, L->base // RB = old base (for vmeta_call).
476 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
477 | sub PC, PC, RB // PC = frame delta + frame type
478 | mv_vmstate CARG2, INTERP
479 | sub NARGS8:RC, CARG1, BASE
483 | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC
484 | ldrd CARG34, [BASE, FRAME_FUNC]
485 | checkfunc CARG4, ->vmeta_call
487 |->vm_call_dispatch_f:
489 | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC
491 |->vm_cpcall: // Setup protected C frame, call C.
492 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
495 | ldr RA, L:CARG1->stack
497 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
499 | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
501 | add DISPATCH, DISPATCH, #GG_G2DISP
502 | sub RA, RA, RB // Compute -savestack(L, L->top).
504 | str RA, SAVE_NRES // Neg. delta means cframe w/o frame.
505 | str RB, SAVE_ERRF // No error function.
506 | str RC, SAVE_CFRAME
507 | str sp, L->cframe // Add our C frame to cframe chain.
508 | str L, [DISPATCH, #DISPATCH_GL(cur_L)]
509 | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud)
512 | bne <3 // Else continue with the call.
513 | b ->vm_leave_cp // No base? Just remove C frame.
515 |//-----------------------------------------------------------------------
516 |//-- Metamethod handling ------------------------------------------------
517 |//-----------------------------------------------------------------------
519 |//-- Continuation dispatch ----------------------------------------------
522 | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8
523 | ldr LFUNC:CARG3, [RB, FRAME_FUNC]
524 | ldr CARG1, [BASE, #-16] // Get continuation.
526 | mov BASE, RB // Restore caller BASE.
530 | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC].
531 | ldr CARG3, LFUNC:CARG3->field_pc
534 | str INS, [CARG2, #-4] // Ensure one valid arg.
538 | ldr KBASE, [CARG3, #PC2PROTO(k)]
539 | // BASE = base, RA = resultptr, CARG4 = meta base
544 | beq ->cont_ffi_callback // cont = 1: return from FFI callback.
545 | // cont = 0: tailcall from C function.
546 | sub CARG4, CARG4, #16
547 | sub RC, CARG4, BASE
551 |->cont_cat: // RA = resultptr, CARG4 = meta base
553 | sub CARG2, CARG4, #16
558 | add CARG1, BASE, RC
559 | subs CARG1, CARG2, CARG1
560 | strdne CARG34, [CARG2]
563 | strd CARG34, [BASE, RA]
566 |//-- Table indexing metamethods -----------------------------------------
569 | add CARG2, BASE, RB
573 | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
574 | mvn CARG4, #~LJ_TTAB
575 | str TAB:RB, [CARG2]
576 | str CARG4, [CARG2, #4]
578 | mvn CARG4, #~LJ_TSTR
584 |->vmeta_tgetb: // RC = index
587 | mvn CARG4, #~LJ_TISNUM
588 | add CARG2, BASE, RB
594 | add CARG2, BASE, RB
595 | add CARG3, BASE, RC
600 | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
601 | // Returns TValue * (finished) or NULL (metamethod).
602 | .IOS ldr BASE, L->base
605 | ldrd CARG34, [CRET1]
608 | strd CARG34, [BASE, RA]
611 |3: // Call __index metamethod.
612 | // BASE = base, L->top = new base, stack = cont/func/t/k
613 | rsb CARG1, BASE, #FRAME_CONT
615 | mov NARGS8:RC, #16 // 2 args for func(t, k).
616 | str PC, [BASE, #-12] // [cont|PC]
617 | add PC, CARG1, BASE
618 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
619 | b ->vm_call_dispatch_f
623 | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
624 | // Returns cTValue * or NULL.
627 | ldrdne CARG12, [CRET1]
628 | mvneq CARG2, #~LJ_TNIL
631 |//-----------------------------------------------------------------------
634 | add CARG2, BASE, RB
638 | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
639 | mvn CARG4, #~LJ_TTAB
640 | str TAB:RB, [CARG2]
641 | str CARG4, [CARG2, #4]
643 | mvn CARG4, #~LJ_TSTR
649 |->vmeta_tsetb: // RC = index
652 | mvn CARG4, #~LJ_TISNUM
653 | add CARG2, BASE, RB
659 | add CARG2, BASE, RB
660 | add CARG3, BASE, RC
665 | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
666 | // Returns TValue * (finished) or NULL (metamethod).
667 | .IOS ldr BASE, L->base
669 | ldrd CARG34, [BASE, RA]
672 | // NOBARRIER: lj_meta_tset ensures the table is not black.
673 | strd CARG34, [CRET1]
677 |3: // Call __newindex metamethod.
678 | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
679 | rsb CARG1, BASE, #FRAME_CONT
681 | mov NARGS8:RC, #24 // 3 args for func(t, k, v).
682 | strd CARG34, [BASE, #16] // Copy value to third argument.
683 | str PC, [BASE, #-12] // [cont|PC]
684 | add PC, CARG1, BASE
685 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
686 | b ->vm_call_dispatch_f
692 | bl extern lj_tab_setinth // (lua_State *L, GCtab *t, int32_t key)
693 | // Returns TValue *.
697 |//-- Comparison metamethods ---------------------------------------------
706 | decode_OP CARG4, INS
707 | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
708 | // Returns 0/1 or TValue * (metamethod).
710 | .IOS ldr BASE, L->base
716 | add RB, PC, RB, lsl #2
717 | subhs PC, RB, #0x20000
721 |->cont_ra: // RA = resultptr
724 | decode_RA8 CARG3, INS
725 | strd CARG12, [BASE, CARG3]
728 |->cont_condt: // RA = resultptr
729 | ldr CARG2, [RA, #4]
730 | mvn CARG1, #~LJ_TTRUE
731 | cmp CARG1, CARG2 // Branch if result is true.
734 |->cont_condf: // RA = resultptr
735 | ldr CARG2, [RA, #4]
736 | checktp CARG2, LJ_TFALSE // Branch if result is false.
740 | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
745 | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
746 | // Returns 0/1 or TValue * (metamethod).
756 | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op)
757 | // Returns 0/1 or TValue * (metamethod).
768 | bl extern lj_meta_istype // (lua_State *L, BCReg ra, BCReg tp)
769 | .IOS ldr BASE, L->base
772 |//-- Arithmetic metamethods ---------------------------------------------
777 | add CARG3, BASE, RB
778 | add CARG4, KBASE, RC
784 | add CARG4, BASE, RB
785 | add CARG3, KBASE, RC
791 | add CARG3, BASE, RC
792 | add CARG4, BASE, RC
798 | add CARG3, BASE, RB
799 | add CARG4, BASE, RC
802 | add CARG2, BASE, RA
807 | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
808 | // Returns NULL (finished) or TValue * (metamethod).
809 | .IOS ldr BASE, L->base
813 | // Call metamethod for binary op.
815 | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
816 | sub CARG2, CRET1, BASE
817 | str PC, [CRET1, #-12] // [cont|PC]
818 | add PC, CARG2, #FRAME_CONT
820 | mov NARGS8:RC, #16 // 2 args for func(o1, o2).
821 | b ->vm_call_dispatch
824 | add CARG2, BASE, RC
828 | bl extern lj_meta_len // (lua_State *L, TValue *o)
829 | // Returns NULL (retry) or TValue * (metamethod base).
830 | .IOS ldr BASE, L->base
833 | bne ->vmeta_binop // Binop call for compatibility.
834 | ldr TAB:CARG1, [BASE, RC]
837 | b ->vmeta_binop // Binop call for compatibility.
840 |//-- Call metamethod ----------------------------------------------------
842 |->vmeta_call: // Resolve and call __call metamethod.
843 | // RB = old base, BASE = new base, RC = nargs*8
845 | str RB, L->base // This is the callers base!
846 | sub CARG2, BASE, #8
848 | add CARG3, BASE, NARGS8:RC
850 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
852 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
853 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
856 |->vmeta_callt: // Resolve __call for BC_CALLT.
857 | // BASE = old base, RA = new base, RC = nargs*8
862 | add CARG3, RA, NARGS8:RC
863 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
864 | .IOS ldr BASE, L->base
865 | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
866 | ldr PC, [BASE, FRAME_PC]
867 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
870 |//-- Argument coercion for 'for' statement ------------------------------
877 | bl extern lj_meta_for // (lua_State *L, TValue *base)
878 | .IOS ldr BASE, L->base
893 |//-----------------------------------------------------------------------
894 |//-- Fast functions -----------------------------------------------------
895 |//-----------------------------------------------------------------------
901 |.macro .ffunc_1, name
903 | ldrd CARG12, [BASE]
908 |.macro .ffunc_2, name
910 | ldrd CARG12, [BASE]
911 | ldrd CARG34, [BASE, #8]
916 |.macro .ffunc_n, name
918 | checktp CARG2, LJ_TISNUM
922 |.macro .ffunc_nn, name
924 | checktp CARG2, LJ_TISNUM
925 | cmnlo CARG4, #-LJ_TISNUM
929 |.macro .ffunc_d, name
931 | ldr CARG2, [BASE, #4]
935 | checktp CARG2, LJ_TISNUM
939 |.macro .ffunc_dd, name
941 | ldr CARG2, [BASE, #4]
942 | ldr CARG4, [BASE, #12]
945 | vldr d1, [BASE, #8]
947 | checktp CARG2, LJ_TISNUM
948 | cmnlo CARG4, #-LJ_TISNUM
952 |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.
954 | ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)]
955 | ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)]
960 |//-- Base library: checks -----------------------------------------------
963 | checktp CARG2, LJ_TTRUE
965 | ldr PC, [BASE, FRAME_PC]
966 | strd CARG12, [BASE, #-8]
968 | subs RA, NARGS8:RC, #8
969 | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8.
970 | beq ->fff_res // Done if exactly 1 argument.
972 | ldrd CARG12, [RB, #8]
974 | strd CARG12, [RB], #8
979 | ldr CARG2, [BASE, #4]
982 | checktp CARG2, LJ_TISNUM
983 | mvnlo CARG2, #~LJ_TISNUM
984 | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1
985 | lsl CARG4, CARG4, #3
986 | ldrd CARG12, [CFUNC:CARG3, CARG4]
989 |//-- Base library: getters and setters ---------------------------------
991 |.ffunc_1 getmetatable
992 | checktp CARG2, LJ_TTAB
993 | cmnne CARG2, #-LJ_TUDATA
995 |1: // Field metatable must be at same offset for GCtab and GCudata!
996 | ldr TAB:RB, TAB:CARG1->metatable
998 | mvn CARG2, #~LJ_TNIL
999 | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])]
1002 | ldr CARG3, TAB:RB->hmask
1003 | ldr CARG4, STR:RC->hash
1004 | ldr NODE:INS, TAB:RB->node
1005 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
1006 | add CARG3, CARG3, CARG3, lsl #1
1007 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
1008 |3: // Rearranged logic, because we expect _not_ to find the key.
1009 | ldrd CARG34, NODE:INS->key // STALL: early NODE:INS.
1010 | ldrd CARG12, NODE:INS->val
1011 | ldr NODE:INS, NODE:INS->next
1012 | checktp CARG4, LJ_TSTR
1013 | cmpeq CARG3, STR:RC
1018 | mov CARG1, RB // Use metatable as default result.
1019 | mvn CARG2, #~LJ_TTAB
1022 | checktp CARG2, LJ_TNIL
1027 | checktp CARG2, LJ_TISNUM
1028 | mvnhs CARG2, CARG2
1029 | movlo CARG2, #~LJ_TISNUM
1030 | add CARG4, DISPATCH, CARG2, lsl #2
1031 | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])]
1034 |.ffunc_2 setmetatable
1035 | // Fast path: no mt for table yet and not clearing the mt.
1036 | checktp CARG2, LJ_TTAB
1037 | ldreq TAB:RB, TAB:CARG1->metatable
1038 | checktpeq CARG4, LJ_TTAB
1039 | ldrbeq CARG4, TAB:CARG1->marked
1041 | bne ->fff_fallback
1042 | tst CARG4, #LJ_GC_BLACK // isblack(table)
1043 | str TAB:CARG3, TAB:CARG1->metatable
1045 | barrierback TAB:CARG1, CARG4, CARG3
1049 | ldrd CARG34, [BASE]
1050 | cmp NARGS8:RC, #16
1051 | blo ->fff_fallback
1053 | checktab CARG4, ->fff_fallback
1055 | add CARG3, BASE, #8
1057 | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
1058 | // Returns cTValue *.
1060 | ldrd CARG12, [CRET1]
1063 |//-- Base library: conversions ------------------------------------------
1066 | // Only handles the number case inline (without a base argument).
1067 | ldrd CARG12, [BASE]
1069 | bne ->fff_fallback
1070 | checktp CARG2, LJ_TISNUM
1075 | // Only handles the string or number case inline.
1076 | checktp CARG2, LJ_TSTR
1077 | // A __tostring method in the string base metatable is ignored.
1079 | // Handle numbers inline, unless a number base metatable is present.
1080 | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])]
1082 | checktp CARG2, LJ_TISNUM
1084 | str PC, SAVE_PC // Redundant (but a defined value).
1085 | bhi ->fff_fallback
1089 | bl extern lj_strfmt_number // (lua_State *L, cTValue *o)
1090 | // Returns GCstr *.
1092 | mvn CARG2, #~LJ_TSTR
1095 |//-- Base library: iterators -------------------------------------------
1098 | mvn CARG4, #~LJ_TNIL
1099 | checktab CARG2, ->fff_fallback
1100 | strd CARG34, [BASE, NARGS8:RC] // Set missing 2nd arg to nil.
1101 | ldr PC, [BASE, FRAME_PC]
1103 | str BASE, L->base // Add frame since C call can throw.
1105 | str BASE, L->top // Dummy frame length is ok.
1106 | add CARG3, BASE, #8
1108 | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
1109 | // Returns 0 at end of traversal.
1110 | .IOS ldr BASE, L->base
1112 | mvneq CRET2, #~LJ_TNIL
1113 | beq ->fff_restv // End of traversal: return nil.
1114 | ldrd CARG12, [BASE, #8] // Copy key and value to results.
1115 | ldrd CARG34, [BASE, #16]
1117 | strd CARG12, [BASE, #-8]
1118 | strd CARG34, [BASE]
1122 | checktab CARG2, ->fff_fallback
1124 | ldr TAB:RB, TAB:CARG1->metatable
1126 | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
1127 | ldr PC, [BASE, FRAME_PC]
1130 | bne ->fff_fallback
1132 | mvn CARG2, #~LJ_TNIL
1134 | strd CFUNC:CARG34, [BASE, #-8]
1135 | str CARG2, [BASE, #12]
1138 |.ffunc_2 ipairs_aux
1139 | checktp CARG2, LJ_TTAB
1140 | checktpeq CARG4, LJ_TISNUM
1141 | bne ->fff_fallback
1142 | ldr RB, TAB:CARG1->asize
1143 | ldr RC, TAB:CARG1->array
1144 | add CARG3, CARG3, #1
1145 | ldr PC, [BASE, FRAME_PC]
1147 | add RC, RC, CARG3, lsl #3
1148 | strd CARG34, [BASE, #-8]
1149 | ldrdlo CARG12, [RC]
1151 | bhs >2 // Not in array part?
1153 | checktp CARG2, LJ_TNIL
1154 | movne RC, #(2+1)*8
1155 | strdne CARG12, [BASE]
1157 |2: // Check for empty hash part first. Otherwise call C function.
1158 | ldr RB, TAB:CARG1->hmask
1163 | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
1164 | // Returns cTValue * or NULL.
1168 | ldrd CARG12, [CRET1]
1172 | checktab CARG2, ->fff_fallback
1174 | ldr TAB:RB, TAB:CARG1->metatable
1176 | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
1177 | ldr PC, [BASE, FRAME_PC]
1180 | bne ->fff_fallback
1183 | mvn CARG2, #~LJ_TISNUM
1185 | strd CFUNC:CARG34, [BASE, #-8]
1186 | strd CARG12, [BASE, #8]
1189 |//-- Base library: catch errors ----------------------------------------
1192 | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
1194 | blo ->fff_fallback
1195 | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
1197 | add BASE, BASE, #8
1198 | moveq PC, #8+FRAME_PCALL
1199 | movne PC, #8+FRAME_PCALLH
1200 | sub NARGS8:RC, NARGS8:RC, #8
1201 | b ->vm_call_dispatch
1204 | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
1205 | checkfunc CARG4, ->fff_fallback // Traceback must be a function.
1207 | strd CARG12, [BASE, #8] // Swap function and traceback.
1208 | strd CARG34, [BASE]
1209 | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
1210 | add BASE, BASE, #16
1211 | moveq PC, #16+FRAME_PCALL
1212 | movne PC, #16+FRAME_PCALLH
1213 | sub NARGS8:RC, NARGS8:RC, #16
1214 | b ->vm_call_dispatch
1216 |//-- Coroutine library --------------------------------------------------
1218 |.macro coroutine_resume_wrap, resume
1220 |.ffunc_1 coroutine_resume
1221 | checktp CARG2, LJ_TTHREAD
1222 | bne ->fff_fallback
1224 |.ffunc coroutine_wrap_aux
1225 | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr
1227 | ldr PC, [BASE, FRAME_PC]
1229 | ldr CARG2, L:CARG1->top
1230 | ldrb RA, L:CARG1->status
1231 | ldr RB, L:CARG1->base
1232 | add CARG3, CARG2, NARGS8:RC
1233 | add CARG4, CARG2, RA
1236 | beq ->fff_fallback
1237 | ldr CARG4, L:CARG1->maxstack
1238 | ldr RB, L:CARG1->cframe
1239 | cmp RA, #LUA_YIELD
1240 | cmpls CARG3, CARG4
1242 | bhi ->fff_fallback
1245 | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC.
1246 | add BASE, BASE, #8
1247 | sub NARGS8:RC, NARGS8:RC, #8
1249 | str CARG3, L:CARG1->top
1251 |2: // Move args to coroutine.
1252 | ldrd CARG34, [BASE, RB]
1254 | strdne CARG34, [CARG2, RB]
1261 | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
1262 | // Returns thread status.
1264 | ldr CARG3, L:RA->base
1265 | mv_vmstate CARG2, INTERP
1266 | ldr CARG4, L:RA->top
1267 | cmp CRET1, #LUA_YIELD
1269 | str L, [DISPATCH, #DISPATCH_GL(cur_L)]
1272 | subs RC, CARG4, CARG3
1273 | ldr CARG1, L->maxstack
1274 | add CARG2, BASE, RC
1275 | beq >6 // No results?
1278 | bhi >9 // Need to grow stack?
1281 | str CARG3, L:RA->top // Clear coroutine stack.
1282 |5: // Move results from coroutine.
1283 | ldrd CARG12, [CARG3, RB]
1285 | strd CARG12, [BASE, RB]
1290 | mvn CARG3, #~LJ_TTRUE
1293 | str CARG3, [BASE, #-4] // Prepend true/false to results.
1299 | ands CARG1, PC, #FRAME_TYPE
1301 | str RC, SAVE_MULTRES
1305 |8: // Coroutine returned with error (at co->top-1).
1307 | ldrd CARG12, [CARG4, #-8]!
1308 | mvn CARG3, #~LJ_TFALSE
1310 | str CARG4, L:RA->top // Remove error from coroutine stack.
1311 | strd CARG12, [BASE] // Copy error message.
1316 | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
1320 |9: // Handle stack expansion on return from yield.
1323 | bl extern lj_state_growstack // (lua_State *L, int n)
1328 | coroutine_resume_wrap 1 // coroutine.resume
1329 | coroutine_resume_wrap 0 // coroutine.wrap
1331 |.ffunc coroutine_yield
1332 | ldr CARG1, L->cframe
1333 | add CARG2, BASE, NARGS8:RC
1335 | tst CARG1, #CFRAME_RESUME
1337 | mov CRET1, #LUA_YIELD
1339 | beq ->fff_fallback
1340 | str CARG3, L->cframe
1341 | strb CRET1, L->status
1344 |//-- Math library -------------------------------------------------------
1346 |.macro math_round, func
1347 | .ffunc_1 math_ .. func
1348 | checktp CARG2, LJ_TISNUM
1350 | bhi ->fff_fallback
1351 | // Round FP value and normalize result.
1352 | lsl CARG3, CARG2, #1
1353 | adds RB, CARG3, #0x00200000
1354 | bpl >2 // |x| < 1?
1356 | subs RB, CARG4, RB, asr #21
1357 | lsl CARG4, CARG2, #11
1358 | lsl CARG3, CARG1, #11
1359 | orr CARG4, CARG4, #0x80000000
1361 | orr CARG4, CARG4, CARG1, lsr #21
1362 | bls >3 // |x| >= 2^31?
1363 | orr CARG3, CARG3, CARG4, lsl INS
1364 | lsr CARG1, CARG4, RB
1365 |.if "func" == "floor"
1366 | tst CARG3, CARG2, asr #31
1367 | addne CARG1, CARG1, #1
1369 | bics CARG3, CARG3, CARG2, asr #31
1370 | addsne CARG1, CARG1, #1
1375 | rsblt CARG1, CARG1, #0
1377 | mvn CARG2, #~LJ_TISNUM
1381 | bcs ->fff_restv // |x| is not finite.
1382 | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo
1383 |.if "func" == "floor"
1384 | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1
1388 | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1
1392 | mvn CARG2, #~LJ_TISNUM
1395 |3: // |x| >= 2^31. Check for x == -(2^31).
1396 | cmpeq CARG4, #0x80000000
1397 |.if "func" == "floor"
1402 | movmi CARG1, #0x80000000
1405 | bl ->vm_..func.._sf
1414 | .long 0x00000000, 0x41e00000 // 2^31.
1417 | checktp CARG2, LJ_TISNUM
1418 | bhi ->fff_fallback
1419 | bicne CARG2, CARG2, #0x80000000
1422 | rsbslt CARG1, CARG1, #0
1427 | // CARG12 = TValue result.
1428 | ldr PC, [BASE, FRAME_PC]
1429 | strd CARG12, [BASE, #-8]
1434 | // RC = (nresults+1)*8, PC = return.
1435 | ands CARG1, PC, #FRAME_TYPE
1436 | ldreq INS, [PC, #-4]
1437 | str RC, SAVE_MULTRES
1440 | decode_RB8 RB, INS
1442 | cmp RB, RC // More results expected?
1444 | decode_RA8 CARG1, INS
1447 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
1448 | sub BASE, RA, CARG1
1451 |6: // Fill up results with nil.
1453 | mvn CARG1, #~LJ_TNIL
1455 | str CARG1, [CARG2, #-4]
1458 |.macro math_extern, func
1460 | .ffunc_d math_ .. func
1462 | .ffunc_n math_ .. func
1474 |.macro math_extern2, func
1476 | .ffunc_dd math_ .. func
1478 | .ffunc_nn math_ .. func
1491 | .ffunc_d math_sqrt
1494 | ldr PC, [BASE, FRAME_PC]
1495 | vstr d0, [BASE, #-8]
1503 | ldr CARG2, [BASE, #4]
1504 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1506 | bne ->fff_fallback
1508 | ldrd CARG12, [BASE]
1509 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1510 | bne ->fff_fallback
1512 | checktp CARG2, LJ_TISNUM
1513 | bhs ->fff_fallback
1535 | math_extern2 atan2
1540 | ldr CARG4, [BASE, #4]
1541 | ldrd CARG12, [BASE, #8]
1542 | cmp NARGS8:RC, #16
1543 | blo ->fff_fallback
1545 | checktp CARG4, LJ_TISNUM
1546 | bhs ->fff_fallback
1547 | checktp CARG2, LJ_TISNUM
1548 | bne ->fff_fallback
1550 | bl extern ldexp // (double x, int exp)
1554 |.ffunc_2 math_ldexp
1555 | checktp CARG2, LJ_TISNUM
1556 | bhs ->fff_fallback
1557 | checktp CARG4, LJ_TISNUM
1558 | bne ->fff_fallback
1560 | bl extern ldexp // (double x, int exp)
1566 |.ffunc_d math_frexp
1572 | mvn CARG4, #~LJ_TISNUM
1573 | ldr PC, [BASE, FRAME_PC]
1574 | vstr d0, [BASE, #-8]
1576 | strd CARG34, [BASE]
1579 |.ffunc_n math_frexp
1585 | mvn CARG4, #~LJ_TISNUM
1586 | ldr PC, [BASE, FRAME_PC]
1587 | strd CARG12, [BASE, #-8]
1589 | strd CARG34, [BASE]
1595 | sub CARG1, BASE, #8
1596 | ldr PC, [BASE, FRAME_PC]
1605 | sub CARG3, BASE, #8
1606 | ldr PC, [BASE, FRAME_PC]
1611 | strd CARG12, [BASE]
1615 |.macro math_minmax, name, cond, fcond
1619 | checktp CARG2, LJ_TISNUM
1622 |1: // Handle integers.
1626 | checktp CARG4, LJ_TISNUM
1630 | mov..cond CARG1, CARG3
1632 |3: // Convert intermediate result to number and continue below.
1634 | bhi ->fff_fallback
1636 | vcvt.f64.s32 d0, s4
1641 | bhi ->fff_fallback
1642 |5: // Handle numbers.
1647 | checktp CARG4, LJ_TISNUM
1653 | vmov..fcond.f64 d0, d1
1655 |7: // Convert integer to number and continue above.
1657 | bhi ->fff_fallback
1658 | vcvt.f64.s32 d1, s4
1664 | checktp CARG2, LJ_TISNUM
1667 |1: // Handle integers.
1668 | ldrd CARG34, [BASE, RA]
1671 | checktp CARG4, LJ_TISNUM
1675 | mov..cond CARG1, CARG3
1677 |3: // Convert intermediate result to number and continue below.
1678 | bhi ->fff_fallback
1679 | bl extern __aeabi_i2d
1680 | ldrd CARG34, [BASE, RA]
1684 | bhi ->fff_fallback
1685 |5: // Handle numbers.
1686 | ldrd CARG34, [BASE, RA]
1689 | checktp CARG4, LJ_TISNUM
1692 | bl extern __aeabi_cdcmple
1694 | mov..fcond CARG1, CARG3
1695 | mov..fcond CARG2, CARG4
1697 |7: // Convert integer to number and continue above.
1698 | bhi ->fff_fallback
1701 | bl extern __aeabi_i2d
1707 | math_minmax math_min, gt, hi
1708 | math_minmax math_max, lt, lo
1710 |//-- String library -----------------------------------------------------
1712 |.ffunc string_byte // Only handle the 1-arg case here.
1713 | ldrd CARG12, [BASE]
1714 | ldr PC, [BASE, FRAME_PC]
1716 | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument.
1717 | bne ->fff_fallback
1718 | ldr CARG3, STR:CARG1->len
1719 | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
1720 | mvn CARG2, #~LJ_TISNUM
1722 | moveq RC, #(0+1)*8
1723 | movne RC, #(1+1)*8
1724 | strd CARG12, [BASE, #-8]
1727 |.ffunc string_char // Only handle the 1-arg case here.
1729 | ldrd CARG12, [BASE]
1730 | ldr PC, [BASE, FRAME_PC]
1731 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1732 | checktpeq CARG2, LJ_TISNUM
1733 | bicseq CARG4, CARG1, #255
1735 | bne ->fff_fallback
1737 | mov CARG2, TMPDp // Points to stack. Little-endian.
1739 | // CARG2 = str, CARG3 = len.
1743 | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
1745 | // Returns GCstr *.
1747 | mvn CARG2, #~LJ_TSTR
1752 | ldrd CARG12, [BASE]
1753 | ldrd CARG34, [BASE, #16]
1754 | cmp NARGS8:RC, #16
1757 | blo ->fff_fallback
1758 | checktp CARG4, LJ_TISNUM
1760 | bne ->fff_fallback
1762 | ldrd CARG34, [BASE, #8]
1763 | checktp CARG2, LJ_TSTR
1764 | ldreq CARG2, STR:CARG1->len
1765 | checktpeq CARG4, LJ_TISNUM
1766 | bne ->fff_fallback
1767 | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end
1768 | add CARG4, CARG2, #1
1769 | cmp CARG3, #0 // if (start < 0) start += len+1
1770 | addlt CARG3, CARG3, CARG4
1771 | cmp CARG3, #1 // if (start < 1) start = 1
1773 | cmp RB, #0 // if (end < 0) end += len+1
1774 | addlt RB, RB, CARG4
1775 | bic RB, RB, RB, asr #31 // if (end < 0) end = 0
1776 | cmp RB, CARG2 // if (end > len) end = len
1777 | add CARG1, STR:CARG1, #sizeof(GCstr)-1
1779 | add CARG2, CARG1, CARG3
1780 | subs CARG3, RB, CARG3 // len = end - start
1781 | add CARG3, CARG3, #1 // len += 1
1784 | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)
1785 | mvn CARG2, #~LJ_TSTR
1788 |.macro ffstring_op, name
1789 | .ffunc string_ .. name
1791 | ldr CARG3, [BASE, #4]
1793 | ldr STR:CARG2, [BASE]
1794 | blo ->fff_fallback
1795 | sub SBUF:CARG1, DISPATCH, #-DISPATCH_GL(tmpbuf)
1796 | checkstr CARG3, ->fff_fallback
1797 | ldr CARG4, SBUF:CARG1->b
1800 | str L, SBUF:CARG1->L
1801 | str CARG4, SBUF:CARG1->p
1802 | bl extern lj_buf_putstr_ .. name
1803 | bl extern lj_buf_tostr
1807 |ffstring_op reverse
1811 |//-- Bit library --------------------------------------------------------
1813 |// FP number to bit conversion for soft-float. Clobbers r0-r3.
1815 | bhi ->fff_fallback
1818 | adds RB, RB, #0x00200000
1819 | movpl CARG1, #0 // |x| < 1?
1822 | subs RB, CARG4, RB, asr #21
1823 | bmi >1 // |x| >= 2^32?
1824 | lsl CARG4, CARG2, #11
1825 | orr CARG4, CARG4, #0x80000000
1826 | orr CARG4, CARG4, CARG1, lsr #21
1828 | lsr CARG1, CARG4, RB
1829 | rsblt CARG1, CARG1, #0
1833 | lsr CARG4, CARG1, RB
1835 | lsl CARG1, CARG2, #12
1837 | orr CARG1, CARG4, CARG1, lsl RB
1838 | rsblt CARG1, CARG1, #0
1841 |.macro .ffunc_bit, name
1842 | .ffunc_1 bit_..name
1843 | checktp CARG2, LJ_TISNUM
1844 | blne ->vm_tobit_fb
1848 | mvn CARG2, #~LJ_TISNUM
1851 |.macro .ffunc_bit_op, name, ins
1856 | ldrd CARG12, [BASE, RA]
1860 | checktp CARG2, LJ_TISNUM
1861 | blne ->vm_tobit_fb
1862 | ins CARG3, CARG3, CARG1
1866 |.ffunc_bit_op band, and
1867 |.ffunc_bit_op bor, orr
1868 |.ffunc_bit_op bxor, eor
1871 | mvn CARG4, #~LJ_TISNUM
1872 | ldr PC, [BASE, FRAME_PC]
1873 | strd CARG34, [BASE, #-8]
1877 | eor CARG3, CARG1, CARG1, ror #16
1878 | bic CARG3, CARG3, #0x00ff0000
1879 | ror CARG1, CARG1, #8
1880 | mvn CARG2, #~LJ_TISNUM
1881 | eor CARG1, CARG1, CARG3, lsr #8
1886 | mvn CARG2, #~LJ_TISNUM
1889 |.macro .ffunc_bit_sh, name, ins, shmod
1891 | ldrd CARG12, [BASE, #8]
1892 | cmp NARGS8:RC, #16
1893 | blo ->fff_fallback
1894 | checktp CARG2, LJ_TISNUM
1895 | blne ->vm_tobit_fb
1897 | and RA, CARG1, #31
1901 | ldrd CARG12, [BASE]
1902 | checktp CARG2, LJ_TISNUM
1903 | blne ->vm_tobit_fb
1904 | ins CARG1, CARG1, RA
1905 | mvn CARG2, #~LJ_TISNUM
1909 |.ffunc_bit_sh lshift, lsl, 0
1910 |.ffunc_bit_sh rshift, lsr, 0
1911 |.ffunc_bit_sh arshift, asr, 0
1912 |.ffunc_bit_sh rol, ror, 1
1913 |.ffunc_bit_sh ror, ror, 0
1915 |//-----------------------------------------------------------------------
1917 |->fff_fallback: // Call fast function fallback handler.
1918 | // BASE = new base, RC = nargs*8
1919 | ldr CARG3, [BASE, FRAME_FUNC]
1920 | ldr CARG2, L->maxstack
1921 | add CARG1, BASE, NARGS8:RC
1922 | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC.
1924 | ldr CARG3, CFUNC:CARG3->f
1926 | add CARG1, CARG1, #8*LUA_MINSTACK
1927 | str PC, SAVE_PC // Redundant (but a defined value).
1930 | bhi >5 // Need to grow stack.
1931 | blx CARG3 // (lua_State *L)
1932 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
1937 | bgt ->fff_res // Returned nresults+1?
1938 |1: // Returned 0 or -1: retry fast path.
1940 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
1941 | sub NARGS8:RC, CARG1, BASE
1942 | bne ->vm_call_tail // Returned -1?
1943 | ins_callt // Returned 0: retry fast path.
1945 |// Reconstruct previous base for vmeta_call during tailcall.
1947 | ands CARG1, PC, #FRAME_TYPE
1948 | bic CARG2, PC, #FRAME_TYPEP
1949 | ldreq INS, [PC, #-4]
1950 | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8.
1951 | addeq CARG2, CARG2, #8
1952 | sub RB, BASE, CARG2
1953 | b ->vm_call_dispatch // Resolve again for tailcall.
1955 |5: // Grow stack for fallback handler.
1956 | mov CARG2, #LUA_MINSTACK
1957 | bl extern lj_state_growstack // (lua_State *L, int n)
1959 | cmp CARG1, CARG1 // Set zero-flag to force retry.
1962 |->fff_gcstep: // Call GC step function.
1963 | // BASE = new base, RC = nargs*8
1966 | add CARG2, BASE, NARGS8:RC
1967 | str PC, SAVE_PC // Redundant (but a defined value).
1970 | bl extern lj_gc_step // (lua_State *L)
1972 | mov lr, RA // Help return address predictor.
1973 | ldr CFUNC:CARG3, [BASE, FRAME_FUNC]
1976 |//-----------------------------------------------------------------------
1977 |//-- Special dispatch targets -------------------------------------------
1978 |//-----------------------------------------------------------------------
1980 |->vm_record: // Dispatch target for recording phase.
1982 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
1983 | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent.
1985 | // Decrement the hookcount for consistency, but always do the call.
1986 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
1987 | tst CARG1, #HOOK_ACTIVE
1989 | sub CARG2, CARG2, #1
1990 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
1991 | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
1995 |->vm_rethook: // Dispatch target for return hooks.
1996 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
1997 | tst CARG1, #HOOK_ACTIVE // Hook already active?
1999 |5: // Re-dispatch to static ins.
2001 | add OP, DISPATCH, OP, lsl #2
2002 | ldr pc, [OP, #GG_DISP2STATIC]
2004 |->vm_inshook: // Dispatch target for instr/line hooks.
2005 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2006 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2007 | tst CARG1, #HOOK_ACTIVE // Hook already active?
2009 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
2011 | subs CARG2, CARG2, #1
2012 | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2014 | tst CARG1, #LUA_MASKLINE
2020 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
2021 | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
2024 |4: // Re-dispatch to static ins.
2025 | ldrb OP, [PC, #-4]
2026 | ldr INS, [PC, #-4]
2027 | add OP, DISPATCH, OP, lsl #2
2028 | ldr OP, [OP, #GG_DISP2STATIC]
2029 | decode_RA8 RA, INS
2033 |->cont_hook: // Continue from hook yield.
2034 | ldr CARG1, [CARG4, #-24]
2036 | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins.
2039 |->vm_hotloop: // Hot loop counter underflow.
2041 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L).
2042 | sub CARG1, DISPATCH, #-GG_DISP2J
2044 | ldr CARG3, LFUNC:CARG3->field_pc
2046 | str L, [DISPATCH, #DISPATCH_J(L)]
2047 | ldrb CARG3, [CARG3, #PC2PROTO(framesize)]
2049 | add CARG3, BASE, CARG3, lsl #3
2051 | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
2055 |->vm_callhook: // Dispatch target for call hooks.
2061 |->vm_hotcall: // Hot call counter underflow.
2066 | add CARG4, BASE, RC
2072 | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
2073 | // Returns ASMFunction.
2078 | sub NARGS8:RC, CARG4, BASE
2079 | str CARG2, SAVE_PC // Invalidate for subsequent line hook.
2080 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2081 | ldr INS, [PC, #-4]
2084 |->cont_stitch: // Trace stitching.
2086 | // RA = resultptr, CARG4 = meta base
2087 | ldr RB, SAVE_MULTRES
2088 | ldr INS, [PC, #-4]
2089 | ldr CARG3, [CARG4, #-24] // Save previous trace number.
2091 | decode_RA8 RC, INS // Call base.
2093 |1: // Move results down.
2097 | strd CARG12, [BASE, RC]
2101 | decode_RA8 RA, INS
2102 | decode_RB8 RB, INS
2104 | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
2107 | mvn CARG2, #~LJ_TNIL
2108 | bhi >9 // More results wanted?
2110 | ldr TRACE:RA, [CARG1, CARG3, lsl #2]
2113 | ldrh RC, TRACE:RA->link
2115 | beq ->cont_nop // Blacklisted.
2117 | bne =>BC_JLOOP // Jump to stitched trace.
2119 | // Stitch a new trace to the previous trace.
2120 | str CARG3, [DISPATCH, #DISPATCH_J(exitno)]
2121 | str L, [DISPATCH, #DISPATCH_J(L)]
2123 | sub CARG1, DISPATCH, #-GG_DISP2J
2125 | bl extern lj_dispatch_stitch // (jit_State *J, const BCIns *pc)
2129 |9: // Fill up results with nil.
2130 | strd CARG12, [BASE, RC]
2135 |->vm_profhook: // Dispatch target for profiler hook.
2140 | bl extern lj_dispatch_profile // (lua_State *L, const BCIns *pc)
2141 | // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.
2147 |//-----------------------------------------------------------------------
2148 |//-- Trace exit handler -------------------------------------------------
2149 |//-----------------------------------------------------------------------
2154 | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}
2155 | ldr CARG1, [sp, #64] // Load original value of lr.
2156 | ldr DISPATCH, [lr] // Load DISPATCH.
2157 | add CARG3, sp, #64 // Recompute original value of sp.
2158 | mv_vmstate CARG4, EXIT
2159 | str CARG3, [sp, #52] // Store sp in RID_SP
2161 | ldr CARG2, [CARG1, #-4]! // Get exit instruction.
2162 | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC.
2163 | str CARG1, [sp, #60]
2167 | lsl CARG2, CARG2, #8
2168 | add CARG1, CARG1, CARG2, asr #6
2169 | ldr CARG2, [lr, #4] // Load exit stub group offset.
2170 | sub CARG1, CARG1, lr
2171 | ldr L, [DISPATCH, #DISPATCH_GL(cur_L)]
2172 | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number.
2173 | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
2174 | str CARG1, [DISPATCH, #DISPATCH_J(exitno)]
2177 | str L, [DISPATCH, #DISPATCH_J(L)]
2178 | str CARG4, [DISPATCH, #DISPATCH_GL(jit_base)]
2179 | sub CARG1, DISPATCH, #-GG_DISP2J
2181 | bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
2182 | // Returns MULTRES (unscaled) or negated error code.
2183 | ldr CARG2, L->cframe
2185 | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
2187 | ldr PC, SAVE_PC // Get SAVE_PC.
2188 | str L, SAVE_L // Set SAVE_L (on-trace resume/yield).
2192 | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.
2197 | blt >9 // Check for error from exit.
2199 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
2200 | str RC, SAVE_MULTRES
2203 | ldr CARG2, LFUNC:CARG2->field_pc
2204 | str CARG3, [DISPATCH, #DISPATCH_GL(jit_base)]
2205 | mv_vmstate CARG4, INTERP
2206 | ldr KBASE, [CARG2, #PC2PROTO(k)]
2207 | // Modified copy of ins_next which handles function header dispatch, too.
2211 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2213 | cmp OP, #BC_FUNCC+2 // Fast function?
2216 | cmp OP, #BC_FUNCF // Function header?
2217 | ldr OP, [DISPATCH, OP, lsl #2]
2218 | decode_RA8 RA, INS
2219 | lsrlo RC, INS, #16 // No: Decode operands A*8 and D.
2221 | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8
2222 | ldrhs CARG3, [BASE, FRAME_FUNC]
2225 |4: // Check frame below fast function.
2226 | ldr CARG1, [BASE, FRAME_PC]
2227 | ands CARG2, CARG1, #FRAME_TYPE
2228 | bne <2 // Trace stitching continuation?
2229 | // Otherwise set KBASE for Lua function below fast function.
2230 | ldr CARG3, [CARG1, #-4]
2231 | decode_RA8 CARG1, CARG3
2232 | sub CARG2, BASE, CARG1
2233 | ldr LFUNC:CARG3, [CARG2, #-16]
2234 | ldr CARG3, LFUNC:CARG3->field_pc
2235 | ldr KBASE, [CARG3, #PC2PROTO(k)]
2238 |9: // Rethrow error from the right C frame.
2239 | rsb CARG2, CARG1, #0
2241 | bl extern lj_err_throw // (lua_State *L, int errcode)
2244 |//-----------------------------------------------------------------------
2245 |//-- Math helper functions ----------------------------------------------
2246 |//-----------------------------------------------------------------------
2248 |// FP value rounding. Called from JIT code.
2250 |// double lj_vm_floor/ceil/trunc(double x);
2251 |.macro vm_round, func, hf
2253 | vmov CARG1, CARG2, d0
2255 | lsl CARG3, CARG2, #1
2256 | adds RB, CARG3, #0x00200000
2257 | bpl >2 // |x| < 1?
2259 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2260 | bxlo lr // |x| >= 2^52: done.
2262 | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask
2263 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2265 | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask
2266 | orrpl CARG3, CARG3, CARG4
2268 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2269 |.if "func" == "floor"
2270 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2272 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2275 | vmoveq d0, CARG1, CARG2
2277 | bxeq lr // iszero: done.
2280 | lslpl CARG3, CARG4, RB
2283 | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask
2284 | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry
2286 | vmov d0, CARG1, CARG2
2291 | bxcs lr // |x| is not finite.
2292 | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo
2293 |.if "func" == "floor"
2294 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2296 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2298 | mov CARG1, #0 // lo = 0
2299 | and CARG2, CARG2, #0x80000000
2300 | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0)
2301 | orrne CARG2, CARG2, CARG4
2303 | vmov d0, CARG1, CARG2
2309 | .long 0x3ff00000 // hiword(+1.0)
2325 |.macro vm_trunc, hf
2328 | vmov CARG1, CARG2, d0
2330 | lsl CARG3, CARG2, #1
2331 | adds RB, CARG3, #0x00200000
2332 | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0.
2335 | vmovpl d0, CARG1, CARG2
2339 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2340 | bxlo lr // |x| >= 2^52: already done.
2342 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2344 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2346 | vmov d0, CARG1, CARG2
2359 | // double lj_vm_mod(double dividend, double divisor);
2362 | // Special calling convention. Also, RC (r11) is not preserved.
2363 | vdiv.f64 d0, d6, d7
2365 | vmov CARG1, CARG2, d0
2367 | vmov d0, CARG1, CARG2
2368 | vmul.f64 d0, d0, d7
2370 | vsub.f64 d6, d6, d0
2373 | push {r0, r1, r2, r3, r4, lr}
2374 | bl extern __aeabi_ddiv
2376 | ldrd CARG34, [sp, #8]
2377 | bl extern __aeabi_dmul
2379 | eor CARG2, CARG2, #0x80000000
2380 | bl extern __aeabi_dadd
2385 | // int lj_vm_modi(int dividend, int divisor);
2387 | ands RB, CARG1, #0x80000000
2388 | rsbmi CARG1, CARG1, #0 // a = |dividend|
2389 | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor).
2391 | rsbmi CARG2, CARG2, #0 // b = |divisor|
2392 | subs CARG4, CARG2, #1
2393 | cmpne CARG1, CARG2
2394 | moveq CARG1, #0 // if (b == 1 || a == b) a = 0
2395 | tsthi CARG2, CARG4
2396 | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1
2398 | // Use repeated subtraction to get the remainder.
2401 | sub CARG4, CARG4, CARG3
2402 | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8
2403 | addne pc, pc, CARG3, lsl #3 // Duff's device.
2407 for (i = 31; i >= 0; i--) {
2408 | cmp CARG1, CARG2, lsl #i
2409 | subhs CARG1, CARG1, CARG2, lsl #i
2415 | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b
2416 | eors CARG2, CARG1, RB, lsl #1
2417 | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y
2420 |//-----------------------------------------------------------------------
2421 |//-- Miscellaneous functions --------------------------------------------
2422 |//-----------------------------------------------------------------------
2424 |//-----------------------------------------------------------------------
2425 |//-- FFI helper functions -----------------------------------------------
2426 |//-----------------------------------------------------------------------
2428 |// Handler for callback functions.
2429 |// Saveregs already performed. Callback slot number in [sp], g in r12.
2432 |.type CTSTATE, CTState, PC
2433 | ldr CTSTATE, GL:r12->ctype_state
2434 | add DISPATCH, r12, #GG_G2DISP
2437 | add r4, sp, CFRAME_SPACE+4+8*8
2438 | vstmdb r4!, {d8-d15}
2441 | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])
2443 | strd CARG34, CTSTATE->cb.gpr[2]
2444 | strd CARG12, CTSTATE->cb.gpr[0]
2446 | vstmdb r12!, {d0-d7}
2449 | add CARG3, sp, #CFRAME_SIZE
2450 | mov CARG1, CTSTATE
2451 | lsr CARG4, CARG4, #3
2452 | str CARG3, CTSTATE->cb.stack
2454 | str CARG4, CTSTATE->cb.slot
2455 | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
2456 | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
2457 | // Returns lua_State *.
2458 | ldr BASE, L:CRET1->base
2459 | mv_vmstate CARG2, INTERP
2460 | ldr RC, L:CRET1->top
2462 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2465 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2470 |->cont_ffi_callback: // Return from FFI callback.
2472 | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]
2476 | mov CARG1, CTSTATE
2478 | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
2479 | ldrd CARG12, CTSTATE->cb.gpr[0]
2481 | vldr d0, CTSTATE->cb.fpr[0]
2486 |->vm_ffi_call: // Call C function via FFI.
2487 | // Caveat: needs special frame unwinding, see below.
2489 | .type CCSTATE, CCallState, r4
2490 | push {CCSTATE, r5, r11, lr}
2491 | mov CCSTATE, CARG1
2492 | ldr CARG1, CCSTATE:CARG1->spadj
2493 | ldrb CARG2, CCSTATE->nsp
2494 | add CARG3, CCSTATE, #offsetof(CCallState, stack)
2496 | add RB, CCSTATE, #offsetof(CCallState, fpr[0])
2499 | sub sp, sp, CARG1 // Readjust stack.
2500 | subs CARG2, CARG2, #1
2504 | ldr RB, CCSTATE->func
2506 |1: // Copy stack slots.
2507 | ldr CARG4, [CARG3, CARG2, lsl #2]
2508 | str CARG4, [sp, CARG2, lsl #2]
2509 | subs CARG2, CARG2, #1
2512 | ldrd CARG12, CCSTATE->gpr[0]
2513 | ldrd CARG34, CCSTATE->gpr[2]
2517 | add r12, CCSTATE, #offsetof(CCallState, fpr[4])
2519 | strd CRET1, CCSTATE->gpr[0]
2521 | vstmdb r12!, {d0-d3}
2523 | pop {CCSTATE, r5, r11, pc}
2525 |// Note: vm_ffi_call must be the last function in this object file!
2527 |//-----------------------------------------------------------------------
2530 /* Generate the code for a single instruction. */
2531 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2538 /* -- Comparison ops ---------------------------------------------------- */
2540 /* Remember: all ops branch for a true comparison, fall through otherwise. */
2542 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
2543 | // RA = src1*8, RC = src2, JMP with RC = target
2545 | ldrd CARG12, [RA, BASE]!
2547 | ldrd CARG34, [RC, BASE]!
2549 | add RB, PC, RB, lsl #2
2550 | checktp CARG2, LJ_TISNUM
2552 | checktp CARG4, LJ_TISNUM
2555 if (op == BC_ISLT) {
2556 | sublt PC, RB, #0x20000
2557 } else if (op == BC_ISGE) {
2558 | subge PC, RB, #0x20000
2559 } else if (op == BC_ISLE) {
2560 | suble PC, RB, #0x20000
2562 | subgt PC, RB, #0x20000
2567 |3: // CARG12 is not an integer.
2571 | // d0 is a number.
2572 | checktp CARG4, LJ_TISNUM
2576 | // d0 is a number, CARG3 is an integer.
2578 | vcvt.f64.s32 d1, s4
2580 |4: // CARG1 is an integer, CARG34 is not an integer.
2583 | // CARG1 is an integer, d1 is a number.
2585 | vcvt.f64.s32 d0, s4
2586 |5: // d0 and d1 are numbers.
2589 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2590 if (op == BC_ISLT) {
2591 | sublo PC, RB, #0x20000
2592 } else if (op == BC_ISGE) {
2593 | subhs PC, RB, #0x20000
2594 } else if (op == BC_ISLE) {
2595 | subls PC, RB, #0x20000
2597 | subhi PC, RB, #0x20000
2602 | // CARG12 is a number.
2603 | checktp CARG4, LJ_TISNUM
2604 | movlo RA, RB // Save RB.
2607 | // CARG12 is a number, CARG3 is an integer.
2610 | mov RA, RB // Save RB.
2611 | bl extern __aeabi_i2d
2614 | ldrd CARG12, [RC] // Restore first operand.
2616 |4: // CARG1 is an integer, CARG34 is not an integer.
2618 | // CARG1 is an integer, CARG34 is a number.
2619 | mov RA, RB // Save RB.
2620 | bl extern __aeabi_i2d
2621 | ldrd CARG34, [RC] // Restore second operand.
2622 |5: // CARG12 and CARG34 are numbers.
2623 | bl extern __aeabi_cdcmple
2624 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2625 if (op == BC_ISLT) {
2626 | sublo PC, RA, #0x20000
2627 } else if (op == BC_ISGE) {
2628 | subhs PC, RA, #0x20000
2629 } else if (op == BC_ISLE) {
2630 | subls PC, RA, #0x20000
2632 | subhi PC, RA, #0x20000
2638 case BC_ISEQV: case BC_ISNEV:
2639 vk = op == BC_ISEQV;
2640 | // RA = src1*8, RC = src2, JMP with RC = target
2642 | ldrd CARG12, [RA, BASE]!
2644 | ldrd CARG34, [RC, BASE]!
2646 | add RB, PC, RB, lsl #2
2647 | checktp CARG2, LJ_TISNUM
2648 | cmnls CARG4, #-LJ_TISNUM
2654 | // Either or both types are not numbers.
2656 | checktp CARG2, LJ_TCDATA
2657 | checktpne CARG4, LJ_TCDATA
2658 | beq ->vmeta_equal_cd
2660 | cmp CARG2, CARG4 // Compare types.
2661 | bne >2 // Not the same type?
2662 | checktp CARG2, LJ_TISPRI
2663 | bhs >1 // Same type and primitive type?
2665 | // Same types and not a primitive type. Compare GCobj or pvalue.
2668 | bne >3 // Different GCobjs or pvalues?
2669 |1: // Branch if same.
2670 | sub PC, RB, #0x20000
2674 | checktp CARG2, LJ_TISTABUD
2675 | bhi <2 // Different objects and not table/ud?
2677 | beq >1 // Same GCobjs or pvalues?
2678 | checktp CARG2, LJ_TISTABUD
2679 | bhi >2 // Different objects and not table/ud?
2681 | // Different tables or userdatas. Need to check __eq metamethod.
2682 | // Field metatable must be at same offset for GCtab and GCudata!
2683 | ldr TAB:RA, TAB:CARG1->metatable
2686 | beq <2 // No metatable?
2688 | beq >2 // No metatable?
2690 | ldrb RA, TAB:RA->nomm
2691 | mov CARG4, #1-vk // ne = 0 or 1.
2694 | beq ->vmeta_equal // 'no __eq' flag not set?
2698 |2: // Branch if different.
2699 | sub PC, RB, #0x20000
2705 case BC_ISEQS: case BC_ISNES:
2706 vk = op == BC_ISEQS;
2707 | // RA = src*8, RC = str_const (~), JMP with RC = target
2709 | ldrd CARG12, [BASE, RA]
2711 | ldr STR:CARG3, [KBASE, RC, lsl #2]
2713 | add RB, PC, RB, lsl #2
2714 | checktp CARG2, LJ_TSTR
2719 | cmpeq CARG1, CARG3
2722 | subeq PC, RB, #0x20000
2726 | subne PC, RB, #0x20000
2732 | checktp CARG2, LJ_TCDATA
2734 | b ->vmeta_equal_cd
2738 case BC_ISEQN: case BC_ISNEN:
2739 vk = op == BC_ISEQN;
2740 | // RA = src*8, RC = num_const (~), JMP with RC = target
2742 | ldrd CARG12, [RA, BASE]!
2744 | ldrd CARG34, [RC, KBASE]!
2746 | add RB, PC, RB, lsl #2
2752 | checktp CARG2, LJ_TISNUM
2754 | checktp CARG4, LJ_TISNUM
2758 | subeq PC, RB, #0x20000
2762 | subne PC, RB, #0x20000
2767 |3: // CARG12 is not an integer.
2772 | subhi PC, RB, #0x20000
2777 | checktp CARG4, LJ_TISNUM
2781 | vcvths.f64.s32 d1, s4
2783 |4: // CARG1 is an integer, d1 is a number.
2786 | vcvt.f64.s32 d0, s4
2787 |5: // d0 and d1 are numbers.
2791 | subeq PC, RB, #0x20000
2793 | subne PC, RB, #0x20000
2797 | // CARG12 is a number.
2798 | checktp CARG4, LJ_TISNUM
2799 | movlo RA, RB // Save RB.
2801 | // CARG12 is a number, CARG3 is an integer.
2804 |4: // CARG1 is an integer, CARG34 is a number.
2805 | mov RA, RB // Save RB.
2806 | bl extern __aeabi_i2d
2807 | ldrd CARG34, [RC] // Restore other operand.
2808 |5: // CARG12 and CARG34 are numbers.
2809 | bl extern __aeabi_cdcmpeq
2811 | subeq PC, RA, #0x20000
2813 | subne PC, RA, #0x20000
2820 | checktp CARG2, LJ_TCDATA
2822 | b ->vmeta_equal_cd
2826 case BC_ISEQP: case BC_ISNEP:
2827 vk = op == BC_ISEQP;
2828 | // RA = src*8, RC = primitive_type (~), JMP with RC = target
2829 | ldrd CARG12, [BASE, RA]
2833 | add RB, PC, RB, lsl #2
2835 | checktp CARG2, LJ_TCDATA
2836 | beq ->vmeta_equal_cd
2840 | subeq PC, RB, #0x20000
2842 | subne PC, RB, #0x20000
2847 /* -- Unary test and copy ops ------------------------------------------- */
2849 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
2850 | // RA = dst*8 or unused, RC = src, JMP with RC = target
2851 | add RC, BASE, RC, lsl #3
2855 | add RB, PC, RB, lsl #2
2856 | checktp CARG2, LJ_TTRUE
2857 if (op == BC_ISTC || op == BC_IST) {
2858 | subls PC, RB, #0x20000
2859 if (op == BC_ISTC) {
2860 | strdls CARG12, [BASE, RA]
2863 | subhi PC, RB, #0x20000
2864 if (op == BC_ISFC) {
2865 | strdhi CARG12, [BASE, RA]
2872 | // RA = src*8, RC = -type
2873 | ldrd CARG12, [BASE, RA]
2877 | bne ->vmeta_istype
2881 | // RA = src*8, RC = -(TISNUM-1)
2882 | ldrd CARG12, [BASE, RA]
2884 | checktp CARG2, LJ_TISNUM
2886 | bhs ->vmeta_istype
2890 /* -- Unary ops --------------------------------------------------------- */
2893 | // RA = dst*8, RC = src
2896 | ldrd CARG12, [BASE, RC]
2898 | strd CARG12, [BASE, RA]
2902 | // RA = dst*8, RC = src
2903 | add RC, BASE, RC, lsl #3
2905 | ldr CARG1, [RC, #4]
2908 | checktp CARG1, LJ_TTRUE
2909 | mvnls CARG2, #~LJ_TFALSE
2910 | mvnhi CARG2, #~LJ_TTRUE
2911 | str CARG2, [RA, #4]
2915 | // RA = dst*8, RC = src
2917 | ldrd CARG12, [BASE, RC]
2920 | checktp CARG2, LJ_TISNUM
2922 | eorne CARG2, CARG2, #0x80000000
2924 | rsbseq CARG1, CARG1, #0
2927 | strd CARG12, [BASE, RA]
2932 | .long 0x00000000, 0x41e00000 // 2^31.
2935 | // RA = dst*8, RC = src
2937 | ldrd CARG12, [BASE, RC]
2938 | checkstr CARG2, >2
2939 | ldr CARG1, STR:CARG1->len
2941 | mvn CARG2, #~LJ_TISNUM
2944 | strd CARG12, [BASE, RA]
2947 | checktab CARG2, ->vmeta_len
2949 | ldr TAB:CARG3, TAB:CARG1->metatable
2956 | bl extern lj_tab_len // (GCtab *t)
2957 | // Returns uint32_t (but less than 2^31).
2962 | ldrb CARG4, TAB:CARG3->nomm
2963 | tst CARG4, #1<<MM_len
2964 | bne <3 // 'no __len' flag set: done.
2969 /* -- Binary ops -------------------------------------------------------- */
2971 |.macro ins_arithcheck, cond, ncond, target
2973 | cmn CARG4, #-LJ_TISNUM
2974 | cmn..cond CARG2, #-LJ_TISNUM
2976 | cmn CARG2, #-LJ_TISNUM
2977 | cmn..cond CARG4, #-LJ_TISNUM
2981 |.macro ins_arithcheck_int, target
2982 | ins_arithcheck eq, ne, target
2984 |.macro ins_arithcheck_num, target
2985 | ins_arithcheck lo, hs, target
2988 |.macro ins_arithpre
2989 | decode_RB8 RB, INS
2990 | decode_RC8 RC, INS
2991 | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
2992 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
2996 | ldrd CARG12, [RB, BASE]!
2997 | ldrd CARG34, [RC, KBASE]!
2999 | ldrd CARG12, [BASE, RB]
3000 | ldrd CARG34, [KBASE, RC]
3005 | ldrd CARG34, [RB, BASE]!
3006 | ldrd CARG12, [RC, KBASE]!
3008 | ldrd CARG34, [BASE, RB]
3009 | ldrd CARG12, [KBASE, RC]
3014 | ldrd CARG12, [RB, BASE]!
3015 | ldrd CARG34, [RC, BASE]!
3017 | ldrd CARG12, [BASE, RB]
3018 | ldrd CARG34, [BASE, RC]
3024 |.macro ins_arithpre_fpu, reg1, reg2
3036 |.macro ins_arithpost_fpu, reg
3044 |.macro ins_arithfallback, ins
3047 | ins ->vmeta_arith_vn
3050 | ins ->vmeta_arith_nv
3053 | ins ->vmeta_arith_vv
3058 |.macro ins_arithdn, intins, fpins, fpcall
3060 |.if "intins" ~= "vm_modi" and not FPU
3063 | ins_arithcheck_int >5
3064 |.if "intins" == "smull"
3065 | smull CARG1, RC, CARG3, CARG1
3066 | cmp RC, CARG1, asr #31
3067 | ins_arithfallback bne
3068 |.elif "intins" == "vm_modi"
3070 | ins_arithfallback beq
3072 | mvn CARG2, #~LJ_TISNUM
3074 | intins CARG1, CARG1, CARG3
3075 | ins_arithfallback bvs
3078 |.if "intins" == "vm_modi" or FPU
3082 | strd CARG12, [BASE, RA]
3085 | ins_arithpre_fpu d6, d7
3086 | ins_arithfallback ins_arithcheck_num
3088 |.if "intins" == "vm_modi"
3093 | ins_arithpost_fpu d6
3096 |.if "intins" ~= "vm_modi"
3103 |.macro ins_arithfp, fpins, fpcall
3105 |.if "fpins" ~= "extern" or HFABI
3106 | ins_arithpre_fpu d0, d1
3108 | ins_arithfallback ins_arithcheck_num
3109 |.if "fpins" == "extern"
3118 |.if ("fpins" ~= "extern" or HFABI) and FPU
3119 | ins_arithpost_fpu d0
3123 | strd CARG12, [BASE, RA]
3128 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
3129 | ins_arithdn adds, vadd.f64, extern __aeabi_dadd
3131 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
3132 | ins_arithdn subs, vsub.f64, extern __aeabi_dsub
3134 case BC_MULVN: case BC_MULNV: case BC_MULVV:
3135 | ins_arithdn smull, vmul.f64, extern __aeabi_dmul
3137 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
3138 | ins_arithfp vdiv.f64, extern __aeabi_ddiv
3140 case BC_MODVN: case BC_MODNV: case BC_MODVV:
3141 | ins_arithdn vm_modi, vm_mod, ->vm_mod
3144 | // NYI: (partial) integer arithmetic.
3145 | ins_arithfp extern, extern pow
3149 | decode_RB8 RC, INS
3150 | decode_RC8 RB, INS
3151 | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!)
3154 | add CARG2, BASE, RB
3156 | // RA = dst*8, RC = src_start*8, CARG2 = top-1
3159 | lsr CARG3, CARG3, #3
3160 | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
3161 | // Returns NULL (finished) or TValue * (metamethod).
3165 | ldrd CARG34, [BASE, RC]
3168 | strd CARG34, [BASE, RA] // Copy result to RA.
3172 /* -- Constant ops ------------------------------------------------------ */
3175 | // RA = dst*8, RC = str_const (~)
3178 | ldr CARG1, [KBASE, RC, lsl #2]
3179 | mvn CARG2, #~LJ_TSTR
3181 | strd CARG12, [BASE, RA]
3186 | // RA = dst*8, RC = cdata_const (~)
3189 | ldr CARG1, [KBASE, RC, lsl #2]
3190 | mvn CARG2, #~LJ_TCDATA
3192 | strd CARG12, [BASE, RA]
3197 | // RA = dst*8, (RC = int16_literal)
3198 | mov CARG1, INS, asr #16 // Refetch sign-extended reg.
3199 | mvn CARG2, #~LJ_TISNUM
3202 | strd CARG12, [BASE, RA]
3206 | // RA = dst*8, RC = num_const
3209 | ldrd CARG12, [KBASE, RC]
3211 | strd CARG12, [BASE, RA]
3215 | // RA = dst*8, RC = primitive_type (~)
3224 | // RA = base*8, RC = end
3226 | add RC, BASE, RC, lsl #3
3227 | mvn CARG1, #~LJ_TNIL
3228 | str CARG1, [RA, #4]
3231 | str CARG1, [RA, #4]
3238 /* -- Upvalue and function ops ------------------------------------------ */
3241 | // RA = dst*8, RC = uvnum
3242 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3244 | add RC, RC, #offsetof(GCfuncL, uvptr)
3245 | ldr UPVAL:CARG2, [LFUNC:CARG2, RC]
3246 | ldr CARG2, UPVAL:CARG2->v
3247 | ldrd CARG34, [CARG2]
3250 | strd CARG34, [BASE, RA]
3254 | // RA = uvnum*8, RC = src
3255 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3257 | add RA, RA, #offsetof(GCfuncL, uvptr)
3259 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3260 | ldrd CARG34, [BASE, RC]
3261 | ldrb RB, UPVAL:CARG2->marked
3262 | ldrb RC, UPVAL:CARG2->closed
3263 | ldr CARG2, UPVAL:CARG2->v
3264 | tst RB, #LJ_GC_BLACK // isblack(uv)
3265 | add RB, CARG4, #-LJ_TISGCV
3267 | strd CARG34, [CARG2]
3268 | bne >2 // Upvalue is closed and black?
3272 |2: // Check if new value is collectable.
3273 | cmn RB, #-(LJ_TNUMX - LJ_TISGCV)
3274 | ldrbhi RC, GCOBJ:CARG3->gch.marked
3275 | bls <1 // tvisgcv(v)
3276 | sub CARG1, DISPATCH, #-GG_DISP2G
3277 | tst RC, #LJ_GC_WHITES
3278 | // Crossed a write barrier. Move the barrier forward.
3282 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3285 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3290 | // RA = uvnum*8, RC = str_const (~)
3291 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3293 | add RA, RA, #offsetof(GCfuncL, uvptr)
3295 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3296 | ldr STR:CARG3, [KBASE, RC, lsl #2]
3297 | ldrb RB, UPVAL:CARG2->marked
3298 | ldrb RC, UPVAL:CARG2->closed
3299 | ldr CARG2, UPVAL:CARG2->v
3300 | mvn CARG4, #~LJ_TSTR
3301 | tst RB, #LJ_GC_BLACK // isblack(uv)
3302 | ldrb RB, STR:CARG3->marked
3303 | strd CARG34, [CARG2]
3308 |2: // Check if string is white and ensure upvalue is closed.
3309 | tst RB, #LJ_GC_WHITES // iswhite(str)
3311 | sub CARG1, DISPATCH, #-GG_DISP2G
3312 | // Crossed a write barrier. Move the barrier forward.
3316 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3319 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3324 | // RA = uvnum*8, RC = num_const
3325 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3327 | add RA, RA, #offsetof(GCfuncL, uvptr)
3329 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3330 | ldrd CARG34, [KBASE, RC]
3331 | ldr CARG2, UPVAL:CARG2->v
3334 | strd CARG34, [CARG2]
3338 | // RA = uvnum*8, RC = primitive_type (~)
3339 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3341 | add RA, RA, #offsetof(GCfuncL, uvptr)
3342 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3344 | ldr CARG2, UPVAL:CARG2->v
3347 | str RC, [CARG2, #4]
3352 | // RA = level*8, RC = target
3353 | ldr CARG3, L->openupval
3354 | add RC, PC, RC, lsl #2
3357 | sub PC, RC, #0x20000
3360 | add CARG2, BASE, RA
3361 | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
3368 | // RA = dst*8, RC = proto_const (~) (holding function prototype)
3371 | ldr CARG2, [KBASE, RC, lsl #2]
3373 | ldr CARG3, [BASE, FRAME_FUNC]
3375 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
3376 | bl extern lj_func_newL_gc
3377 | // Returns GCfuncL *.
3379 | mvn CARG2, #~LJ_TFUNC
3382 | strd CARG12, [BASE, RA]
3386 /* -- Table ops --------------------------------------------------------- */
3390 | // RA = dst*8, RC = (hbits|asize) | tab_const (~)
3391 if (op == BC_TDUP) {
3394 | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]
3395 | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]
3402 if (op == BC_TNEW) {
3403 | lsl CARG2, RC, #21
3404 | lsr CARG3, RC, #11
3405 | asr RC, CARG2, #21
3406 | lsr CARG2, CARG2, #21
3408 | addeq CARG2, CARG2, #2
3409 | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
3410 | // Returns GCtab *.
3412 | ldr CARG2, [KBASE, RC, lsl #2]
3413 | bl extern lj_tab_dup // (lua_State *L, Table *kt)
3414 | // Returns GCtab *.
3417 | mvn CARG2, #~LJ_TTAB
3420 | strd CARG12, [BASE, RA]
3423 | bl extern lj_gc_step_fixtop // (lua_State *L)
3429 | // RA = dst*8, RC = str_const (~)
3431 | // RA = dst*8, RC = str_const (~)
3432 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3434 | ldr TAB:CARG1, LFUNC:CARG2->env
3435 | ldr STR:RC, [KBASE, RC, lsl #2]
3436 if (op == BC_GGET) {
3444 | decode_RB8 RB, INS
3445 | decode_RC8 RC, INS
3446 | // RA = dst*8, RB = table*8, RC = key*8
3447 | ldrd TAB:CARG12, [BASE, RB]
3448 | ldrd CARG34, [BASE, RC]
3449 | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12.
3450 | checktp CARG4, LJ_TISNUM // Integer key?
3451 | ldreq CARG4, TAB:CARG1->array
3452 | ldreq CARG2, TAB:CARG1->asize
3455 | add CARG4, CARG4, CARG3, lsl #3
3456 | cmp CARG3, CARG2 // In array part?
3457 | ldrdlo CARG34, [CARG4]
3459 | ins_next1 // Overwrites RB!
3460 | checktp CARG4, LJ_TNIL
3464 | strd CARG34, [BASE, RA]
3467 |5: // Check for __index if table value is nil.
3468 | ldr TAB:CARG2, TAB:CARG1->metatable
3470 | beq <1 // No metatable: done.
3471 | ldrb CARG2, TAB:CARG2->nomm
3472 | tst CARG2, #1<<MM_index
3473 | bne <1 // 'no __index' flag set: done.
3474 | decode_RB8 RB, INS // Restore RB.
3478 | checktp CARG4, LJ_TSTR // String key?
3479 | moveq STR:RC, CARG3
3484 | decode_RB8 RB, INS
3486 | // RA = dst*8, RB = table*8, RC = str_const (~)
3487 | ldrd CARG12, [BASE, RB]
3489 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3490 | checktab CARG2, ->vmeta_tgets1
3492 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3493 | ldr CARG3, TAB:CARG1->hmask
3494 | ldr CARG4, STR:RC->hash
3495 | ldr NODE:INS, TAB:CARG1->node
3496 | mov TAB:RB, TAB:CARG1
3497 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3498 | add CARG3, CARG3, CARG3, lsl #1
3499 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3501 | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS.
3502 | ldrd CARG34, NODE:INS->val
3503 | ldr NODE:INS, NODE:INS->next
3504 | checktp CARG2, LJ_TSTR
3505 | cmpeq CARG1, STR:RC
3507 | checktp CARG4, LJ_TNIL
3512 | strd CARG34, [BASE, RA]
3515 |4: // Follow hash chain.
3518 | // End of hash chain: key not found, nil result.
3520 |5: // Check for __index if table value is nil.
3521 | ldr TAB:CARG1, TAB:RB->metatable
3522 | mov CARG3, #0 // Optional clear of undef. value (during load stall).
3523 | mvn CARG4, #~LJ_TNIL
3525 | beq <3 // No metatable: done.
3526 | ldrb CARG2, TAB:CARG1->nomm
3527 | tst CARG2, #1<<MM_index
3528 | bne <3 // 'no __index' flag set: done.
3532 | decode_RB8 RB, INS
3534 | // RA = dst*8, RB = table*8, RC = index
3535 | ldrd CARG12, [BASE, RB]
3536 | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12.
3537 | ldr CARG3, TAB:CARG1->asize
3538 | ldr CARG4, TAB:CARG1->array
3541 | ldrdlo CARG34, [CARG4, CARG2]
3543 | ins_next1 // Overwrites RB!
3544 | checktp CARG4, LJ_TNIL
3548 | strd CARG34, [BASE, RA]
3551 |5: // Check for __index if table value is nil.
3552 | ldr TAB:CARG2, TAB:CARG1->metatable
3554 | beq <1 // No metatable: done.
3555 | ldrb CARG2, TAB:CARG2->nomm
3556 | tst CARG2, #1<<MM_index
3557 | bne <1 // 'no __index' flag set: done.
3561 | decode_RB8 RB, INS
3562 | decode_RC8 RC, INS
3563 | // RA = dst*8, RB = table*8, RC = key*8
3564 | ldr TAB:CARG1, [BASE, RB]
3565 | ldr CARG2, [BASE, RC]
3566 | ldr CARG4, TAB:CARG1->array
3567 | ldr CARG3, TAB:CARG1->asize
3568 | add CARG4, CARG4, CARG2, lsl #3
3569 | cmp CARG2, CARG3 // In array part?
3571 | ldrd CARG12, [CARG4]
3575 | strd CARG12, [BASE, RA]
3580 | decode_RB8 RB, INS
3581 | decode_RC8 RC, INS
3582 | // RA = src*8, RB = table*8, RC = key*8
3583 | ldrd TAB:CARG12, [BASE, RB]
3584 | ldrd CARG34, [BASE, RC]
3585 | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12.
3586 | checktp CARG4, LJ_TISNUM // Integer key?
3587 | ldreq CARG2, TAB:CARG1->array
3588 | ldreq CARG4, TAB:CARG1->asize
3591 | add CARG2, CARG2, CARG3, lsl #3
3592 | cmp CARG3, CARG4 // In array part?
3593 | ldrlo INS, [CARG2, #4]
3595 | ins_next1 // Overwrites RB!
3596 | checktp INS, LJ_TNIL
3597 | ldrb INS, TAB:CARG1->marked
3598 | ldrd CARG34, [BASE, RA]
3601 | tst INS, #LJ_GC_BLACK // isblack(table)
3602 | strd CARG34, [CARG2]
3608 |5: // Check for __newindex if previous value is nil.
3609 | ldr TAB:RA, TAB:CARG1->metatable
3611 | beq <1 // No metatable: done.
3612 | ldrb RA, TAB:RA->nomm
3613 | tst RA, #1<<MM_newindex
3614 | bne <1 // 'no __newindex' flag set: done.
3615 | ldr INS, [PC, #-4] // Restore RA and RB.
3616 | decode_RB8 RB, INS
3617 | decode_RA8 RA, INS
3620 |7: // Possible table write barrier for the value. Skip valiswhite check.
3621 | barrierback TAB:CARG1, INS, CARG3
3625 | checktp CARG4, LJ_TSTR // String key?
3626 | moveq STR:RC, CARG3
3631 | decode_RB8 RB, INS
3633 | // RA = src*8, RB = table*8, RC = str_const (~)
3634 | ldrd CARG12, [BASE, RB]
3636 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3637 | checktab CARG2, ->vmeta_tsets1
3639 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3640 | ldr CARG3, TAB:CARG1->hmask
3641 | ldr CARG4, STR:RC->hash
3642 | ldr NODE:INS, TAB:CARG1->node
3643 | mov TAB:RB, TAB:CARG1
3644 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3645 | add CARG3, CARG3, CARG3, lsl #1
3647 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3648 | strb CARG4, TAB:RB->nomm // Clear metamethod cache.
3650 | ldrd CARG12, NODE:INS->key
3651 | ldr CARG4, NODE:INS->val.it
3652 | ldr NODE:CARG3, NODE:INS->next
3653 | checktp CARG2, LJ_TSTR
3654 | cmpeq CARG1, STR:RC
3656 | ldrb CARG2, TAB:RB->marked
3657 | checktp CARG4, LJ_TNIL // Key found, but nil value?
3658 | ldrd CARG34, [BASE, RA]
3661 | tst CARG2, #LJ_GC_BLACK // isblack(table)
3662 | strd CARG34, NODE:INS->val
3667 |4: // Check for __newindex if previous value is nil.
3668 | ldr TAB:CARG1, TAB:RB->metatable
3670 | beq <2 // No metatable: done.
3671 | ldrb CARG1, TAB:CARG1->nomm
3672 | tst CARG1, #1<<MM_newindex
3673 | bne <2 // 'no __newindex' flag set: done.
3676 |5: // Follow hash chain.
3677 | movs NODE:INS, NODE:CARG3
3679 | // End of hash chain: key not found, add a new one.
3681 | // But check for __newindex first.
3682 | ldr TAB:CARG1, TAB:RB->metatable
3685 | cmp TAB:CARG1, #0 // No metatable: continue.
3687 | ldrbne CARG2, TAB:CARG1->nomm
3690 | tst CARG2, #1<<MM_newindex
3691 | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
3693 | mvn CARG4, #~LJ_TSTR
3694 | str STR:RC, TMPDlo
3697 | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
3698 | // Returns TValue *.
3700 | ldrd CARG34, [BASE, RA]
3701 | strd CARG34, [CRET1]
3702 | b <3 // No 2nd write barrier needed.
3704 |7: // Possible table write barrier for the value. Skip valiswhite check.
3705 | barrierback TAB:RB, CARG2, CARG3
3709 | decode_RB8 RB, INS
3711 | // RA = src*8, RB = table*8, RC = index
3712 | ldrd CARG12, [BASE, RB]
3713 | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12.
3714 | ldr CARG3, TAB:CARG1->asize
3715 | ldr RB, TAB:CARG1->array
3718 | ldrdlo CARG34, [CARG2, RB]!
3720 | ins_next1 // Overwrites RB!
3721 | checktp CARG4, LJ_TNIL
3722 | ldrb INS, TAB:CARG1->marked
3723 | ldrd CARG34, [BASE, RA]
3726 | tst INS, #LJ_GC_BLACK // isblack(table)
3727 | strd CARG34, [CARG2]
3733 |5: // Check for __newindex if previous value is nil.
3734 | ldr TAB:RA, TAB:CARG1->metatable
3736 | beq <1 // No metatable: done.
3737 | ldrb RA, TAB:RA->nomm
3738 | tst RA, #1<<MM_newindex
3739 | bne <1 // 'no __newindex' flag set: done.
3740 | ldr INS, [PC, #-4] // Restore INS.
3741 | decode_RA8 RA, INS
3744 |7: // Possible table write barrier for the value. Skip valiswhite check.
3745 | barrierback TAB:CARG1, INS, CARG3
3749 | decode_RB8 RB, INS
3750 | decode_RC8 RC, INS
3751 | // RA = src*8, RB = table*8, RC = key*8
3752 | ldr TAB:CARG2, [BASE, RB]
3753 | ldr CARG3, [BASE, RC]
3754 | ldrb INS, TAB:CARG2->marked
3755 | ldr CARG1, TAB:CARG2->array
3756 | ldr CARG4, TAB:CARG2->asize
3757 | tst INS, #LJ_GC_BLACK // isblack(table)
3758 | add CARG1, CARG1, CARG3, lsl #3
3761 | cmp CARG3, CARG4 // In array part?
3764 | ldrd CARG34, [BASE, RA]
3767 | strd CARG34, [CARG1]
3770 |7: // Possible table write barrier for the value. Skip valiswhite check.
3771 | barrierback TAB:CARG2, INS, RB
3776 | // RA = base*8 (table at base-1), RC = num_const (start index)
3779 | ldr RB, SAVE_MULTRES
3780 | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table.
3781 | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word.
3783 | ldr CARG4, TAB:CARG2->asize
3784 | beq >4 // Nothing to copy?
3785 | add CARG3, CARG1, RB, lsr #3
3787 | ldr CARG4, TAB:CARG2->array
3790 | add INS, CARG4, CARG1, lsl #3
3791 | ldrb CARG1, TAB:CARG2->marked
3792 |3: // Copy result slots to table.
3793 | ldrd CARG34, [RA], #8
3794 | strd CARG34, [INS], #8
3797 | tst CARG1, #LJ_GC_BLACK // isblack(table)
3802 |5: // Need to resize array part.
3806 | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
3807 | // Must not reallocate the stack.
3808 | .IOS ldr BASE, L->base
3811 |7: // Possible table write barrier for any value. Skip valiswhite check.
3812 | barrierback TAB:CARG2, CARG1, CARG3
3816 /* -- Calls and vararg handling ----------------------------------------- */
3819 | // RA = base*8, (RB = nresults+1,) RC = extra_nargs
3820 | ldr CARG1, SAVE_MULTRES
3821 | decode_RC8 NARGS8:RC, INS
3822 | add NARGS8:RC, NARGS8:RC, CARG1
3826 | decode_RC8 NARGS8:RC, INS
3827 | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8
3829 | mov RB, BASE // Save old BASE for vmeta_call.
3830 | ldrd CARG34, [BASE, RA]!
3831 | sub NARGS8:RC, NARGS8:RC, #8
3832 | add BASE, BASE, #8
3833 | checkfunc CARG4, ->vmeta_call
3838 | // RA = base*8, (RB = 0,) RC = extra_nargs
3839 | ldr CARG1, SAVE_MULTRES
3840 | add NARGS8:RC, CARG1, RC, lsl #3
3844 | lsl NARGS8:RC, RC, #3
3845 | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
3847 | ldrd LFUNC:CARG34, [RA, BASE]!
3848 | sub NARGS8:RC, NARGS8:RC, #8
3850 | checkfunc CARG4, ->vmeta_callt
3851 | ldr PC, [BASE, FRAME_PC]
3854 | ldrb CARG4, LFUNC:CARG3->ffid
3855 | tst PC, #FRAME_TYPE
3858 | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC.
3862 | ldrd CARG12, [RA, RB]
3864 | cmp INS, NARGS8:RC
3865 | strd CARG12, [BASE, RB]
3869 | cmp CARG4, #1 // (> FF_C) Calling a fast function?
3874 |5: // Tailcall to a fast function with a Lua frame below.
3875 | ldr INS, [PC, #-4]
3876 | decode_RA8 RA, INS
3877 | sub CARG1, BASE, RA
3878 | ldr LFUNC:CARG1, [CARG1, #-16]
3879 | ldr CARG1, LFUNC:CARG1->field_pc
3880 | ldr KBASE, [CARG1, #PC2PROTO(k)]
3883 |7: // Tailcall from a vararg function.
3884 | eor PC, PC, #FRAME_VARG
3885 | tst PC, #FRAME_TYPEP // Vararg frame below?
3886 | movne CARG4, #0 // Clear ffid if no Lua function below.
3888 | sub BASE, BASE, PC
3889 | ldr PC, [BASE, FRAME_PC]
3890 | tst PC, #FRAME_TYPE
3891 | movne CARG4, #0 // Clear ffid if no Lua function below.
3896 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3898 | mov RB, BASE // Save old BASE for vmeta_call.
3899 | ldrd CARG34, [RA, #-16]
3900 | ldrd CARG12, [RA, #-8]
3902 | strd CARG34, [RA, #8] // Copy state.
3903 | strd CARG12, [RA, #16] // Copy control var.
3904 | // STALL: locked CARG34.
3905 | ldrd LFUNC:CARG34, [RA, #-24]
3906 | mov NARGS8:RC, #16 // Iterators get 2 arguments.
3907 | // STALL: load CARG34.
3908 | strd LFUNC:CARG34, [RA] // Copy callable.
3909 | checkfunc CARG4, ->vmeta_call
3914 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3916 | // NYI: add hotloop, record BC_ITERN.
3919 | ldr TAB:RB, [RA, #-16]
3920 | ldr CARG1, [RA, #-8] // Get index from control var.
3921 | ldr INS, TAB:RB->asize
3922 | ldr CARG2, TAB:RB->array
3924 |1: // Traverse array part.
3925 | subs RC, CARG1, INS
3926 | add CARG3, CARG2, CARG1, lsl #3
3927 | bhs >5 // Index points after array part?
3928 | ldrd CARG34, [CARG3]
3929 | checktp CARG4, LJ_TNIL
3930 | addeq CARG1, CARG1, #1 // Skip holes in array part.
3932 | ldrh RC, [PC, #-2]
3933 | mvn CARG2, #~LJ_TISNUM
3934 | strd CARG34, [RA, #8]
3935 | add RC, PC, RC, lsl #2
3938 | sub PC, RC, #0x20000
3939 | str RB, [RA, #-8] // Update control var.
3943 |5: // Traverse hash part.
3944 | ldr CARG4, TAB:RB->hmask
3945 | ldr NODE:RB, TAB:RB->node
3947 | add CARG1, RC, RC, lsl #1
3948 | cmp RC, CARG4 // End of iteration? Branch to ITERL+1.
3949 | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8
3951 | ldrd CARG12, NODE:CARG3->val
3952 | checktp CARG2, LJ_TNIL
3954 | beq <6 // Skip holes in hash part.
3955 | ldrh RB, [PC, #-2]
3957 | ldrd CARG34, NODE:CARG3->key
3958 | str RC, [RA, #-8] // Update control var.
3959 | strd CARG12, [RA, #8]
3960 | add RC, PC, RB, lsl #2
3961 | sub PC, RC, #0x20000
3967 | // RA = base*8, RC = target (points to ITERN)
3969 | add RC, PC, RC, lsl #2
3970 | ldrd CFUNC:CARG12, [RA, #-24]
3971 | ldr CARG3, [RA, #-12]
3972 | ldr CARG4, [RA, #-4]
3973 | checktp CARG2, LJ_TFUNC
3974 | ldrbeq CARG1, CFUNC:CARG1->ffid
3975 | checktpeq CARG3, LJ_TTAB
3976 | checktpeq CARG4, LJ_TNIL
3977 | cmpeq CARG1, #FF_next_N
3978 | subeq PC, RC, #0x20000
3983 | mvn CARG2, #0x00018000
3984 | strd CARG1, [RA, #-8] // Initialize control var.
3987 |5: // Despecialize bytecode if any of the checks fail.
3988 | mov CARG1, #BC_JMP
3990 | strb CARG1, [PC, #-4]
3991 | sub PC, RC, #0x20000
3992 | strb OP, [PC] // Subsumes ins_next1.
3998 | decode_RB8 RB, INS
3999 | decode_RC8 RC, INS
4000 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
4001 | ldr CARG1, [BASE, FRAME_PC]
4004 | add RC, RC, #FRAME_VARG
4006 | sub CARG3, BASE, #8 // CARG3 = vtop
4007 | sub RC, RC, CARG1 // RC = vbase
4008 | // Note: RC may now be even _above_ BASE if nargs was < numparams.
4010 | sub CARG1, CARG3, RC
4011 | beq >5 // Copy all varargs?
4012 | sub CARG4, CARG4, #16
4013 |1: // Copy vararg slots to destination slots.
4015 | ldrdlo CARG12, [RC], #8
4016 | mvnhs CARG2, #~LJ_TNIL
4018 | strd CARG12, [RA], #8
4023 |5: // Copy all varargs.
4024 | ldr CARG4, L->maxstack
4026 | movle RB, #8 // MULTRES = (0+1)*8
4027 | addgt RB, CARG1, #8
4028 | add CARG2, RA, CARG1
4029 | str RB, SAVE_MULTRES
4034 | ldrd CARG12, [RC], #8
4035 | strd CARG12, [RA], #8
4040 |7: // Grow stack for varargs.
4041 | lsr CARG2, CARG1, #3
4045 | sub RC, RC, BASE // Need delta, because BASE may change.
4048 | bl extern lj_state_growstack // (lua_State *L, int n)
4052 | sub CARG3, BASE, #8
4056 /* -- Returns ----------------------------------------------------------- */
4059 | // RA = results*8, RC = extra results
4060 | ldr CARG1, SAVE_MULTRES
4061 | ldr PC, [BASE, FRAME_PC]
4063 | add RC, CARG1, RC, lsl #3
4068 | // RA = results*8, RC = nresults+1
4069 | ldr PC, [BASE, FRAME_PC]
4073 | str RC, SAVE_MULTRES
4075 | ands CARG1, PC, #FRAME_TYPE
4076 | eor CARG2, PC, #FRAME_VARG
4080 | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return
4081 | ldr INS, [PC, #-4]
4082 | subs CARG4, RC, #8
4083 | sub CARG3, BASE, #8
4086 | ldrd CARG12, [RA], #8
4087 | add BASE, BASE, #8
4088 | subs CARG4, CARG4, #8
4089 | strd CARG12, [BASE, #-16]
4092 | decode_RA8 RA, INS
4093 | sub CARG4, CARG3, RA
4094 | decode_RB8 RB, INS
4095 | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]
4097 | cmp RB, RC // More results expected?
4100 | ldr CARG2, LFUNC:CARG1->field_pc
4103 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4106 |6: // Fill up results with nil.
4107 | mvn CARG2, #~LJ_TNIL
4108 | add BASE, BASE, #8
4110 | str CARG2, [BASE, #-12]
4113 |->BC_RETV1_Z: // Non-standard return case.
4116 | tst CARG2, #FRAME_TYPEP
4118 | // Return from vararg function: relocate BASE down.
4119 | sub BASE, BASE, CARG2
4120 | ldr PC, [BASE, FRAME_PC]
4124 case BC_RET0: case BC_RET1:
4125 | // RA = results*8, RC = nresults+1
4126 | ldr PC, [BASE, FRAME_PC]
4128 | str RC, SAVE_MULTRES
4129 | ands CARG1, PC, #FRAME_TYPE
4130 | eor CARG2, PC, #FRAME_VARG
4131 | ldreq INS, [PC, #-4]
4133 if (op == BC_RET1) {
4134 | ldrd CARG12, [BASE, RA]
4136 | sub CARG4, BASE, #8
4137 | decode_RA8 RA, INS
4138 if (op == BC_RET1) {
4139 | strd CARG12, [CARG4]
4141 | sub BASE, CARG4, RA
4142 | decode_RB8 RB, INS
4143 | ldr LFUNC:CARG1, [BASE, FRAME_FUNC]
4147 | ldr CARG2, LFUNC:CARG1->field_pc
4150 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4153 |6: // Fill up results with nil.
4154 | sub CARG2, CARG4, #4
4155 | mvn CARG3, #~LJ_TNIL
4156 | str CARG3, [CARG2, RC]
4161 /* -- Loops and branches ------------------------------------------------ */
4163 |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4]
4164 |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12]
4165 |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]
4166 |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28]
4172 | // Fall through. Assumes BC_IFORL follows.
4182 | // RA = base*8, RC = target (after end of loop or start of loop)
4183 vk = (op == BC_IFORL || op == BC_JFORL);
4184 | ldrd CARG12, [RA, BASE]!
4185 if (op != BC_JFORL) {
4186 | add RC, PC, RC, lsl #2
4189 | ldrd CARG34, FOR_STOP
4190 | checktp CARG2, LJ_TISNUM
4193 | checktp CARG4, LJ_TISNUM
4194 | ldr CARG4, FOR_STEP
4195 | checktpeq RB, LJ_TISNUM
4201 | ldrd CARG34, FOR_STEP
4202 | checktp CARG2, LJ_TISNUM
4204 | adds CARG1, CARG1, CARG3
4205 | ldr CARG4, FOR_STOP
4206 if (op == BC_IFORL) {
4207 | addvs RC, PC, #0x20000 // Overflow: prevent branch.
4209 | bvs >2 // Overflow: do not enter mcode.
4216 if (op == BC_FORI) {
4217 | subgt PC, RC, #0x20000
4218 } else if (op == BC_JFORI) {
4219 | sub PC, RC, #0x20000
4220 | ldrhle RC, [PC, #-2]
4221 } else if (op == BC_IFORL) {
4222 | suble PC, RC, #0x20000
4225 | strd CARG12, FOR_IDX
4230 | strd CARG12, FOR_EXT
4231 if (op == BC_JFORI || op == BC_JFORL) {
4237 |4: // Invert check for negative step.
4247 | cmnlo CARG4, #-LJ_TISNUM
4248 | cmnlo RB, #-LJ_TISNUM
4257 | strd CARG12, FOR_EXT
4266 | vadd.f64 d0, d0, d2
4270 | bl extern __aeabi_dadd
4271 | strd CARG12, FOR_IDX
4272 | ldrd CARG34, FOR_STOP
4273 | strd CARG12, FOR_EXT
4282 | bl extern __aeabi_cdcmple
4290 if (op == BC_FORI) {
4291 | subhi PC, RC, #0x20000
4292 } else if (op == BC_JFORI) {
4293 | sub PC, RC, #0x20000
4294 | ldrhls RC, [PC, #-2]
4296 } else if (op == BC_IFORL) {
4297 | subls PC, RC, #0x20000
4306 |8: // Invert check for negative step.
4308 | bl extern __aeabi_dadd
4309 | strd CARG12, FOR_IDX
4310 | strd CARG12, FOR_EXT
4314 | ldrd CARG12, FOR_STOP
4323 | // Fall through. Assumes BC_IITERL follows.
4331 | // RA = base*8, RC = target
4332 | ldrd CARG12, [RA, BASE]!
4333 if (op == BC_JITERL) {
4334 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4335 | strdne CARG12, [RA, #-8]
4338 | add RC, PC, RC, lsl #2
4339 | // STALL: load CARG12.
4340 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4341 | subne PC, RC, #0x20000 // Otherwise save control var + branch.
4342 | strdne CARG12, [RA, #-8]
4348 | // RA = base*8, RC = target (loop extent)
4349 | // Note: RA/RC is only used by trace recorder to determine scope/extent
4350 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
4354 | // Fall through. Assumes BC_ILOOP follows.
4358 | // RA = base*8, RC = target (loop extent)
4364 | // RA = base (ignored), RC = traceno
4365 | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
4366 | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0.
4367 | ldr TRACE:RC, [CARG1, RC, lsl #2]
4369 | ldr RA, TRACE:RC->mcode
4370 | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
4371 | str L, [DISPATCH, #DISPATCH_GL(tmpbuf.L)]
4377 | // RA = base*8 (only used by trace recorder), RC = target
4378 | add RC, PC, RC, lsl #2
4379 | sub PC, RC, #0x20000
4383 /* -- Function headers -------------------------------------------------- */
4389 case BC_FUNCV: /* NYI: compiled vararg functions. */
4390 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
4398 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4399 | ldr CARG1, L->maxstack
4400 | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]
4401 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4403 | bhi ->vm_growstack_l
4404 if (op != BC_JFUNCF) {
4409 | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters.
4410 | mvn CARG4, #~LJ_TNIL
4412 if (op == BC_JFUNCF) {
4419 |3: // Clear missing parameters.
4420 | strd CARG34, [BASE, NARGS8:RC]
4421 | add NARGS8:RC, NARGS8:RC, #8
4429 | NYI // NYI: compiled vararg functions
4430 break; /* NYI: compiled vararg functions. */
4433 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4434 | ldr CARG1, L->maxstack
4435 | add CARG4, BASE, RC
4437 | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC.
4438 | add CARG2, RC, #8+FRAME_VARG
4439 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4441 | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG.
4442 | bhs ->vm_growstack_l
4443 | ldrb RB, [PC, #-4+PC2PROTO(numparams)]
4447 | add BASE, CARG4, #8
4449 | mvn CARG3, #~LJ_TNIL
4451 | cmp RA, RC // Less args than parameters?
4452 | ldrdlo CARG12, [RA], #8
4453 | movhs CARG2, CARG3
4454 | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC).
4457 | strd CARG12, [CARG4, #8]!
4465 | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8
4466 if (op == BC_FUNCC) {
4467 | ldr CARG4, CFUNC:CARG3->f
4469 | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]
4471 | add CARG2, RA, NARGS8:RC
4472 | ldr CARG1, L->maxstack
4473 | add RC, BASE, NARGS8:RC
4477 if (op == BC_FUNCCW) {
4478 | ldr CARG2, CFUNC:CARG3->f
4480 | mv_vmstate CARG3, C
4482 | bhi ->vm_growstack_c // Need to grow stack.
4484 | blx CARG4 // (lua_State *L [, lua_CFunction f])
4485 | // Returns nresults.
4487 | mv_vmstate CARG3, INTERP
4489 | str L, [DISPATCH, #DISPATCH_GL(cur_L)]
4492 | ldr PC, [BASE, FRAME_PC]
4493 | sub RA, CRET2, RC // RA = L->top - nresults*8
4497 /* ---------------------------------------------------------------------- */
4500 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
4506 static int build_backend(BuildCtx *ctx)
4510 dasm_growpc(Dst, BC__MAX);
4512 build_subroutines(ctx);
4515 for (op = 0; op < BC__MAX; op++)
4516 build_ins(ctx, (BCOp)op, op);
4521 /* Emit pseudo frame-info for all assembler functions. */
4522 static void emit_asm_debug(BuildCtx *ctx)
4524 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
4526 switch (ctx->mode) {
4528 fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n");
4531 "\t.long .LECIE0-.LSCIE0\n"
4533 "\t.long 0xffffffff\n"
4538 "\t.byte 0xe\n" /* Return address is in lr. */
4539 "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */
4544 "\t.long .LEFDE0-.LASFDE0\n"
4546 "\t.long .Lframe0\n"
4549 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
4550 "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */
4551 fcofs, CFRAME_SIZE);
4552 for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */
4553 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i));
4555 for (i = 15; i >= 8; i--) /* offset d8-d15 */
4556 fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n",
4557 64+2*i, 10+2*(15-i));
4558 fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */
4566 "\t.long .LEFDE1-.LASFDE1\n"
4568 "\t.long .Lframe0\n"
4569 "\t.long lj_vm_ffi_call\n"
4571 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
4572 "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */
4573 "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */
4574 "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */
4575 "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */
4576 "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */
4578 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);