1 |// Low-level VM code for ARM CPUs.
2 |// Bytecode interpreter, fast functions and helper functions.
3 |// Copyright (C) 2005-2012 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
103 |//-----------------------------------------------------------------------
105 |// Trap for not-yet-implemented parts.
106 |.macro NYI; ud; .endmacro
108 |//-----------------------------------------------------------------------
110 |// Access to frame relative to BASE.
111 |.define FRAME_FUNC, #-8
112 |.define FRAME_PC, #-4
114 |.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro
115 |.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro
116 |.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro
117 |.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro
118 |.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro
120 |// Instruction fetch.
127 |// Instruction decode+dispatch.
129 | ldr OP, [DISPATCH, OP, lsl #2]
140 |// Instruction footer.
142 | // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
143 | .define ins_next, ins_NEXT
144 | .define ins_next_, ins_NEXT
145 | .define ins_next1, ins_NEXT1
146 | .define ins_next2, ins_NEXT2
147 | .define ins_next3, ins_NEXT3
149 | // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
150 | // Affects only certain kinds of benchmarks (and only with -j off).
167 |// Avoid register name substitution for field name.
170 |// Call decode and dispatch.
172 | // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
173 | ldr PC, LFUNC:CARG3->field_pc
174 | ldrb OP, [PC] // STALL: load PC. early PC.
176 | ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP.
183 | // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
184 | str PC, [BASE, FRAME_PC]
185 | ins_callt // STALL: locked PC.
188 |//-----------------------------------------------------------------------
190 |// Macros to test operand types.
191 |.macro checktp, reg, tp; cmn reg, #-tp; .endmacro
192 |.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro
193 |.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro
194 |.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro
195 |.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro
196 |.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro
198 |// Assumes DISPATCH is relative to GL.
199 #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
200 #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
202 #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
204 |.macro hotcheck, delta
206 | and CARG1, CARG1, #126
207 | sub CARG1, CARG1, #-GG_DISP2HOT
208 | ldrh CARG2, [DISPATCH, CARG1]
209 | subs CARG2, CARG2, #delta
210 | strh CARG2, [DISPATCH, CARG1]
214 | hotcheck HOTCOUNT_LOOP
219 | hotcheck HOTCOUNT_CALL
223 |// Set current VM state.
224 |.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro
225 |.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro
227 |// Move table write barrier back. Overwrites mark and tmp.
228 |.macro barrierback, tab, mark, tmp
229 | ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
230 | bic mark, mark, #LJ_GC_BLACK // black2gray(tab)
231 | str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
232 | strb mark, tab->marked
233 | str tmp, tab->gclist
242 |//-----------------------------------------------------------------------
245 #error "Only dual-number mode supported for ARM target"
248 /* Generate subroutines used by opcodes and other parts of the VM. */
249 /* The .code_sub section should be last to help static branch prediction. */
250 static void build_subroutines(BuildCtx *ctx)
254 |//-----------------------------------------------------------------------
255 |//-- Return handling ----------------------------------------------------
256 |//-----------------------------------------------------------------------
259 | // See vm_return. Also: RB = previous base.
261 | beq ->cont_dispatch
263 | // Return from pcall or xpcall fast func.
264 | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame.
265 | mvn CARG2, #~LJ_TTRUE
267 | // Prepending may overwrite the pcall frame, so do it at the end.
268 | str CARG2, [RA, FRAME_PC] // Prepend true to results.
272 | adds RC, RC, #8 // RC = (nresults+1)*8.
273 | mov CRET1, #LUA_YIELD
274 | beq ->vm_unwind_c_eh
275 | str RC, SAVE_MULTRES
276 | ands CARG1, PC, #FRAME_TYPE
277 | beq ->BC_RET_Z // Handle regular return to Lua.
280 | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return
281 | // CARG1 = PC & FRAME_TYPE
282 | bic RB, PC, #FRAME_TYPEP
283 | cmp CARG1, #FRAME_C
284 | sub RB, BASE, RB // RB = previous base.
288 | ldr KBASE, SAVE_NRES
289 | mv_vmstate CARG4, C
292 | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8
296 | subs CARG3, CARG3, #8
297 | ldrd CARG12, [RA], #8
298 | strd CARG12, [BASE], #8
301 | cmp KBASE, RC // More/less results wanted?
304 | str BASE, L->top // Store new top.
307 | ldr RC, SAVE_CFRAME // Restore previous C frame.
308 | mov CRET1, #0 // Ok return status for vm_pcall.
315 | blt >7 // Less results wanted?
316 | // More results wanted. Check stack size and fill up results with nil.
317 | ldr CARG3, L->maxstack
318 | mvn CARG2, #~LJ_TNIL
321 | str CARG2, [BASE, #4]
326 |7: // Less results wanted.
327 | sub CARG1, RC, KBASE
328 | cmp KBASE, #0 // LUA_MULTRET+1 case?
329 | subne BASE, BASE, CARG1 // Either keep top or shrink it.
332 |8: // Corner case: need to grow stack for filling up results.
333 | // This can happen if:
334 | // - A C function grows the stack (a lot).
335 | // - The GC shrinks the stack in between.
336 | // - A return back from a lua_call() with (high) nresults adjustment.
337 | str BASE, L->top // Save current top held in BASE (yes).
340 | bl extern lj_state_growstack // (lua_State *L, int n)
341 | ldr BASE, L->top // Need the (realloced) L->top in BASE.
344 |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
345 | // (void *cframe, int errcode)
348 |->vm_unwind_c_eh: // Landing pad for external unwinder.
350 | mv_vmstate CARG4, C
351 | ldr GL:CARG3, L->glref
352 | str CARG4, GL:CARG3->vmstate
355 |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
357 | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
359 |->vm_unwind_ff_eh: // Landing pad for external unwinder.
362 | mov RC, #16 // 2 results: false + error message.
363 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
365 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
366 | mvn CARG1, #~LJ_TFALSE
367 | sub RA, BASE, #8 // Results start at BASE-8.
368 | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame.
369 | add DISPATCH, DISPATCH, #GG_G2DISP
370 | mv_vmstate CARG2, INTERP
371 | str CARG1, [BASE, #-4] // Prepend false to error message.
375 |//-----------------------------------------------------------------------
376 |//-- Grow stack for calls -----------------------------------------------
377 |//-----------------------------------------------------------------------
379 |->vm_growstack_c: // Grow stack for C function.
381 | mov CARG2, #LUA_MINSTACK
384 |->vm_growstack_l: // Grow stack for Lua function.
385 | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
390 | add PC, PC, #4 // Must point after first instruction.
394 | // L->base = new base, L->top = top
396 | bl extern lj_state_growstack // (lua_State *L, int n)
399 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
400 | sub NARGS8:RC, RC, BASE
401 | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
402 | ins_callt // Just retry the call.
404 |//-----------------------------------------------------------------------
405 |//-- Entry points into the assembler VM ---------------------------------
406 |//-----------------------------------------------------------------------
408 |->vm_resume: // Setup C frame and resume thread.
409 | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
412 | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table.
414 | add DISPATCH, DISPATCH, #GG_G2DISP
417 | str CARG3, SAVE_NRES
418 | add CARG2, sp, #CFRAME_RESUME
419 | ldrb CARG1, L->status
420 | str CARG3, SAVE_ERRF
421 | str CARG2, L->cframe
422 | str CARG3, SAVE_CFRAME
424 | str L, SAVE_PC // Any value outside of bytecode is ok.
427 | // Resume after yield (like a return).
432 | strb CARG3, L->status
433 | sub RC, CARG1, BASE
434 | ldr PC, [BASE, FRAME_PC]
435 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
436 | mv_vmstate CARG2, INTERP
438 | ands CARG1, PC, #FRAME_TYPE
440 | str RC, SAVE_MULTRES
444 |->vm_pcall: // Setup protected C frame and enter VM.
445 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
448 | str CARG4, SAVE_ERRF
451 |->vm_call: // Setup C frame and enter VM.
452 | // (lua_State *L, TValue *base, int nres1)
456 |1: // Entry point for vm_pcall above (PC = ftype).
457 | ldr RC, L:CARG1->cframe
458 | str CARG3, SAVE_NRES
462 | str sp, L->cframe // Add our C frame to cframe chain.
463 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
464 | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
465 | str RC, SAVE_CFRAME
466 | add DISPATCH, DISPATCH, #GG_G2DISP
468 |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
469 | ldr RB, L->base // RB = old base (for vmeta_call).
473 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
474 | sub PC, PC, RB // PC = frame delta + frame type
475 | mv_vmstate CARG2, INTERP
476 | sub NARGS8:RC, CARG1, BASE
480 | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC
481 | ldrd CARG34, [BASE, FRAME_FUNC]
482 | checkfunc CARG4, ->vmeta_call
484 |->vm_call_dispatch_f:
486 | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC
488 |->vm_cpcall: // Setup protected C frame, call C.
489 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
492 | ldr RA, L:CARG1->stack
495 | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
497 | sub RA, RA, RB // Compute -savestack(L, L->top).
498 | str sp, L->cframe // Add our C frame to cframe chain.
500 | str RA, SAVE_NRES // Neg. delta means cframe w/o frame.
501 | str RB, SAVE_ERRF // No error function.
502 | str RC, SAVE_CFRAME
503 | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud)
504 | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
507 | add DISPATCH, DISPATCH, #GG_G2DISP
508 | bne <3 // Else continue with the call.
509 | b ->vm_leave_cp // No base? Just remove C frame.
511 |//-----------------------------------------------------------------------
512 |//-- Metamethod handling ------------------------------------------------
513 |//-----------------------------------------------------------------------
515 |//-- Continuation dispatch ----------------------------------------------
518 | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8
519 | ldr LFUNC:CARG3, [RB, FRAME_FUNC]
520 | ldr CARG1, [BASE, #-16] // Get continuation.
522 | mov BASE, RB // Restore caller BASE.
526 | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC].
527 | ldr CARG3, LFUNC:CARG3->field_pc
530 | str INS, [CARG2, #-4] // Ensure one valid arg.
534 | ldr KBASE, [CARG3, #PC2PROTO(k)]
535 | // BASE = base, RA = resultptr, CARG4 = meta base
540 | beq ->cont_ffi_callback // cont = 1: return from FFI callback.
541 | // cont = 0: tailcall from C function.
542 | ldr CARG3, [BASE, FRAME_FUNC]
543 | sub CARG4, CARG4, #16
544 | sub RC, CARG4, BASE
548 |->cont_cat: // RA = resultptr, CARG4 = meta base
550 | sub CARG2, CARG4, #16
555 | add CARG1, BASE, RC
556 | subs CARG1, CARG2, CARG1
557 | strdne CARG34, [CARG2]
560 | strd CARG34, [BASE, RA]
563 |//-- Table indexing metamethods -----------------------------------------
566 | add CARG2, BASE, RB
570 | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
571 | mvn CARG4, #~LJ_TTAB
572 | str TAB:RB, [CARG2]
573 | str CARG4, [CARG2, #4]
575 | mvn CARG4, #~LJ_TSTR
581 |->vmeta_tgetb: // RC = index
584 | mvn CARG4, #~LJ_TISNUM
585 | add CARG2, BASE, RB
591 | add CARG2, BASE, RB
592 | add CARG3, BASE, RC
597 | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
598 | // Returns TValue * (finished) or NULL (metamethod).
599 | .IOS ldr BASE, L->base
602 | ldrd CARG34, [CRET1]
605 | strd CARG34, [BASE, RA]
608 |3: // Call __index metamethod.
609 | // BASE = base, L->top = new base, stack = cont/func/t/k
610 | rsb CARG1, BASE, #FRAME_CONT
612 | mov NARGS8:RC, #16 // 2 args for func(t, k).
613 | str PC, [BASE, #-12] // [cont|PC]
614 | add PC, CARG1, BASE
615 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
616 | b ->vm_call_dispatch_f
618 |//-----------------------------------------------------------------------
621 | add CARG2, BASE, RB
625 | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
626 | mvn CARG4, #~LJ_TTAB
627 | str TAB:RB, [CARG2]
628 | str CARG4, [CARG2, #4]
630 | mvn CARG4, #~LJ_TSTR
636 |->vmeta_tsetb: // RC = index
639 | mvn CARG4, #~LJ_TISNUM
640 | add CARG2, BASE, RB
646 | add CARG2, BASE, RB
647 | add CARG3, BASE, RC
652 | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
653 | // Returns TValue * (finished) or NULL (metamethod).
654 | .IOS ldr BASE, L->base
656 | ldrd CARG34, [BASE, RA]
659 | // NOBARRIER: lj_meta_tset ensures the table is not black.
660 | strd CARG34, [CRET1]
664 |3: // Call __newindex metamethod.
665 | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
666 | rsb CARG1, BASE, #FRAME_CONT
668 | mov NARGS8:RC, #24 // 3 args for func(t, k, v).
669 | strd CARG34, [BASE, #16] // Copy value to third argument.
670 | str PC, [BASE, #-12] // [cont|PC]
671 | add PC, CARG1, BASE
672 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
673 | b ->vm_call_dispatch_f
675 |//-- Comparison metamethods ---------------------------------------------
684 | decode_OP CARG4, INS
685 | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
686 | // Returns 0/1 or TValue * (metamethod).
688 | .IOS ldr BASE, L->base
694 | add RB, PC, RB, lsl #2
695 | subhs PC, RB, #0x20000
699 |->cont_ra: // RA = resultptr
702 | decode_RA8 CARG3, INS
703 | strd CARG12, [BASE, CARG3]
706 |->cont_condt: // RA = resultptr
707 | ldr CARG2, [RA, #4]
708 | mvn CARG1, #~LJ_TTRUE
709 | cmp CARG1, CARG2 // Branch if result is true.
712 |->cont_condf: // RA = resultptr
713 | ldr CARG2, [RA, #4]
714 | checktp CARG2, LJ_TFALSE // Branch if result is false.
718 | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
723 | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
724 | // Returns 0/1 or TValue * (metamethod).
734 | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op)
735 | // Returns 0/1 or TValue * (metamethod).
739 |//-- Arithmetic metamethods ---------------------------------------------
744 | add CARG3, BASE, RB
745 | add CARG4, KBASE, RC
751 | add CARG4, BASE, RB
752 | add CARG3, KBASE, RC
758 | add CARG3, BASE, RC
759 | add CARG4, BASE, RC
765 | add CARG3, BASE, RB
766 | add CARG4, BASE, RC
769 | add CARG2, BASE, RA
774 | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
775 | // Returns NULL (finished) or TValue * (metamethod).
776 | .IOS ldr BASE, L->base
780 | // Call metamethod for binary op.
782 | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
783 | sub CARG2, CRET1, BASE
784 | str PC, [CRET1, #-12] // [cont|PC]
785 | add PC, CARG2, #FRAME_CONT
787 | mov NARGS8:RC, #16 // 2 args for func(o1, o2).
788 | b ->vm_call_dispatch
791 | add CARG2, BASE, RC
795 | bl extern lj_meta_len // (lua_State *L, TValue *o)
796 | // Returns NULL (retry) or TValue * (metamethod base).
797 | .IOS ldr BASE, L->base
800 | bne ->vmeta_binop // Binop call for compatibility.
801 | ldr TAB:CARG1, [BASE, RC]
804 | b ->vmeta_binop // Binop call for compatibility.
807 |//-- Call metamethod ----------------------------------------------------
809 |->vmeta_call: // Resolve and call __call metamethod.
810 | // RB = old base, BASE = new base, RC = nargs*8
812 | str RB, L->base // This is the callers base!
813 | sub CARG2, BASE, #8
815 | add CARG3, BASE, NARGS8:RC
817 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
819 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
820 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
823 |->vmeta_callt: // Resolve __call for BC_CALLT.
824 | // BASE = old base, RA = new base, RC = nargs*8
829 | add CARG3, RA, NARGS8:RC
830 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
831 | .IOS ldr BASE, L->base
832 | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
833 | ldr PC, [BASE, FRAME_PC]
834 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
837 |//-- Argument coercion for 'for' statement ------------------------------
844 | bl extern lj_meta_for // (lua_State *L, TValue *base)
845 | .IOS ldr BASE, L->base
860 |//-----------------------------------------------------------------------
861 |//-- Fast functions -----------------------------------------------------
862 |//-----------------------------------------------------------------------
868 |.macro .ffunc_1, name
870 | ldrd CARG12, [BASE]
875 |.macro .ffunc_2, name
877 | ldrd CARG12, [BASE]
878 | ldrd CARG34, [BASE, #8]
883 |.macro .ffunc_n, name
885 | checktp CARG2, LJ_TISNUM
889 |.macro .ffunc_nn, name
891 | checktp CARG2, LJ_TISNUM
892 | cmnlo CARG4, #-LJ_TISNUM
896 |.macro .ffunc_d, name
898 | ldr CARG2, [BASE, #4]
902 | checktp CARG2, LJ_TISNUM
906 |.macro .ffunc_dd, name
908 | ldr CARG2, [BASE, #4]
909 | ldr CARG4, [BASE, #12]
912 | vldr d1, [BASE, #8]
914 | checktp CARG2, LJ_TISNUM
915 | cmnlo CARG4, #-LJ_TISNUM
919 |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.
921 | ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)]
922 | ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)]
927 |//-- Base library: checks -----------------------------------------------
930 | checktp CARG2, LJ_TTRUE
932 | ldr PC, [BASE, FRAME_PC]
933 | strd CARG12, [BASE, #-8]
935 | subs RA, NARGS8:RC, #8
936 | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8.
937 | beq ->fff_res // Done if exactly 1 argument.
939 | ldrd CARG12, [RB, #8]
941 | strd CARG12, [RB], #8
946 | ldr CARG2, [BASE, #4]
949 | checktp CARG2, LJ_TISNUM
950 | mvnlo CARG2, #~LJ_TISNUM
951 | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1
952 | lsl CARG4, CARG4, #3
953 | ldrd CARG12, [CFUNC:CARG3, CARG4]
956 |//-- Base library: getters and setters ---------------------------------
958 |.ffunc_1 getmetatable
959 | checktp CARG2, LJ_TTAB
960 | cmnne CARG2, #-LJ_TUDATA
962 |1: // Field metatable must be at same offset for GCtab and GCudata!
963 | ldr TAB:RB, TAB:CARG1->metatable
965 | mvn CARG2, #~LJ_TNIL
966 | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])]
969 | ldr CARG3, TAB:RB->hmask
970 | ldr CARG4, STR:RC->hash
971 | ldr NODE:INS, TAB:RB->node
972 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
973 | add CARG3, CARG3, CARG3, lsl #1
974 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
975 |3: // Rearranged logic, because we expect _not_ to find the key.
976 | ldrd CARG34, NODE:INS->key // STALL: early NODE:INS.
977 | ldrd CARG12, NODE:INS->val
978 | ldr NODE:INS, NODE:INS->next
979 | checktp CARG4, LJ_TSTR
980 | cmpeq CARG3, STR:RC
985 | mov CARG1, RB // Use metatable as default result.
986 | mvn CARG2, #~LJ_TTAB
989 | checktp CARG2, LJ_TNIL
994 | checktp CARG2, LJ_TISNUM
996 | movlo CARG2, #~LJ_TISNUM
997 | add CARG4, DISPATCH, CARG2, lsl #2
998 | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])]
1001 |.ffunc_2 setmetatable
1002 | // Fast path: no mt for table yet and not clearing the mt.
1003 | checktp CARG2, LJ_TTAB
1004 | ldreq TAB:RB, TAB:CARG1->metatable
1005 | checktpeq CARG4, LJ_TTAB
1006 | ldrbeq CARG4, TAB:CARG1->marked
1008 | bne ->fff_fallback
1009 | tst CARG4, #LJ_GC_BLACK // isblack(table)
1010 | str TAB:CARG3, TAB:CARG1->metatable
1012 | barrierback TAB:CARG1, CARG4, CARG3
1016 | ldrd CARG34, [BASE]
1017 | cmp NARGS8:RC, #16
1018 | blo ->fff_fallback
1020 | checktab CARG4, ->fff_fallback
1022 | add CARG3, BASE, #8
1024 | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
1025 | // Returns cTValue *.
1027 | ldrd CARG12, [CRET1]
1030 |//-- Base library: conversions ------------------------------------------
1033 | // Only handles the number case inline (without a base argument).
1034 | ldrd CARG12, [BASE]
1036 | bne ->fff_fallback
1037 | checktp CARG2, LJ_TISNUM
1042 | // Only handles the string or number case inline.
1043 | checktp CARG2, LJ_TSTR
1044 | // A __tostring method in the string base metatable is ignored.
1046 | // Handle numbers inline, unless a number base metatable is present.
1047 | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])]
1049 | checktp CARG2, LJ_TISNUM
1051 | str PC, SAVE_PC // Redundant (but a defined value).
1052 | bhi ->fff_fallback
1056 | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o)
1057 | // Returns GCstr *.
1059 | mvn CARG2, #~LJ_TSTR
1062 |//-- Base library: iterators -------------------------------------------
1065 | mvn CARG4, #~LJ_TNIL
1066 | checktab CARG2, ->fff_fallback
1067 | strd CARG34, [BASE, NARGS8:RC] // Set missing 2nd arg to nil.
1068 | ldr PC, [BASE, FRAME_PC]
1070 | str BASE, L->base // Add frame since C call can throw.
1072 | str BASE, L->top // Dummy frame length is ok.
1073 | add CARG3, BASE, #8
1075 | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
1076 | // Returns 0 at end of traversal.
1077 | .IOS ldr BASE, L->base
1079 | mvneq CRET2, #~LJ_TNIL
1080 | beq ->fff_restv // End of traversal: return nil.
1081 | ldrd CARG12, [BASE, #8] // Copy key and value to results.
1082 | ldrd CARG34, [BASE, #16]
1084 | strd CARG12, [BASE, #-8]
1085 | strd CARG34, [BASE]
1089 | checktab CARG2, ->fff_fallback
1091 | ldr TAB:RB, TAB:CARG1->metatable
1093 | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
1094 | ldr PC, [BASE, FRAME_PC]
1097 | bne ->fff_fallback
1099 | mvn CARG2, #~LJ_TNIL
1101 | strd CFUNC:CARG34, [BASE, #-8]
1102 | str CARG2, [BASE, #12]
1105 |.ffunc_2 ipairs_aux
1106 | checktp CARG2, LJ_TTAB
1107 | checktpeq CARG4, LJ_TISNUM
1108 | bne ->fff_fallback
1109 | ldr RB, TAB:CARG1->asize
1110 | ldr RC, TAB:CARG1->array
1111 | add CARG3, CARG3, #1
1112 | ldr PC, [BASE, FRAME_PC]
1114 | add RC, RC, CARG3, lsl #3
1115 | strd CARG34, [BASE, #-8]
1116 | ldrdlo CARG12, [RC]
1118 | bhs >2 // Not in array part?
1120 | checktp CARG2, LJ_TNIL
1121 | movne RC, #(2+1)*8
1122 | strdne CARG12, [BASE]
1124 |2: // Check for empty hash part first. Otherwise call C function.
1125 | ldr RB, TAB:CARG1->hmask
1130 | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
1131 | // Returns cTValue * or NULL.
1135 | ldrd CARG12, [CRET1]
1139 | checktab CARG2, ->fff_fallback
1141 | ldr TAB:RB, TAB:CARG1->metatable
1143 | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
1144 | ldr PC, [BASE, FRAME_PC]
1147 | bne ->fff_fallback
1150 | mvn CARG2, #~LJ_TISNUM
1152 | strd CFUNC:CARG34, [BASE, #-8]
1153 | strd CARG12, [BASE, #8]
1156 |//-- Base library: catch errors ----------------------------------------
1159 | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
1161 | blo ->fff_fallback
1162 | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
1164 | add BASE, BASE, #8
1165 | moveq PC, #8+FRAME_PCALL
1166 | movne PC, #8+FRAME_PCALLH
1167 | sub NARGS8:RC, NARGS8:RC, #8
1168 | b ->vm_call_dispatch
1171 | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
1172 | checkfunc CARG4, ->fff_fallback // Traceback must be a function.
1174 | strd CARG12, [BASE, #8] // Swap function and traceback.
1175 | strd CARG34, [BASE]
1176 | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
1177 | add BASE, BASE, #16
1178 | moveq PC, #16+FRAME_PCALL
1179 | movne PC, #16+FRAME_PCALLH
1180 | sub NARGS8:RC, NARGS8:RC, #16
1181 | b ->vm_call_dispatch
1183 |//-- Coroutine library --------------------------------------------------
1185 |.macro coroutine_resume_wrap, resume
1187 |.ffunc_1 coroutine_resume
1188 | checktp CARG2, LJ_TTHREAD
1189 | bne ->fff_fallback
1191 |.ffunc coroutine_wrap_aux
1192 | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr
1194 | ldr PC, [BASE, FRAME_PC]
1196 | ldr CARG2, L:CARG1->top
1197 | ldrb RA, L:CARG1->status
1198 | ldr RB, L:CARG1->base
1199 | add CARG3, CARG2, NARGS8:RC
1200 | add CARG4, CARG2, RA
1203 | beq ->fff_fallback
1204 | ldr CARG4, L:CARG1->maxstack
1205 | ldr RB, L:CARG1->cframe
1206 | cmp RA, #LUA_YIELD
1207 | cmpls CARG3, CARG4
1209 | bhi ->fff_fallback
1212 | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC.
1213 | add BASE, BASE, #8
1214 | sub NARGS8:RC, NARGS8:RC, #8
1216 | str CARG3, L:CARG1->top
1218 |2: // Move args to coroutine.
1219 | ldrd CARG34, [BASE, RB]
1221 | strdne CARG34, [CARG2, RB]
1228 | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
1229 | // Returns thread status.
1231 | ldr CARG3, L:RA->base
1232 | mv_vmstate CARG2, INTERP
1233 | ldr CARG4, L:RA->top
1235 | cmp CRET1, #LUA_YIELD
1238 | subs RC, CARG4, CARG3
1239 | ldr CARG1, L->maxstack
1240 | add CARG2, BASE, RC
1241 | beq >6 // No results?
1244 | bhi >9 // Need to grow stack?
1247 | str CARG3, L:RA->top // Clear coroutine stack.
1248 |5: // Move results from coroutine.
1249 | ldrd CARG12, [CARG3, RB]
1251 | strd CARG12, [BASE, RB]
1256 | mvn CARG3, #~LJ_TTRUE
1259 | str CARG3, [BASE, #-4] // Prepend true/false to results.
1265 | ands CARG1, PC, #FRAME_TYPE
1267 | str RC, SAVE_MULTRES
1271 |8: // Coroutine returned with error (at co->top-1).
1273 | ldrd CARG12, [CARG4, #-8]!
1274 | mvn CARG3, #~LJ_TFALSE
1276 | str CARG4, L:RA->top // Remove error from coroutine stack.
1277 | strd CARG12, [BASE] // Copy error message.
1282 | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
1286 |9: // Handle stack expansion on return from yield.
1289 | bl extern lj_state_growstack // (lua_State *L, int n)
1294 | coroutine_resume_wrap 1 // coroutine.resume
1295 | coroutine_resume_wrap 0 // coroutine.wrap
1297 |.ffunc coroutine_yield
1298 | ldr CARG1, L->cframe
1299 | add CARG2, BASE, NARGS8:RC
1301 | tst CARG1, #CFRAME_RESUME
1303 | mov CRET1, #LUA_YIELD
1305 | beq ->fff_fallback
1306 | str CARG3, L->cframe
1307 | strb CRET1, L->status
1310 |//-- Math library -------------------------------------------------------
1312 |.macro math_round, func
1313 | .ffunc_1 math_ .. func
1314 | checktp CARG2, LJ_TISNUM
1316 | bhi ->fff_fallback
1317 | // Round FP value and normalize result.
1318 | lsl CARG3, CARG2, #1
1319 | adds RB, CARG3, #0x00200000
1320 | bpl >2 // |x| < 1?
1322 | subs RB, CARG4, RB, asr #21
1323 | lsl CARG4, CARG2, #11
1324 | lsl CARG3, CARG1, #11
1325 | orr CARG4, CARG4, #0x80000000
1327 | orr CARG4, CARG4, CARG1, lsr #21
1328 | bls >3 // |x| >= 2^31?
1329 | orr CARG3, CARG3, CARG4, lsl INS
1330 | lsr CARG1, CARG4, RB
1331 |.if "func" == "floor"
1332 | tst CARG3, CARG2, asr #31
1333 | addne CARG1, CARG1, #1
1335 | bics CARG3, CARG3, CARG2, asr #31
1336 | addsne CARG1, CARG1, #1
1341 | rsblt CARG1, CARG1, #0
1343 | mvn CARG2, #~LJ_TISNUM
1347 | bcs ->fff_restv // |x| is not finite.
1348 | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo
1349 |.if "func" == "floor"
1350 | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1
1354 | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1
1358 | mvn CARG2, #~LJ_TISNUM
1361 |3: // |x| >= 2^31. Check for x == -(2^31).
1362 | cmpeq CARG4, #0x80000000
1363 |.if "func" == "floor"
1368 | movmi CARG1, #0x80000000
1372 | vmov d0, CARG1, CARG2
1373 | bl ->vm_..func.._hf
1386 | .long 0x00000000, 0x41e00000 // 2^31.
1389 | checktp CARG2, LJ_TISNUM
1390 | bhi ->fff_fallback
1391 | bicne CARG2, CARG2, #0x80000000
1394 | rsbslt CARG1, CARG1, #0
1399 | // CARG12 = TValue result.
1400 | ldr PC, [BASE, FRAME_PC]
1401 | strd CARG12, [BASE, #-8]
1406 | // RC = (nresults+1)*8, PC = return.
1407 | ands CARG1, PC, #FRAME_TYPE
1408 | ldreq INS, [PC, #-4]
1409 | str RC, SAVE_MULTRES
1412 | decode_RB8 RB, INS
1414 | cmp RB, RC // More results expected?
1416 | decode_RA8 CARG1, INS
1419 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
1420 | sub BASE, RA, CARG1
1423 |6: // Fill up results with nil.
1425 | mvn CARG1, #~LJ_TNIL
1427 | str CARG1, [CARG2, #-4]
1430 |.macro math_extern, func
1432 | .ffunc_d math_ .. func
1434 | .ffunc_n math_ .. func
1446 |.macro math_extern2, func
1448 | .ffunc_dd math_ .. func
1450 | .ffunc_nn math_ .. func
1463 | .ffunc_d math_sqrt
1466 | ldr PC, [BASE, FRAME_PC]
1467 | vstr d0, [BASE, #-8]
1475 | ldr CARG2, [BASE, #4]
1476 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1478 | bne ->fff_fallback
1480 | ldrd CARG12, [BASE]
1481 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1482 | bne ->fff_fallback
1484 | checktp CARG2, LJ_TISNUM
1485 | bhs ->fff_fallback
1507 | math_extern2 atan2
1513 | vldr d1, CFUNC:CARG3->upvalue[0]
1514 | vmul.f64 d0, d0, d1
1518 | ldrd CARG34, CFUNC:CARG3->upvalue[0]
1519 | bl extern __aeabi_dmul
1525 | ldr CARG4, [BASE, #4]
1526 | ldrd CARG12, [BASE, #8]
1527 | cmp NARGS8:RC, #16
1528 | blo ->fff_fallback
1530 | checktp CARG4, LJ_TISNUM
1531 | bhs ->fff_fallback
1532 | checktp CARG2, LJ_TISNUM
1533 | bne ->fff_fallback
1535 | bl extern ldexp // (double x, int exp)
1539 |.ffunc_2 math_ldexp
1540 | checktp CARG2, LJ_TISNUM
1541 | bhs ->fff_fallback
1542 | checktp CARG4, LJ_TISNUM
1543 | bne ->fff_fallback
1545 | bl extern ldexp // (double x, int exp)
1551 |.ffunc_d math_frexp
1557 | mvn CARG4, #~LJ_TISNUM
1558 | ldr PC, [BASE, FRAME_PC]
1559 | vstr d0, [BASE, #-8]
1561 | strd CARG34, [BASE]
1564 |.ffunc_n math_frexp
1570 | mvn CARG4, #~LJ_TISNUM
1571 | ldr PC, [BASE, FRAME_PC]
1572 | strd CARG12, [BASE, #-8]
1574 | strd CARG34, [BASE]
1580 | sub CARG1, BASE, #8
1581 | ldr PC, [BASE, FRAME_PC]
1590 | sub CARG3, BASE, #8
1591 | ldr PC, [BASE, FRAME_PC]
1596 | strd CARG12, [BASE]
1600 |.macro math_minmax, name, cond, fcond
1604 | checktp CARG2, LJ_TISNUM
1607 |1: // Handle integers.
1611 | checktp CARG4, LJ_TISNUM
1615 | mov..cond CARG1, CARG3
1617 |3: // Convert intermediate result to number and continue below.
1619 | bhi ->fff_fallback
1621 | vcvt.f64.s32 d0, s4
1626 | bhi ->fff_fallback
1627 |5: // Handle numbers.
1632 | checktp CARG4, LJ_TISNUM
1638 | vmov..fcond.f64 d0, d1
1640 |7: // Convert integer to number and continue above.
1642 | bhi ->fff_fallback
1643 | vcvt.f64.s32 d1, s4
1649 | checktp CARG2, LJ_TISNUM
1652 |1: // Handle integers.
1653 | ldrd CARG34, [BASE, RA]
1656 | checktp CARG4, LJ_TISNUM
1660 | mov..cond CARG1, CARG3
1662 |3: // Convert intermediate result to number and continue below.
1663 | bhi ->fff_fallback
1664 | bl extern __aeabi_i2d
1665 | ldrd CARG34, [BASE, RA]
1669 | bhi ->fff_fallback
1670 |5: // Handle numbers.
1671 | ldrd CARG34, [BASE, RA]
1674 | checktp CARG4, LJ_TISNUM
1677 | bl extern __aeabi_cdcmple
1679 | mov..fcond CARG1, CARG3
1680 | mov..fcond CARG2, CARG4
1682 |7: // Convert integer to number and continue above.
1683 | bhi ->fff_fallback
1686 | bl extern __aeabi_i2d
1692 | math_minmax math_min, gt, hi
1693 | math_minmax math_max, lt, lo
1695 |//-- String library -----------------------------------------------------
1697 |.ffunc_1 string_len
1698 | checkstr CARG2, ->fff_fallback
1699 | ldr CARG1, STR:CARG1->len
1700 | mvn CARG2, #~LJ_TISNUM
1703 |.ffunc string_byte // Only handle the 1-arg case here.
1704 | ldrd CARG12, [BASE]
1705 | ldr PC, [BASE, FRAME_PC]
1707 | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument.
1708 | bne ->fff_fallback
1709 | ldr CARG3, STR:CARG1->len
1710 | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
1711 | mvn CARG2, #~LJ_TISNUM
1713 | moveq RC, #(0+1)*8
1714 | movne RC, #(1+1)*8
1715 | strd CARG12, [BASE, #-8]
1718 |.ffunc string_char // Only handle the 1-arg case here.
1720 | ldrd CARG12, [BASE]
1721 | ldr PC, [BASE, FRAME_PC]
1722 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1723 | checktpeq CARG2, LJ_TISNUM
1724 | bicseq CARG4, CARG1, #255
1726 | bne ->fff_fallback
1728 | mov CARG2, TMPDp // Points to stack. Little-endian.
1730 | // CARG2 = str, CARG3 = len.
1734 | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
1735 | // Returns GCstr *.
1737 | mvn CARG2, #~LJ_TSTR
1742 | ldrd CARG12, [BASE]
1743 | ldrd CARG34, [BASE, #16]
1744 | cmp NARGS8:RC, #16
1747 | blo ->fff_fallback
1748 | checktp CARG4, LJ_TISNUM
1750 | bne ->fff_fallback
1752 | ldrd CARG34, [BASE, #8]
1753 | checktp CARG2, LJ_TSTR
1754 | ldreq CARG2, STR:CARG1->len
1755 | checktpeq CARG4, LJ_TISNUM
1756 | bne ->fff_fallback
1757 | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end
1758 | add CARG4, CARG2, #1
1759 | cmp CARG3, #0 // if (start < 0) start += len+1
1760 | addlt CARG3, CARG3, CARG4
1761 | cmp CARG3, #1 // if (start < 1) start = 1
1763 | cmp RB, #0 // if (end < 0) end += len+1
1764 | addlt RB, RB, CARG4
1765 | bic RB, RB, RB, asr #31 // if (end < 0) end = 0
1766 | cmp RB, CARG2 // if (end > len) end = len
1767 | add CARG1, STR:CARG1, #sizeof(GCstr)-1
1769 | add CARG2, CARG1, CARG3
1770 | subs CARG3, RB, CARG3 // len = end - start
1771 | add CARG3, CARG3, #1 // len += 1
1774 | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)
1775 | mvn CARG2, #~LJ_TSTR
1778 |.ffunc string_rep // Only handle the 1-char case inline.
1780 | ldrd CARG12, [BASE]
1781 | ldrd CARG34, [BASE, #8]
1782 | cmp NARGS8:RC, #16
1783 | bne ->fff_fallback // Exactly 2 arguments
1784 | checktp CARG2, LJ_TSTR
1785 | checktpeq CARG4, LJ_TISNUM
1786 | bne ->fff_fallback
1787 | subs CARG4, CARG3, #1
1788 | ldr CARG2, STR:CARG1->len
1789 | blt ->fff_emptystr // Count <= 0?
1791 | blo ->fff_emptystr // Zero-length string?
1792 | bne ->fff_fallback // Fallback for > 1-char strings.
1793 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1794 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1795 | ldr CARG1, STR:CARG1[1]
1797 | blo ->fff_fallback
1798 |1: // Fill buffer with char.
1799 | strb CARG1, [CARG2, CARG4]
1800 | subs CARG4, CARG4, #1
1804 |.ffunc string_reverse
1806 | ldrd CARG12, [BASE]
1808 | blo ->fff_fallback
1809 | checkstr CARG2, ->fff_fallback
1810 | ldr CARG3, STR:CARG1->len
1811 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1812 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1814 | add CARG1, STR:CARG1, #sizeof(GCstr)
1816 | blo ->fff_fallback
1817 |1: // Reverse string copy.
1818 | ldrb RB, [CARG1], #1
1819 | subs CARG4, CARG4, #1
1821 | strb RB, [CARG2, CARG4]
1824 |.macro ffstring_case, name, lo
1827 | ldrd CARG12, [BASE]
1829 | blo ->fff_fallback
1830 | checkstr CARG2, ->fff_fallback
1831 | ldr CARG3, STR:CARG1->len
1832 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1833 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1835 | add CARG1, STR:CARG1, #sizeof(GCstr)
1837 | blo ->fff_fallback
1838 |1: // ASCII case conversion.
1839 | ldrb RB, [CARG1, CARG4]
1844 | eorlo RB, RB, #0x20
1845 | strb RB, [CARG2, CARG4]
1846 | add CARG4, CARG4, #1
1850 |ffstring_case string_lower, 65
1851 |ffstring_case string_upper, 97
1853 |//-- Table library ------------------------------------------------------
1855 |.ffunc_1 table_getn
1856 | checktab CARG2, ->fff_fallback
1858 | bl extern lj_tab_len // (GCtab *t)
1859 | // Returns uint32_t (but less than 2^31).
1861 | mvn CARG2, #~LJ_TISNUM
1864 |//-- Bit library --------------------------------------------------------
1866 |// FP number to bit conversion for soft-float. Clobbers r0-r3.
1868 | bhi ->fff_fallback
1871 | adds RB, RB, #0x00200000
1872 | movpl CARG1, #0 // |x| < 1?
1875 | subs RB, CARG4, RB, asr #21
1876 | bmi >1 // |x| >= 2^32?
1877 | lsl CARG4, CARG2, #11
1878 | orr CARG4, CARG4, #0x80000000
1879 | orr CARG4, CARG4, CARG1, lsr #21
1881 | lsr CARG1, CARG4, RB
1882 | rsblt CARG1, CARG1, #0
1886 | lsr CARG4, CARG1, RB
1888 | lsl CARG1, CARG2, #12
1890 | orr CARG1, CARG4, CARG1, lsl RB
1891 | rsblt CARG1, CARG1, #0
1894 |.macro .ffunc_bit, name
1895 | .ffunc_1 bit_..name
1896 | checktp CARG2, LJ_TISNUM
1897 | blne ->vm_tobit_fb
1901 | mvn CARG2, #~LJ_TISNUM
1904 |.macro .ffunc_bit_op, name, ins
1909 | ldrd CARG12, [BASE, RA]
1913 | checktp CARG2, LJ_TISNUM
1914 | blne ->vm_tobit_fb
1915 | ins CARG3, CARG3, CARG1
1919 |.ffunc_bit_op band, and
1920 |.ffunc_bit_op bor, orr
1921 |.ffunc_bit_op bxor, eor
1924 | mvn CARG4, #~LJ_TISNUM
1925 | ldr PC, [BASE, FRAME_PC]
1926 | strd CARG34, [BASE, #-8]
1930 | eor CARG3, CARG1, CARG1, ror #16
1931 | bic CARG3, CARG3, #0x00ff0000
1932 | ror CARG1, CARG1, #8
1933 | mvn CARG2, #~LJ_TISNUM
1934 | eor CARG1, CARG1, CARG3, lsr #8
1939 | mvn CARG2, #~LJ_TISNUM
1942 |.macro .ffunc_bit_sh, name, ins, shmod
1944 | ldrd CARG12, [BASE, #8]
1945 | cmp NARGS8:RC, #16
1946 | blo ->fff_fallback
1947 | checktp CARG2, LJ_TISNUM
1948 | blne ->vm_tobit_fb
1950 | and RA, CARG1, #31
1954 | ldrd CARG12, [BASE]
1955 | checktp CARG2, LJ_TISNUM
1956 | blne ->vm_tobit_fb
1957 | ins CARG1, CARG1, RA
1958 | mvn CARG2, #~LJ_TISNUM
1962 |.ffunc_bit_sh lshift, lsl, 0
1963 |.ffunc_bit_sh rshift, lsr, 0
1964 |.ffunc_bit_sh arshift, asr, 0
1965 |.ffunc_bit_sh rol, ror, 1
1966 |.ffunc_bit_sh ror, ror, 0
1968 |//-----------------------------------------------------------------------
1970 |->fff_fallback: // Call fast function fallback handler.
1971 | // BASE = new base, RC = nargs*8
1972 | ldr CARG3, [BASE, FRAME_FUNC]
1973 | ldr CARG2, L->maxstack
1974 | add CARG1, BASE, NARGS8:RC
1975 | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC.
1977 | ldr CARG3, CFUNC:CARG3->f
1979 | add CARG1, CARG1, #8*LUA_MINSTACK
1980 | str PC, SAVE_PC // Redundant (but a defined value).
1983 | bhi >5 // Need to grow stack.
1984 | blx CARG3 // (lua_State *L)
1985 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
1990 | bgt ->fff_res // Returned nresults+1?
1991 |1: // Returned 0 or -1: retry fast path.
1993 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
1994 | sub NARGS8:RC, CARG1, BASE
1995 | bne ->vm_call_tail // Returned -1?
1996 | ins_callt // Returned 0: retry fast path.
1998 |// Reconstruct previous base for vmeta_call during tailcall.
2000 | ands CARG1, PC, #FRAME_TYPE
2001 | bic CARG2, PC, #FRAME_TYPEP
2002 | ldreq INS, [PC, #-4]
2003 | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8.
2004 | addeq CARG2, CARG2, #8
2005 | sub RB, BASE, CARG2
2006 | b ->vm_call_dispatch // Resolve again for tailcall.
2008 |5: // Grow stack for fallback handler.
2009 | mov CARG2, #LUA_MINSTACK
2010 | bl extern lj_state_growstack // (lua_State *L, int n)
2012 | cmp CARG1, CARG1 // Set zero-flag to force retry.
2015 |->fff_gcstep: // Call GC step function.
2016 | // BASE = new base, RC = nargs*8
2019 | add CARG2, BASE, NARGS8:RC
2020 | str PC, SAVE_PC // Redundant (but a defined value).
2023 | bl extern lj_gc_step // (lua_State *L)
2025 | mov lr, RA // Help return address predictor.
2026 | ldr CFUNC:CARG3, [BASE, FRAME_FUNC]
2029 |//-----------------------------------------------------------------------
2030 |//-- Special dispatch targets -------------------------------------------
2031 |//-----------------------------------------------------------------------
2033 |->vm_record: // Dispatch target for recording phase.
2035 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2036 | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent.
2038 | // Decrement the hookcount for consistency, but always do the call.
2039 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2040 | tst CARG1, #HOOK_ACTIVE
2042 | sub CARG2, CARG2, #1
2043 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
2044 | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2048 |->vm_rethook: // Dispatch target for return hooks.
2049 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2050 | tst CARG1, #HOOK_ACTIVE // Hook already active?
2052 |5: // Re-dispatch to static ins.
2054 | add OP, DISPATCH, OP, lsl #2
2055 | ldr pc, [OP, #GG_DISP2STATIC]
2057 |->vm_inshook: // Dispatch target for instr/line hooks.
2058 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2059 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2060 | tst CARG1, #HOOK_ACTIVE // Hook already active?
2062 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
2064 | subs CARG2, CARG2, #1
2065 | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2067 | tst CARG1, #LUA_MASKLINE
2073 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
2074 | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
2077 |4: // Re-dispatch to static ins.
2078 | ldrb OP, [PC, #-4]
2079 | ldr INS, [PC, #-4]
2080 | add OP, DISPATCH, OP, lsl #2
2081 | ldr OP, [OP, #GG_DISP2STATIC]
2082 | decode_RA8 RA, INS
2086 |->cont_hook: // Continue from hook yield.
2087 | ldr CARG1, [CARG4, #-24]
2089 | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins.
2092 |->vm_hotloop: // Hot loop counter underflow.
2094 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L).
2095 | sub CARG1, DISPATCH, #-GG_DISP2J
2097 | ldr CARG3, LFUNC:CARG3->field_pc
2099 | str L, [DISPATCH, #DISPATCH_J(L)]
2100 | ldrb CARG3, [CARG3, #PC2PROTO(framesize)]
2102 | add CARG3, BASE, CARG3, lsl #3
2104 | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
2108 |->vm_callhook: // Dispatch target for call hooks.
2114 |->vm_hotcall: // Hot call counter underflow.
2119 | add CARG4, BASE, RC
2125 | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
2126 | // Returns ASMFunction.
2131 | sub NARGS8:RC, CARG4, BASE
2132 | str CARG2, SAVE_PC // Invalidate for subsequent line hook.
2133 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2134 | ldr INS, [PC, #-4]
2137 |//-----------------------------------------------------------------------
2138 |//-- Trace exit handler -------------------------------------------------
2139 |//-----------------------------------------------------------------------
2144 | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}
2145 | ldr CARG1, [sp, #64] // Load original value of lr.
2146 | ldr DISPATCH, [lr] // Load DISPATCH.
2147 | add CARG3, sp, #64 // Recompute original value of sp.
2148 | mv_vmstate CARG4, EXIT
2149 | str CARG3, [sp, #52] // Store sp in RID_SP
2151 | ldr CARG2, [CARG1, #-4]! // Get exit instruction.
2152 | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC.
2153 | str CARG1, [sp, #60]
2157 | lsl CARG2, CARG2, #8
2158 | add CARG1, CARG1, CARG2, asr #6
2159 | ldr CARG2, [lr, #4] // Load exit stub group offset.
2160 | sub CARG1, CARG1, lr
2161 | ldr L, [DISPATCH, #DISPATCH_GL(jit_L)]
2162 | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number.
2163 | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
2164 | str CARG1, [DISPATCH, #DISPATCH_J(exitno)]
2166 | str L, [DISPATCH, #DISPATCH_J(L)]
2168 | str CARG4, [DISPATCH, #DISPATCH_GL(jit_L)]
2169 | sub CARG1, DISPATCH, #-GG_DISP2J
2171 | bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
2172 | // Returns MULTRES (unscaled) or negated error code.
2173 | ldr CARG2, L->cframe
2175 | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
2177 | ldr PC, SAVE_PC // Get SAVE_PC.
2178 | str L, SAVE_L // Set SAVE_L (on-trace resume/yield).
2182 | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.
2187 | blt >3 // Check for error from exit.
2189 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
2190 | str RC, SAVE_MULTRES
2192 | ldr CARG2, LFUNC:CARG2->field_pc
2193 | str CARG3, [DISPATCH, #DISPATCH_GL(jit_L)]
2194 | mv_vmstate CARG4, INTERP
2195 | ldr KBASE, [CARG2, #PC2PROTO(k)]
2196 | // Modified copy of ins_next which handles function header dispatch, too.
2200 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2202 | cmp OP, #BC_FUNCF // Function header?
2203 | ldr OP, [DISPATCH, OP, lsl #2]
2204 | decode_RA8 RA, INS
2205 | lsrlo RC, INS, #16 // No: Decode operands A*8 and D.
2207 | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8
2210 |3: // Rethrow error from the right C frame.
2211 | rsb CARG2, CARG1, #0
2213 | bl extern lj_err_throw // (lua_State *L, int errcode)
2216 |//-----------------------------------------------------------------------
2217 |//-- Math helper functions ----------------------------------------------
2218 |//-----------------------------------------------------------------------
2220 |// FP value rounding. Called from JIT code.
2222 |// double lj_vm_floor/ceil/trunc(double x);
2223 |.macro vm_round, func, hf
2226 | vmov d0, CARG1, CARG2
2227 | vldr d2, <8 // 2^52
2229 | vldr d2, <8 // 2^52
2230 | vmov CARG1, CARG2, d0
2233 | vcmp.f64 d1, d2 // |x| >= 2^52 or NaN?
2235 |.if "func" == "trunc"
2236 | bxpl lr // Return argument unchanged.
2237 | vadd.f64 d0, d1, d2
2238 | vsub.f64 d0, d0, d2 // (|x| + 2^52) - 2^52
2239 | vldr d2, <9 // +1.0
2240 | vcmp.f64 d1, d0 // |x| < result: subtract +1.0
2242 | vsubmi.f64 d0, d0, d2
2244 | vnegmi.f64 d0, d0 // Merge sign bit back in.
2246 | vadd.f64 d1, d1, d2
2247 | bxpl lr // Return argument unchanged.
2249 | vsub.f64 d1, d1, d2 // (|x| + 2^52) - 2^52
2250 | vldr d2, <9 // +1.0
2251 | vnegmi.f64 d1, d1 // Merge sign bit back in.
2252 |.if "func" == "floor"
2253 | vcmp.f64 d0, d1 // x < result: subtract +1.0.
2255 | vsubmi.f64 d0, d1, d2
2257 | vcmp.f64 d1, d0 // x > result: add +1.0.
2259 | vaddmi.f64 d0, d1, d2
2264 | vmov CARG1, CARG2, d0
2270 | lsl CARG3, CARG2, #1
2271 | adds RB, CARG3, #0x00200000
2272 | bpl >2 // |x| < 1?
2274 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2275 | bxlo lr // |x| >= 2^52: done.
2277 | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask
2278 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2280 | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask
2281 | orrpl CARG3, CARG3, CARG4
2283 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2284 |.if "func" == "floor"
2285 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2287 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2289 | bxeq lr // iszero: done.
2292 | lslpl CARG3, CARG4, RB
2295 | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask
2296 | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry
2300 | bxcs lr // |x| is not finite.
2301 | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo
2302 |.if "func" == "floor"
2303 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2305 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2307 | mov CARG1, #0 // lo = 0
2308 | and CARG2, CARG2, #0x80000000
2309 | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0)
2310 | orrne CARG2, CARG2, CARG4
2318 | .long 0, 0x3ff00000 // +1.0
2320 | .long 0, 0x43300000 // 2^52
2323 | .long 0x3ff00000 // hiword(+1.0)
2345 |.if JIT and not HFABI
2346 | lsl CARG3, CARG2, #1
2347 | adds RB, CARG3, #0x00200000
2348 | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0.
2352 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2353 | bxlo lr // |x| >= 2^52: already done.
2355 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2357 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2366 | // double lj_vm_mod(double dividend, double divisor);
2369 | // Special calling convention. Also, RC (r11) is not preserved.
2370 | vdiv.f64 d0, d6, d7
2373 | vmul.f64 d0, d0, d7
2375 | vsub.f64 d6, d6, d0
2378 | push {r0, r1, r2, r3, r4, lr}
2379 | bl extern __aeabi_ddiv
2381 | ldrd CARG34, [sp, #8]
2382 | bl extern __aeabi_dmul
2384 | eor CARG2, CARG2, #0x80000000
2385 | bl extern __aeabi_dadd
2390 | // int lj_vm_modi(int dividend, int divisor);
2392 | ands RB, CARG1, #0x80000000
2393 | rsbmi CARG1, CARG1, #0 // a = |dividend|
2394 | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor).
2396 | rsbmi CARG2, CARG2, #0 // b = |divisor|
2397 | subs CARG4, CARG2, #1
2398 | cmpne CARG1, CARG2
2399 | moveq CARG1, #0 // if (b == 1 || a == b) a = 0
2400 | tsthi CARG2, CARG4
2401 | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1
2403 | // Use repeated subtraction to get the remainder.
2406 | sub CARG4, CARG4, CARG3
2407 | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8
2408 | addne pc, pc, CARG3, lsl #3 // Duff's device.
2412 for (i = 31; i >= 0; i--) {
2413 | cmp CARG1, CARG2, lsl #i
2414 | subhs CARG1, CARG1, CARG2, lsl #i
2420 | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b
2421 | eors CARG2, CARG1, RB, lsl #1
2422 | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y
2425 |//-----------------------------------------------------------------------
2426 |//-- Miscellaneous functions --------------------------------------------
2427 |//-----------------------------------------------------------------------
2429 |//-----------------------------------------------------------------------
2430 |//-- FFI helper functions -----------------------------------------------
2431 |//-----------------------------------------------------------------------
2433 |// Handler for callback functions.
2434 |// Saveregs already performed. Callback slot number in [sp], g in r12.
2437 |.type CTSTATE, CTState, PC
2438 | ldr CTSTATE, GL:r12->ctype_state
2439 | add DISPATCH, r12, #GG_G2DISP
2442 | add r4, sp, CFRAME_SPACE+4+8*8
2443 | vstmdb r4!, {d8-d15}
2446 | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])
2448 | strd CARG34, CTSTATE->cb.gpr[2]
2449 | strd CARG12, CTSTATE->cb.gpr[0]
2451 | vstmdb r12!, {d0-d7}
2454 | add CARG3, sp, #CFRAME_SIZE
2455 | mov CARG1, CTSTATE
2456 | lsr CARG4, CARG4, #3
2457 | str CARG3, CTSTATE->cb.stack
2459 | str CARG4, CTSTATE->cb.slot
2460 | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
2461 | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
2462 | // Returns lua_State *.
2463 | ldr BASE, L:CRET1->base
2464 | mv_vmstate CARG2, INTERP
2465 | ldr RC, L:CRET1->top
2467 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2470 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2475 |->cont_ffi_callback: // Return from FFI callback.
2477 | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]
2481 | mov CARG1, CTSTATE
2483 | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
2484 | ldrd CARG12, CTSTATE->cb.gpr[0]
2486 | vldr d0, CTSTATE->cb.fpr[0]
2491 |->vm_ffi_call: // Call C function via FFI.
2492 | // Caveat: needs special frame unwinding, see below.
2494 | .type CCSTATE, CCallState, r4
2495 | push {CCSTATE, r5, r11, lr}
2496 | mov CCSTATE, CARG1
2497 | ldr CARG1, CCSTATE:CARG1->spadj
2498 | ldrb CARG2, CCSTATE->nsp
2499 | add CARG3, CCSTATE, #offsetof(CCallState, stack)
2501 | add RB, CCSTATE, #offsetof(CCallState, fpr[0])
2504 | sub sp, sp, CARG1 // Readjust stack.
2505 | subs CARG2, CARG2, #1
2509 | ldr RB, CCSTATE->func
2511 |1: // Copy stack slots.
2512 | ldr CARG4, [CARG3, CARG2, lsl #2]
2513 | str CARG4, [sp, CARG2, lsl #2]
2514 | subs CARG2, CARG2, #1
2517 | ldrd CARG12, CCSTATE->gpr[0]
2518 | ldrd CARG34, CCSTATE->gpr[2]
2522 | add r12, CCSTATE, #offsetof(CCallState, fpr[4])
2524 | strd CRET1, CCSTATE->gpr[0]
2526 | vstmdb r12!, {d0-d3}
2528 | pop {CCSTATE, r5, r11, pc}
2530 |// Note: vm_ffi_call must be the last function in this object file!
2532 |//-----------------------------------------------------------------------
2535 /* Generate the code for a single instruction. */
2536 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2543 /* -- Comparison ops ---------------------------------------------------- */
2545 /* Remember: all ops branch for a true comparison, fall through otherwise. */
2547 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
2548 | // RA = src1*8, RC = src2, JMP with RC = target
2550 | ldrd CARG12, [RA, BASE]!
2552 | ldrd CARG34, [RC, BASE]!
2554 | add RB, PC, RB, lsl #2
2555 | checktp CARG2, LJ_TISNUM
2557 | checktp CARG4, LJ_TISNUM
2560 if (op == BC_ISLT) {
2561 | sublt PC, RB, #0x20000
2562 } else if (op == BC_ISGE) {
2563 | subge PC, RB, #0x20000
2564 } else if (op == BC_ISLE) {
2565 | suble PC, RB, #0x20000
2567 | subgt PC, RB, #0x20000
2572 |3: // CARG12 is not an integer.
2576 | // d0 is a number.
2577 | checktp CARG4, LJ_TISNUM
2580 | // d0 is a number, CARG3 is an integer.
2582 | vcvt.f64.s32 d1, s4
2584 |4: // CARG1 is an integer, CARG34 is not an integer.
2587 | // CARG1 is an integer, d1 is a number.
2589 | vcvt.f64.s32 d0, s4
2590 |5: // d0 and d1 are numbers.
2593 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2594 if (op == BC_ISLT) {
2595 | sublo PC, RB, #0x20000
2596 } else if (op == BC_ISGE) {
2597 | subhs PC, RB, #0x20000
2598 } else if (op == BC_ISLE) {
2599 | subls PC, RB, #0x20000
2601 | subhi PC, RB, #0x20000
2606 | // CARG12 is a number.
2607 | checktp CARG4, LJ_TISNUM
2608 | movlo RA, RB // Save RB.
2610 | // CARG12 is a number, CARG3 is an integer.
2613 | mov RA, RB // Save RB.
2614 | bl extern __aeabi_i2d
2617 | ldrd CARG12, [RC] // Restore first operand.
2619 |4: // CARG1 is an integer, CARG34 is not an integer.
2621 | // CARG1 is an integer, CARG34 is a number.
2622 | mov RA, RB // Save RB.
2623 | bl extern __aeabi_i2d
2624 | ldrd CARG34, [RC] // Restore second operand.
2625 |5: // CARG12 and CARG34 are numbers.
2626 | bl extern __aeabi_cdcmple
2627 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2628 if (op == BC_ISLT) {
2629 | sublo PC, RA, #0x20000
2630 } else if (op == BC_ISGE) {
2631 | subhs PC, RA, #0x20000
2632 } else if (op == BC_ISLE) {
2633 | subls PC, RA, #0x20000
2635 | subhi PC, RA, #0x20000
2641 case BC_ISEQV: case BC_ISNEV:
2642 vk = op == BC_ISEQV;
2643 | // RA = src1*8, RC = src2, JMP with RC = target
2645 | ldrd CARG12, [RA, BASE]!
2647 | ldrd CARG34, [RC, BASE]!
2649 | add RB, PC, RB, lsl #2
2650 | checktp CARG2, LJ_TISNUM
2651 | cmnls CARG4, #-LJ_TISNUM
2657 | // Either or both types are not numbers.
2659 | checktp CARG2, LJ_TCDATA
2660 | checktpne CARG4, LJ_TCDATA
2661 | beq ->vmeta_equal_cd
2663 | cmp CARG2, CARG4 // Compare types.
2664 | bne >2 // Not the same type?
2665 | checktp CARG2, LJ_TISPRI
2666 | bhs >1 // Same type and primitive type?
2668 | // Same types and not a primitive type. Compare GCobj or pvalue.
2671 | bne >3 // Different GCobjs or pvalues?
2672 |1: // Branch if same.
2673 | sub PC, RB, #0x20000
2677 | checktp CARG2, LJ_TISTABUD
2678 | bhi <2 // Different objects and not table/ud?
2680 | beq >1 // Same GCobjs or pvalues?
2681 | checktp CARG2, LJ_TISTABUD
2682 | bhi >2 // Different objects and not table/ud?
2684 | // Different tables or userdatas. Need to check __eq metamethod.
2685 | // Field metatable must be at same offset for GCtab and GCudata!
2686 | ldr TAB:RA, TAB:CARG1->metatable
2689 | beq <2 // No metatable?
2691 | beq >2 // No metatable?
2693 | ldrb RA, TAB:RA->nomm
2694 | mov CARG4, #1-vk // ne = 0 or 1.
2697 | beq ->vmeta_equal // 'no __eq' flag not set?
2701 |2: // Branch if different.
2702 | sub PC, RB, #0x20000
2708 case BC_ISEQS: case BC_ISNES:
2709 vk = op == BC_ISEQS;
2710 | // RA = src*8, RC = str_const (~), JMP with RC = target
2712 | ldrd CARG12, [BASE, RA]
2714 | ldr STR:CARG3, [KBASE, RC, lsl #2]
2716 | add RB, PC, RB, lsl #2
2717 | checktp CARG2, LJ_TSTR
2722 | cmpeq CARG1, CARG3
2725 | subeq PC, RB, #0x20000
2729 | subne PC, RB, #0x20000
2735 | checktp CARG2, LJ_TCDATA
2737 | b ->vmeta_equal_cd
2741 case BC_ISEQN: case BC_ISNEN:
2742 vk = op == BC_ISEQN;
2743 | // RA = src*8, RC = num_const (~), JMP with RC = target
2745 | ldrd CARG12, [RA, BASE]!
2747 | ldrd CARG34, [RC, KBASE]!
2749 | add RB, PC, RB, lsl #2
2755 | checktp CARG2, LJ_TISNUM
2757 | checktp CARG4, LJ_TISNUM
2761 | subeq PC, RB, #0x20000
2765 | subne PC, RB, #0x20000
2770 |3: // CARG12 is not an integer.
2775 | subhi PC, RB, #0x20000
2780 | checktp CARG4, LJ_TISNUM
2784 | vcvths.f64.s32 d1, s4
2786 |4: // CARG1 is an integer, d1 is a number.
2789 | vcvt.f64.s32 d0, s4
2790 |5: // d0 and d1 are numbers.
2794 | subeq PC, RB, #0x20000
2796 | subne PC, RB, #0x20000
2800 | // CARG12 is a number.
2801 | checktp CARG4, LJ_TISNUM
2802 | movlo RA, RB // Save RB.
2804 | // CARG12 is a number, CARG3 is an integer.
2807 |4: // CARG1 is an integer, CARG34 is a number.
2808 | mov RA, RB // Save RB.
2809 | bl extern __aeabi_i2d
2810 | ldrd CARG34, [RC] // Restore other operand.
2811 |5: // CARG12 and CARG34 are numbers.
2812 | bl extern __aeabi_cdcmpeq
2814 | subeq PC, RA, #0x20000
2816 | subne PC, RA, #0x20000
2823 | checktp CARG2, LJ_TCDATA
2825 | b ->vmeta_equal_cd
2829 case BC_ISEQP: case BC_ISNEP:
2830 vk = op == BC_ISEQP;
2831 | // RA = src*8, RC = primitive_type (~), JMP with RC = target
2832 | ldrd CARG12, [BASE, RA]
2836 | add RB, PC, RB, lsl #2
2838 | checktp CARG2, LJ_TCDATA
2839 | beq ->vmeta_equal_cd
2843 | subeq PC, RB, #0x20000
2845 | subne PC, RB, #0x20000
2850 /* -- Unary test and copy ops ------------------------------------------- */
2852 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
2853 | // RA = dst*8 or unused, RC = src, JMP with RC = target
2854 | add RC, BASE, RC, lsl #3
2858 | add RB, PC, RB, lsl #2
2859 | checktp CARG2, LJ_TTRUE
2860 if (op == BC_ISTC || op == BC_IST) {
2861 | subls PC, RB, #0x20000
2862 if (op == BC_ISTC) {
2863 | strdls CARG12, [BASE, RA]
2866 | subhi PC, RB, #0x20000
2867 if (op == BC_ISFC) {
2868 | strdhi CARG12, [BASE, RA]
2874 /* -- Unary ops --------------------------------------------------------- */
2877 | // RA = dst*8, RC = src
2880 | ldrd CARG12, [BASE, RC]
2882 | strd CARG12, [BASE, RA]
2886 | // RA = dst*8, RC = src
2887 | add RC, BASE, RC, lsl #3
2889 | ldr CARG1, [RC, #4]
2892 | checktp CARG1, LJ_TTRUE
2893 | mvnls CARG2, #~LJ_TFALSE
2894 | mvnhi CARG2, #~LJ_TTRUE
2895 | str CARG2, [RA, #4]
2899 | // RA = dst*8, RC = src
2901 | ldrd CARG12, [BASE, RC]
2904 | checktp CARG2, LJ_TISNUM
2906 | eorne CARG2, CARG2, #0x80000000
2908 | rsbseq CARG1, CARG1, #0
2911 | strd CARG12, [BASE, RA]
2916 | .long 0x00000000, 0x41e00000 // 2^31.
2919 | // RA = dst*8, RC = src
2921 | ldrd CARG12, [BASE, RC]
2922 | checkstr CARG2, >2
2923 | ldr CARG1, STR:CARG1->len
2925 | mvn CARG2, #~LJ_TISNUM
2928 | strd CARG12, [BASE, RA]
2931 | checktab CARG2, ->vmeta_len
2933 | ldr TAB:CARG3, TAB:CARG1->metatable
2940 | bl extern lj_tab_len // (GCtab *t)
2941 | // Returns uint32_t (but less than 2^31).
2946 | ldrb CARG4, TAB:CARG3->nomm
2947 | tst CARG4, #1<<MM_len
2948 | bne <3 // 'no __len' flag set: done.
2953 /* -- Binary ops -------------------------------------------------------- */
2955 |.macro ins_arithcheck, cond, ncond, target
2957 | cmn CARG4, #-LJ_TISNUM
2958 | cmn..cond CARG2, #-LJ_TISNUM
2960 | cmn CARG2, #-LJ_TISNUM
2961 | cmn..cond CARG4, #-LJ_TISNUM
2965 |.macro ins_arithcheck_int, target
2966 | ins_arithcheck eq, ne, target
2968 |.macro ins_arithcheck_num, target
2969 | ins_arithcheck lo, hs, target
2972 |.macro ins_arithpre
2973 | decode_RB8 RB, INS
2974 | decode_RC8 RC, INS
2975 | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
2976 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
2980 | ldrd CARG12, [RB, BASE]!
2981 | ldrd CARG34, [RC, KBASE]!
2983 | ldrd CARG12, [BASE, RB]
2984 | ldrd CARG34, [KBASE, RC]
2989 | ldrd CARG34, [RB, BASE]!
2990 | ldrd CARG12, [RC, KBASE]!
2992 | ldrd CARG34, [BASE, RB]
2993 | ldrd CARG12, [KBASE, RC]
2998 | ldrd CARG12, [RB, BASE]!
2999 | ldrd CARG34, [RC, BASE]!
3001 | ldrd CARG12, [BASE, RB]
3002 | ldrd CARG34, [BASE, RC]
3008 |.macro ins_arithpre_fpu, reg1, reg2
3020 |.macro ins_arithpost_fpu, reg
3028 |.macro ins_arithfallback, ins
3031 | ins ->vmeta_arith_vn
3034 | ins ->vmeta_arith_nv
3037 | ins ->vmeta_arith_vv
3042 |.macro ins_arithdn, intins, fpins, fpcall
3044 |.if "intins" ~= "vm_modi" and not FPU
3047 | ins_arithcheck_int >5
3048 |.if "intins" == "smull"
3049 | smull CARG1, RC, CARG3, CARG1
3050 | cmp RC, CARG1, asr #31
3051 | ins_arithfallback bne
3052 |.elif "intins" == "vm_modi"
3054 | ins_arithfallback beq
3056 | mvn CARG2, #~LJ_TISNUM
3058 | intins CARG1, CARG1, CARG3
3059 | ins_arithfallback bvs
3062 |.if "intins" == "vm_modi" or FPU
3066 | strd CARG12, [BASE, RA]
3069 | ins_arithpre_fpu d6, d7
3070 | ins_arithfallback ins_arithcheck_num
3072 |.if "intins" == "vm_modi"
3077 | ins_arithpost_fpu d6
3080 |.if "intins" ~= "vm_modi"
3087 |.macro ins_arithfp, fpins, fpcall
3089 |.if "fpins" ~= "extern" or HFABI
3090 | ins_arithpre_fpu d0, d1
3092 | ins_arithfallback ins_arithcheck_num
3093 |.if "fpins" == "extern"
3102 |.if ("fpins" ~= "extern" or HFABI) and FPU
3103 | ins_arithpost_fpu d0
3107 | strd CARG12, [BASE, RA]
3112 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
3113 | ins_arithdn adds, vadd.f64, extern __aeabi_dadd
3115 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
3116 | ins_arithdn subs, vsub.f64, extern __aeabi_dsub
3118 case BC_MULVN: case BC_MULNV: case BC_MULVV:
3119 | ins_arithdn smull, vmul.f64, extern __aeabi_dmul
3121 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
3122 | ins_arithfp vdiv.f64, extern __aeabi_ddiv
3124 case BC_MODVN: case BC_MODNV: case BC_MODVV:
3125 | ins_arithdn vm_modi, vm_mod, ->vm_mod
3128 | // NYI: (partial) integer arithmetic.
3129 | ins_arithfp extern, extern pow
3133 | decode_RB8 RC, INS
3134 | decode_RC8 RB, INS
3135 | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!)
3138 | add CARG2, BASE, RB
3140 | // RA = dst*8, RC = src_start*8, CARG2 = top-1
3143 | lsr CARG3, CARG3, #3
3144 | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
3145 | // Returns NULL (finished) or TValue * (metamethod).
3149 | ldrd CARG34, [BASE, RC]
3152 | strd CARG34, [BASE, RA] // Copy result to RA.
3156 /* -- Constant ops ------------------------------------------------------ */
3159 | // RA = dst*8, RC = str_const (~)
3162 | ldr CARG1, [KBASE, RC, lsl #2]
3163 | mvn CARG2, #~LJ_TSTR
3165 | strd CARG12, [BASE, RA]
3170 | // RA = dst*8, RC = cdata_const (~)
3173 | ldr CARG1, [KBASE, RC, lsl #2]
3174 | mvn CARG2, #~LJ_TCDATA
3176 | strd CARG12, [BASE, RA]
3181 | // RA = dst*8, (RC = int16_literal)
3182 | mov CARG1, INS, asr #16 // Refetch sign-extended reg.
3183 | mvn CARG2, #~LJ_TISNUM
3186 | strd CARG12, [BASE, RA]
3190 | // RA = dst*8, RC = num_const
3193 | ldrd CARG12, [KBASE, RC]
3195 | strd CARG12, [BASE, RA]
3199 | // RA = dst*8, RC = primitive_type (~)
3208 | // RA = base*8, RC = end
3210 | add RC, BASE, RC, lsl #3
3211 | mvn CARG1, #~LJ_TNIL
3212 | str CARG1, [RA, #4]
3215 | str CARG1, [RA, #4]
3222 /* -- Upvalue and function ops ------------------------------------------ */
3225 | // RA = dst*8, RC = uvnum
3226 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3228 | add RC, RC, #offsetof(GCfuncL, uvptr)
3229 | ldr UPVAL:CARG2, [LFUNC:CARG2, RC]
3230 | ldr CARG2, UPVAL:CARG2->v
3231 | ldrd CARG34, [CARG2]
3234 | strd CARG34, [BASE, RA]
3238 | // RA = uvnum*8, RC = src
3239 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3241 | add RA, RA, #offsetof(GCfuncL, uvptr)
3243 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3244 | ldrd CARG34, [BASE, RC]
3245 | ldrb RB, UPVAL:CARG2->marked
3246 | ldrb RC, UPVAL:CARG2->closed
3247 | ldr CARG2, UPVAL:CARG2->v
3248 | tst RB, #LJ_GC_BLACK // isblack(uv)
3249 | add RB, CARG4, #-LJ_TISGCV
3251 | strd CARG34, [CARG2]
3252 | bne >2 // Upvalue is closed and black?
3256 |2: // Check if new value is collectable.
3257 | cmn RB, #-(LJ_TISNUM - LJ_TISGCV)
3258 | ldrbhi RC, GCOBJ:CARG3->gch.marked
3259 | bls <1 // tvisgcv(v)
3260 | sub CARG1, DISPATCH, #-GG_DISP2G
3261 | tst RC, #LJ_GC_WHITES
3262 | // Crossed a write barrier. Move the barrier forward.
3266 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3269 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3274 | // RA = uvnum*8, RC = str_const (~)
3275 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3277 | add RA, RA, #offsetof(GCfuncL, uvptr)
3279 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3280 | ldr STR:CARG3, [KBASE, RC, lsl #2]
3281 | mvn CARG4, #~LJ_TSTR
3282 | ldrb RB, UPVAL:CARG2->marked
3283 | ldr CARG2, UPVAL:CARG2->v
3284 | ldrb RC, UPVAL:CARG2->closed
3285 | tst RB, #LJ_GC_BLACK // isblack(uv)
3286 | ldrb RB, STR:CARG3->marked
3287 | strd CARG34, [CARG2]
3292 |2: // Check if string is white and ensure upvalue is closed.
3293 | tst RB, #LJ_GC_WHITES // iswhite(str)
3295 | sub CARG1, DISPATCH, #-GG_DISP2G
3296 | // Crossed a write barrier. Move the barrier forward.
3300 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3303 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3308 | // RA = uvnum*8, RC = num_const
3309 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3311 | add RA, RA, #offsetof(GCfuncL, uvptr)
3313 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3314 | ldrd CARG34, [KBASE, RC]
3315 | ldr CARG2, UPVAL:CARG2->v
3318 | strd CARG34, [CARG2]
3322 | // RA = uvnum*8, RC = primitive_type (~)
3323 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3325 | add RA, RA, #offsetof(GCfuncL, uvptr)
3326 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3328 | ldr CARG2, UPVAL:CARG2->v
3331 | str RC, [CARG2, #4]
3336 | // RA = level*8, RC = target
3337 | ldr CARG3, L->openupval
3338 | add RC, PC, RC, lsl #2
3341 | sub PC, RC, #0x20000
3344 | add CARG2, BASE, RA
3345 | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
3352 | // RA = dst*8, RC = proto_const (~) (holding function prototype)
3355 | ldr CARG2, [KBASE, RC, lsl #2]
3357 | ldr CARG3, [BASE, FRAME_FUNC]
3359 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
3360 | bl extern lj_func_newL_gc
3361 | // Returns GCfuncL *.
3363 | mvn CARG2, #~LJ_TFUNC
3366 | strd CARG12, [BASE, RA]
3370 /* -- Table ops --------------------------------------------------------- */
3374 | // RA = dst*8, RC = (hbits|asize) | tab_const (~)
3375 if (op == BC_TDUP) {
3378 | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]
3379 | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]
3386 if (op == BC_TNEW) {
3387 | lsl CARG2, RC, #21
3388 | lsr CARG3, RC, #11
3389 | asr RC, CARG2, #21
3390 | lsr CARG2, CARG2, #21
3392 | addeq CARG2, CARG2, #2
3393 | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
3394 | // Returns GCtab *.
3396 | ldr CARG2, [KBASE, RC, lsl #2]
3397 | bl extern lj_tab_dup // (lua_State *L, Table *kt)
3398 | // Returns GCtab *.
3401 | mvn CARG2, #~LJ_TTAB
3404 | strd CARG12, [BASE, RA]
3407 | bl extern lj_gc_step_fixtop // (lua_State *L)
3413 | // RA = dst*8, RC = str_const (~)
3415 | // RA = dst*8, RC = str_const (~)
3416 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3418 | ldr TAB:CARG1, LFUNC:CARG2->env
3419 | ldr STR:RC, [KBASE, RC, lsl #2]
3420 if (op == BC_GGET) {
3428 | decode_RB8 RB, INS
3429 | decode_RC8 RC, INS
3430 | // RA = dst*8, RB = table*8, RC = key*8
3431 | ldrd TAB:CARG12, [BASE, RB]
3432 | ldrd CARG34, [BASE, RC]
3433 | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12.
3434 | checktp CARG4, LJ_TISNUM // Integer key?
3435 | ldreq CARG4, TAB:CARG1->array
3436 | ldreq CARG2, TAB:CARG1->asize
3439 | add CARG4, CARG4, CARG3, lsl #3
3440 | cmp CARG3, CARG2 // In array part?
3441 | ldrdlo CARG34, [CARG4]
3443 | ins_next1 // Overwrites RB!
3444 | checktp CARG4, LJ_TNIL
3448 | strd CARG34, [BASE, RA]
3451 |5: // Check for __index if table value is nil.
3452 | ldr TAB:CARG2, TAB:CARG1->metatable
3454 | beq <1 // No metatable: done.
3455 | ldrb CARG2, TAB:CARG2->nomm
3456 | tst CARG2, #1<<MM_index
3457 | bne <1 // 'no __index' flag set: done.
3458 | decode_RB8 RB, INS // Restore RB.
3462 | checktp CARG4, LJ_TSTR // String key?
3463 | moveq STR:RC, CARG3
3468 | decode_RB8 RB, INS
3470 | // RA = dst*8, RB = table*8, RC = str_const (~)
3471 | ldrd CARG12, [BASE, RB]
3473 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3474 | checktab CARG2, ->vmeta_tgets1
3476 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3477 | ldr CARG3, TAB:CARG1->hmask
3478 | ldr CARG4, STR:RC->hash
3479 | ldr NODE:INS, TAB:CARG1->node
3480 | mov TAB:RB, TAB:CARG1
3481 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3482 | add CARG3, CARG3, CARG3, lsl #1
3483 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3485 | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS.
3486 | ldrd CARG34, NODE:INS->val
3487 | ldr NODE:INS, NODE:INS->next
3488 | checktp CARG2, LJ_TSTR
3489 | cmpeq CARG1, STR:RC
3491 | checktp CARG4, LJ_TNIL
3496 | strd CARG34, [BASE, RA]
3499 |4: // Follow hash chain.
3502 | // End of hash chain: key not found, nil result.
3504 |5: // Check for __index if table value is nil.
3505 | ldr TAB:CARG1, TAB:RB->metatable
3506 | mov CARG3, #0 // Optional clear of undef. value (during load stall).
3507 | mvn CARG4, #~LJ_TNIL
3509 | beq <3 // No metatable: done.
3510 | ldrb CARG2, TAB:CARG1->nomm
3511 | tst CARG2, #1<<MM_index
3512 | bne <3 // 'no __index' flag set: done.
3516 | decode_RB8 RB, INS
3518 | // RA = dst*8, RB = table*8, RC = index
3519 | ldrd CARG12, [BASE, RB]
3520 | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12.
3521 | ldr CARG3, TAB:CARG1->asize
3522 | ldr CARG4, TAB:CARG1->array
3525 | ldrdlo CARG34, [CARG4, CARG2]
3527 | ins_next1 // Overwrites RB!
3528 | checktp CARG4, LJ_TNIL
3532 | strd CARG34, [BASE, RA]
3535 |5: // Check for __index if table value is nil.
3536 | ldr TAB:CARG2, TAB:CARG1->metatable
3538 | beq <1 // No metatable: done.
3539 | ldrb CARG2, TAB:CARG2->nomm
3540 | tst CARG2, #1<<MM_index
3541 | bne <1 // 'no __index' flag set: done.
3546 | decode_RB8 RB, INS
3547 | decode_RC8 RC, INS
3548 | // RA = src*8, RB = table*8, RC = key*8
3549 | ldrd TAB:CARG12, [BASE, RB]
3550 | ldrd CARG34, [BASE, RC]
3551 | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12.
3552 | checktp CARG4, LJ_TISNUM // Integer key?
3553 | ldreq CARG2, TAB:CARG1->array
3554 | ldreq CARG4, TAB:CARG1->asize
3557 | add CARG2, CARG2, CARG3, lsl #3
3558 | cmp CARG3, CARG4 // In array part?
3559 | ldrlo INS, [CARG2, #4]
3561 | ins_next1 // Overwrites RB!
3562 | checktp INS, LJ_TNIL
3563 | ldrb INS, TAB:CARG1->marked
3564 | ldrd CARG34, [BASE, RA]
3567 | tst INS, #LJ_GC_BLACK // isblack(table)
3568 | strd CARG34, [CARG2]
3574 |5: // Check for __newindex if previous value is nil.
3575 | ldr TAB:RA, TAB:CARG1->metatable
3577 | beq <1 // No metatable: done.
3578 | ldrb RA, TAB:RA->nomm
3579 | tst RA, #1<<MM_newindex
3580 | bne <1 // 'no __newindex' flag set: done.
3581 | ldr INS, [PC, #-4] // Restore RA and RB.
3582 | decode_RB8 RB, INS
3583 | decode_RA8 RA, INS
3586 |7: // Possible table write barrier for the value. Skip valiswhite check.
3587 | barrierback TAB:CARG1, INS, CARG3
3591 | checktp CARG4, LJ_TSTR // String key?
3592 | moveq STR:RC, CARG3
3597 | decode_RB8 RB, INS
3599 | // RA = src*8, RB = table*8, RC = str_const (~)
3600 | ldrd CARG12, [BASE, RB]
3602 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3603 | checktab CARG2, ->vmeta_tsets1
3605 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3606 | ldr CARG3, TAB:CARG1->hmask
3607 | ldr CARG4, STR:RC->hash
3608 | ldr NODE:INS, TAB:CARG1->node
3609 | mov TAB:RB, TAB:CARG1
3610 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3611 | add CARG3, CARG3, CARG3, lsl #1
3613 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3614 | strb CARG4, TAB:RB->nomm // Clear metamethod cache.
3616 | ldrd CARG12, NODE:INS->key
3617 | ldr CARG4, NODE:INS->val.it
3618 | ldr NODE:CARG3, NODE:INS->next
3619 | checktp CARG2, LJ_TSTR
3620 | cmpeq CARG1, STR:RC
3622 | ldrb CARG2, TAB:RB->marked
3623 | checktp CARG4, LJ_TNIL // Key found, but nil value?
3624 | ldrd CARG34, [BASE, RA]
3627 | tst CARG2, #LJ_GC_BLACK // isblack(table)
3628 | strd CARG34, NODE:INS->val
3633 |4: // Check for __newindex if previous value is nil.
3634 | ldr TAB:CARG1, TAB:RB->metatable
3636 | beq <2 // No metatable: done.
3637 | ldrb CARG1, TAB:CARG1->nomm
3638 | tst CARG1, #1<<MM_newindex
3639 | bne <2 // 'no __newindex' flag set: done.
3642 |5: // Follow hash chain.
3643 | movs NODE:INS, NODE:CARG3
3645 | // End of hash chain: key not found, add a new one.
3647 | // But check for __newindex first.
3648 | ldr TAB:CARG1, TAB:RB->metatable
3651 | cmp TAB:CARG1, #0 // No metatable: continue.
3653 | ldrbne CARG2, TAB:CARG1->nomm
3656 | tst CARG2, #1<<MM_newindex
3657 | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
3659 | mvn CARG4, #~LJ_TSTR
3660 | str STR:RC, TMPDlo
3663 | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
3664 | // Returns TValue *.
3666 | ldrd CARG34, [BASE, RA]
3667 | strd CARG34, [CRET1]
3668 | b <3 // No 2nd write barrier needed.
3670 |7: // Possible table write barrier for the value. Skip valiswhite check.
3671 | barrierback TAB:RB, CARG2, CARG3
3675 | decode_RB8 RB, INS
3677 | // RA = src*8, RB = table*8, RC = index
3678 | ldrd CARG12, [BASE, RB]
3679 | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12.
3680 | ldr CARG3, TAB:CARG1->asize
3681 | ldr RB, TAB:CARG1->array
3684 | ldrdlo CARG34, [CARG2, RB]!
3686 | ins_next1 // Overwrites RB!
3687 | checktp CARG4, LJ_TNIL
3688 | ldrb INS, TAB:CARG1->marked
3689 | ldrd CARG34, [BASE, RA]
3692 | tst INS, #LJ_GC_BLACK // isblack(table)
3693 | strd CARG34, [CARG2]
3699 |5: // Check for __newindex if previous value is nil.
3700 | ldr TAB:RA, TAB:CARG1->metatable
3702 | beq <1 // No metatable: done.
3703 | ldrb RA, TAB:RA->nomm
3704 | tst RA, #1<<MM_newindex
3705 | bne <1 // 'no __newindex' flag set: done.
3706 | ldr INS, [PC, #-4] // Restore INS.
3707 | decode_RA8 RA, INS
3710 |7: // Possible table write barrier for the value. Skip valiswhite check.
3711 | barrierback TAB:CARG1, INS, CARG3
3716 | // RA = base*8 (table at base-1), RC = num_const (start index)
3719 | ldr RB, SAVE_MULTRES
3720 | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table.
3721 | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word.
3723 | ldr CARG4, TAB:CARG2->asize
3724 | beq >4 // Nothing to copy?
3725 | add CARG3, CARG1, RB, lsr #3
3727 | ldr CARG4, TAB:CARG2->array
3730 | add INS, CARG4, CARG1, lsl #3
3731 | ldrb CARG1, TAB:CARG2->marked
3732 |3: // Copy result slots to table.
3733 | ldrd CARG34, [RA], #8
3734 | strd CARG34, [INS], #8
3737 | tst CARG1, #LJ_GC_BLACK // isblack(table)
3742 |5: // Need to resize array part.
3746 | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
3747 | // Must not reallocate the stack.
3748 | .IOS ldr BASE, L->base
3751 |7: // Possible table write barrier for any value. Skip valiswhite check.
3752 | barrierback TAB:CARG2, CARG1, CARG3
3756 /* -- Calls and vararg handling ----------------------------------------- */
3759 | // RA = base*8, (RB = nresults+1,) RC = extra_nargs
3760 | ldr CARG1, SAVE_MULTRES
3761 | decode_RC8 NARGS8:RC, INS
3762 | add NARGS8:RC, NARGS8:RC, CARG1
3766 | decode_RC8 NARGS8:RC, INS
3767 | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8
3769 | mov RB, BASE // Save old BASE for vmeta_call.
3770 | ldrd CARG34, [BASE, RA]!
3771 | sub NARGS8:RC, NARGS8:RC, #8
3772 | add BASE, BASE, #8
3773 | checkfunc CARG4, ->vmeta_call
3778 | // RA = base*8, (RB = 0,) RC = extra_nargs
3779 | ldr CARG1, SAVE_MULTRES
3780 | add NARGS8:RC, CARG1, RC, lsl #3
3784 | lsl NARGS8:RC, RC, #3
3785 | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
3787 | ldrd LFUNC:CARG34, [RA, BASE]!
3788 | sub NARGS8:RC, NARGS8:RC, #8
3790 | checkfunc CARG4, ->vmeta_callt
3791 | ldr PC, [BASE, FRAME_PC]
3794 | ldrb CARG4, LFUNC:CARG3->ffid
3795 | tst PC, #FRAME_TYPE
3798 | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC.
3802 | ldrd CARG12, [RA, RB]
3804 | cmp INS, NARGS8:RC
3805 | strd CARG12, [BASE, RB]
3809 | cmp CARG4, #1 // (> FF_C) Calling a fast function?
3814 |5: // Tailcall to a fast function with a Lua frame below.
3815 | ldr INS, [PC, #-4]
3816 | decode_RA8 RA, INS
3817 | sub CARG1, BASE, RA
3818 | ldr LFUNC:CARG1, [CARG1, #-16]
3819 | ldr CARG1, LFUNC:CARG1->field_pc
3820 | ldr KBASE, [CARG1, #PC2PROTO(k)]
3823 |7: // Tailcall from a vararg function.
3824 | eor PC, PC, #FRAME_VARG
3825 | tst PC, #FRAME_TYPEP // Vararg frame below?
3826 | movne CARG4, #0 // Clear ffid if no Lua function below.
3828 | sub BASE, BASE, PC
3829 | ldr PC, [BASE, FRAME_PC]
3830 | tst PC, #FRAME_TYPE
3831 | movne CARG4, #0 // Clear ffid if no Lua function below.
3836 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3838 | mov RB, BASE // Save old BASE for vmeta_call.
3839 | ldrd CARG34, [RA, #-16]
3840 | ldrd CARG12, [RA, #-8]
3842 | strd CARG34, [RA, #8] // Copy state.
3843 | strd CARG12, [RA, #16] // Copy control var.
3844 | // STALL: locked CARG34.
3845 | ldrd LFUNC:CARG34, [RA, #-24]
3846 | mov NARGS8:RC, #16 // Iterators get 2 arguments.
3847 | // STALL: load CARG34.
3848 | strd LFUNC:CARG34, [RA] // Copy callable.
3849 | checkfunc CARG4, ->vmeta_call
3854 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3856 | // NYI: add hotloop, record BC_ITERN.
3859 | ldr TAB:RB, [RA, #-16]
3860 | ldr CARG1, [RA, #-8] // Get index from control var.
3861 | ldr INS, TAB:RB->asize
3862 | ldr CARG2, TAB:RB->array
3864 |1: // Traverse array part.
3865 | subs RC, CARG1, INS
3866 | add CARG3, CARG2, CARG1, lsl #3
3867 | bhs >5 // Index points after array part?
3868 | ldrd CARG34, [CARG3]
3869 | checktp CARG4, LJ_TNIL
3870 | addeq CARG1, CARG1, #1 // Skip holes in array part.
3872 | ldrh RC, [PC, #-2]
3873 | mvn CARG2, #~LJ_TISNUM
3874 | strd CARG34, [RA, #8]
3875 | add RC, PC, RC, lsl #2
3878 | sub PC, RC, #0x20000
3879 | str RB, [RA, #-8] // Update control var.
3883 |5: // Traverse hash part.
3884 | ldr CARG4, TAB:RB->hmask
3885 | ldr NODE:RB, TAB:RB->node
3887 | add CARG1, RC, RC, lsl #1
3888 | cmp RC, CARG4 // End of iteration? Branch to ITERL+1.
3889 | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8
3891 | ldrd CARG12, NODE:CARG3->val
3892 | checktp CARG2, LJ_TNIL
3894 | beq <6 // Skip holes in hash part.
3895 | ldrh RB, [PC, #-2]
3897 | ldrd CARG34, NODE:CARG3->key
3898 | str RC, [RA, #-8] // Update control var.
3899 | strd CARG12, [RA, #8]
3900 | add RC, PC, RB, lsl #2
3901 | sub PC, RC, #0x20000
3907 | // RA = base*8, RC = target (points to ITERN)
3909 | add RC, PC, RC, lsl #2
3910 | ldrd CFUNC:CARG12, [RA, #-24]
3911 | ldr CARG3, [RA, #-12]
3912 | ldr CARG4, [RA, #-4]
3913 | checktp CARG2, LJ_TFUNC
3914 | ldrbeq CARG1, CFUNC:CARG1->ffid
3915 | checktpeq CARG3, LJ_TTAB
3916 | checktpeq CARG4, LJ_TNIL
3917 | cmpeq CARG1, #FF_next_N
3918 | subeq PC, RC, #0x20000
3923 | mvn CARG2, #0x00018000
3924 | strd CARG1, [RA, #-8] // Initialize control var.
3927 |5: // Despecialize bytecode if any of the checks fail.
3928 | mov CARG1, #BC_JMP
3930 | strb CARG1, [PC, #-4]
3931 | sub PC, RC, #0x20000
3932 | strb OP, [PC] // Subsumes ins_next1.
3938 | decode_RB8 RB, INS
3939 | decode_RC8 RC, INS
3940 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
3941 | ldr CARG1, [BASE, FRAME_PC]
3944 | add RC, RC, #FRAME_VARG
3946 | sub CARG3, BASE, #8 // CARG3 = vtop
3947 | sub RC, RC, CARG1 // RC = vbase
3948 | // Note: RC may now be even _above_ BASE if nargs was < numparams.
3950 | sub CARG1, CARG3, RC
3951 | beq >5 // Copy all varargs?
3952 | sub CARG4, CARG4, #16
3953 |1: // Copy vararg slots to destination slots.
3955 | ldrdlo CARG12, [RC], #8
3956 | mvnhs CARG2, #~LJ_TNIL
3958 | strd CARG12, [RA], #8
3963 |5: // Copy all varargs.
3964 | ldr CARG4, L->maxstack
3966 | movle RB, #8 // MULTRES = (0+1)*8
3967 | addgt RB, CARG1, #8
3968 | add CARG2, RA, CARG1
3969 | str RB, SAVE_MULTRES
3974 | ldrd CARG12, [RC], #8
3975 | strd CARG12, [RA], #8
3980 |7: // Grow stack for varargs.
3981 | lsr CARG2, CARG1, #3
3985 | sub RC, RC, BASE // Need delta, because BASE may change.
3988 | bl extern lj_state_growstack // (lua_State *L, int n)
3992 | sub CARG3, BASE, #8
3996 /* -- Returns ----------------------------------------------------------- */
3999 | // RA = results*8, RC = extra results
4000 | ldr CARG1, SAVE_MULTRES
4001 | ldr PC, [BASE, FRAME_PC]
4003 | add RC, CARG1, RC, lsl #3
4008 | // RA = results*8, RC = nresults+1
4009 | ldr PC, [BASE, FRAME_PC]
4013 | str RC, SAVE_MULTRES
4015 | ands CARG1, PC, #FRAME_TYPE
4016 | eor CARG2, PC, #FRAME_VARG
4020 | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return
4021 | ldr INS, [PC, #-4]
4022 | subs CARG4, RC, #8
4023 | sub CARG3, BASE, #8
4026 | ldrd CARG12, [RA], #8
4027 | add BASE, BASE, #8
4028 | subs CARG4, CARG4, #8
4029 | strd CARG12, [BASE, #-16]
4032 | decode_RA8 RA, INS
4033 | sub CARG4, CARG3, RA
4034 | decode_RB8 RB, INS
4035 | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]
4037 | cmp RB, RC // More results expected?
4040 | ldr CARG2, LFUNC:CARG1->field_pc
4043 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4046 |6: // Fill up results with nil.
4047 | mvn CARG2, #~LJ_TNIL
4048 | add BASE, BASE, #8
4050 | str CARG2, [BASE, #-12]
4053 |->BC_RETV1_Z: // Non-standard return case.
4056 | tst CARG2, #FRAME_TYPEP
4058 | // Return from vararg function: relocate BASE down.
4059 | sub BASE, BASE, CARG2
4060 | ldr PC, [BASE, FRAME_PC]
4064 case BC_RET0: case BC_RET1:
4065 | // RA = results*8, RC = nresults+1
4066 | ldr PC, [BASE, FRAME_PC]
4068 | str RC, SAVE_MULTRES
4069 | ands CARG1, PC, #FRAME_TYPE
4070 | eor CARG2, PC, #FRAME_VARG
4071 | ldreq INS, [PC, #-4]
4073 if (op == BC_RET1) {
4074 | ldrd CARG12, [BASE, RA]
4076 | sub CARG4, BASE, #8
4077 | decode_RA8 RA, INS
4078 if (op == BC_RET1) {
4079 | strd CARG12, [CARG4]
4081 | sub BASE, CARG4, RA
4082 | decode_RB8 RB, INS
4083 | ldr LFUNC:CARG1, [BASE, FRAME_FUNC]
4087 | ldr CARG2, LFUNC:CARG1->field_pc
4090 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4093 |6: // Fill up results with nil.
4094 | sub CARG2, CARG4, #4
4095 | mvn CARG3, #~LJ_TNIL
4096 | str CARG3, [CARG2, RC]
4101 /* -- Loops and branches ------------------------------------------------ */
4103 |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4]
4104 |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12]
4105 |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]
4106 |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28]
4112 | // Fall through. Assumes BC_IFORL follows.
4122 | // RA = base*8, RC = target (after end of loop or start of loop)
4123 vk = (op == BC_IFORL || op == BC_JFORL);
4124 | ldrd CARG12, [RA, BASE]!
4125 if (op != BC_JFORL) {
4126 | add RC, PC, RC, lsl #2
4129 | ldrd CARG34, FOR_STOP
4130 | checktp CARG2, LJ_TISNUM
4133 | checktp CARG4, LJ_TISNUM
4134 | ldr CARG4, FOR_STEP
4135 | checktpeq RB, LJ_TISNUM
4141 | ldrd CARG34, FOR_STEP
4142 | checktp CARG2, LJ_TISNUM
4144 | adds CARG1, CARG1, CARG3
4145 | ldr CARG4, FOR_STOP
4146 if (op == BC_IFORL) {
4147 | addvs RC, PC, #0x20000 // Overflow: prevent branch.
4149 | bvs >2 // Overflow: do not enter mcode.
4156 if (op == BC_FORI) {
4157 | subgt PC, RC, #0x20000
4158 } else if (op == BC_JFORI) {
4159 | sub PC, RC, #0x20000
4160 | ldrhle RC, [PC, #-2]
4161 } else if (op == BC_IFORL) {
4162 | suble PC, RC, #0x20000
4165 | strd CARG12, FOR_IDX
4170 | strd CARG12, FOR_EXT
4171 if (op == BC_JFORI || op == BC_JFORL) {
4177 |4: // Invert check for negative step.
4187 | cmnlo CARG4, #-LJ_TISNUM
4188 | cmnlo RB, #-LJ_TISNUM
4197 | strd CARG12, FOR_EXT
4206 | vadd.f64 d0, d0, d2
4210 | bl extern __aeabi_dadd
4211 | strd CARG12, FOR_IDX
4212 | ldrd CARG34, FOR_STOP
4213 | strd CARG12, FOR_EXT
4222 | bl extern __aeabi_cdcmple
4230 if (op == BC_FORI) {
4231 | subhi PC, RC, #0x20000
4232 } else if (op == BC_JFORI) {
4233 | sub PC, RC, #0x20000
4234 | ldrhls RC, [PC, #-2]
4236 } else if (op == BC_IFORL) {
4237 | subls PC, RC, #0x20000
4246 |8: // Invert check for negative step.
4248 | bl extern __aeabi_dadd
4249 | strd CARG12, FOR_IDX
4250 | strd CARG12, FOR_EXT
4254 | ldrd CARG12, FOR_STOP
4263 | // Fall through. Assumes BC_IITERL follows.
4271 | // RA = base*8, RC = target
4272 | ldrd CARG12, [RA, BASE]!
4273 if (op == BC_JITERL) {
4274 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4275 | strdne CARG12, [RA, #-8]
4278 | add RC, PC, RC, lsl #2
4279 | // STALL: load CARG12.
4280 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4281 | subne PC, RC, #0x20000 // Otherwise save control var + branch.
4282 | strdne CARG12, [RA, #-8]
4288 | // RA = base*8, RC = target (loop extent)
4289 | // Note: RA/RC is only used by trace recorder to determine scope/extent
4290 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
4294 | // Fall through. Assumes BC_ILOOP follows.
4298 | // RA = base*8, RC = target (loop extent)
4304 | // RA = base (ignored), RC = traceno
4305 | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
4306 | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0.
4307 | ldr TRACE:RC, [CARG1, RC, lsl #2]
4309 | ldr RA, TRACE:RC->mcode
4310 | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
4311 | str L, [DISPATCH, #DISPATCH_GL(jit_L)]
4317 | // RA = base*8 (only used by trace recorder), RC = target
4318 | add RC, PC, RC, lsl #2
4319 | sub PC, RC, #0x20000
4323 /* -- Function headers -------------------------------------------------- */
4329 case BC_FUNCV: /* NYI: compiled vararg functions. */
4330 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
4338 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4339 | ldr CARG1, L->maxstack
4340 | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]
4341 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4343 | bhi ->vm_growstack_l
4344 if (op != BC_JFUNCF) {
4349 | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters.
4350 | mvn CARG4, #~LJ_TNIL
4352 if (op == BC_JFUNCF) {
4359 |3: // Clear missing parameters.
4360 | strd CARG34, [BASE, NARGS8:RC]
4361 | add NARGS8:RC, NARGS8:RC, #8
4369 | NYI // NYI: compiled vararg functions
4370 break; /* NYI: compiled vararg functions. */
4373 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4374 | ldr CARG1, L->maxstack
4375 | add CARG4, BASE, RC
4377 | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC.
4378 | add CARG2, RC, #8+FRAME_VARG
4379 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4381 | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG.
4382 | bhs ->vm_growstack_l
4383 | ldrb RB, [PC, #-4+PC2PROTO(numparams)]
4387 | add BASE, CARG4, #8
4389 | mvn CARG3, #~LJ_TNIL
4391 | cmp RA, RC // Less args than parameters?
4392 | ldrdlo CARG12, [RA], #8
4393 | movhs CARG2, CARG3
4394 | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC).
4397 | strd CARG12, [CARG4, #8]!
4405 | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8
4406 if (op == BC_FUNCC) {
4407 | ldr CARG4, CFUNC:CARG3->f
4409 | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]
4411 | add CARG2, RA, NARGS8:RC
4412 | ldr CARG1, L->maxstack
4413 | add RC, BASE, NARGS8:RC
4417 if (op == BC_FUNCCW) {
4418 | ldr CARG2, CFUNC:CARG3->f
4420 | mv_vmstate CARG3, C
4422 | bhi ->vm_growstack_c // Need to grow stack.
4424 | blx CARG4 // (lua_State *L [, lua_CFunction f])
4425 | // Returns nresults.
4427 | mv_vmstate CARG3, INTERP
4431 | ldr PC, [BASE, FRAME_PC]
4432 | sub RA, CRET2, RC // RA = L->top - nresults*8
4436 /* ---------------------------------------------------------------------- */
4439 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
4445 static int build_backend(BuildCtx *ctx)
4449 dasm_growpc(Dst, BC__MAX);
4451 build_subroutines(ctx);
4454 for (op = 0; op < BC__MAX; op++)
4455 build_ins(ctx, (BCOp)op, op);
4460 /* Emit pseudo frame-info for all assembler functions. */
4461 static void emit_asm_debug(BuildCtx *ctx)
4463 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
4465 switch (ctx->mode) {
4467 fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n");
4470 "\t.long .LECIE0-.LSCIE0\n"
4472 "\t.long 0xffffffff\n"
4477 "\t.byte 0xe\n" /* Return address is in lr. */
4478 "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */
4483 "\t.long .LEFDE0-.LASFDE0\n"
4485 "\t.long .Lframe0\n"
4488 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
4489 "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */
4490 fcofs, CFRAME_SIZE);
4491 for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */
4492 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i));
4494 for (i = 15; i >= 8; i--) /* offset d8-d15 */
4495 fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n",
4496 64+2*i, 10+2*(15-i));
4497 fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */
4505 "\t.long .LEFDE1-.LASFDE1\n"
4507 "\t.long .Lframe0\n"
4508 "\t.long lj_vm_ffi_call\n"
4510 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
4511 "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */
4512 "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */
4513 "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */
4514 "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */
4515 "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */
4517 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);