1 |// Low-level VM code for ARM CPUs.
2 |// Bytecode interpreter, fast functions and helper functions.
3 |// Copyright (C) 2005-2014 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).
338 | lsr CARG2, KBASE, #3
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
1371 | bl ->vm_..func.._sf
1380 | .long 0x00000000, 0x41e00000 // 2^31.
1383 | checktp CARG2, LJ_TISNUM
1384 | bhi ->fff_fallback
1385 | bicne CARG2, CARG2, #0x80000000
1388 | rsbslt CARG1, CARG1, #0
1393 | // CARG12 = TValue result.
1394 | ldr PC, [BASE, FRAME_PC]
1395 | strd CARG12, [BASE, #-8]
1400 | // RC = (nresults+1)*8, PC = return.
1401 | ands CARG1, PC, #FRAME_TYPE
1402 | ldreq INS, [PC, #-4]
1403 | str RC, SAVE_MULTRES
1406 | decode_RB8 RB, INS
1408 | cmp RB, RC // More results expected?
1410 | decode_RA8 CARG1, INS
1413 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
1414 | sub BASE, RA, CARG1
1417 |6: // Fill up results with nil.
1419 | mvn CARG1, #~LJ_TNIL
1421 | str CARG1, [CARG2, #-4]
1424 |.macro math_extern, func
1426 | .ffunc_d math_ .. func
1428 | .ffunc_n math_ .. func
1440 |.macro math_extern2, func
1442 | .ffunc_dd math_ .. func
1444 | .ffunc_nn math_ .. func
1457 | .ffunc_d math_sqrt
1460 | ldr PC, [BASE, FRAME_PC]
1461 | vstr d0, [BASE, #-8]
1469 | ldr CARG2, [BASE, #4]
1470 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1472 | bne ->fff_fallback
1474 | ldrd CARG12, [BASE]
1475 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1476 | bne ->fff_fallback
1478 | checktp CARG2, LJ_TISNUM
1479 | bhs ->fff_fallback
1501 | math_extern2 atan2
1507 | vldr d1, CFUNC:CARG3->upvalue[0]
1508 | vmul.f64 d0, d0, d1
1512 | ldrd CARG34, CFUNC:CARG3->upvalue[0]
1513 | bl extern __aeabi_dmul
1519 | ldr CARG4, [BASE, #4]
1520 | ldrd CARG12, [BASE, #8]
1521 | cmp NARGS8:RC, #16
1522 | blo ->fff_fallback
1524 | checktp CARG4, LJ_TISNUM
1525 | bhs ->fff_fallback
1526 | checktp CARG2, LJ_TISNUM
1527 | bne ->fff_fallback
1529 | bl extern ldexp // (double x, int exp)
1533 |.ffunc_2 math_ldexp
1534 | checktp CARG2, LJ_TISNUM
1535 | bhs ->fff_fallback
1536 | checktp CARG4, LJ_TISNUM
1537 | bne ->fff_fallback
1539 | bl extern ldexp // (double x, int exp)
1545 |.ffunc_d math_frexp
1551 | mvn CARG4, #~LJ_TISNUM
1552 | ldr PC, [BASE, FRAME_PC]
1553 | vstr d0, [BASE, #-8]
1555 | strd CARG34, [BASE]
1558 |.ffunc_n math_frexp
1564 | mvn CARG4, #~LJ_TISNUM
1565 | ldr PC, [BASE, FRAME_PC]
1566 | strd CARG12, [BASE, #-8]
1568 | strd CARG34, [BASE]
1574 | sub CARG1, BASE, #8
1575 | ldr PC, [BASE, FRAME_PC]
1584 | sub CARG3, BASE, #8
1585 | ldr PC, [BASE, FRAME_PC]
1590 | strd CARG12, [BASE]
1594 |.macro math_minmax, name, cond, fcond
1598 | checktp CARG2, LJ_TISNUM
1601 |1: // Handle integers.
1605 | checktp CARG4, LJ_TISNUM
1609 | mov..cond CARG1, CARG3
1611 |3: // Convert intermediate result to number and continue below.
1613 | bhi ->fff_fallback
1615 | vcvt.f64.s32 d0, s4
1620 | bhi ->fff_fallback
1621 |5: // Handle numbers.
1626 | checktp CARG4, LJ_TISNUM
1632 | vmov..fcond.f64 d0, d1
1634 |7: // Convert integer to number and continue above.
1636 | bhi ->fff_fallback
1637 | vcvt.f64.s32 d1, s4
1643 | checktp CARG2, LJ_TISNUM
1646 |1: // Handle integers.
1647 | ldrd CARG34, [BASE, RA]
1650 | checktp CARG4, LJ_TISNUM
1654 | mov..cond CARG1, CARG3
1656 |3: // Convert intermediate result to number and continue below.
1657 | bhi ->fff_fallback
1658 | bl extern __aeabi_i2d
1659 | ldrd CARG34, [BASE, RA]
1663 | bhi ->fff_fallback
1664 |5: // Handle numbers.
1665 | ldrd CARG34, [BASE, RA]
1668 | checktp CARG4, LJ_TISNUM
1671 | bl extern __aeabi_cdcmple
1673 | mov..fcond CARG1, CARG3
1674 | mov..fcond CARG2, CARG4
1676 |7: // Convert integer to number and continue above.
1677 | bhi ->fff_fallback
1680 | bl extern __aeabi_i2d
1686 | math_minmax math_min, gt, hi
1687 | math_minmax math_max, lt, lo
1689 |//-- String library -----------------------------------------------------
1691 |.ffunc_1 string_len
1692 | checkstr CARG2, ->fff_fallback
1693 | ldr CARG1, STR:CARG1->len
1694 | mvn CARG2, #~LJ_TISNUM
1697 |.ffunc string_byte // Only handle the 1-arg case here.
1698 | ldrd CARG12, [BASE]
1699 | ldr PC, [BASE, FRAME_PC]
1701 | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument.
1702 | bne ->fff_fallback
1703 | ldr CARG3, STR:CARG1->len
1704 | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
1705 | mvn CARG2, #~LJ_TISNUM
1707 | moveq RC, #(0+1)*8
1708 | movne RC, #(1+1)*8
1709 | strd CARG12, [BASE, #-8]
1712 |.ffunc string_char // Only handle the 1-arg case here.
1714 | ldrd CARG12, [BASE]
1715 | ldr PC, [BASE, FRAME_PC]
1716 | cmp NARGS8:RC, #8 // Need exactly 1 argument.
1717 | checktpeq CARG2, LJ_TISNUM
1718 | bicseq CARG4, CARG1, #255
1720 | bne ->fff_fallback
1722 | mov CARG2, TMPDp // Points to stack. Little-endian.
1724 | // CARG2 = str, CARG3 = len.
1728 | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
1729 | // Returns GCstr *.
1731 | mvn CARG2, #~LJ_TSTR
1736 | ldrd CARG12, [BASE]
1737 | ldrd CARG34, [BASE, #16]
1738 | cmp NARGS8:RC, #16
1741 | blo ->fff_fallback
1742 | checktp CARG4, LJ_TISNUM
1744 | bne ->fff_fallback
1746 | ldrd CARG34, [BASE, #8]
1747 | checktp CARG2, LJ_TSTR
1748 | ldreq CARG2, STR:CARG1->len
1749 | checktpeq CARG4, LJ_TISNUM
1750 | bne ->fff_fallback
1751 | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end
1752 | add CARG4, CARG2, #1
1753 | cmp CARG3, #0 // if (start < 0) start += len+1
1754 | addlt CARG3, CARG3, CARG4
1755 | cmp CARG3, #1 // if (start < 1) start = 1
1757 | cmp RB, #0 // if (end < 0) end += len+1
1758 | addlt RB, RB, CARG4
1759 | bic RB, RB, RB, asr #31 // if (end < 0) end = 0
1760 | cmp RB, CARG2 // if (end > len) end = len
1761 | add CARG1, STR:CARG1, #sizeof(GCstr)-1
1763 | add CARG2, CARG1, CARG3
1764 | subs CARG3, RB, CARG3 // len = end - start
1765 | add CARG3, CARG3, #1 // len += 1
1768 | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)
1769 | mvn CARG2, #~LJ_TSTR
1772 |.ffunc string_rep // Only handle the 1-char case inline.
1774 | ldrd CARG12, [BASE]
1775 | ldrd CARG34, [BASE, #8]
1776 | cmp NARGS8:RC, #16
1777 | bne ->fff_fallback // Exactly 2 arguments
1778 | checktp CARG2, LJ_TSTR
1779 | checktpeq CARG4, LJ_TISNUM
1780 | bne ->fff_fallback
1781 | subs CARG4, CARG3, #1
1782 | ldr CARG2, STR:CARG1->len
1783 | blt ->fff_emptystr // Count <= 0?
1785 | blo ->fff_emptystr // Zero-length string?
1786 | bne ->fff_fallback // Fallback for > 1-char strings.
1787 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1788 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1789 | ldr CARG1, STR:CARG1[1]
1791 | blo ->fff_fallback
1792 |1: // Fill buffer with char.
1793 | strb CARG1, [CARG2, CARG4]
1794 | subs CARG4, CARG4, #1
1798 |.ffunc string_reverse
1800 | ldrd CARG12, [BASE]
1802 | blo ->fff_fallback
1803 | checkstr CARG2, ->fff_fallback
1804 | ldr CARG3, STR:CARG1->len
1805 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1806 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1808 | add CARG1, STR:CARG1, #sizeof(GCstr)
1810 | blo ->fff_fallback
1811 |1: // Reverse string copy.
1812 | ldrb RB, [CARG1], #1
1813 | subs CARG4, CARG4, #1
1815 | strb RB, [CARG2, CARG4]
1818 |.macro ffstring_case, name, lo
1821 | ldrd CARG12, [BASE]
1823 | blo ->fff_fallback
1824 | checkstr CARG2, ->fff_fallback
1825 | ldr CARG3, STR:CARG1->len
1826 | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
1827 | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
1829 | add CARG1, STR:CARG1, #sizeof(GCstr)
1831 | blo ->fff_fallback
1832 |1: // ASCII case conversion.
1833 | ldrb RB, [CARG1, CARG4]
1838 | eorlo RB, RB, #0x20
1839 | strb RB, [CARG2, CARG4]
1840 | add CARG4, CARG4, #1
1844 |ffstring_case string_lower, 65
1845 |ffstring_case string_upper, 97
1847 |//-- Table library ------------------------------------------------------
1849 |.ffunc_1 table_getn
1850 | checktab CARG2, ->fff_fallback
1852 | bl extern lj_tab_len // (GCtab *t)
1853 | // Returns uint32_t (but less than 2^31).
1855 | mvn CARG2, #~LJ_TISNUM
1858 |//-- Bit library --------------------------------------------------------
1860 |// FP number to bit conversion for soft-float. Clobbers r0-r3.
1862 | bhi ->fff_fallback
1865 | adds RB, RB, #0x00200000
1866 | movpl CARG1, #0 // |x| < 1?
1869 | subs RB, CARG4, RB, asr #21
1870 | bmi >1 // |x| >= 2^32?
1871 | lsl CARG4, CARG2, #11
1872 | orr CARG4, CARG4, #0x80000000
1873 | orr CARG4, CARG4, CARG1, lsr #21
1875 | lsr CARG1, CARG4, RB
1876 | rsblt CARG1, CARG1, #0
1880 | lsr CARG4, CARG1, RB
1882 | lsl CARG1, CARG2, #12
1884 | orr CARG1, CARG4, CARG1, lsl RB
1885 | rsblt CARG1, CARG1, #0
1888 |.macro .ffunc_bit, name
1889 | .ffunc_1 bit_..name
1890 | checktp CARG2, LJ_TISNUM
1891 | blne ->vm_tobit_fb
1895 | mvn CARG2, #~LJ_TISNUM
1898 |.macro .ffunc_bit_op, name, ins
1903 | ldrd CARG12, [BASE, RA]
1907 | checktp CARG2, LJ_TISNUM
1908 | blne ->vm_tobit_fb
1909 | ins CARG3, CARG3, CARG1
1913 |.ffunc_bit_op band, and
1914 |.ffunc_bit_op bor, orr
1915 |.ffunc_bit_op bxor, eor
1918 | mvn CARG4, #~LJ_TISNUM
1919 | ldr PC, [BASE, FRAME_PC]
1920 | strd CARG34, [BASE, #-8]
1924 | eor CARG3, CARG1, CARG1, ror #16
1925 | bic CARG3, CARG3, #0x00ff0000
1926 | ror CARG1, CARG1, #8
1927 | mvn CARG2, #~LJ_TISNUM
1928 | eor CARG1, CARG1, CARG3, lsr #8
1933 | mvn CARG2, #~LJ_TISNUM
1936 |.macro .ffunc_bit_sh, name, ins, shmod
1938 | ldrd CARG12, [BASE, #8]
1939 | cmp NARGS8:RC, #16
1940 | blo ->fff_fallback
1941 | checktp CARG2, LJ_TISNUM
1942 | blne ->vm_tobit_fb
1944 | and RA, CARG1, #31
1948 | ldrd CARG12, [BASE]
1949 | checktp CARG2, LJ_TISNUM
1950 | blne ->vm_tobit_fb
1951 | ins CARG1, CARG1, RA
1952 | mvn CARG2, #~LJ_TISNUM
1956 |.ffunc_bit_sh lshift, lsl, 0
1957 |.ffunc_bit_sh rshift, lsr, 0
1958 |.ffunc_bit_sh arshift, asr, 0
1959 |.ffunc_bit_sh rol, ror, 1
1960 |.ffunc_bit_sh ror, ror, 0
1962 |//-----------------------------------------------------------------------
1964 |->fff_fallback: // Call fast function fallback handler.
1965 | // BASE = new base, RC = nargs*8
1966 | ldr CARG3, [BASE, FRAME_FUNC]
1967 | ldr CARG2, L->maxstack
1968 | add CARG1, BASE, NARGS8:RC
1969 | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC.
1971 | ldr CARG3, CFUNC:CARG3->f
1973 | add CARG1, CARG1, #8*LUA_MINSTACK
1974 | str PC, SAVE_PC // Redundant (but a defined value).
1977 | bhi >5 // Need to grow stack.
1978 | blx CARG3 // (lua_State *L)
1979 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
1984 | bgt ->fff_res // Returned nresults+1?
1985 |1: // Returned 0 or -1: retry fast path.
1987 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
1988 | sub NARGS8:RC, CARG1, BASE
1989 | bne ->vm_call_tail // Returned -1?
1990 | ins_callt // Returned 0: retry fast path.
1992 |// Reconstruct previous base for vmeta_call during tailcall.
1994 | ands CARG1, PC, #FRAME_TYPE
1995 | bic CARG2, PC, #FRAME_TYPEP
1996 | ldreq INS, [PC, #-4]
1997 | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8.
1998 | addeq CARG2, CARG2, #8
1999 | sub RB, BASE, CARG2
2000 | b ->vm_call_dispatch // Resolve again for tailcall.
2002 |5: // Grow stack for fallback handler.
2003 | mov CARG2, #LUA_MINSTACK
2004 | bl extern lj_state_growstack // (lua_State *L, int n)
2006 | cmp CARG1, CARG1 // Set zero-flag to force retry.
2009 |->fff_gcstep: // Call GC step function.
2010 | // BASE = new base, RC = nargs*8
2013 | add CARG2, BASE, NARGS8:RC
2014 | str PC, SAVE_PC // Redundant (but a defined value).
2017 | bl extern lj_gc_step // (lua_State *L)
2019 | mov lr, RA // Help return address predictor.
2020 | ldr CFUNC:CARG3, [BASE, FRAME_FUNC]
2023 |//-----------------------------------------------------------------------
2024 |//-- Special dispatch targets -------------------------------------------
2025 |//-----------------------------------------------------------------------
2027 |->vm_record: // Dispatch target for recording phase.
2029 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2030 | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent.
2032 | // Decrement the hookcount for consistency, but always do the call.
2033 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2034 | tst CARG1, #HOOK_ACTIVE
2036 | sub CARG2, CARG2, #1
2037 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
2038 | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2042 |->vm_rethook: // Dispatch target for return hooks.
2043 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2044 | tst CARG1, #HOOK_ACTIVE // Hook already active?
2046 |5: // Re-dispatch to static ins.
2048 | add OP, DISPATCH, OP, lsl #2
2049 | ldr pc, [OP, #GG_DISP2STATIC]
2051 |->vm_inshook: // Dispatch target for instr/line hooks.
2052 | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
2053 | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2054 | tst CARG1, #HOOK_ACTIVE // Hook already active?
2056 | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
2058 | subs CARG2, CARG2, #1
2059 | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
2061 | tst CARG1, #LUA_MASKLINE
2067 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
2068 | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
2071 |4: // Re-dispatch to static ins.
2072 | ldrb OP, [PC, #-4]
2073 | ldr INS, [PC, #-4]
2074 | add OP, DISPATCH, OP, lsl #2
2075 | ldr OP, [OP, #GG_DISP2STATIC]
2076 | decode_RA8 RA, INS
2080 |->cont_hook: // Continue from hook yield.
2081 | ldr CARG1, [CARG4, #-24]
2083 | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins.
2086 |->vm_hotloop: // Hot loop counter underflow.
2088 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L).
2089 | sub CARG1, DISPATCH, #-GG_DISP2J
2091 | ldr CARG3, LFUNC:CARG3->field_pc
2093 | str L, [DISPATCH, #DISPATCH_J(L)]
2094 | ldrb CARG3, [CARG3, #PC2PROTO(framesize)]
2096 | add CARG3, BASE, CARG3, lsl #3
2098 | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
2102 |->vm_callhook: // Dispatch target for call hooks.
2108 |->vm_hotcall: // Hot call counter underflow.
2113 | add CARG4, BASE, RC
2119 | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
2120 | // Returns ASMFunction.
2125 | sub NARGS8:RC, CARG4, BASE
2126 | str CARG2, SAVE_PC // Invalidate for subsequent line hook.
2127 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2128 | ldr INS, [PC, #-4]
2131 |//-----------------------------------------------------------------------
2132 |//-- Trace exit handler -------------------------------------------------
2133 |//-----------------------------------------------------------------------
2138 | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}
2139 | ldr CARG1, [sp, #64] // Load original value of lr.
2140 | ldr DISPATCH, [lr] // Load DISPATCH.
2141 | add CARG3, sp, #64 // Recompute original value of sp.
2142 | mv_vmstate CARG4, EXIT
2143 | str CARG3, [sp, #52] // Store sp in RID_SP
2145 | ldr CARG2, [CARG1, #-4]! // Get exit instruction.
2146 | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC.
2147 | str CARG1, [sp, #60]
2151 | lsl CARG2, CARG2, #8
2152 | add CARG1, CARG1, CARG2, asr #6
2153 | ldr CARG2, [lr, #4] // Load exit stub group offset.
2154 | sub CARG1, CARG1, lr
2155 | ldr L, [DISPATCH, #DISPATCH_GL(jit_L)]
2156 | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number.
2157 | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
2158 | str CARG1, [DISPATCH, #DISPATCH_J(exitno)]
2160 | str L, [DISPATCH, #DISPATCH_J(L)]
2162 | str CARG4, [DISPATCH, #DISPATCH_GL(jit_L)]
2163 | sub CARG1, DISPATCH, #-GG_DISP2J
2165 | bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
2166 | // Returns MULTRES (unscaled) or negated error code.
2167 | ldr CARG2, L->cframe
2169 | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
2171 | ldr PC, SAVE_PC // Get SAVE_PC.
2172 | str L, SAVE_L // Set SAVE_L (on-trace resume/yield).
2176 | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.
2181 | blt >3 // Check for error from exit.
2183 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
2184 | str RC, SAVE_MULTRES
2186 | ldr CARG2, LFUNC:CARG2->field_pc
2187 | str CARG3, [DISPATCH, #DISPATCH_GL(jit_L)]
2188 | mv_vmstate CARG4, INTERP
2189 | ldr KBASE, [CARG2, #PC2PROTO(k)]
2190 | // Modified copy of ins_next which handles function header dispatch, too.
2194 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2196 | cmp OP, #BC_FUNCF // Function header?
2197 | ldr OP, [DISPATCH, OP, lsl #2]
2198 | decode_RA8 RA, INS
2199 | lsrlo RC, INS, #16 // No: Decode operands A*8 and D.
2201 | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8
2204 |3: // Rethrow error from the right C frame.
2205 | rsb CARG2, CARG1, #0
2207 | bl extern lj_err_throw // (lua_State *L, int errcode)
2210 |//-----------------------------------------------------------------------
2211 |//-- Math helper functions ----------------------------------------------
2212 |//-----------------------------------------------------------------------
2214 |// FP value rounding. Called from JIT code.
2216 |// double lj_vm_floor/ceil/trunc(double x);
2217 |.macro vm_round, func, hf
2219 | vmov CARG1, CARG2, d0
2221 | lsl CARG3, CARG2, #1
2222 | adds RB, CARG3, #0x00200000
2223 | bpl >2 // |x| < 1?
2225 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2226 | bxlo lr // |x| >= 2^52: done.
2228 | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask
2229 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2231 | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask
2232 | orrpl CARG3, CARG3, CARG4
2234 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2235 |.if "func" == "floor"
2236 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2238 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2241 | vmoveq d0, CARG1, CARG2
2243 | bxeq lr // iszero: done.
2246 | lslpl CARG3, CARG4, RB
2249 | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask
2250 | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry
2252 | vmov d0, CARG1, CARG2
2257 | bxcs lr // |x| is not finite.
2258 | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo
2259 |.if "func" == "floor"
2260 | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
2262 | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
2264 | mov CARG1, #0 // lo = 0
2265 | and CARG2, CARG2, #0x80000000
2266 | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0)
2267 | orrne CARG2, CARG2, CARG4
2269 | vmov d0, CARG1, CARG2
2275 | .long 0x3ff00000 // hiword(+1.0)
2291 |.macro vm_trunc, hf
2294 | vmov CARG1, CARG2, d0
2296 | lsl CARG3, CARG2, #1
2297 | adds RB, CARG3, #0x00200000
2298 | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0.
2301 | vmovpl d0, CARG1, CARG2
2305 | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
2306 | bxlo lr // |x| >= 2^52: already done.
2308 | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
2310 | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
2312 | vmov d0, CARG1, CARG2
2325 | // double lj_vm_mod(double dividend, double divisor);
2328 | // Special calling convention. Also, RC (r11) is not preserved.
2329 | vdiv.f64 d0, d6, d7
2331 | vmov CARG1, CARG2, d0
2333 | vmov d0, CARG1, CARG2
2334 | vmul.f64 d0, d0, d7
2336 | vsub.f64 d6, d6, d0
2339 | push {r0, r1, r2, r3, r4, lr}
2340 | bl extern __aeabi_ddiv
2342 | ldrd CARG34, [sp, #8]
2343 | bl extern __aeabi_dmul
2345 | eor CARG2, CARG2, #0x80000000
2346 | bl extern __aeabi_dadd
2351 | // int lj_vm_modi(int dividend, int divisor);
2353 | ands RB, CARG1, #0x80000000
2354 | rsbmi CARG1, CARG1, #0 // a = |dividend|
2355 | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor).
2357 | rsbmi CARG2, CARG2, #0 // b = |divisor|
2358 | subs CARG4, CARG2, #1
2359 | cmpne CARG1, CARG2
2360 | moveq CARG1, #0 // if (b == 1 || a == b) a = 0
2361 | tsthi CARG2, CARG4
2362 | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1
2364 | // Use repeated subtraction to get the remainder.
2367 | sub CARG4, CARG4, CARG3
2368 | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8
2369 | addne pc, pc, CARG3, lsl #3 // Duff's device.
2373 for (i = 31; i >= 0; i--) {
2374 | cmp CARG1, CARG2, lsl #i
2375 | subhs CARG1, CARG1, CARG2, lsl #i
2381 | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b
2382 | eors CARG2, CARG1, RB, lsl #1
2383 | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y
2386 |//-----------------------------------------------------------------------
2387 |//-- Miscellaneous functions --------------------------------------------
2388 |//-----------------------------------------------------------------------
2390 |//-----------------------------------------------------------------------
2391 |//-- FFI helper functions -----------------------------------------------
2392 |//-----------------------------------------------------------------------
2394 |// Handler for callback functions.
2395 |// Saveregs already performed. Callback slot number in [sp], g in r12.
2398 |.type CTSTATE, CTState, PC
2399 | ldr CTSTATE, GL:r12->ctype_state
2400 | add DISPATCH, r12, #GG_G2DISP
2403 | add r4, sp, CFRAME_SPACE+4+8*8
2404 | vstmdb r4!, {d8-d15}
2407 | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])
2409 | strd CARG34, CTSTATE->cb.gpr[2]
2410 | strd CARG12, CTSTATE->cb.gpr[0]
2412 | vstmdb r12!, {d0-d7}
2415 | add CARG3, sp, #CFRAME_SIZE
2416 | mov CARG1, CTSTATE
2417 | lsr CARG4, CARG4, #3
2418 | str CARG3, CTSTATE->cb.stack
2420 | str CARG4, CTSTATE->cb.slot
2421 | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
2422 | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
2423 | // Returns lua_State *.
2424 | ldr BASE, L:CRET1->base
2425 | mv_vmstate CARG2, INTERP
2426 | ldr RC, L:CRET1->top
2428 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2431 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2436 |->cont_ffi_callback: // Return from FFI callback.
2438 | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]
2442 | mov CARG1, CTSTATE
2444 | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
2445 | ldrd CARG12, CTSTATE->cb.gpr[0]
2447 | vldr d0, CTSTATE->cb.fpr[0]
2452 |->vm_ffi_call: // Call C function via FFI.
2453 | // Caveat: needs special frame unwinding, see below.
2455 | .type CCSTATE, CCallState, r4
2456 | push {CCSTATE, r5, r11, lr}
2457 | mov CCSTATE, CARG1
2458 | ldr CARG1, CCSTATE:CARG1->spadj
2459 | ldrb CARG2, CCSTATE->nsp
2460 | add CARG3, CCSTATE, #offsetof(CCallState, stack)
2462 | add RB, CCSTATE, #offsetof(CCallState, fpr[0])
2465 | sub sp, sp, CARG1 // Readjust stack.
2466 | subs CARG2, CARG2, #1
2470 | ldr RB, CCSTATE->func
2472 |1: // Copy stack slots.
2473 | ldr CARG4, [CARG3, CARG2, lsl #2]
2474 | str CARG4, [sp, CARG2, lsl #2]
2475 | subs CARG2, CARG2, #1
2478 | ldrd CARG12, CCSTATE->gpr[0]
2479 | ldrd CARG34, CCSTATE->gpr[2]
2483 | add r12, CCSTATE, #offsetof(CCallState, fpr[4])
2485 | strd CRET1, CCSTATE->gpr[0]
2487 | vstmdb r12!, {d0-d3}
2489 | pop {CCSTATE, r5, r11, pc}
2491 |// Note: vm_ffi_call must be the last function in this object file!
2493 |//-----------------------------------------------------------------------
2496 /* Generate the code for a single instruction. */
2497 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2504 /* -- Comparison ops ---------------------------------------------------- */
2506 /* Remember: all ops branch for a true comparison, fall through otherwise. */
2508 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
2509 | // RA = src1*8, RC = src2, JMP with RC = target
2511 | ldrd CARG12, [RA, BASE]!
2513 | ldrd CARG34, [RC, BASE]!
2515 | add RB, PC, RB, lsl #2
2516 | checktp CARG2, LJ_TISNUM
2518 | checktp CARG4, LJ_TISNUM
2521 if (op == BC_ISLT) {
2522 | sublt PC, RB, #0x20000
2523 } else if (op == BC_ISGE) {
2524 | subge PC, RB, #0x20000
2525 } else if (op == BC_ISLE) {
2526 | suble PC, RB, #0x20000
2528 | subgt PC, RB, #0x20000
2533 |3: // CARG12 is not an integer.
2537 | // d0 is a number.
2538 | checktp CARG4, LJ_TISNUM
2542 | // d0 is a number, CARG3 is an integer.
2544 | vcvt.f64.s32 d1, s4
2546 |4: // CARG1 is an integer, CARG34 is not an integer.
2549 | // CARG1 is an integer, d1 is a number.
2551 | vcvt.f64.s32 d0, s4
2552 |5: // d0 and d1 are numbers.
2555 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2556 if (op == BC_ISLT) {
2557 | sublo PC, RB, #0x20000
2558 } else if (op == BC_ISGE) {
2559 | subhs PC, RB, #0x20000
2560 } else if (op == BC_ISLE) {
2561 | subls PC, RB, #0x20000
2563 | subhi PC, RB, #0x20000
2568 | // CARG12 is a number.
2569 | checktp CARG4, LJ_TISNUM
2570 | movlo RA, RB // Save RB.
2573 | // CARG12 is a number, CARG3 is an integer.
2576 | mov RA, RB // Save RB.
2577 | bl extern __aeabi_i2d
2580 | ldrd CARG12, [RC] // Restore first operand.
2582 |4: // CARG1 is an integer, CARG34 is not an integer.
2584 | // CARG1 is an integer, CARG34 is a number.
2585 | mov RA, RB // Save RB.
2586 | bl extern __aeabi_i2d
2587 | ldrd CARG34, [RC] // Restore second operand.
2588 |5: // CARG12 and CARG34 are numbers.
2589 | bl extern __aeabi_cdcmple
2590 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
2591 if (op == BC_ISLT) {
2592 | sublo PC, RA, #0x20000
2593 } else if (op == BC_ISGE) {
2594 | subhs PC, RA, #0x20000
2595 } else if (op == BC_ISLE) {
2596 | subls PC, RA, #0x20000
2598 | subhi PC, RA, #0x20000
2604 case BC_ISEQV: case BC_ISNEV:
2605 vk = op == BC_ISEQV;
2606 | // RA = src1*8, RC = src2, JMP with RC = target
2608 | ldrd CARG12, [RA, BASE]!
2610 | ldrd CARG34, [RC, BASE]!
2612 | add RB, PC, RB, lsl #2
2613 | checktp CARG2, LJ_TISNUM
2614 | cmnls CARG4, #-LJ_TISNUM
2620 | // Either or both types are not numbers.
2622 | checktp CARG2, LJ_TCDATA
2623 | checktpne CARG4, LJ_TCDATA
2624 | beq ->vmeta_equal_cd
2626 | cmp CARG2, CARG4 // Compare types.
2627 | bne >2 // Not the same type?
2628 | checktp CARG2, LJ_TISPRI
2629 | bhs >1 // Same type and primitive type?
2631 | // Same types and not a primitive type. Compare GCobj or pvalue.
2634 | bne >3 // Different GCobjs or pvalues?
2635 |1: // Branch if same.
2636 | sub PC, RB, #0x20000
2640 | checktp CARG2, LJ_TISTABUD
2641 | bhi <2 // Different objects and not table/ud?
2643 | beq >1 // Same GCobjs or pvalues?
2644 | checktp CARG2, LJ_TISTABUD
2645 | bhi >2 // Different objects and not table/ud?
2647 | // Different tables or userdatas. Need to check __eq metamethod.
2648 | // Field metatable must be at same offset for GCtab and GCudata!
2649 | ldr TAB:RA, TAB:CARG1->metatable
2652 | beq <2 // No metatable?
2654 | beq >2 // No metatable?
2656 | ldrb RA, TAB:RA->nomm
2657 | mov CARG4, #1-vk // ne = 0 or 1.
2660 | beq ->vmeta_equal // 'no __eq' flag not set?
2664 |2: // Branch if different.
2665 | sub PC, RB, #0x20000
2671 case BC_ISEQS: case BC_ISNES:
2672 vk = op == BC_ISEQS;
2673 | // RA = src*8, RC = str_const (~), JMP with RC = target
2675 | ldrd CARG12, [BASE, RA]
2677 | ldr STR:CARG3, [KBASE, RC, lsl #2]
2679 | add RB, PC, RB, lsl #2
2680 | checktp CARG2, LJ_TSTR
2685 | cmpeq CARG1, CARG3
2688 | subeq PC, RB, #0x20000
2692 | subne PC, RB, #0x20000
2698 | checktp CARG2, LJ_TCDATA
2700 | b ->vmeta_equal_cd
2704 case BC_ISEQN: case BC_ISNEN:
2705 vk = op == BC_ISEQN;
2706 | // RA = src*8, RC = num_const (~), JMP with RC = target
2708 | ldrd CARG12, [RA, BASE]!
2710 | ldrd CARG34, [RC, KBASE]!
2712 | add RB, PC, RB, lsl #2
2718 | checktp CARG2, LJ_TISNUM
2720 | checktp CARG4, LJ_TISNUM
2724 | subeq PC, RB, #0x20000
2728 | subne PC, RB, #0x20000
2733 |3: // CARG12 is not an integer.
2738 | subhi PC, RB, #0x20000
2743 | checktp CARG4, LJ_TISNUM
2747 | vcvths.f64.s32 d1, s4
2749 |4: // CARG1 is an integer, d1 is a number.
2752 | vcvt.f64.s32 d0, s4
2753 |5: // d0 and d1 are numbers.
2757 | subeq PC, RB, #0x20000
2759 | subne PC, RB, #0x20000
2763 | // CARG12 is a number.
2764 | checktp CARG4, LJ_TISNUM
2765 | movlo RA, RB // Save RB.
2767 | // CARG12 is a number, CARG3 is an integer.
2770 |4: // CARG1 is an integer, CARG34 is a number.
2771 | mov RA, RB // Save RB.
2772 | bl extern __aeabi_i2d
2773 | ldrd CARG34, [RC] // Restore other operand.
2774 |5: // CARG12 and CARG34 are numbers.
2775 | bl extern __aeabi_cdcmpeq
2777 | subeq PC, RA, #0x20000
2779 | subne PC, RA, #0x20000
2786 | checktp CARG2, LJ_TCDATA
2788 | b ->vmeta_equal_cd
2792 case BC_ISEQP: case BC_ISNEP:
2793 vk = op == BC_ISEQP;
2794 | // RA = src*8, RC = primitive_type (~), JMP with RC = target
2795 | ldrd CARG12, [BASE, RA]
2799 | add RB, PC, RB, lsl #2
2801 | checktp CARG2, LJ_TCDATA
2802 | beq ->vmeta_equal_cd
2806 | subeq PC, RB, #0x20000
2808 | subne PC, RB, #0x20000
2813 /* -- Unary test and copy ops ------------------------------------------- */
2815 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
2816 | // RA = dst*8 or unused, RC = src, JMP with RC = target
2817 | add RC, BASE, RC, lsl #3
2821 | add RB, PC, RB, lsl #2
2822 | checktp CARG2, LJ_TTRUE
2823 if (op == BC_ISTC || op == BC_IST) {
2824 | subls PC, RB, #0x20000
2825 if (op == BC_ISTC) {
2826 | strdls CARG12, [BASE, RA]
2829 | subhi PC, RB, #0x20000
2830 if (op == BC_ISFC) {
2831 | strdhi CARG12, [BASE, RA]
2837 /* -- Unary ops --------------------------------------------------------- */
2840 | // RA = dst*8, RC = src
2843 | ldrd CARG12, [BASE, RC]
2845 | strd CARG12, [BASE, RA]
2849 | // RA = dst*8, RC = src
2850 | add RC, BASE, RC, lsl #3
2852 | ldr CARG1, [RC, #4]
2855 | checktp CARG1, LJ_TTRUE
2856 | mvnls CARG2, #~LJ_TFALSE
2857 | mvnhi CARG2, #~LJ_TTRUE
2858 | str CARG2, [RA, #4]
2862 | // RA = dst*8, RC = src
2864 | ldrd CARG12, [BASE, RC]
2867 | checktp CARG2, LJ_TISNUM
2869 | eorne CARG2, CARG2, #0x80000000
2871 | rsbseq CARG1, CARG1, #0
2874 | strd CARG12, [BASE, RA]
2879 | .long 0x00000000, 0x41e00000 // 2^31.
2882 | // RA = dst*8, RC = src
2884 | ldrd CARG12, [BASE, RC]
2885 | checkstr CARG2, >2
2886 | ldr CARG1, STR:CARG1->len
2888 | mvn CARG2, #~LJ_TISNUM
2891 | strd CARG12, [BASE, RA]
2894 | checktab CARG2, ->vmeta_len
2896 | ldr TAB:CARG3, TAB:CARG1->metatable
2903 | bl extern lj_tab_len // (GCtab *t)
2904 | // Returns uint32_t (but less than 2^31).
2909 | ldrb CARG4, TAB:CARG3->nomm
2910 | tst CARG4, #1<<MM_len
2911 | bne <3 // 'no __len' flag set: done.
2916 /* -- Binary ops -------------------------------------------------------- */
2918 |.macro ins_arithcheck, cond, ncond, target
2920 | cmn CARG4, #-LJ_TISNUM
2921 | cmn..cond CARG2, #-LJ_TISNUM
2923 | cmn CARG2, #-LJ_TISNUM
2924 | cmn..cond CARG4, #-LJ_TISNUM
2928 |.macro ins_arithcheck_int, target
2929 | ins_arithcheck eq, ne, target
2931 |.macro ins_arithcheck_num, target
2932 | ins_arithcheck lo, hs, target
2935 |.macro ins_arithpre
2936 | decode_RB8 RB, INS
2937 | decode_RC8 RC, INS
2938 | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
2939 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
2943 | ldrd CARG12, [RB, BASE]!
2944 | ldrd CARG34, [RC, KBASE]!
2946 | ldrd CARG12, [BASE, RB]
2947 | ldrd CARG34, [KBASE, RC]
2952 | ldrd CARG34, [RB, BASE]!
2953 | ldrd CARG12, [RC, KBASE]!
2955 | ldrd CARG34, [BASE, RB]
2956 | ldrd CARG12, [KBASE, RC]
2961 | ldrd CARG12, [RB, BASE]!
2962 | ldrd CARG34, [RC, BASE]!
2964 | ldrd CARG12, [BASE, RB]
2965 | ldrd CARG34, [BASE, RC]
2971 |.macro ins_arithpre_fpu, reg1, reg2
2983 |.macro ins_arithpost_fpu, reg
2991 |.macro ins_arithfallback, ins
2994 | ins ->vmeta_arith_vn
2997 | ins ->vmeta_arith_nv
3000 | ins ->vmeta_arith_vv
3005 |.macro ins_arithdn, intins, fpins, fpcall
3007 |.if "intins" ~= "vm_modi" and not FPU
3010 | ins_arithcheck_int >5
3011 |.if "intins" == "smull"
3012 | smull CARG1, RC, CARG3, CARG1
3013 | cmp RC, CARG1, asr #31
3014 | ins_arithfallback bne
3015 |.elif "intins" == "vm_modi"
3017 | ins_arithfallback beq
3019 | mvn CARG2, #~LJ_TISNUM
3021 | intins CARG1, CARG1, CARG3
3022 | ins_arithfallback bvs
3025 |.if "intins" == "vm_modi" or FPU
3029 | strd CARG12, [BASE, RA]
3032 | ins_arithpre_fpu d6, d7
3033 | ins_arithfallback ins_arithcheck_num
3035 |.if "intins" == "vm_modi"
3040 | ins_arithpost_fpu d6
3043 |.if "intins" ~= "vm_modi"
3050 |.macro ins_arithfp, fpins, fpcall
3052 |.if "fpins" ~= "extern" or HFABI
3053 | ins_arithpre_fpu d0, d1
3055 | ins_arithfallback ins_arithcheck_num
3056 |.if "fpins" == "extern"
3065 |.if ("fpins" ~= "extern" or HFABI) and FPU
3066 | ins_arithpost_fpu d0
3070 | strd CARG12, [BASE, RA]
3075 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
3076 | ins_arithdn adds, vadd.f64, extern __aeabi_dadd
3078 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
3079 | ins_arithdn subs, vsub.f64, extern __aeabi_dsub
3081 case BC_MULVN: case BC_MULNV: case BC_MULVV:
3082 | ins_arithdn smull, vmul.f64, extern __aeabi_dmul
3084 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
3085 | ins_arithfp vdiv.f64, extern __aeabi_ddiv
3087 case BC_MODVN: case BC_MODNV: case BC_MODVV:
3088 | ins_arithdn vm_modi, vm_mod, ->vm_mod
3091 | // NYI: (partial) integer arithmetic.
3092 | ins_arithfp extern, extern pow
3096 | decode_RB8 RC, INS
3097 | decode_RC8 RB, INS
3098 | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!)
3101 | add CARG2, BASE, RB
3103 | // RA = dst*8, RC = src_start*8, CARG2 = top-1
3106 | lsr CARG3, CARG3, #3
3107 | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
3108 | // Returns NULL (finished) or TValue * (metamethod).
3112 | ldrd CARG34, [BASE, RC]
3115 | strd CARG34, [BASE, RA] // Copy result to RA.
3119 /* -- Constant ops ------------------------------------------------------ */
3122 | // RA = dst*8, RC = str_const (~)
3125 | ldr CARG1, [KBASE, RC, lsl #2]
3126 | mvn CARG2, #~LJ_TSTR
3128 | strd CARG12, [BASE, RA]
3133 | // RA = dst*8, RC = cdata_const (~)
3136 | ldr CARG1, [KBASE, RC, lsl #2]
3137 | mvn CARG2, #~LJ_TCDATA
3139 | strd CARG12, [BASE, RA]
3144 | // RA = dst*8, (RC = int16_literal)
3145 | mov CARG1, INS, asr #16 // Refetch sign-extended reg.
3146 | mvn CARG2, #~LJ_TISNUM
3149 | strd CARG12, [BASE, RA]
3153 | // RA = dst*8, RC = num_const
3156 | ldrd CARG12, [KBASE, RC]
3158 | strd CARG12, [BASE, RA]
3162 | // RA = dst*8, RC = primitive_type (~)
3171 | // RA = base*8, RC = end
3173 | add RC, BASE, RC, lsl #3
3174 | mvn CARG1, #~LJ_TNIL
3175 | str CARG1, [RA, #4]
3178 | str CARG1, [RA, #4]
3185 /* -- Upvalue and function ops ------------------------------------------ */
3188 | // RA = dst*8, RC = uvnum
3189 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3191 | add RC, RC, #offsetof(GCfuncL, uvptr)
3192 | ldr UPVAL:CARG2, [LFUNC:CARG2, RC]
3193 | ldr CARG2, UPVAL:CARG2->v
3194 | ldrd CARG34, [CARG2]
3197 | strd CARG34, [BASE, RA]
3201 | // RA = uvnum*8, RC = src
3202 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3204 | add RA, RA, #offsetof(GCfuncL, uvptr)
3206 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3207 | ldrd CARG34, [BASE, RC]
3208 | ldrb RB, UPVAL:CARG2->marked
3209 | ldrb RC, UPVAL:CARG2->closed
3210 | ldr CARG2, UPVAL:CARG2->v
3211 | tst RB, #LJ_GC_BLACK // isblack(uv)
3212 | add RB, CARG4, #-LJ_TISGCV
3214 | strd CARG34, [CARG2]
3215 | bne >2 // Upvalue is closed and black?
3219 |2: // Check if new value is collectable.
3220 | cmn RB, #-(LJ_TNUMX - LJ_TISGCV)
3221 | ldrbhi RC, GCOBJ:CARG3->gch.marked
3222 | bls <1 // tvisgcv(v)
3223 | sub CARG1, DISPATCH, #-GG_DISP2G
3224 | tst RC, #LJ_GC_WHITES
3225 | // Crossed a write barrier. Move the barrier forward.
3229 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3232 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3237 | // RA = uvnum*8, RC = str_const (~)
3238 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3240 | add RA, RA, #offsetof(GCfuncL, uvptr)
3242 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3243 | ldr STR:CARG3, [KBASE, RC, lsl #2]
3244 | mvn CARG4, #~LJ_TSTR
3245 | ldrb RB, UPVAL:CARG2->marked
3246 | ldr CARG2, UPVAL:CARG2->v
3247 | ldrb RC, UPVAL:CARG2->closed
3248 | tst RB, #LJ_GC_BLACK // isblack(uv)
3249 | ldrb RB, STR:CARG3->marked
3250 | strd CARG34, [CARG2]
3255 |2: // Check if string is white and ensure upvalue is closed.
3256 | tst RB, #LJ_GC_WHITES // iswhite(str)
3258 | sub CARG1, DISPATCH, #-GG_DISP2G
3259 | // Crossed a write barrier. Move the barrier forward.
3263 | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3266 | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
3271 | // RA = uvnum*8, RC = num_const
3272 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3274 | add RA, RA, #offsetof(GCfuncL, uvptr)
3276 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3277 | ldrd CARG34, [KBASE, RC]
3278 | ldr CARG2, UPVAL:CARG2->v
3281 | strd CARG34, [CARG2]
3285 | // RA = uvnum*8, RC = primitive_type (~)
3286 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3288 | add RA, RA, #offsetof(GCfuncL, uvptr)
3289 | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
3291 | ldr CARG2, UPVAL:CARG2->v
3294 | str RC, [CARG2, #4]
3299 | // RA = level*8, RC = target
3300 | ldr CARG3, L->openupval
3301 | add RC, PC, RC, lsl #2
3304 | sub PC, RC, #0x20000
3307 | add CARG2, BASE, RA
3308 | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
3315 | // RA = dst*8, RC = proto_const (~) (holding function prototype)
3318 | ldr CARG2, [KBASE, RC, lsl #2]
3320 | ldr CARG3, [BASE, FRAME_FUNC]
3322 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
3323 | bl extern lj_func_newL_gc
3324 | // Returns GCfuncL *.
3326 | mvn CARG2, #~LJ_TFUNC
3329 | strd CARG12, [BASE, RA]
3333 /* -- Table ops --------------------------------------------------------- */
3337 | // RA = dst*8, RC = (hbits|asize) | tab_const (~)
3338 if (op == BC_TDUP) {
3341 | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]
3342 | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]
3349 if (op == BC_TNEW) {
3350 | lsl CARG2, RC, #21
3351 | lsr CARG3, RC, #11
3352 | asr RC, CARG2, #21
3353 | lsr CARG2, CARG2, #21
3355 | addeq CARG2, CARG2, #2
3356 | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
3357 | // Returns GCtab *.
3359 | ldr CARG2, [KBASE, RC, lsl #2]
3360 | bl extern lj_tab_dup // (lua_State *L, Table *kt)
3361 | // Returns GCtab *.
3364 | mvn CARG2, #~LJ_TTAB
3367 | strd CARG12, [BASE, RA]
3370 | bl extern lj_gc_step_fixtop // (lua_State *L)
3376 | // RA = dst*8, RC = str_const (~)
3378 | // RA = dst*8, RC = str_const (~)
3379 | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
3381 | ldr TAB:CARG1, LFUNC:CARG2->env
3382 | ldr STR:RC, [KBASE, RC, lsl #2]
3383 if (op == BC_GGET) {
3391 | decode_RB8 RB, INS
3392 | decode_RC8 RC, INS
3393 | // RA = dst*8, RB = table*8, RC = key*8
3394 | ldrd TAB:CARG12, [BASE, RB]
3395 | ldrd CARG34, [BASE, RC]
3396 | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12.
3397 | checktp CARG4, LJ_TISNUM // Integer key?
3398 | ldreq CARG4, TAB:CARG1->array
3399 | ldreq CARG2, TAB:CARG1->asize
3402 | add CARG4, CARG4, CARG3, lsl #3
3403 | cmp CARG3, CARG2 // In array part?
3404 | ldrdlo CARG34, [CARG4]
3406 | ins_next1 // Overwrites RB!
3407 | checktp CARG4, LJ_TNIL
3411 | strd CARG34, [BASE, RA]
3414 |5: // Check for __index if table value is nil.
3415 | ldr TAB:CARG2, TAB:CARG1->metatable
3417 | beq <1 // No metatable: done.
3418 | ldrb CARG2, TAB:CARG2->nomm
3419 | tst CARG2, #1<<MM_index
3420 | bne <1 // 'no __index' flag set: done.
3421 | decode_RB8 RB, INS // Restore RB.
3425 | checktp CARG4, LJ_TSTR // String key?
3426 | moveq STR:RC, CARG3
3431 | decode_RB8 RB, INS
3433 | // RA = dst*8, RB = table*8, RC = str_const (~)
3434 | ldrd CARG12, [BASE, RB]
3436 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3437 | checktab CARG2, ->vmeta_tgets1
3439 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3440 | ldr CARG3, TAB:CARG1->hmask
3441 | ldr CARG4, STR:RC->hash
3442 | ldr NODE:INS, TAB:CARG1->node
3443 | mov TAB:RB, TAB:CARG1
3444 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3445 | add CARG3, CARG3, CARG3, lsl #1
3446 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3448 | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS.
3449 | ldrd CARG34, NODE:INS->val
3450 | ldr NODE:INS, NODE:INS->next
3451 | checktp CARG2, LJ_TSTR
3452 | cmpeq CARG1, STR:RC
3454 | checktp CARG4, LJ_TNIL
3459 | strd CARG34, [BASE, RA]
3462 |4: // Follow hash chain.
3465 | // End of hash chain: key not found, nil result.
3467 |5: // Check for __index if table value is nil.
3468 | ldr TAB:CARG1, TAB:RB->metatable
3469 | mov CARG3, #0 // Optional clear of undef. value (during load stall).
3470 | mvn CARG4, #~LJ_TNIL
3472 | beq <3 // No metatable: done.
3473 | ldrb CARG2, TAB:CARG1->nomm
3474 | tst CARG2, #1<<MM_index
3475 | bne <3 // 'no __index' flag set: done.
3479 | decode_RB8 RB, INS
3481 | // RA = dst*8, RB = table*8, RC = index
3482 | ldrd CARG12, [BASE, RB]
3483 | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12.
3484 | ldr CARG3, TAB:CARG1->asize
3485 | ldr CARG4, TAB:CARG1->array
3488 | ldrdlo CARG34, [CARG4, CARG2]
3490 | ins_next1 // Overwrites RB!
3491 | checktp CARG4, LJ_TNIL
3495 | strd CARG34, [BASE, RA]
3498 |5: // Check for __index if table value is nil.
3499 | ldr TAB:CARG2, TAB:CARG1->metatable
3501 | beq <1 // No metatable: done.
3502 | ldrb CARG2, TAB:CARG2->nomm
3503 | tst CARG2, #1<<MM_index
3504 | bne <1 // 'no __index' flag set: done.
3509 | decode_RB8 RB, INS
3510 | decode_RC8 RC, INS
3511 | // RA = src*8, RB = table*8, RC = key*8
3512 | ldrd TAB:CARG12, [BASE, RB]
3513 | ldrd CARG34, [BASE, RC]
3514 | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12.
3515 | checktp CARG4, LJ_TISNUM // Integer key?
3516 | ldreq CARG2, TAB:CARG1->array
3517 | ldreq CARG4, TAB:CARG1->asize
3520 | add CARG2, CARG2, CARG3, lsl #3
3521 | cmp CARG3, CARG4 // In array part?
3522 | ldrlo INS, [CARG2, #4]
3524 | ins_next1 // Overwrites RB!
3525 | checktp INS, LJ_TNIL
3526 | ldrb INS, TAB:CARG1->marked
3527 | ldrd CARG34, [BASE, RA]
3530 | tst INS, #LJ_GC_BLACK // isblack(table)
3531 | strd CARG34, [CARG2]
3537 |5: // Check for __newindex if previous value is nil.
3538 | ldr TAB:RA, TAB:CARG1->metatable
3540 | beq <1 // No metatable: done.
3541 | ldrb RA, TAB:RA->nomm
3542 | tst RA, #1<<MM_newindex
3543 | bne <1 // 'no __newindex' flag set: done.
3544 | ldr INS, [PC, #-4] // Restore RA and RB.
3545 | decode_RB8 RB, INS
3546 | decode_RA8 RA, INS
3549 |7: // Possible table write barrier for the value. Skip valiswhite check.
3550 | barrierback TAB:CARG1, INS, CARG3
3554 | checktp CARG4, LJ_TSTR // String key?
3555 | moveq STR:RC, CARG3
3560 | decode_RB8 RB, INS
3562 | // RA = src*8, RB = table*8, RC = str_const (~)
3563 | ldrd CARG12, [BASE, RB]
3565 | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
3566 | checktab CARG2, ->vmeta_tsets1
3568 | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
3569 | ldr CARG3, TAB:CARG1->hmask
3570 | ldr CARG4, STR:RC->hash
3571 | ldr NODE:INS, TAB:CARG1->node
3572 | mov TAB:RB, TAB:CARG1
3573 | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
3574 | add CARG3, CARG3, CARG3, lsl #1
3576 | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
3577 | strb CARG4, TAB:RB->nomm // Clear metamethod cache.
3579 | ldrd CARG12, NODE:INS->key
3580 | ldr CARG4, NODE:INS->val.it
3581 | ldr NODE:CARG3, NODE:INS->next
3582 | checktp CARG2, LJ_TSTR
3583 | cmpeq CARG1, STR:RC
3585 | ldrb CARG2, TAB:RB->marked
3586 | checktp CARG4, LJ_TNIL // Key found, but nil value?
3587 | ldrd CARG34, [BASE, RA]
3590 | tst CARG2, #LJ_GC_BLACK // isblack(table)
3591 | strd CARG34, NODE:INS->val
3596 |4: // Check for __newindex if previous value is nil.
3597 | ldr TAB:CARG1, TAB:RB->metatable
3599 | beq <2 // No metatable: done.
3600 | ldrb CARG1, TAB:CARG1->nomm
3601 | tst CARG1, #1<<MM_newindex
3602 | bne <2 // 'no __newindex' flag set: done.
3605 |5: // Follow hash chain.
3606 | movs NODE:INS, NODE:CARG3
3608 | // End of hash chain: key not found, add a new one.
3610 | // But check for __newindex first.
3611 | ldr TAB:CARG1, TAB:RB->metatable
3614 | cmp TAB:CARG1, #0 // No metatable: continue.
3616 | ldrbne CARG2, TAB:CARG1->nomm
3619 | tst CARG2, #1<<MM_newindex
3620 | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
3622 | mvn CARG4, #~LJ_TSTR
3623 | str STR:RC, TMPDlo
3626 | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
3627 | // Returns TValue *.
3629 | ldrd CARG34, [BASE, RA]
3630 | strd CARG34, [CRET1]
3631 | b <3 // No 2nd write barrier needed.
3633 |7: // Possible table write barrier for the value. Skip valiswhite check.
3634 | barrierback TAB:RB, CARG2, CARG3
3638 | decode_RB8 RB, INS
3640 | // RA = src*8, RB = table*8, RC = index
3641 | ldrd CARG12, [BASE, RB]
3642 | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12.
3643 | ldr CARG3, TAB:CARG1->asize
3644 | ldr RB, TAB:CARG1->array
3647 | ldrdlo CARG34, [CARG2, RB]!
3649 | ins_next1 // Overwrites RB!
3650 | checktp CARG4, LJ_TNIL
3651 | ldrb INS, TAB:CARG1->marked
3652 | ldrd CARG34, [BASE, RA]
3655 | tst INS, #LJ_GC_BLACK // isblack(table)
3656 | strd CARG34, [CARG2]
3662 |5: // Check for __newindex if previous value is nil.
3663 | ldr TAB:RA, TAB:CARG1->metatable
3665 | beq <1 // No metatable: done.
3666 | ldrb RA, TAB:RA->nomm
3667 | tst RA, #1<<MM_newindex
3668 | bne <1 // 'no __newindex' flag set: done.
3669 | ldr INS, [PC, #-4] // Restore INS.
3670 | decode_RA8 RA, INS
3673 |7: // Possible table write barrier for the value. Skip valiswhite check.
3674 | barrierback TAB:CARG1, INS, CARG3
3679 | // RA = base*8 (table at base-1), RC = num_const (start index)
3682 | ldr RB, SAVE_MULTRES
3683 | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table.
3684 | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word.
3686 | ldr CARG4, TAB:CARG2->asize
3687 | beq >4 // Nothing to copy?
3688 | add CARG3, CARG1, RB, lsr #3
3690 | ldr CARG4, TAB:CARG2->array
3693 | add INS, CARG4, CARG1, lsl #3
3694 | ldrb CARG1, TAB:CARG2->marked
3695 |3: // Copy result slots to table.
3696 | ldrd CARG34, [RA], #8
3697 | strd CARG34, [INS], #8
3700 | tst CARG1, #LJ_GC_BLACK // isblack(table)
3705 |5: // Need to resize array part.
3709 | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
3710 | // Must not reallocate the stack.
3711 | .IOS ldr BASE, L->base
3714 |7: // Possible table write barrier for any value. Skip valiswhite check.
3715 | barrierback TAB:CARG2, CARG1, CARG3
3719 /* -- Calls and vararg handling ----------------------------------------- */
3722 | // RA = base*8, (RB = nresults+1,) RC = extra_nargs
3723 | ldr CARG1, SAVE_MULTRES
3724 | decode_RC8 NARGS8:RC, INS
3725 | add NARGS8:RC, NARGS8:RC, CARG1
3729 | decode_RC8 NARGS8:RC, INS
3730 | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8
3732 | mov RB, BASE // Save old BASE for vmeta_call.
3733 | ldrd CARG34, [BASE, RA]!
3734 | sub NARGS8:RC, NARGS8:RC, #8
3735 | add BASE, BASE, #8
3736 | checkfunc CARG4, ->vmeta_call
3741 | // RA = base*8, (RB = 0,) RC = extra_nargs
3742 | ldr CARG1, SAVE_MULTRES
3743 | add NARGS8:RC, CARG1, RC, lsl #3
3747 | lsl NARGS8:RC, RC, #3
3748 | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
3750 | ldrd LFUNC:CARG34, [RA, BASE]!
3751 | sub NARGS8:RC, NARGS8:RC, #8
3753 | checkfunc CARG4, ->vmeta_callt
3754 | ldr PC, [BASE, FRAME_PC]
3757 | ldrb CARG4, LFUNC:CARG3->ffid
3758 | tst PC, #FRAME_TYPE
3761 | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC.
3765 | ldrd CARG12, [RA, RB]
3767 | cmp INS, NARGS8:RC
3768 | strd CARG12, [BASE, RB]
3772 | cmp CARG4, #1 // (> FF_C) Calling a fast function?
3777 |5: // Tailcall to a fast function with a Lua frame below.
3778 | ldr INS, [PC, #-4]
3779 | decode_RA8 RA, INS
3780 | sub CARG1, BASE, RA
3781 | ldr LFUNC:CARG1, [CARG1, #-16]
3782 | ldr CARG1, LFUNC:CARG1->field_pc
3783 | ldr KBASE, [CARG1, #PC2PROTO(k)]
3786 |7: // Tailcall from a vararg function.
3787 | eor PC, PC, #FRAME_VARG
3788 | tst PC, #FRAME_TYPEP // Vararg frame below?
3789 | movne CARG4, #0 // Clear ffid if no Lua function below.
3791 | sub BASE, BASE, PC
3792 | ldr PC, [BASE, FRAME_PC]
3793 | tst PC, #FRAME_TYPE
3794 | movne CARG4, #0 // Clear ffid if no Lua function below.
3799 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3801 | mov RB, BASE // Save old BASE for vmeta_call.
3802 | ldrd CARG34, [RA, #-16]
3803 | ldrd CARG12, [RA, #-8]
3805 | strd CARG34, [RA, #8] // Copy state.
3806 | strd CARG12, [RA, #16] // Copy control var.
3807 | // STALL: locked CARG34.
3808 | ldrd LFUNC:CARG34, [RA, #-24]
3809 | mov NARGS8:RC, #16 // Iterators get 2 arguments.
3810 | // STALL: load CARG34.
3811 | strd LFUNC:CARG34, [RA] // Copy callable.
3812 | checkfunc CARG4, ->vmeta_call
3817 | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
3819 | // NYI: add hotloop, record BC_ITERN.
3822 | ldr TAB:RB, [RA, #-16]
3823 | ldr CARG1, [RA, #-8] // Get index from control var.
3824 | ldr INS, TAB:RB->asize
3825 | ldr CARG2, TAB:RB->array
3827 |1: // Traverse array part.
3828 | subs RC, CARG1, INS
3829 | add CARG3, CARG2, CARG1, lsl #3
3830 | bhs >5 // Index points after array part?
3831 | ldrd CARG34, [CARG3]
3832 | checktp CARG4, LJ_TNIL
3833 | addeq CARG1, CARG1, #1 // Skip holes in array part.
3835 | ldrh RC, [PC, #-2]
3836 | mvn CARG2, #~LJ_TISNUM
3837 | strd CARG34, [RA, #8]
3838 | add RC, PC, RC, lsl #2
3841 | sub PC, RC, #0x20000
3842 | str RB, [RA, #-8] // Update control var.
3846 |5: // Traverse hash part.
3847 | ldr CARG4, TAB:RB->hmask
3848 | ldr NODE:RB, TAB:RB->node
3850 | add CARG1, RC, RC, lsl #1
3851 | cmp RC, CARG4 // End of iteration? Branch to ITERL+1.
3852 | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8
3854 | ldrd CARG12, NODE:CARG3->val
3855 | checktp CARG2, LJ_TNIL
3857 | beq <6 // Skip holes in hash part.
3858 | ldrh RB, [PC, #-2]
3860 | ldrd CARG34, NODE:CARG3->key
3861 | str RC, [RA, #-8] // Update control var.
3862 | strd CARG12, [RA, #8]
3863 | add RC, PC, RB, lsl #2
3864 | sub PC, RC, #0x20000
3870 | // RA = base*8, RC = target (points to ITERN)
3872 | add RC, PC, RC, lsl #2
3873 | ldrd CFUNC:CARG12, [RA, #-24]
3874 | ldr CARG3, [RA, #-12]
3875 | ldr CARG4, [RA, #-4]
3876 | checktp CARG2, LJ_TFUNC
3877 | ldrbeq CARG1, CFUNC:CARG1->ffid
3878 | checktpeq CARG3, LJ_TTAB
3879 | checktpeq CARG4, LJ_TNIL
3880 | cmpeq CARG1, #FF_next_N
3881 | subeq PC, RC, #0x20000
3886 | mvn CARG2, #0x00018000
3887 | strd CARG1, [RA, #-8] // Initialize control var.
3890 |5: // Despecialize bytecode if any of the checks fail.
3891 | mov CARG1, #BC_JMP
3893 | strb CARG1, [PC, #-4]
3894 | sub PC, RC, #0x20000
3895 | strb OP, [PC] // Subsumes ins_next1.
3901 | decode_RB8 RB, INS
3902 | decode_RC8 RC, INS
3903 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
3904 | ldr CARG1, [BASE, FRAME_PC]
3907 | add RC, RC, #FRAME_VARG
3909 | sub CARG3, BASE, #8 // CARG3 = vtop
3910 | sub RC, RC, CARG1 // RC = vbase
3911 | // Note: RC may now be even _above_ BASE if nargs was < numparams.
3913 | sub CARG1, CARG3, RC
3914 | beq >5 // Copy all varargs?
3915 | sub CARG4, CARG4, #16
3916 |1: // Copy vararg slots to destination slots.
3918 | ldrdlo CARG12, [RC], #8
3919 | mvnhs CARG2, #~LJ_TNIL
3921 | strd CARG12, [RA], #8
3926 |5: // Copy all varargs.
3927 | ldr CARG4, L->maxstack
3929 | movle RB, #8 // MULTRES = (0+1)*8
3930 | addgt RB, CARG1, #8
3931 | add CARG2, RA, CARG1
3932 | str RB, SAVE_MULTRES
3937 | ldrd CARG12, [RC], #8
3938 | strd CARG12, [RA], #8
3943 |7: // Grow stack for varargs.
3944 | lsr CARG2, CARG1, #3
3948 | sub RC, RC, BASE // Need delta, because BASE may change.
3951 | bl extern lj_state_growstack // (lua_State *L, int n)
3955 | sub CARG3, BASE, #8
3959 /* -- Returns ----------------------------------------------------------- */
3962 | // RA = results*8, RC = extra results
3963 | ldr CARG1, SAVE_MULTRES
3964 | ldr PC, [BASE, FRAME_PC]
3966 | add RC, CARG1, RC, lsl #3
3971 | // RA = results*8, RC = nresults+1
3972 | ldr PC, [BASE, FRAME_PC]
3976 | str RC, SAVE_MULTRES
3978 | ands CARG1, PC, #FRAME_TYPE
3979 | eor CARG2, PC, #FRAME_VARG
3983 | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return
3984 | ldr INS, [PC, #-4]
3985 | subs CARG4, RC, #8
3986 | sub CARG3, BASE, #8
3989 | ldrd CARG12, [RA], #8
3990 | add BASE, BASE, #8
3991 | subs CARG4, CARG4, #8
3992 | strd CARG12, [BASE, #-16]
3995 | decode_RA8 RA, INS
3996 | sub CARG4, CARG3, RA
3997 | decode_RB8 RB, INS
3998 | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]
4000 | cmp RB, RC // More results expected?
4003 | ldr CARG2, LFUNC:CARG1->field_pc
4006 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4009 |6: // Fill up results with nil.
4010 | mvn CARG2, #~LJ_TNIL
4011 | add BASE, BASE, #8
4013 | str CARG2, [BASE, #-12]
4016 |->BC_RETV1_Z: // Non-standard return case.
4019 | tst CARG2, #FRAME_TYPEP
4021 | // Return from vararg function: relocate BASE down.
4022 | sub BASE, BASE, CARG2
4023 | ldr PC, [BASE, FRAME_PC]
4027 case BC_RET0: case BC_RET1:
4028 | // RA = results*8, RC = nresults+1
4029 | ldr PC, [BASE, FRAME_PC]
4031 | str RC, SAVE_MULTRES
4032 | ands CARG1, PC, #FRAME_TYPE
4033 | eor CARG2, PC, #FRAME_VARG
4034 | ldreq INS, [PC, #-4]
4036 if (op == BC_RET1) {
4037 | ldrd CARG12, [BASE, RA]
4039 | sub CARG4, BASE, #8
4040 | decode_RA8 RA, INS
4041 if (op == BC_RET1) {
4042 | strd CARG12, [CARG4]
4044 | sub BASE, CARG4, RA
4045 | decode_RB8 RB, INS
4046 | ldr LFUNC:CARG1, [BASE, FRAME_FUNC]
4050 | ldr CARG2, LFUNC:CARG1->field_pc
4053 | ldr KBASE, [CARG2, #PC2PROTO(k)]
4056 |6: // Fill up results with nil.
4057 | sub CARG2, CARG4, #4
4058 | mvn CARG3, #~LJ_TNIL
4059 | str CARG3, [CARG2, RC]
4064 /* -- Loops and branches ------------------------------------------------ */
4066 |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4]
4067 |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12]
4068 |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]
4069 |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28]
4075 | // Fall through. Assumes BC_IFORL follows.
4085 | // RA = base*8, RC = target (after end of loop or start of loop)
4086 vk = (op == BC_IFORL || op == BC_JFORL);
4087 | ldrd CARG12, [RA, BASE]!
4088 if (op != BC_JFORL) {
4089 | add RC, PC, RC, lsl #2
4092 | ldrd CARG34, FOR_STOP
4093 | checktp CARG2, LJ_TISNUM
4096 | checktp CARG4, LJ_TISNUM
4097 | ldr CARG4, FOR_STEP
4098 | checktpeq RB, LJ_TISNUM
4104 | ldrd CARG34, FOR_STEP
4105 | checktp CARG2, LJ_TISNUM
4107 | adds CARG1, CARG1, CARG3
4108 | ldr CARG4, FOR_STOP
4109 if (op == BC_IFORL) {
4110 | addvs RC, PC, #0x20000 // Overflow: prevent branch.
4112 | bvs >2 // Overflow: do not enter mcode.
4119 if (op == BC_FORI) {
4120 | subgt PC, RC, #0x20000
4121 } else if (op == BC_JFORI) {
4122 | sub PC, RC, #0x20000
4123 | ldrhle RC, [PC, #-2]
4124 } else if (op == BC_IFORL) {
4125 | suble PC, RC, #0x20000
4128 | strd CARG12, FOR_IDX
4133 | strd CARG12, FOR_EXT
4134 if (op == BC_JFORI || op == BC_JFORL) {
4140 |4: // Invert check for negative step.
4150 | cmnlo CARG4, #-LJ_TISNUM
4151 | cmnlo RB, #-LJ_TISNUM
4160 | strd CARG12, FOR_EXT
4169 | vadd.f64 d0, d0, d2
4173 | bl extern __aeabi_dadd
4174 | strd CARG12, FOR_IDX
4175 | ldrd CARG34, FOR_STOP
4176 | strd CARG12, FOR_EXT
4185 | bl extern __aeabi_cdcmple
4193 if (op == BC_FORI) {
4194 | subhi PC, RC, #0x20000
4195 } else if (op == BC_JFORI) {
4196 | sub PC, RC, #0x20000
4197 | ldrhls RC, [PC, #-2]
4199 } else if (op == BC_IFORL) {
4200 | subls PC, RC, #0x20000
4209 |8: // Invert check for negative step.
4211 | bl extern __aeabi_dadd
4212 | strd CARG12, FOR_IDX
4213 | strd CARG12, FOR_EXT
4217 | ldrd CARG12, FOR_STOP
4226 | // Fall through. Assumes BC_IITERL follows.
4234 | // RA = base*8, RC = target
4235 | ldrd CARG12, [RA, BASE]!
4236 if (op == BC_JITERL) {
4237 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4238 | strdne CARG12, [RA, #-8]
4241 | add RC, PC, RC, lsl #2
4242 | // STALL: load CARG12.
4243 | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
4244 | subne PC, RC, #0x20000 // Otherwise save control var + branch.
4245 | strdne CARG12, [RA, #-8]
4251 | // RA = base*8, RC = target (loop extent)
4252 | // Note: RA/RC is only used by trace recorder to determine scope/extent
4253 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
4257 | // Fall through. Assumes BC_ILOOP follows.
4261 | // RA = base*8, RC = target (loop extent)
4267 | // RA = base (ignored), RC = traceno
4268 | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
4269 | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0.
4270 | ldr TRACE:RC, [CARG1, RC, lsl #2]
4272 | ldr RA, TRACE:RC->mcode
4273 | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
4274 | str L, [DISPATCH, #DISPATCH_GL(jit_L)]
4280 | // RA = base*8 (only used by trace recorder), RC = target
4281 | add RC, PC, RC, lsl #2
4282 | sub PC, RC, #0x20000
4286 /* -- Function headers -------------------------------------------------- */
4292 case BC_FUNCV: /* NYI: compiled vararg functions. */
4293 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
4301 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4302 | ldr CARG1, L->maxstack
4303 | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]
4304 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4306 | bhi ->vm_growstack_l
4307 if (op != BC_JFUNCF) {
4312 | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters.
4313 | mvn CARG4, #~LJ_TNIL
4315 if (op == BC_JFUNCF) {
4322 |3: // Clear missing parameters.
4323 | strd CARG34, [BASE, NARGS8:RC]
4324 | add NARGS8:RC, NARGS8:RC, #8
4332 | NYI // NYI: compiled vararg functions
4333 break; /* NYI: compiled vararg functions. */
4336 | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
4337 | ldr CARG1, L->maxstack
4338 | add CARG4, BASE, RC
4340 | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC.
4341 | add CARG2, RC, #8+FRAME_VARG
4342 | ldr KBASE, [PC, #-4+PC2PROTO(k)]
4344 | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG.
4345 | bhs ->vm_growstack_l
4346 | ldrb RB, [PC, #-4+PC2PROTO(numparams)]
4350 | add BASE, CARG4, #8
4352 | mvn CARG3, #~LJ_TNIL
4354 | cmp RA, RC // Less args than parameters?
4355 | ldrdlo CARG12, [RA], #8
4356 | movhs CARG2, CARG3
4357 | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC).
4360 | strd CARG12, [CARG4, #8]!
4368 | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8
4369 if (op == BC_FUNCC) {
4370 | ldr CARG4, CFUNC:CARG3->f
4372 | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]
4374 | add CARG2, RA, NARGS8:RC
4375 | ldr CARG1, L->maxstack
4376 | add RC, BASE, NARGS8:RC
4380 if (op == BC_FUNCCW) {
4381 | ldr CARG2, CFUNC:CARG3->f
4383 | mv_vmstate CARG3, C
4385 | bhi ->vm_growstack_c // Need to grow stack.
4387 | blx CARG4 // (lua_State *L [, lua_CFunction f])
4388 | // Returns nresults.
4390 | mv_vmstate CARG3, INTERP
4394 | ldr PC, [BASE, FRAME_PC]
4395 | sub RA, CRET2, RC // RA = L->top - nresults*8
4399 /* ---------------------------------------------------------------------- */
4402 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
4408 static int build_backend(BuildCtx *ctx)
4412 dasm_growpc(Dst, BC__MAX);
4414 build_subroutines(ctx);
4417 for (op = 0; op < BC__MAX; op++)
4418 build_ins(ctx, (BCOp)op, op);
4423 /* Emit pseudo frame-info for all assembler functions. */
4424 static void emit_asm_debug(BuildCtx *ctx)
4426 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
4428 switch (ctx->mode) {
4430 fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n");
4433 "\t.long .LECIE0-.LSCIE0\n"
4435 "\t.long 0xffffffff\n"
4440 "\t.byte 0xe\n" /* Return address is in lr. */
4441 "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */
4446 "\t.long .LEFDE0-.LASFDE0\n"
4448 "\t.long .Lframe0\n"
4451 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
4452 "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */
4453 fcofs, CFRAME_SIZE);
4454 for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */
4455 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i));
4457 for (i = 15; i >= 8; i--) /* offset d8-d15 */
4458 fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n",
4459 64+2*i, 10+2*(15-i));
4460 fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */
4468 "\t.long .LEFDE1-.LASFDE1\n"
4470 "\t.long .Lframe0\n"
4471 "\t.long lj_vm_ffi_call\n"
4473 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
4474 "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */
4475 "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */
4476 "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */
4477 "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */
4478 "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */
4480 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);