1 |// Low-level VM code for MIPS 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.
19 |// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra
21 |// The following must be C callee-save (but BASE is often refetched).
22 |.define BASE, r16 // Base of current Lua stack frame.
23 |.define KBASE, r17 // Constants of current Lua function.
24 |.define PC, r18 // Next PC.
25 |.define DISPATCH, r19 // Opcode dispatch table.
26 |.define LREG, r20 // Register holding lua_State (also in SAVE_L).
27 |.define MULTRES, r21 // Size of multi-result: (nresults+1)*8.
28 |// NYI: r22 currently unused.
30 |.define JGL, r30 // On-trace: global_State + 32768.
32 |// Constants for type-comparisons, stores and conversions. C callee-save.
34 |.define TOBIT, f30 // 2^52 + 2^51.
36 |// The following temporaries are not saved across C calls, except for RA.
37 |.define RA, r23 // Callee-save.
43 |.define AT, r1 // Assembler temporary.
49 |// Calling conventions.
50 |.define CFUNCADDR, r25
65 |// Stack layout while in interpreter. Must match with lj_frame.h.
66 |.define CFRAME_SPACE, 112 // Delta for sp.
68 |.define SAVE_ERRF, 124(sp) // 32 bit C frame info.
69 |.define SAVE_NRES, 120(sp)
70 |.define SAVE_CFRAME, 116(sp)
71 |.define SAVE_L, 112(sp)
72 |//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.
73 |.define SAVE_GPR_, 72 // .. 72+10*4: 32 bit GPR saves.
74 |.define SAVE_FPR_, 24 // .. 24+6*8: 64 bit FPR saves.
75 |.define SAVE_PC, 20(sp)
77 |.define CSAVE_4, 12(sp)
78 |.define CSAVE_3, 8(sp)
79 |.define CSAVE_2, 4(sp)
80 |.define CSAVE_1, 0(sp)
81 |//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee.
84 |.define SAVE_MULTRES, ARG5
87 | addiu sp, sp, -CFRAME_SPACE
88 | sw ra, SAVE_GPR_+9*4(sp)
89 | sw r30, SAVE_GPR_+8*4(sp)
90 | sdc1 f30, SAVE_FPR_+5*8(sp)
91 | sw r23, SAVE_GPR_+7*4(sp)
92 | sw r22, SAVE_GPR_+6*4(sp)
93 | sdc1 f28, SAVE_FPR_+4*8(sp)
94 | sw r21, SAVE_GPR_+5*4(sp)
95 | sw r20, SAVE_GPR_+4*4(sp)
96 | sdc1 f26, SAVE_FPR_+3*8(sp)
97 | sw r19, SAVE_GPR_+3*4(sp)
98 | sw r18, SAVE_GPR_+2*4(sp)
99 | sdc1 f24, SAVE_FPR_+2*8(sp)
100 | sw r17, SAVE_GPR_+1*4(sp)
101 | sw r16, SAVE_GPR_+0*4(sp)
102 | sdc1 f22, SAVE_FPR_+1*8(sp)
103 | sdc1 f20, SAVE_FPR_+0*8(sp)
106 |.macro restoreregs_ret
107 | lw ra, SAVE_GPR_+9*4(sp)
108 | lw r30, SAVE_GPR_+8*4(sp)
109 | ldc1 f30, SAVE_FPR_+5*8(sp)
110 | lw r23, SAVE_GPR_+7*4(sp)
111 | lw r22, SAVE_GPR_+6*4(sp)
112 | ldc1 f28, SAVE_FPR_+4*8(sp)
113 | lw r21, SAVE_GPR_+5*4(sp)
114 | lw r20, SAVE_GPR_+4*4(sp)
115 | ldc1 f26, SAVE_FPR_+3*8(sp)
116 | lw r19, SAVE_GPR_+3*4(sp)
117 | lw r18, SAVE_GPR_+2*4(sp)
118 | ldc1 f24, SAVE_FPR_+2*8(sp)
119 | lw r17, SAVE_GPR_+1*4(sp)
120 | lw r16, SAVE_GPR_+0*4(sp)
121 | ldc1 f22, SAVE_FPR_+1*8(sp)
122 | ldc1 f20, SAVE_FPR_+0*8(sp)
124 | addiu sp, sp, CFRAME_SPACE
127 |// Type definitions. Some of these are only used for documentation.
128 |.type L, lua_State, LREG
129 |.type GL, global_State
130 |.type TVALUE, TValue
134 |.type LFUNC, GCfuncL
135 |.type CFUNC, GCfuncC
136 |.type PROTO, GCproto
137 |.type UPVAL, GCupval
140 |.type TRACE, GCtrace
142 |//-----------------------------------------------------------------------
144 |// Trap for not-yet-implemented parts.
145 |.macro NYI; .long 0xf0f0f0f0; .endmacro
147 |// Macros to mark delay slots.
148 |.macro ., a; a; .endmacro
149 |.macro ., a,b; a,b; .endmacro
150 |.macro ., a,b,c; a,b,c; .endmacro
152 |//-----------------------------------------------------------------------
154 |// Endian-specific defines.
155 |.define FRAME_PC, LJ_ENDIAN_SELECT(-4,-8)
156 |.define FRAME_FUNC, LJ_ENDIAN_SELECT(-8,-4)
157 |.define HI, LJ_ENDIAN_SELECT(4,0)
158 |.define LO, LJ_ENDIAN_SELECT(0,4)
159 |.define OFS_RD, LJ_ENDIAN_SELECT(2,0)
160 |.define OFS_RA, LJ_ENDIAN_SELECT(1,2)
161 |.define OFS_OP, LJ_ENDIAN_SELECT(0,3)
163 |// Instruction decode.
164 |.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro
165 |.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro
166 |.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro
167 |.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro
168 |.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro
169 |.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro
170 |.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro
171 |.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro
172 |.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro
173 |.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro
174 |.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro
175 |.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro
176 |.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro
178 |// Instruction fetch.
183 |// Instruction decode+dispatch.
185 | decode_OP4a TMP1, INS
187 | addu TMP0, DISPATCH, TMP1
188 | decode_RD8a RD, INS
190 | decode_RA8a RA, INS
200 |// Instruction footer.
202 | // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
203 | .define ins_next, ins_NEXT
204 | .define ins_next_, ins_NEXT
205 | .define ins_next1, ins_NEXT1
206 | .define ins_next2, ins_NEXT2
208 | // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
209 | // Affects only certain kinds of benchmarks (and only with -j off).
224 |// Call decode and dispatch.
226 | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
227 | lw PC, LFUNC:RB->pc
230 | decode_OP4a TMP1, INS
231 | decode_RA8a RA, INS
234 | addu TMP0, DISPATCH, TMP1
241 | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
242 | sw PC, FRAME_PC(BASE)
246 |//-----------------------------------------------------------------------
250 | lui AT, (-(BCBIAS_J*4 >> 16) & 65535)
251 | addu TMP0, TMP0, AT
255 |// Assumes DISPATCH is relative to GL.
256 #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
257 #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
258 #define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch))
259 #define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name)
261 #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
263 |.macro load_got, func
264 | lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)
266 |// Much faster. Sadly, there's no easy way to force the required code layout.
267 |// .macro call_intern, func; bal extern func; .endmacro
268 |.macro call_intern, func; jalr CFUNCADDR; .endmacro
269 |.macro call_extern; jalr CFUNCADDR; .endmacro
270 |.macro jmp_extern; jr CFUNCADDR; .endmacro
272 |.macro hotcheck, delta, target
274 | andi TMP1, TMP1, 126
275 | addu TMP1, TMP1, DISPATCH
276 | lhu TMP2, GG_DISP2HOT(TMP1)
277 | addiu TMP2, TMP2, -delta
279 |. sh TMP2, GG_DISP2HOT(TMP1)
283 | hotcheck HOTCOUNT_LOOP, ->vm_hotloop
287 | hotcheck HOTCOUNT_CALL, ->vm_hotcall
290 |// Set current VM state. Uses TMP0.
291 |.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
292 |.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
294 |// Move table write barrier back. Overwrites mark and tmp.
295 |.macro barrierback, tab, mark, tmp, target
296 | lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
297 | andi mark, mark, ~LJ_GC_BLACK & 255 // black2gray(tab)
298 | sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
299 | sb mark, tab->marked
301 |. sw tmp, tab->gclist
304 |//-----------------------------------------------------------------------
306 /* Generate subroutines used by opcodes and other parts of the VM. */
307 /* The .code_sub section should be last to help static branch prediction. */
308 static void build_subroutines(BuildCtx *ctx)
312 |//-----------------------------------------------------------------------
313 |//-- Return handling ----------------------------------------------------
314 |//-----------------------------------------------------------------------
317 | // See vm_return. Also: TMP2 = previous base.
318 | andi AT, PC, FRAME_P
319 | beqz AT, ->cont_dispatch
322 | // Return from pcall or xpcall fast func.
323 | lw PC, FRAME_PC(TMP2) // Fetch PC of previous frame.
324 | move BASE, TMP2 // Restore caller base.
325 | // Prepending may overwrite the pcall frame, so do it at the end.
326 | sw TMP1, FRAME_PC(RA) // Prepend true to results.
330 | addiu RD, RD, 8 // RD = (nresults+1)*8.
331 | andi TMP0, PC, FRAME_TYPE
332 | beqz RD, ->vm_unwind_c_eh
333 |. li CRET1, LUA_YIELD
334 | beqz TMP0, ->BC_RET_Z // Handle regular return to Lua.
338 | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
339 | // TMP0 = PC & FRAME_TYPE
341 | xori AT, TMP0, FRAME_C
343 | bnez AT, ->vm_returnp
344 | subu TMP2, BASE, TMP2 // TMP2 = previous base.
350 | addiu BASE, BASE, -8
355 | addiu TMP1, TMP1, -8
360 |. addiu BASE, BASE, 8
365 |. sw BASE, L->top // Store new top.
368 | lw TMP0, SAVE_CFRAME // Restore previous C frame.
369 | move CRET1, r0 // Ok return status for vm_pcall.
376 | lw TMP1, L->maxstack
378 | bnez AT, >7 // Less results wanted?
379 | // More results wanted. Check stack size and fill up results with nil.
380 |. slt AT, BASE, TMP1
383 | sw TISNIL, HI(BASE)
386 |. addiu BASE, BASE, 8
388 |7: // Less results wanted.
389 | subu TMP0, RD, TMP2
390 | subu TMP0, BASE, TMP0 // Either keep top or shrink it.
392 |. movn BASE, TMP0, TMP2 // LUA_MULTRET+1 case?
394 |8: // Corner case: need to grow stack for filling up results.
395 | // This can happen if:
396 | // - A C function grows the stack (a lot).
397 | // - The GC shrinks the stack in between.
398 | // - A return back from a lua_call() with (high) nresults adjustment.
399 | load_got lj_state_growstack
402 | call_intern lj_state_growstack // (lua_State *L, int n)
405 | lw BASE, L->top // Need the (realloced) L->top in BASE.
410 |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
411 | // (void *cframe, int errcode)
414 |->vm_unwind_c_eh: // Landing pad for external unwinder.
416 | li TMP0, ~LJ_VMST_C
417 | lw GL:TMP1, L->glref
419 |. sw TMP0, GL:TMP1->vmstate
421 |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
425 |->vm_unwind_ff_eh: // Landing pad for external unwinder.
427 | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
430 | lw DISPATCH, L->glref // Setup pointer to dispatch table.
434 | lw PC, FRAME_PC(BASE) // Fetch PC of previous frame.
435 | cvt.d.s TOBIT, TOBIT
436 | addiu RA, BASE, -8 // Results start at BASE-8.
437 | addiu DISPATCH, DISPATCH, GG_G2DISP
438 | sw TMP1, HI(RA) // Prepend false to error message.
441 |. li RD, 16 // 2 results: false + error message.
443 |//-----------------------------------------------------------------------
444 |//-- Grow stack for calls -----------------------------------------------
445 |//-----------------------------------------------------------------------
447 |->vm_growstack_c: // Grow stack for C function.
449 |. li CARG2, LUA_MINSTACK
451 |->vm_growstack_l: // Grow stack for Lua function.
452 | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
456 | addiu PC, PC, 4 // Must point after first instruction.
460 | // L->base = new base, L->top = top
461 | load_got lj_state_growstack
463 | call_intern lj_state_growstack // (lua_State *L, int n)
467 | lw LFUNC:RB, FRAME_FUNC(BASE)
469 | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
470 | ins_callt // Just retry the call.
472 |//-----------------------------------------------------------------------
473 |//-- Entry points into the assembler VM ---------------------------------
474 |//-----------------------------------------------------------------------
476 |->vm_resume: // Setup C frame and resume thread.
477 | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
480 | lw DISPATCH, L->glref // Setup pointer to dispatch table.
482 | lbu TMP1, L->status
485 | addiu TMP0, sp, CFRAME_RESUME
486 | addiu DISPATCH, DISPATCH, GG_G2DISP
492 |. sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
494 | // Resume after yield (like a return).
498 | lw PC, FRAME_PC(BASE)
499 | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
500 | subu RD, TMP1, BASE
503 | cvt.d.s TOBIT, TOBIT
508 | andi TMP0, PC, FRAME_TYPE
509 | beqz TMP0, ->BC_RET_Z
510 |. li TISNIL, LJ_TNIL
514 |->vm_pcall: // Setup protected C frame and enter VM.
515 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
517 | sw CARG4, SAVE_ERRF
521 |->vm_call: // Setup C frame and enter VM.
522 | // (lua_State *L, TValue *base, int nres1)
526 |1: // Entry point for vm_pcall above (PC = ftype).
527 | lw TMP1, L:CARG1->cframe
528 | sw CARG3, SAVE_NRES
532 | sw sp, L->cframe // Add our C frame to cframe chain.
533 | lw DISPATCH, L->glref // Setup pointer to dispatch table.
534 | sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
535 | sw TMP1, SAVE_CFRAME
536 | addiu DISPATCH, DISPATCH, GG_G2DISP
538 |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
539 | lw TMP2, L->base // TMP2 = old base (used in vmeta_call).
540 | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
544 | subu NARGS8:RC, TMP1, BASE
545 | subu PC, PC, TMP2 // PC = frame delta + frame type
546 | cvt.d.s TOBIT, TOBIT
552 | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
553 | lw TMP0, FRAME_PC(BASE)
555 | bne TMP0, AT, ->vmeta_call
556 |. lw LFUNC:RB, FRAME_FUNC(BASE)
558 |->vm_call_dispatch_f:
560 | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
562 |->vm_cpcall: // Setup protected C frame, call C.
563 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
566 | lw TMP0, L:CARG1->stack
569 | sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
570 | subu TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
572 | sw sp, L->cframe // Add our C frame to cframe chain.
573 | sw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
574 | sw r0, SAVE_ERRF // No error function.
575 | move CFUNCADDR, CARG4
576 | jalr CARG4 // (lua_State *L, lua_CFunction func, void *ud)
577 |. sw TMP1, SAVE_CFRAME
579 | lw DISPATCH, L->glref // Setup pointer to dispatch table.
581 | bnez CRET1, <3 // Else continue with the call.
582 |. addiu DISPATCH, DISPATCH, GG_G2DISP
583 | b ->vm_leave_cp // No base? Just remove C frame.
586 |//-----------------------------------------------------------------------
587 |//-- Metamethod handling ------------------------------------------------
588 |//-----------------------------------------------------------------------
590 |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
591 |// stack, so BASE doesn't need to be reloaded across these calls.
593 |//-- Continuation dispatch ----------------------------------------------
596 | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
597 | lw TMP0, -16+LO(BASE) // Continuation.
599 | move BASE, TMP2 // Restore caller BASE.
600 | lw LFUNC:TMP1, FRAME_FUNC(TMP2)
604 | lw PC, -16+HI(RB) // Restore PC from [cont|PC].
606 | lw TMP1, LFUNC:TMP1->pc
610 |. sw TISNIL, -8+HI(TMP2) // Ensure one valid arg.
611 | // BASE = base, RA = resultptr, RB = meta base
612 | jr TMP0 // Jump to continuation.
613 |. lw KBASE, PC2PROTO(k)(TMP1)
617 | bnez TMP0, ->cont_ffi_callback // cont = 1: return from FFI callback.
618 | // cont = 0: tailcall from C function.
619 |. addiu TMP1, RB, -16
621 |. subu RC, TMP1, BASE
624 |->cont_cat: // RA = resultptr, RB = meta base
626 | addiu CARG2, RB, -16
628 | decode_RB8a MULTRES, INS
629 | decode_RA8a RA, INS
630 | decode_RB8b MULTRES
632 | addu TMP1, BASE, MULTRES
634 | subu CARG3, CARG2, TMP1
635 | bne TMP1, CARG2, ->BC_CAT_Z
641 |//-- Table indexing metamethods -----------------------------------------
644 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
646 | sw STR:RC, LO(CARG3)
648 |. sw TMP0, HI(CARG3)
651 | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
653 | sw TAB:RB, LO(CARG2)
654 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
657 | sw STR:RC, LO(CARG3)
659 |. sw TMP1, HI(CARG3)
661 |->vmeta_tgetb: // TMP0 = index
664 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
669 | load_got lj_meta_tget
672 | call_intern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
674 | // Returns TValue * (finished) or NULL (metamethod).
676 |. addiu TMP1, BASE, -FRAME_CONT
682 |3: // Call __index metamethod.
683 | // BASE = base, L->top = new base, stack = cont/func/t/k
685 | sw PC, -16+HI(BASE) // [cont|PC]
686 | subu PC, BASE, TMP1
687 | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
688 | b ->vm_call_dispatch_f
689 |. li NARGS8:RC, 16 // 2 args for func(t, k).
691 |//-----------------------------------------------------------------------
694 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
696 | sw STR:RC, LO(CARG3)
698 |. sw TMP0, HI(CARG3)
701 | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
703 | sw TAB:RB, LO(CARG2)
704 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
707 | sw STR:RC, LO(CARG3)
709 |. sw TMP1, HI(CARG3)
711 |->vmeta_tsetb: // TMP0 = index
714 | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
719 | load_got lj_meta_tset
722 | call_intern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
724 | // Returns TValue * (finished) or NULL (metamethod).
727 | // NOBARRIER: lj_meta_tset ensures the table is not black.
732 |3: // Call __newindex metamethod.
733 | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
734 | addiu TMP1, BASE, -FRAME_CONT
736 | sw PC, -16+HI(BASE) // [cont|PC]
737 | subu PC, BASE, TMP1
738 | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
739 | sdc1 f0, 16(BASE) // Copy value to third argument.
740 | b ->vm_call_dispatch_f
741 |. li NARGS8:RC, 24 // 3 args for func(t, k, v)
743 |//-- Comparison metamethods ---------------------------------------------
746 | // CARG2, CARG3 are already set by BC_ISLT/BC_ISGE/BC_ISLE/BC_ISGT.
747 | load_got lj_meta_comp
751 | decode_OP1 CARG4, INS
752 | call_intern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
754 | // Returns 0/1 or TValue * (metamethod).
757 | beqz AT, ->vmeta_binop
762 | lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)
770 |->cont_ra: // RA = resultptr
771 | lbu TMP1, -4+OFS_RA(PC)
774 | addu TMP1, BASE, TMP1
778 |->cont_condt: // RA = resultptr
780 | sltiu AT, TMP0, LJ_TISTRUECOND
782 |. negu TMP2, AT // Branch if result is true.
784 |->cont_condf: // RA = resultptr
786 | sltiu AT, TMP0, LJ_TISTRUECOND
788 |. addiu TMP2, AT, -1 // Branch if result is false.
791 | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
792 | load_got lj_meta_equal
796 | call_intern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
798 | // Returns 0/1 or TValue * (metamethod).
804 | load_got lj_meta_equal_cd
809 | call_intern lj_meta_equal_cd // (lua_State *L, BCIns op)
811 | // Returns 0/1 or TValue * (metamethod).
816 |//-- Arithmetic metamethods ---------------------------------------------
822 | load_got lj_meta_arith
823 | decode_OP1 TMP0, INS
828 | call_intern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
830 | // Returns NULL (finished) or TValue * (metamethod).
831 | beqz CRET1, ->cont_nop
834 | // Call metamethod for binary op.
836 | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
837 | subu TMP1, CRET1, BASE
838 | sw PC, -16+HI(CRET1) // [cont|PC]
840 | addiu PC, TMP1, FRAME_CONT
842 | b ->vm_call_dispatch
843 |. li NARGS8:RC, 16 // 2 args for func(o1, o2).
846 | // CARG2 already set by BC_LEN.
848 | move MULTRES, CARG1
850 | load_got lj_meta_len
853 | call_intern lj_meta_len // (lua_State *L, TValue *o)
855 | // Returns NULL (retry) or TValue * (metamethod base).
857 | bnez CRET1, ->vmeta_binop // Binop call for compatibility.
860 |. move CARG1, MULTRES
862 | b ->vmeta_binop // Binop call for compatibility.
866 |//-- Call metamethod ----------------------------------------------------
868 |->vmeta_call: // Resolve and call __call metamethod.
869 | // TMP2 = old base, BASE = new base, RC = nargs*8
870 | load_got lj_meta_call
871 | sw TMP2, L->base // This is the callers base!
872 | addiu CARG2, BASE, -8
874 | addu CARG3, BASE, RC
875 | move MULTRES, NARGS8:RC
876 | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
878 | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
879 | addiu NARGS8:RC, MULTRES, 8 // Got one more argument now.
882 |->vmeta_callt: // Resolve __call for BC_CALLT.
883 | // BASE = old base, RA = new base, RC = nargs*8
884 | load_got lj_meta_call
886 | addiu CARG2, RA, -8
889 | move MULTRES, NARGS8:RC
890 | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
892 | lw TMP1, FRAME_PC(BASE)
893 | lw LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here.
895 |. addiu NARGS8:RC, MULTRES, 8 // Got one more argument now.
897 |//-- Argument coercion for 'for' statement ------------------------------
900 | load_got lj_meta_for
905 | call_intern lj_meta_for // (lua_State *L, TValue *base)
908 | decode_OP1 TMP0, MULTRES
911 | decode_RA8a RA, MULTRES
912 | decode_RD8a RD, MULTRES
915 | beq TMP0, AT, =>BC_JFORI
924 |//-----------------------------------------------------------------------
925 |//-- Fast functions -----------------------------------------------------
926 |//-----------------------------------------------------------------------
932 |.macro .ffunc_1, name
934 | beqz NARGS8:RC, ->fff_fallback
935 |. lw CARG3, HI(BASE)
939 |.macro .ffunc_2, name
941 | sltiu AT, NARGS8:RC, 16
943 | bnez AT, ->fff_fallback
944 |. lw CARG4, 8+HI(BASE)
946 | lw CARG2, 8+LO(BASE)
949 |.macro .ffunc_n, name // Caveat: has delay slot!
952 | beqz NARGS8:RC, ->fff_fallback
953 |. ldc1 FARG1, 0(BASE)
954 | sltiu AT, CARG3, LJ_TISNUM
955 | beqz AT, ->fff_fallback
958 |.macro .ffunc_nn, name // Caveat: has delay slot!
960 | sltiu AT, NARGS8:RC, 16
962 | bnez AT, ->fff_fallback
963 |. lw CARG4, 8+HI(BASE)
964 | ldc1 FARG1, 0(BASE)
965 | ldc1 FARG2, 8(BASE)
966 | sltiu TMP0, CARG3, LJ_TISNUM
967 | sltiu TMP1, CARG4, LJ_TISNUM
968 | and TMP0, TMP0, TMP1
969 | beqz TMP0, ->fff_fallback
972 |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!
974 | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)
975 | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
976 | subu AT, TMP0, TMP1
977 | bgezal AT, ->fff_gcstep
980 |//-- Base library: checks -----------------------------------------------
983 | sltiu AT, CARG3, LJ_TISTRUECOND
984 | beqz AT, ->fff_fallback
985 |. addiu RA, BASE, -8
986 | lw PC, FRAME_PC(BASE)
987 | addiu RD, NARGS8:RC, 8 // Compute (nresults+1)*8.
988 | addu TMP2, RA, NARGS8:RC
990 | addiu TMP1, BASE, 8
991 | beq BASE, TMP2, ->fff_res // Done if exactly 1 argument.
997 |. addiu TMP1, TMP1, 8
1002 | lw CARG3, HI(BASE)
1003 | li TMP1, LJ_TISNUM
1004 | beqz NARGS8:RC, ->fff_fallback
1005 |. sltiu TMP0, CARG3, LJ_TISNUM
1006 | movz TMP1, CARG3, TMP0
1009 | addu TMP1, CFUNC:RB, TMP1
1011 |. ldc1 FRET1, CFUNC:TMP1->upvalue
1013 |//-- Base library: getters and setters ---------------------------------
1015 |.ffunc_1 getmetatable
1019 |1: // Field metatable must be at same offset for GCtab and GCudata!
1020 | lw TAB:CARG1, TAB:CARG1->metatable
1022 | lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
1023 | beqz TAB:CARG1, ->fff_restv
1024 |. li CARG3, LJ_TNIL
1025 | lw TMP0, TAB:CARG1->hmask
1026 | li CARG3, LJ_TTAB // Use metatable as default result.
1027 | lw TMP1, STR:RC->hash
1028 | lw NODE:TMP2, TAB:CARG1->node
1029 | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
1032 | subu TMP1, TMP0, TMP1
1033 | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
1035 |3: // Rearranged logic, because we expect _not_ to find the key.
1036 | lw CARG4, offsetof(Node, key)+HI(NODE:TMP2)
1037 | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
1038 | lw NODE:TMP3, NODE:TMP2->next
1040 |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
1041 | beq TMP0, STR:RC, >5
1042 |. lw TMP1, offsetof(Node, val)+LO(NODE:TMP2)
1044 | beqz NODE:TMP3, ->fff_restv // Not found, keep default result.
1045 |. move NODE:TMP2, NODE:TMP3
1049 | beq CARG2, TISNIL, ->fff_restv // Ditto for nil value.
1051 | move CARG3, CARG2 // Return value of mt.__metatable.
1057 |. sltiu TMP0, CARG3, LJ_TISNUM
1058 | li TMP1, LJ_TISNUM
1059 | movz TMP1, CARG3, TMP0
1062 | addu TMP1, DISPATCH, TMP1
1064 |. lw TAB:CARG1, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1)
1066 |.ffunc_2 setmetatable
1067 | // Fast path: no mt for table yet and not clearing the mt.
1069 | bne CARG3, AT, ->fff_fallback
1070 |. addiu CARG4, CARG4, -LJ_TTAB
1071 | lw TAB:TMP1, TAB:CARG1->metatable
1072 | lbu TMP3, TAB:CARG1->marked
1073 | or AT, CARG4, TAB:TMP1
1074 | bnez AT, ->fff_fallback
1075 |. andi AT, TMP3, LJ_GC_BLACK // isblack(table)
1076 | beqz AT, ->fff_restv
1077 |. sw TAB:CARG2, TAB:CARG1->metatable
1078 | barrierback TAB:CARG1, TMP3, TMP0, ->fff_restv
1081 | lw CARG4, HI(BASE)
1082 | sltiu AT, NARGS8:RC, 16
1083 | lw TAB:CARG2, LO(BASE)
1084 | load_got lj_tab_get
1085 | addiu CARG4, CARG4, -LJ_TTAB
1087 | bnez AT, ->fff_fallback
1088 | addiu CARG3, BASE, 8
1089 | call_intern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
1091 | // Returns cTValue *.
1093 |. ldc1 FRET1, 0(CRET1)
1095 |//-- Base library: conversions ------------------------------------------
1098 | // Only handles the number case inline (without a base argument).
1099 | lw CARG1, HI(BASE)
1100 | xori AT, NARGS8:RC, 8
1101 | sltiu CARG1, CARG1, LJ_TISNUM
1102 | movn CARG1, r0, AT
1103 | beqz CARG1, ->fff_fallback // Exactly one number argument.
1104 |. ldc1 FRET1, 0(BASE)
1109 | // Only handles the string or number case inline.
1111 | // A __tostring method in the string base metatable is ignored.
1112 | beq CARG3, AT, ->fff_restv // String key?
1113 | // Handle numbers inline, unless a number base metatable is present.
1114 |. lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
1115 | sltiu TMP0, CARG3, LJ_TISNUM
1116 | sltiu TMP1, TMP1, 1
1117 | and TMP0, TMP0, TMP1
1118 | beqz TMP0, ->fff_fallback
1119 |. sw BASE, L->base // Add frame since C call can throw.
1121 |. sw PC, SAVE_PC // Redundant (but a defined value).
1122 | load_got lj_str_fromnum
1124 | call_intern lj_str_fromnum // (lua_State *L, lua_Number *np)
1126 | // Returns GCstr *.
1129 |. move CARG1, CRET1
1131 |//-- Base library: iterators -------------------------------------------
1134 | lw CARG1, HI(BASE)
1135 | lw TAB:CARG2, LO(BASE)
1136 | beqz NARGS8:RC, ->fff_fallback
1137 |. addu TMP2, BASE, NARGS8:RC
1139 | sw TISNIL, HI(TMP2) // Set missing 2nd arg to nil.
1140 | bne CARG1, AT, ->fff_fallback
1141 |. lw PC, FRAME_PC(BASE)
1142 | load_got lj_tab_next
1143 | sw BASE, L->base // Add frame since C call can throw.
1144 | sw BASE, L->top // Dummy frame length is ok.
1145 | addiu CARG3, BASE, 8
1147 | call_intern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
1149 | // Returns 0 at end of traversal.
1150 | beqz CRET1, ->fff_restv // End of traversal: return nil.
1151 |. li CARG3, LJ_TNIL
1152 | ldc1 f0, 8(BASE) // Copy key and value to results.
1153 | addiu RA, BASE, -8
1162 | bne CARG3, AT, ->fff_fallback
1163 |. lw PC, FRAME_PC(BASE)
1165 | lw TAB:TMP2, TAB:CARG1->metatable
1166 | ldc1 f0, CFUNC:RB->upvalue[0]
1167 | bnez TAB:TMP2, ->fff_fallback
1169 | ldc1 f0, CFUNC:RB->upvalue[0]
1171 |. addiu RA, BASE, -8
1172 | sw TISNIL, 8+HI(BASE)
1178 | sltiu AT, NARGS8:RC, 16
1179 | lw CARG3, HI(BASE)
1180 | lw TAB:CARG1, LO(BASE)
1181 | lw CARG4, 8+HI(BASE)
1182 | bnez AT, ->fff_fallback
1183 |. ldc1 FARG2, 8(BASE)
1184 | addiu CARG3, CARG3, -LJ_TTAB
1185 | sltiu AT, CARG4, LJ_TISNUM
1187 | movn AT, r0, CARG3
1189 | beqz AT, ->fff_fallback
1190 |. lw PC, FRAME_PC(BASE)
1191 | cvt.w.d FRET1, FARG2
1192 | cvt.d.w FARG1, FARG1
1193 | lw TMP0, TAB:CARG1->asize
1194 | lw TMP1, TAB:CARG1->array
1196 | addiu RA, BASE, -8
1197 | add.d FARG2, FARG2, FARG1
1198 | addiu TMP2, TMP2, 1
1199 | sltu AT, TMP2, TMP0
1201 | addu TMP3, TMP1, TMP3
1202 | beqz AT, >2 // Not in array part?
1203 |. sdc1 FARG2, 0(RA)
1207 | beq TMP2, TISNIL, ->fff_res // End of iteration, return 0 results.
1212 |2: // Check for empty hash part first. Otherwise call C function.
1213 | lw TMP0, TAB:CARG1->hmask
1214 | load_got lj_tab_getinth
1215 | beqz TMP0, ->fff_res
1217 | call_intern lj_tab_getinth // (GCtab *t, int32_t key)
1219 | // Returns cTValue * or NULL.
1220 | beqz CRET1, ->fff_res
1222 | lw TMP2, HI(CRET1)
1224 |. ldc1 f0, 0(CRET1)
1228 | bne CARG3, AT, ->fff_fallback
1229 |. lw PC, FRAME_PC(BASE)
1231 | lw TAB:TMP2, TAB:CARG1->metatable
1232 | ldc1 f0, CFUNC:RB->upvalue[0]
1233 | bnez TAB:TMP2, ->fff_fallback
1235 | ldc1 f0, CFUNC:RB->upvalue[0]
1237 |. addiu RA, BASE, -8
1244 |//-- Base library: catch errors ----------------------------------------
1247 | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
1248 | beqz NARGS8:RC, ->fff_fallback
1250 | addiu BASE, BASE, 8
1251 | // Remember active hook before pcall.
1252 | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
1253 | andi TMP3, TMP3, 1
1254 | addiu PC, TMP3, 8+FRAME_PCALL
1255 | b ->vm_call_dispatch
1256 |. addiu NARGS8:RC, NARGS8:RC, -8
1259 | sltiu AT, NARGS8:RC, 16
1260 | lw CARG4, 8+HI(BASE)
1261 | bnez AT, ->fff_fallback
1262 |. ldc1 FARG2, 8(BASE)
1263 | ldc1 FARG1, 0(BASE)
1264 | lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)
1267 | bne CARG4, AT, ->fff_fallback // Traceback must be a function.
1268 | addiu BASE, BASE, 16
1269 | // Remember active hook before pcall.
1270 | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
1271 | sdc1 FARG2, 0(TMP2) // Swap function and traceback.
1272 | andi TMP3, TMP3, 1
1273 | sdc1 FARG1, 8(TMP2)
1274 | addiu PC, TMP3, 16+FRAME_PCALL
1275 | b ->vm_call_dispatch
1276 |. addiu NARGS8:RC, NARGS8:RC, -16
1278 |//-- Coroutine library --------------------------------------------------
1280 |.macro coroutine_resume_wrap, resume
1282 |.ffunc_1 coroutine_resume
1284 | bne CARG3, AT, ->fff_fallback
1286 |.ffunc coroutine_wrap_aux
1287 | lw L:CARG1, CFUNC:RB->upvalue[0].gcr
1289 | lbu TMP0, L:CARG1->status
1290 | lw TMP1, L:CARG1->cframe
1291 | lw CARG2, L:CARG1->top
1292 | lw TMP2, L:CARG1->base
1293 | addiu TMP3, TMP0, -LUA_YIELD
1294 | bgtz TMP3, ->fff_fallback // st > LUA_YIELD?
1295 |. xor TMP2, TMP2, CARG2
1296 | bnez TMP1, ->fff_fallback // cframe != 0?
1297 |. or AT, TMP2, TMP0
1298 | lw TMP0, L:CARG1->maxstack
1299 | beqz AT, ->fff_fallback // base == top && st == 0?
1300 |. lw PC, FRAME_PC(BASE)
1301 | addu TMP2, CARG2, NARGS8:RC
1302 | sltu AT, TMP0, TMP2
1303 | bnez AT, ->fff_fallback // Stack overflow?
1308 | addiu BASE, BASE, 8 // Keep resumed thread in stack for GC.
1309 | addiu NARGS8:RC, NARGS8:RC, -8
1310 | addiu TMP2, TMP2, -8
1312 | sw TMP2, L:CARG1->top
1313 | addu TMP1, BASE, NARGS8:RC
1316 |2: // Move args to coroutine.
1318 | sltu AT, BASE, TMP1
1320 |. addiu BASE, BASE, 8
1323 |. addiu CARG3, CARG3, 8
1325 | bal ->vm_resume // (lua_State *L, TValue *base, 0, 0)
1326 |. move L:RA, L:CARG1
1327 | // Returns thread status.
1329 | lw TMP2, L:RA->base
1330 | sltiu AT, CRET1, LUA_YIELD+1
1331 | lw TMP3, L:RA->top
1336 |. subu RD, TMP3, TMP2
1337 | lw TMP0, L->maxstack
1338 | beqz RD, >6 // No results?
1339 |. addu TMP1, BASE, RD
1340 | sltu AT, TMP0, TMP1
1341 | bnez AT, >9 // Need to grow stack?
1342 |. addu TMP3, TMP2, RD
1343 | sw TMP2, L:RA->top // Clear coroutine stack.
1345 |5: // Move results from coroutine.
1347 | addiu TMP2, TMP2, 8
1348 | sltu AT, TMP2, TMP3
1351 |. addiu TMP1, TMP1, 8
1353 | andi TMP0, PC, FRAME_TYPE
1356 | addiu RA, BASE, -8
1357 | sw TMP1, -8+HI(BASE) // Prepend true to results.
1365 | beqz TMP0, ->BC_RET_Z
1370 |8: // Coroutine returned with error (at co->top-1).
1372 | addiu TMP3, TMP3, -8
1373 | li TMP1, LJ_TFALSE
1375 | sw TMP3, L:RA->top // Remove error from coroutine stack.
1377 | sw TMP1, -8+HI(BASE) // Prepend false to results.
1378 | addiu RA, BASE, -8
1379 | sdc1 f0, 0(BASE) // Copy error message.
1381 |. andi TMP0, PC, FRAME_TYPE
1383 | load_got lj_ffh_coroutine_wrap_err
1385 | call_intern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
1389 |9: // Handle stack expansion on return from yield.
1390 | load_got lj_state_growstack
1392 | call_intern lj_state_growstack // (lua_State *L, int n)
1398 | coroutine_resume_wrap 1 // coroutine.resume
1399 | coroutine_resume_wrap 0 // coroutine.wrap
1401 |.ffunc coroutine_yield
1402 | lw TMP0, L->cframe
1403 | addu TMP1, BASE, NARGS8:RC
1405 | andi TMP0, TMP0, CFRAME_RESUME
1407 | beqz TMP0, ->fff_fallback
1408 |. li CRET1, LUA_YIELD
1411 |. sb CRET1, L->status
1413 |//-- Math library -------------------------------------------------------
1416 |. abs.d FRET1, FARG1
1418 | lw PC, FRAME_PC(BASE)
1419 | addiu RA, BASE, -8
1421 |. sdc1 FRET1, -8(BASE)
1424 | // CARG3/CARG1 = TValue result.
1425 | lw PC, FRAME_PC(BASE)
1426 | sw CARG3, -8+HI(BASE)
1427 | addiu RA, BASE, -8
1428 | sw CARG1, -8+LO(BASE)
1430 | // RA = results, PC = return.
1433 | // RA = results, RD = (nresults+1)*8, PC = return.
1434 | andi TMP0, PC, FRAME_TYPE
1435 | bnez TMP0, ->vm_return
1438 | decode_RB8a RB, INS
1442 | bnez AT, >6 // More results expected?
1443 |. decode_RA8a TMP0, INS
1446 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
1447 | subu BASE, RA, TMP0
1450 |6: // Fill up results with nil.
1454 |. sw TISNIL, -8+HI(TMP1)
1456 |.macro math_extern, func
1457 |->ff_math_ .. func:
1458 | lw CARG3, HI(BASE)
1459 | beqz NARGS8:RC, ->fff_fallback
1461 | sltiu AT, CARG3, LJ_TISNUM
1462 | beqz AT, ->fff_fallback
1465 |. ldc1 FARG1, 0(BASE)
1470 |.macro math_extern2, func
1471 | .ffunc_nn math_ .. func
1479 |.macro math_round, func
1480 | .ffunc_n math_ .. func
1492 | lw CARG3, HI(BASE)
1494 | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument.
1496 | sltiu AT, CARG3, LJ_TISNUM
1497 | beqz AT, ->fff_fallback
1500 |. ldc1 FARG1, 0(BASE)
1516 | math_extern2 atan2
1520 |. sqrt.d FRET1, FARG1
1526 |. ldc1 FARG2, CFUNC:RB->upvalue[0]
1528 |. mul.d FRET1, FARG1, FARG2
1530 |.ffunc_nn math_ldexp
1531 | cvt.w.d FARG2, FARG2
1539 |.ffunc_n math_frexp
1541 | lw PC, FRAME_PC(BASE)
1543 |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
1544 | lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)
1545 | addiu RA, BASE, -8
1548 | cvt.d.w FARG2, FARG2
1555 | lw PC, FRAME_PC(BASE)
1557 |. addiu CARG3, BASE, -8
1558 | addiu RA, BASE, -8
1559 | sdc1 FRET1, 0(BASE)
1563 |.macro math_minmax, name, ismax
1565 | lw CARG3, HI(BASE)
1566 | beqz NARGS8:RC, ->fff_fallback
1567 |. ldc1 FRET1, 0(BASE)
1568 | sltiu AT, CARG3, LJ_TISNUM
1569 | beqz AT, ->fff_fallback
1570 |. addu TMP2, BASE, NARGS8:RC
1571 | addiu TMP1, BASE, 8
1572 | beq TMP1, TMP2, ->fff_resn
1574 |. lw CARG3, HI(TMP1)
1575 | ldc1 FARG1, 0(TMP1)
1576 | addiu TMP1, TMP1, 8
1577 | sltiu AT, CARG3, LJ_TISNUM
1578 | beqz AT, ->fff_fallback
1580 |. c.olt.d FARG1, FRET1
1582 |. c.olt.d FRET1, FARG1
1584 | bne TMP1, TMP2, <1
1585 |. movf.d FRET1, FARG1
1590 | math_minmax math_min, 0
1591 | math_minmax math_max, 1
1593 |//-- String library -----------------------------------------------------
1595 |.ffunc_1 string_len
1597 | bne CARG3, AT, ->fff_fallback
1600 |. lw CRET1, STR:CARG1->len
1602 |.ffunc string_byte // Only handle the 1-arg case here.
1603 | lw CARG3, HI(BASE)
1604 | lw STR:CARG1, LO(BASE)
1605 | xori AT, NARGS8:RC, 8
1606 | addiu CARG3, CARG3, -LJ_TSTR
1608 | bnez AT, ->fff_fallback // Need exactly 1 string argument.
1610 | lw TMP0, STR:CARG1->len
1611 | lbu TMP1, STR:CARG1[1] // Access is always ok (NUL at end).
1612 | addiu RA, BASE, -8
1617 | lw PC, FRAME_PC(BASE)
1618 | sll RD, RD, 3 // RD = ((str->len != 0)+1)*8
1622 |.ffunc string_char // Only handle the 1-arg case here.
1624 | lw CARG3, HI(BASE)
1625 | ldc1 FARG1, 0(BASE)
1627 | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument.
1628 |. sltiu AT, CARG3, LJ_TISNUM
1629 | beqz AT, ->fff_fallback
1631 | cvt.w.d FARG1, FARG1
1632 | addiu CARG2, sp, ARG5_OFS
1633 | sltiu AT, TMP0, 256
1635 | beqz AT, ->fff_fallback
1638 | load_got lj_str_new
1641 | call_intern lj_str_new // (lua_State *L, char *str, size_t l)
1643 | // Returns GCstr *.
1647 |. li CARG3, LJ_TSTR
1651 | addiu AT, NARGS8:RC, -16
1652 | lw CARG3, 16+HI(BASE)
1655 | lw STR:CARG1, LO(BASE)
1656 | bltz AT, ->fff_fallback
1657 | lw CARG2, 8+HI(BASE)
1662 | sltiu AT, CARG3, LJ_TISNUM
1663 | beqz AT, ->fff_fallback
1666 | sltiu AT, CARG2, LJ_TISNUM
1667 | beqz AT, ->fff_fallback
1670 | bne TMP0, AT, ->fff_fallback
1671 |. lw CARG2, STR:CARG1->len
1673 | // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end
1675 | addiu TMP0, CARG2, 1
1676 | addu TMP1, CARG4, TMP0
1677 | slt TMP3, CARG3, r0
1678 | movn CARG4, TMP1, AT // if (end < 0) end += len+1
1679 | addu TMP1, CARG3, TMP0
1680 | movn CARG3, TMP1, TMP3 // if (start < 0) start += len+1
1683 | slt TMP3, r0, CARG3
1684 | movn CARG4, r0, AT // if (end < 0) end = 0
1685 | movz CARG3, TMP2, TMP3 // if (start < 1) start = 1
1686 | slt AT, CARG2, CARG4
1687 | movn CARG4, CARG2, AT // if (end > len) end = len
1688 | addu CARG2, STR:CARG1, CARG3
1689 | subu CARG3, CARG4, CARG3 // len = end - start
1690 | addiu CARG2, CARG2, sizeof(GCstr)-1
1691 | bgez CARG3, ->fff_newstr
1692 |. addiu CARG3, CARG3, 1 // len++
1693 |->fff_emptystr: // Return empty string.
1694 | addiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty)
1696 |. li CARG3, LJ_TSTR
1698 |.ffunc string_rep // Only handle the 1-char case inline.
1701 | addiu AT, NARGS8:RC, -16 // Exactly 2 arguments.
1702 | lw CARG4, 8+HI(BASE)
1703 | lw STR:CARG1, LO(BASE)
1704 | addiu TMP0, TMP0, -LJ_TSTR
1707 | bnez AT, ->fff_fallback
1708 |. sltiu AT, CARG4, LJ_TISNUM
1710 | beqz AT, ->fff_fallback
1711 |. lw TMP0, STR:CARG1->len
1713 | lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
1715 | blez CARG3, ->fff_emptystr // Count <= 0?
1716 |. sltu AT, AT, TMP0
1717 | beqz TMP0, ->fff_emptystr // Zero length string?
1718 |. sltu TMP0, TMP1, CARG3
1720 | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
1721 | bnez AT, ->fff_fallback // Fallback for > 1-char strings.
1722 |. lbu TMP0, STR:CARG1[1]
1723 | addu TMP2, CARG2, CARG3
1724 |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
1725 | addiu TMP2, TMP2, -1
1726 | sltu AT, CARG2, TMP2
1732 |.ffunc string_reverse
1734 | lw CARG3, HI(BASE)
1735 | lw STR:CARG1, LO(BASE)
1736 | beqz NARGS8:RC, ->fff_fallback
1738 | bne CARG3, AT, ->fff_fallback
1739 |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
1740 | lw CARG3, STR:CARG1->len
1741 | addiu CARG1, STR:CARG1, #STR
1742 | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
1743 | sltu AT, TMP1, CARG3
1744 | bnez AT, ->fff_fallback
1745 |. addu TMP3, CARG1, CARG3
1746 | addu CARG4, CARG2, CARG3
1747 |1: // Reverse string copy.
1748 | lbu TMP1, 0(CARG1)
1749 | sltu AT, CARG1, TMP3
1750 | beqz AT, ->fff_newstr
1751 |. addiu CARG1, CARG1, 1
1752 | addiu CARG4, CARG4, -1
1756 |.macro ffstring_case, name, lo
1759 | lw CARG3, HI(BASE)
1760 | lw STR:CARG1, LO(BASE)
1761 | beqz NARGS8:RC, ->fff_fallback
1763 | bne CARG3, AT, ->fff_fallback
1764 |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
1765 | lw CARG3, STR:CARG1->len
1766 | addiu CARG1, STR:CARG1, #STR
1767 | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
1768 | sltu AT, TMP1, CARG3
1769 | bnez AT, ->fff_fallback
1770 |. addu TMP3, CARG1, CARG3
1772 |1: // ASCII case conversion.
1773 | lbu TMP1, 0(CARG1)
1774 | sltu AT, CARG1, TMP3
1775 | beqz AT, ->fff_newstr
1776 |. addiu TMP0, TMP1, -lo
1777 | xori TMP2, TMP1, 0x20
1778 | sltiu AT, TMP0, 26
1779 | movn TMP1, TMP2, AT
1780 | addiu CARG1, CARG1, 1
1783 |. addiu CARG4, CARG4, 1
1786 |ffstring_case string_lower, 65
1787 |ffstring_case string_upper, 97
1789 |//-- Table library ------------------------------------------------------
1791 |.ffunc_1 table_getn
1793 | bne CARG3, AT, ->fff_fallback
1794 |. load_got lj_tab_len
1795 | call_intern lj_tab_len // (GCtab *t)
1797 | // Returns uint32_t (but less than 2^31).
1801 |//-- Bit library --------------------------------------------------------
1803 |.macro .ffunc_bit, name
1804 | .ffunc_n bit_..name
1805 |. add.d FARG1, FARG1, TOBIT
1809 |.macro .ffunc_bit_op, name, ins
1811 | addiu TMP1, BASE, 8
1812 | addu TMP2, BASE, NARGS8:RC
1814 | lw CARG4, HI(TMP1)
1815 | beq TMP1, TMP2, ->fff_resi
1816 |. ldc1 FARG1, 0(TMP1)
1817 | sltiu AT, CARG4, LJ_TISNUM
1818 | beqz AT, ->fff_fallback
1819 | add.d FARG1, FARG1, TOBIT
1821 | ins CRET1, CRET1, CARG2
1823 |. addiu TMP1, TMP1, 8
1826 |.ffunc_bit_op band, and
1827 |.ffunc_bit_op bor, or
1828 |.ffunc_bit_op bxor, xor
1831 | srl TMP0, CRET1, 24
1832 | srl TMP2, CRET1, 8
1833 | sll TMP1, CRET1, 24
1834 | andi TMP2, TMP2, 0xff00
1835 | or TMP0, TMP0, TMP1
1836 | andi CRET1, CRET1, 0xff00
1837 | or TMP0, TMP0, TMP2
1838 | sll CRET1, CRET1, 8
1840 |. or CRET1, TMP0, CRET1
1846 |.macro .ffunc_bit_sh, name, ins, shmod
1847 | .ffunc_nn bit_..name
1848 |. add.d FARG1, FARG1, TOBIT
1849 | add.d FARG2, FARG2, TOBIT
1854 | subu TMP0, AT, CARG2
1855 | sllv CARG2, CARG1, CARG2
1856 | srlv CARG1, CARG1, TMP0
1859 | subu TMP0, AT, CARG2
1860 | srlv CARG2, CARG1, CARG2
1861 | sllv CARG1, CARG1, TMP0
1864 |. ins CRET1, CARG1, CARG2
1867 |.ffunc_bit_sh lshift, sllv, 0
1868 |.ffunc_bit_sh rshift, srlv, 0
1869 |.ffunc_bit_sh arshift, srav, 0
1870 |// Can't use rotrv, since it's only in MIPS32R2.
1871 |.ffunc_bit_sh rol, or, 1
1872 |.ffunc_bit_sh ror, or, 2
1878 |. cvt.d.w FRET1, FRET1
1880 |//-----------------------------------------------------------------------
1882 |->fff_fallback: // Call fast function fallback handler.
1883 | // BASE = new base, RB = CFUNC, RC = nargs*8
1884 | lw TMP3, CFUNC:RB->f
1885 | addu TMP1, BASE, NARGS8:RC
1886 | lw PC, FRAME_PC(BASE) // Fallback may overwrite PC.
1887 | addiu TMP0, TMP1, 8*LUA_MINSTACK
1888 | lw TMP2, L->maxstack
1889 | sw PC, SAVE_PC // Redundant (but a defined value).
1890 | sltu AT, TMP2, TMP0
1893 | bnez AT, >5 // Need to grow stack.
1894 |. move CFUNCADDR, TMP3
1895 | jalr TMP3 // (lua_State *L)
1897 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
1900 | bgtz CRET1, ->fff_res // Returned nresults+1?
1901 |. addiu RA, BASE, -8
1902 |1: // Returned 0 or -1: retry fast path.
1904 | lw LFUNC:RB, FRAME_FUNC(BASE)
1905 | bnez CRET1, ->vm_call_tail // Returned -1?
1906 |. subu NARGS8:RC, TMP0, BASE
1907 | ins_callt // Returned 0: retry fast path.
1909 |// Reconstruct previous base for vmeta_call during tailcall.
1911 | andi TMP0, PC, FRAME_TYPE
1915 | lbu TMP1, OFS_RA(PC)
1917 | addiu TMP1, TMP1, 8
1919 | b ->vm_call_dispatch // Resolve again for tailcall.
1920 |. subu TMP2, BASE, TMP1
1922 |5: // Grow stack for fallback handler.
1923 | load_got lj_state_growstack
1924 | li CARG2, LUA_MINSTACK
1925 | call_intern lj_state_growstack // (lua_State *L, int n)
1929 |. li CRET1, 0 // Force retry.
1931 |->fff_gcstep: // Call GC step function.
1932 | // BASE = new base, RC = nargs*8
1934 | load_got lj_gc_step
1936 | addu TMP0, BASE, NARGS8:RC
1937 | sw PC, SAVE_PC // Redundant (but a defined value).
1939 | call_intern lj_gc_step // (lua_State *L)
1944 | lw CFUNC:RB, FRAME_FUNC(BASE)
1946 |. subu NARGS8:RC, TMP0, BASE
1948 |//-----------------------------------------------------------------------
1949 |//-- Special dispatch targets -------------------------------------------
1950 |//-----------------------------------------------------------------------
1952 |->vm_record: // Dispatch target for recording phase.
1954 | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
1955 | andi AT, TMP3, HOOK_VMEVENT // No recording while in vmevent.
1957 | // Decrement the hookcount for consistency, but always do the call.
1958 |. lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
1959 | andi AT, TMP3, HOOK_ACTIVE
1961 |. addiu TMP2, TMP2, -1
1962 | andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
1966 |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
1969 |->vm_rethook: // Dispatch target for return hooks.
1970 | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
1971 | andi AT, TMP3, HOOK_ACTIVE // Hook already active?
1973 |5: // Re-dispatch to static ins.
1974 |. lw AT, GG_DISP2STATIC(TMP0) // Assumes TMP0 holds DISPATCH+OP*4.
1978 |->vm_inshook: // Dispatch target for instr/line hooks.
1979 | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
1980 | lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
1981 | andi AT, TMP3, HOOK_ACTIVE // Hook already active?
1983 |. andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
1985 |. addiu TMP2, TMP2, -1
1987 |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
1988 | andi AT, TMP3, LUA_MASKLINE
1991 |. load_got lj_dispatch_ins
1992 | sw MULTRES, SAVE_MULTRES
1995 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
1996 | call_intern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
2000 |4: // Re-dispatch to static ins.
2002 | decode_OP4a TMP1, INS
2004 | addu TMP0, DISPATCH, TMP1
2005 | decode_RD8a RD, INS
2006 | lw AT, GG_DISP2STATIC(TMP0)
2007 | decode_RA8a RA, INS
2012 |->cont_hook: // Continue from hook yield.
2015 |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins.
2017 |->vm_hotloop: // Hot loop counter underflow.
2019 | lw LFUNC:TMP1, FRAME_FUNC(BASE)
2020 | addiu CARG1, DISPATCH, GG_DISP2J
2022 | lw TMP1, LFUNC:TMP1->pc
2024 | sw L, DISPATCH_J(L)(DISPATCH)
2025 | lbu TMP1, PC2PROTO(framesize)(TMP1)
2026 | load_got lj_trace_hot
2029 | addu TMP1, BASE, TMP1
2030 | call_intern lj_trace_hot // (jit_State *J, const BCIns *pc)
2036 |->vm_callhook: // Dispatch target for call hooks.
2042 |->vm_hotcall: // Hot call counter underflow.
2047 | load_got lj_dispatch_call
2048 | addu TMP0, BASE, RC
2053 | call_intern lj_dispatch_call // (lua_State *L, const BCIns *pc)
2055 | // Returns ASMFunction.
2058 | sw r0, SAVE_PC // Invalidate for subsequent line hook.
2059 | subu NARGS8:RC, TMP0, BASE
2061 | lw LFUNC:RB, FRAME_FUNC(BASE)
2065 |//-----------------------------------------------------------------------
2066 |//-- Trace exit handler -------------------------------------------------
2067 |//-----------------------------------------------------------------------
2069 |.macro savex_, a, b
2070 | sdc1 f..a, 16+a*8(sp)
2071 | sw r..a, 16+32*8+a*4(sp)
2072 | sw r..b, 16+32*8+b*4(sp)
2077 | addiu sp, sp, -(16+32*8+32*4)
2092 | sdc1 f28, 16+28*8(sp)
2093 | sw r28, 16+32*8+28*4(sp)
2094 | sdc1 f30, 16+30*8(sp)
2095 | sw r30, 16+32*8+30*4(sp)
2096 | sw r0, 16+32*8+31*4(sp) // Clear RID_TMP.
2098 | addiu TMP2, sp, 16+32*8+32*4 // Recompute original value of sp.
2099 | addiu DISPATCH, JGL, -GG_DISP2G-32768
2100 | lw TMP1, 0(TMP2) // Load exit number.
2102 | sw TMP2, 16+32*8+29*4(sp) // Store sp in RID_SP.
2103 | lw L, DISPATCH_GL(jit_L)(DISPATCH)
2104 | lw BASE, DISPATCH_GL(jit_base)(DISPATCH)
2105 | load_got lj_trace_exit
2106 | sw L, DISPATCH_J(L)(DISPATCH)
2107 | sw ra, DISPATCH_J(parent)(DISPATCH) // Store trace number.
2108 | sw TMP1, DISPATCH_J(exitno)(DISPATCH) // Store exit number.
2109 | addiu CARG1, DISPATCH, GG_DISP2J
2111 | call_intern lj_trace_exit // (jit_State *J, ExitState *ex)
2112 |. addiu CARG2, sp, 16
2113 | // Returns MULTRES (unscaled) or negated error code.
2114 | lw TMP1, L->cframe
2118 | lw PC, SAVE_PC // Get SAVE_PC.
2120 |. sw L, SAVE_L // Set SAVE_L (on-trace resume/yield).
2124 | // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.
2126 | addiu DISPATCH, JGL, -GG_DISP2G-32768
2128 | bltz CRET1, >3 // Check for error from exit.
2129 |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
2130 | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
2131 | sll MULTRES, CRET1, 3
2132 | li TISNIL, LJ_TNIL
2133 | sw MULTRES, SAVE_MULTRES
2135 | lw TMP1, LFUNC:TMP1->pc
2136 | sw r0, DISPATCH_GL(jit_L)(DISPATCH)
2137 | lw KBASE, PC2PROTO(k)(TMP1)
2138 | cvt.d.s TOBIT, TOBIT
2139 | // Modified copy of ins_next which handles function header dispatch, too.
2142 | // Assumes TISNIL == ~LJ_VMST_INTERP == -1
2143 | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
2144 | decode_OP4a TMP1, INS
2146 | sltiu TMP2, TMP1, BC_FUNCF*4 // Function header?
2147 | addu TMP0, DISPATCH, TMP1
2148 | decode_RD8a RD, INS
2150 | decode_RA8a RA, INS
2156 | addiu RC, MULTRES, -8
2158 |. addu RA, RA, BASE
2160 |3: // Rethrow error from the right C frame.
2161 | load_got lj_err_throw
2163 | call_intern lj_err_throw // (lua_State *L, int errcode)
2167 |//-----------------------------------------------------------------------
2168 |//-- Math helper functions ----------------------------------------------
2169 |//-----------------------------------------------------------------------
2171 |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.
2172 |.macro vm_round, func
2173 | lui TMP0, 0x4330 // Hiword of 2^52 (double).
2176 | abs.d FRET2, FARG1 // |x|
2178 | c.olt.d 0, FRET2, f4
2179 | add.d FRET1, FRET2, f4 // (|x| + 2^52) - 2^52
2180 | bc1f 0, >1 // Truncate only if |x| < 2^52.
2181 |. sub.d FRET1, FRET1, f4
2183 |.if "func" == "ceil"
2184 | lui TMP0, 0xbff0 // Hiword of -1 (double). Preserves -0.
2186 | lui TMP0, 0x3ff0 // Hiword of +1 (double).
2188 |.if "func" == "trunc"
2190 | c.olt.d 0, FRET2, FRET1 // |x| < result?
2191 | sub.d FRET2, FRET1, f4
2192 | movt.d FRET1, FRET2, 0 // If yes, subtract +1.
2193 | neg.d FRET2, FRET1
2195 |. movn.d FRET1, FRET2, AT // Merge sign bit back in.
2197 | neg.d FRET2, FRET1
2199 | movn.d FRET1, FRET2, AT // Merge sign bit back in.
2200 |.if "func" == "ceil"
2201 | c.olt.d 0, FRET1, FARG1 // x > result?
2203 | c.olt.d 0, FARG1, FRET1 // x < result?
2205 | sub.d FRET2, FRET1, f4 // If yes, subtract +-1.
2207 |. movt.d FRET1, FRET2, 0
2211 |. mov.d FRET1, FARG1
2223 |//-----------------------------------------------------------------------
2224 |//-- Miscellaneous functions --------------------------------------------
2225 |//-----------------------------------------------------------------------
2227 |//-----------------------------------------------------------------------
2228 |//-- FFI helper functions -----------------------------------------------
2229 |//-----------------------------------------------------------------------
2231 |// Handler for callback functions. Callback slot number in r1, g in r2.
2234 |.type CTSTATE, CTState, PC
2236 | lw CTSTATE, GL:r2->ctype_state
2237 | addiu DISPATCH, r2, GG_G2DISP
2238 | load_got lj_ccallback_enter
2239 | sw r1, CTSTATE->cb.slot
2240 | sw CARG1, CTSTATE->cb.gpr[0]
2241 | sw CARG2, CTSTATE->cb.gpr[1]
2242 | sdc1 FARG1, CTSTATE->cb.fpr[0]
2243 | sw CARG3, CTSTATE->cb.gpr[2]
2244 | sw CARG4, CTSTATE->cb.gpr[3]
2245 | sdc1 FARG2, CTSTATE->cb.fpr[1]
2246 | addiu TMP0, sp, CFRAME_SPACE+16
2247 | sw TMP0, CTSTATE->cb.stack
2248 | sw r0, SAVE_PC // Any value outside of bytecode is ok.
2250 | call_intern lj_ccallback_enter // (CTState *cts, void *cf)
2251 |. move CARG1, CTSTATE
2252 | // Returns lua_State *.
2253 | lw BASE, L:CRET1->base
2254 | lw RC, L:CRET1->top
2256 | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
2257 | lw LFUNC:RB, FRAME_FUNC(BASE)
2260 | li TISNIL, LJ_TNIL
2263 | cvt.d.s TOBIT, TOBIT
2267 |->cont_ffi_callback: // Return from FFI callback.
2269 | load_got lj_ccallback_leave
2270 | lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)
2275 | call_intern lj_ccallback_leave // (CTState *cts, TValue *o)
2276 |. move CARG1, CTSTATE
2277 | lw CRET1, CTSTATE->cb.gpr[0]
2278 | ldc1 FRET1, CTSTATE->cb.fpr[0]
2279 | lw CRET2, CTSTATE->cb.gpr[1]
2281 |. ldc1 FRET2, CTSTATE->cb.fpr[1]
2284 |->vm_ffi_call: // Call C function via FFI.
2285 | // Caveat: needs special frame unwinding, see below.
2287 | .type CCSTATE, CCallState, CARG1
2288 | lw TMP1, CCSTATE->spadj
2289 | lbu CARG2, CCSTATE->nsp
2293 | sll CARG2, CARG2, 2
2295 | sw CCSTATE, -12(TMP2)
2297 | addiu TMP1, CCSTATE, offsetof(CCallState, stack)
2298 | addiu TMP2, sp, 16
2300 |. addu TMP3, TMP1, CARG2
2303 | addiu TMP1, TMP1, 4
2304 | sltu AT, TMP1, TMP3
2307 |. addiu TMP2, TMP2, 4
2309 | lw CFUNCADDR, CCSTATE->func
2310 | lw CARG2, CCSTATE->gpr[1]
2311 | lw CARG3, CCSTATE->gpr[2]
2312 | lw CARG4, CCSTATE->gpr[3]
2313 | ldc1 FARG1, CCSTATE->fpr[0]
2314 | ldc1 FARG2, CCSTATE->fpr[1]
2316 |. lw CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1.
2317 | lw CCSTATE:TMP1, -12(r16)
2320 | sw CRET1, CCSTATE:TMP1->gpr[0]
2321 | sw CRET2, CCSTATE:TMP1->gpr[1]
2322 | sdc1 FRET1, CCSTATE:TMP1->fpr[0]
2323 | sdc1 FRET2, CCSTATE:TMP1->fpr[1]
2328 |// Note: vm_ffi_call must be the last function in this object file!
2330 |//-----------------------------------------------------------------------
2333 /* Generate the code for a single instruction. */
2334 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2341 /* -- Comparison ops ---------------------------------------------------- */
2343 /* Remember: all ops branch for a true comparison, fall through otherwise. */
2345 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
2346 | // RA = src1*8, RD = src2*8, JMP with RD = target
2347 | addu CARG2, BASE, RA
2348 | addu CARG3, BASE, RD
2349 | lw TMP0, HI(CARG2)
2350 | lw TMP1, HI(CARG3)
2353 | sltiu TMP0, TMP0, LJ_TISNUM
2354 | sltiu TMP1, TMP1, LJ_TISNUM
2355 | lhu TMP2, OFS_RD(PC)
2356 | and TMP0, TMP0, TMP1
2358 | beqz TMP0, ->vmeta_comp
2359 |. lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)
2361 | addu TMP2, TMP2, TMP1
2362 if (op == BC_ISLT || op == BC_ISGE) {
2367 if (op == BC_ISLT || op == BC_ISLE) {
2377 case BC_ISEQV: case BC_ISNEV:
2378 vk = op == BC_ISEQV;
2379 | // RA = src1*8, RD = src2*8, JMP with RD = target
2385 | lhu TMP2, -4+OFS_RD(PC)
2388 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2389 | sltiu AT, TMP0, LJ_TISNUM
2390 | sltiu CARG1, TMP1, LJ_TISNUM
2394 |. addu TMP2, TMP2, TMP3
2404 |5: // Either or both types are not numbers.
2408 | li TMP3, LJ_TCDATA
2409 | beq TMP0, TMP3, ->vmeta_equal_cd
2411 |. sltiu AT, TMP0, LJ_TISPRI // Not a primitive?
2413 | beq TMP1, TMP3, ->vmeta_equal_cd
2415 |. xor TMP3, CARG2, CARG3 // Same tv?
2416 | xor TMP1, TMP1, TMP0 // Same type?
2417 | sltiu CARG1, TMP0, LJ_TISTABUD+1 // Table or userdata?
2418 | movz TMP3, r0, AT // Ignore tv if primitive.
2419 | movn CARG1, r0, TMP1 // Tab/ud and same type?
2420 | or AT, TMP1, TMP3 // Same type && (pri||same tv).
2421 | movz CARG1, r0, AT
2422 | beqz CARG1, <1 // Done if not tab/ud or not same type or same tv.
2424 |. movn TMP2, r0, AT
2426 |. movz TMP2, r0, AT
2428 | // Different tables or userdatas. Need to check __eq metamethod.
2429 | // Field metatable must be at same offset for GCtab and GCudata!
2430 | lw TAB:TMP1, TAB:CARG2->metatable
2431 | beqz TAB:TMP1, <1 // No metatable?
2433 | lbu TMP1, TAB:TMP1->nomm
2434 | andi TMP1, TMP1, 1<<MM_eq
2435 | bnez TMP1, <1 // Or 'no __eq' flag set?
2437 | b ->vmeta_equal // Handle __eq metamethod.
2438 |. li CARG4, 1-vk // ne = 0 or 1.
2441 case BC_ISEQS: case BC_ISNES:
2442 vk = op == BC_ISEQS;
2443 | // RA = src*8, RD = str_const*8 (~), JMP with RD = target
2448 | lw STR:TMP3, LO(RA)
2449 | subu RD, KBASE, RD
2450 | lhu TMP2, -4+OFS_RD(PC)
2453 | beq TMP0, AT, ->vmeta_equal_cd
2455 |. lw STR:TMP1, -4(RD) // KBASE-4-str_const*4
2456 | addiu TMP0, TMP0, -LJ_TSTR
2458 | xor TMP1, STR:TMP1, STR:TMP3
2459 | or TMP0, TMP0, TMP1
2460 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2461 | addu TMP2, TMP2, TMP3
2463 | movn TMP2, r0, TMP0
2465 | movz TMP2, r0, TMP0
2471 case BC_ISEQN: case BC_ISNEN:
2472 vk = op == BC_ISEQN;
2473 | // RA = src*8, RD = num_const*8, JMP with RD = target
2478 | addu RD, KBASE, RD
2479 | lhu TMP2, -4+OFS_RD(PC)
2481 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2482 | sltiu AT, TMP0, LJ_TISNUM
2489 |. addu TMP2, TMP2, TMP3
2504 | beq TMP0, AT, ->vmeta_equal_cd
2511 case BC_ISEQP: case BC_ISNEP:
2512 vk = op == BC_ISEQP;
2513 | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
2517 | lhu TMP2, OFS_RD(PC)
2522 | beq TMP0, AT, ->vmeta_equal_cd
2524 |. xor TMP0, TMP0, TMP1
2526 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2527 | addu TMP2, TMP2, TMP3
2529 | movn TMP2, r0, TMP0
2531 | movz TMP2, r0, TMP0
2537 /* -- Unary test and copy ops ------------------------------------------- */
2539 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
2540 | // RA = dst*8 or unused, RD = src*8, JMP with RD = target
2542 | lhu TMP2, OFS_RD(PC)
2545 if (op == BC_IST || op == BC_ISF) {
2546 | sltiu TMP0, TMP0, LJ_TISTRUECOND
2548 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2549 | addu TMP2, TMP2, TMP3
2551 | movz TMP2, r0, TMP0
2553 | movn TMP2, r0, TMP0
2557 | sltiu TMP0, TMP0, LJ_TISTRUECOND
2559 if (op == BC_ISTC) {
2564 |. addu RA, BASE, RA
2566 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
2567 | addu TMP2, TMP2, TMP3
2575 /* -- Unary ops --------------------------------------------------------- */
2578 | // RA = dst*8, RD = src*8
2587 | // RA = dst*8, RD = src*8
2591 | li TMP1, LJ_TFALSE
2592 | sltiu TMP0, TMP0, LJ_TISTRUECOND
2593 | addiu TMP1, TMP0, LJ_TTRUE
2599 | // RA = dst*8, RD = src*8
2600 | addu CARG3, BASE, RD
2602 | lw TMP0, HI(CARG3)
2604 | sltiu AT, TMP0, LJ_TISNUM
2605 | beqz AT, ->vmeta_unm
2612 | // RA = dst*8, RD = src*8
2613 | addu CARG2, BASE, RD
2615 | lw TMP0, HI(CARG2)
2616 | lw CARG1, LO(CARG2)
2620 | lw CRET1, STR:CARG1->len
2628 | bne TMP0, AT, ->vmeta_len
2631 | lw TAB:TMP2, TAB:CARG1->metatable
2637 | load_got lj_tab_len
2638 | call_intern lj_tab_len // (GCtab *t)
2640 | // Returns uint32_t (but less than 2^31).
2645 | lbu TMP0, TAB:TMP2->nomm
2646 | andi TMP0, TMP0, 1<<MM_len
2647 | bnez TMP0, <3 // 'no __len' flag set: done.
2654 /* -- Binary ops -------------------------------------------------------- */
2656 |.macro ins_arithpre
2657 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
2658 | decode_RB8a RB, INS
2660 | decode_RDtoRC8 RC, RD
2661 | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
2664 | addu CARG3, BASE, RB
2665 | addu CARG4, KBASE, RC
2666 | lw TMP1, HI(CARG3)
2667 | ldc1 f20, 0(CARG3)
2668 | ldc1 f22, 0(CARG4)
2669 | sltiu AT, TMP1, LJ_TISNUM
2672 | addu CARG4, BASE, RB
2673 | addu CARG3, KBASE, RC
2674 | lw TMP1, HI(CARG4)
2675 | ldc1 f22, 0(CARG4)
2676 | ldc1 f20, 0(CARG3)
2677 | sltiu AT, TMP1, LJ_TISNUM
2680 | addu CARG3, BASE, RB
2681 | addu CARG4, BASE, RC
2682 | lw TMP1, HI(CARG3)
2683 | lw TMP2, HI(CARG4)
2684 | ldc1 f20, 0(CARG3)
2685 | ldc1 f22, 0(CARG4)
2686 | sltiu AT, TMP1, LJ_TISNUM
2687 | sltiu TMP0, TMP2, LJ_TISNUM
2691 | beqz AT, ->vmeta_arith
2692 |. addu RA, BASE, RA
2695 |.macro fpmod, a, b, c
2697 | bal ->vm_floor // floor(b/c)
2698 |. div.d FARG1, b, c
2700 | sub.d a, b, a // b - floor(b/c)*c
2703 |.macro ins_arith, ins
2705 |.if "ins" == "fpmod_"
2706 | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
2716 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
2719 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
2722 case BC_MULVN: case BC_MULNV: case BC_MULVV:
2725 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
2731 case BC_MODNV: case BC_MODVV:
2735 | decode_RB8a RB, INS
2737 | decode_RDtoRC8 RC, RD
2738 | addu CARG3, BASE, RB
2739 | addu CARG4, BASE, RC
2740 | lw TMP1, HI(CARG3)
2741 | lw TMP2, HI(CARG4)
2742 | ldc1 FARG1, 0(CARG3)
2743 | ldc1 FARG2, 0(CARG4)
2744 | sltiu AT, TMP1, LJ_TISNUM
2745 | sltiu TMP0, TMP2, LJ_TISNUM
2748 | beqz AT, ->vmeta_arith
2749 |. addu RA, BASE, RA
2758 | // RA = dst*8, RB = src_start*8, RC = src_end*8
2759 | decode_RB8a RB, INS
2761 | decode_RDtoRC8 RC, RD
2762 | subu CARG3, RC, RB
2764 | addu CARG2, BASE, RC
2767 | load_got lj_meta_cat
2768 | srl CARG3, CARG3, 3
2770 | call_intern lj_meta_cat // (lua_State *L, TValue *top, int left)
2772 | // Returns NULL (finished) or TValue * (metamethod).
2773 | bnez CRET1, ->vmeta_binop
2775 | addu RB, BASE, MULTRES
2779 | sdc1 f0, 0(RA) // Copy result from RB to RA.
2783 /* -- Constant ops ------------------------------------------------------ */
2786 | // RA = dst*8, RD = str_const*8 (~)
2788 | subu TMP1, KBASE, TMP1
2790 | lw TMP0, -4(TMP1) // KBASE-4-str_const*4
2799 | // RA = dst*8, RD = cdata_const*8 (~)
2801 | subu TMP1, KBASE, TMP1
2803 | lw TMP0, -4(TMP1) // KBASE-4-cdata_const*4
2805 | li TMP2, LJ_TCDATA
2812 | // RA = dst*8, RD = int16_literal*8
2822 | // RA = dst*8, RD = num_const*8
2823 | addu RD, KBASE, RD
2831 | // RA = dst*8, RD = primitive_type*8 (~)
2840 | // RA = base*8, RD = end*8
2853 /* -- Upvalue and function ops ------------------------------------------ */
2856 | // RA = dst*8, RD = uvnum*8
2857 | lw LFUNC:RB, FRAME_FUNC(BASE)
2859 | addu RD, RD, LFUNC:RB
2860 | lw UPVAL:RB, LFUNC:RD->uvptr
2862 | lw TMP1, UPVAL:RB->v
2869 | // RA = uvnum*8, RD = src*8
2870 | lw LFUNC:RB, FRAME_FUNC(BASE)
2873 | addu RA, RA, LFUNC:RB
2875 | lw UPVAL:RB, LFUNC:RA->uvptr
2876 | lbu TMP3, UPVAL:RB->marked
2877 | lw CARG2, UPVAL:RB->v
2878 | andi TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
2879 | lbu TMP0, UPVAL:RB->closed
2882 | li AT, LJ_GC_BLACK|1
2883 | or TMP3, TMP3, TMP0
2884 | beq TMP3, AT, >2 // Upvalue is closed and black?
2885 |. addiu TMP2, TMP2, -(LJ_TNUMX+1)
2889 |2: // Check if new value is collectable.
2890 | sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)
2891 | beqz AT, <1 // tvisgcv(v)
2893 | lbu TMP3, GCOBJ:TMP1->gch.marked
2894 | andi TMP3, TMP3, LJ_GC_WHITES // iswhite(v)
2896 |. load_got lj_gc_barrieruv
2897 | // Crossed a write barrier. Move the barrier forward.
2898 | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv)
2899 |. addiu CARG1, DISPATCH, GG_DISP2G
2904 | // RA = uvnum*8, RD = str_const*8 (~)
2905 | lw LFUNC:RB, FRAME_FUNC(BASE)
2908 | addu RA, RA, LFUNC:RB
2909 | subu TMP1, KBASE, TMP1
2910 | lw UPVAL:RB, LFUNC:RA->uvptr
2911 | lw STR:TMP1, -4(TMP1) // KBASE-4-str_const*4
2912 | lbu TMP2, UPVAL:RB->marked
2913 | lw CARG2, UPVAL:RB->v
2914 | lbu TMP3, STR:TMP1->marked
2915 | andi AT, TMP2, LJ_GC_BLACK // isblack(uv)
2916 | lbu TMP2, UPVAL:RB->closed
2918 | sw STR:TMP1, LO(CARG2)
2920 |. sw TMP0, HI(CARG2)
2924 |2: // Check if string is white and ensure upvalue is closed.
2926 |. andi AT, TMP3, LJ_GC_WHITES // iswhite(str)
2928 |. load_got lj_gc_barrieruv
2929 | // Crossed a write barrier. Move the barrier forward.
2930 | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv)
2931 |. addiu CARG1, DISPATCH, GG_DISP2G
2936 | // RA = uvnum*8, RD = num_const*8
2937 | lw LFUNC:RB, FRAME_FUNC(BASE)
2939 | addu RD, KBASE, RD
2940 | addu RA, RA, LFUNC:RB
2942 | lw UPVAL:RB, LFUNC:RA->uvptr
2944 | lw TMP1, UPVAL:RB->v
2949 | // RA = uvnum*8, RD = primitive_type*8 (~)
2950 | lw LFUNC:RB, FRAME_FUNC(BASE)
2953 | addu RA, RA, LFUNC:RB
2955 | lw UPVAL:RB, LFUNC:RA->uvptr
2957 | lw TMP1, UPVAL:RB->v
2963 | // RA = level*8, RD = target
2964 | lw TMP2, L->openupval
2965 | branch_RD // Do this first since RD is not saved.
2966 | load_got lj_func_closeuv
2970 | call_intern lj_func_closeuv // (lua_State *L, TValue *level)
2971 |. addu CARG2, BASE, RA
2978 | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
2980 | load_got lj_func_newL_gc
2981 | subu TMP1, KBASE, TMP1
2982 | lw CARG3, FRAME_FUNC(BASE)
2983 | lw CARG2, -4(TMP1) // KBASE-4-tab_const*4
2986 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
2987 | call_intern lj_func_newL_gc
2989 | // Returns GCfuncL *.
2995 | sw LFUNC:CRET1, LO(RA)
2999 /* -- Table ops --------------------------------------------------------- */
3003 | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
3004 | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)
3005 | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
3008 | sltu AT, TMP0, TMP1
3011 if (op == BC_TNEW) {
3012 | load_got lj_tab_new
3014 | andi CARG2, CARG2, 0x7ff
3016 | addiu AT, CARG2, -0x7ff
3018 | movz CARG2, TMP0, AT
3019 | // (lua_State *L, int32_t asize, uint32_t hbits)
3020 | call_intern lj_tab_new
3022 | // Returns Table *.
3024 | load_got lj_tab_dup
3026 | subu TMP1, KBASE, TMP1
3028 | call_intern lj_tab_dup // (lua_State *L, Table *kt)
3029 |. lw CARG2, -4(TMP1) // KBASE-4-str_const*4
3030 | // Returns Table *.
3036 | sw TAB:CRET1, LO(RA)
3040 | load_got lj_gc_step_fixtop
3042 | call_intern lj_gc_step_fixtop // (lua_State *L)
3049 | // RA = dst*8, RD = str_const*8 (~)
3051 | // RA = src*8, RD = str_const*8 (~)
3052 | lw LFUNC:TMP2, FRAME_FUNC(BASE)
3054 | subu TMP1, KBASE, TMP1
3055 | lw TAB:RB, LFUNC:TMP2->env
3056 | lw STR:RC, -4(TMP1) // KBASE-4-str_const*4
3057 if (op == BC_GGET) {
3062 |. addu RA, BASE, RA
3066 | // RA = dst*8, RB = table*8, RC = key*8
3067 | decode_RB8a RB, INS
3069 | decode_RDtoRC8 RC, RD
3070 | addu CARG2, BASE, RB
3071 | addu CARG3, BASE, RC
3072 | lw TMP1, HI(CARG2)
3073 | lw TMP2, HI(CARG3)
3074 | lw TAB:RB, LO(CARG2)
3077 | bne TMP1, AT, ->vmeta_tgetv
3078 |. addu RA, BASE, RA
3079 | sltiu AT, TMP2, LJ_TISNUM
3083 | // Convert number key to integer, check for integerness and range.
3085 | lw TMP0, TAB:RB->asize
3088 | lw TMP1, TAB:RB->array
3090 | sltu AT, TMP2, TMP0
3093 | beqz AT, ->vmeta_tgetv // Integer key and in array part?
3094 |. addu TMP2, TMP1, TMP2
3096 | beq TMP0, TISNIL, >2
3103 |2: // Check for __index if table value is nil.
3104 | lw TAB:TMP2, TAB:RB->metatable
3105 | beqz TAB:TMP2, <1 // No metatable: done.
3107 | lbu TMP0, TAB:TMP2->nomm
3108 | andi TMP0, TMP0, 1<<MM_index
3109 | bnez TMP0, <1 // 'no __index' flag set: done.
3115 | bne TMP2, AT, ->vmeta_tgetv
3116 |. lw STR:RC, LO(CARG3)
3117 | b ->BC_TGETS_Z // String key?
3121 | // RA = dst*8, RB = table*8, RC = str_const*4 (~)
3122 | decode_RB8a RB, INS
3124 | addu CARG2, BASE, RB
3125 | decode_RC4a RC, INS
3126 | lw TMP0, HI(CARG2)
3129 | lw TAB:RB, LO(CARG2)
3130 | subu CARG3, KBASE, RC
3131 | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4
3132 | bne TMP0, AT, ->vmeta_tgets1
3133 |. addu RA, BASE, RA
3135 | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
3136 | lw TMP0, TAB:RB->hmask
3137 | lw TMP1, STR:RC->hash
3138 | lw NODE:TMP2, TAB:RB->node
3139 | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
3142 | subu TMP1, TMP0, TMP1
3143 | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
3145 | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)
3146 | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
3147 | lw NODE:TMP1, NODE:TMP2->next
3148 | lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
3149 | addiu CARG1, CARG1, -LJ_TSTR
3150 | xor TMP0, TMP0, STR:RC
3151 | or AT, CARG1, TMP0
3153 |. lw TAB:TMP3, TAB:RB->metatable
3154 | beq CARG2, TISNIL, >5 // Key found, but nil value?
3155 |. lw CARG1, offsetof(Node, val)+LO(NODE:TMP2)
3162 |4: // Follow hash chain.
3163 | bnez NODE:TMP1, <1
3164 |. move NODE:TMP2, NODE:TMP1
3165 | // End of hash chain: key not found, nil result.
3167 |5: // Check for __index if table value is nil.
3168 | beqz TAB:TMP3, <3 // No metatable: done.
3169 |. li CARG2, LJ_TNIL
3170 | lbu TMP0, TAB:TMP3->nomm
3171 | andi TMP0, TMP0, 1<<MM_index
3172 | bnez TMP0, <3 // 'no __index' flag set: done.
3178 | // RA = dst*8, RB = table*8, RC = index*8
3179 | decode_RB8a RB, INS
3181 | addu CARG2, BASE, RB
3182 | decode_RDtoRC8 RC, RD
3183 | lw CARG1, HI(CARG2)
3185 | lw TAB:RB, LO(CARG2)
3187 | bne CARG1, AT, ->vmeta_tgetb
3189 | lw TMP1, TAB:RB->asize
3190 | lw TMP2, TAB:RB->array
3191 | sltu AT, TMP0, TMP1
3192 | beqz AT, ->vmeta_tgetb
3193 |. addu RC, TMP2, RC
3195 | beq TMP1, TISNIL, >5
3202 |5: // Check for __index if table value is nil.
3203 | lw TAB:TMP2, TAB:RB->metatable
3204 | beqz TAB:TMP2, <1 // No metatable: done.
3206 | lbu TMP1, TAB:TMP2->nomm
3207 | andi TMP1, TMP1, 1<<MM_index
3208 | bnez TMP1, <1 // 'no __index' flag set: done.
3210 | b ->vmeta_tgetb // Caveat: preserve TMP0!
3215 | // RA = src*8, RB = table*8, RC = key*8
3216 | decode_RB8a RB, INS
3218 | decode_RDtoRC8 RC, RD
3219 | addu CARG2, BASE, RB
3220 | addu CARG3, BASE, RC
3221 | lw TMP1, HI(CARG2)
3222 | lw TMP2, HI(CARG3)
3223 | lw TAB:RB, LO(CARG2)
3226 | bne TMP1, AT, ->vmeta_tsetv
3227 |. addu RA, BASE, RA
3228 | sltiu AT, TMP2, LJ_TISNUM
3232 | // Convert number key to integer, check for integerness and range.
3234 | lw TMP0, TAB:RB->asize
3237 | lw TMP1, TAB:RB->array
3239 | sltu AT, TMP2, TMP0
3242 | beqz AT, ->vmeta_tsetv // Integer key and in array part?
3243 |. addu TMP1, TMP1, TMP2
3244 | lbu TMP3, TAB:RB->marked
3246 | beq TMP0, TISNIL, >3
3249 | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
3255 |3: // Check for __newindex if previous value is nil.
3256 | lw TAB:TMP2, TAB:RB->metatable
3257 | beqz TAB:TMP2, <1 // No metatable: done.
3259 | lbu TMP2, TAB:TMP2->nomm
3260 | andi TMP2, TMP2, 1<<MM_newindex
3261 | bnez TMP2, <1 // 'no __newindex' flag set: done.
3267 | bne TMP2, AT, ->vmeta_tsetv
3268 |. lw STR:RC, LO(CARG3)
3269 | b ->BC_TSETS_Z // String key?
3272 |7: // Possible table write barrier for the value. Skip valiswhite check.
3273 | barrierback TAB:RB, TMP3, TMP0, <2
3276 | // RA = src*8, RB = table*8, RC = str_const*8 (~)
3277 | decode_RB8a RB, INS
3279 | addu CARG2, BASE, RB
3280 | decode_RC4a RC, INS
3281 | lw TMP0, HI(CARG2)
3284 | subu CARG3, KBASE, RC
3285 | lw TAB:RB, LO(CARG2)
3286 | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4
3287 | bne TMP0, AT, ->vmeta_tsets1
3288 |. addu RA, BASE, RA
3290 | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8
3291 | lw TMP0, TAB:RB->hmask
3292 | lw TMP1, STR:RC->hash
3293 | lw NODE:TMP2, TAB:RB->node
3294 | sb r0, TAB:RB->nomm // Clear metamethod cache.
3295 | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
3298 | subu TMP1, TMP0, TMP1
3299 | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
3302 | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)
3303 | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
3305 | lw NODE:TMP1, NODE:TMP2->next
3307 |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
3308 | bne TMP0, STR:RC, >5
3309 |. lbu TMP3, TAB:RB->marked
3310 | beq CARG2, TISNIL, >4 // Key found, but nil value?
3311 |. lw TAB:TMP0, TAB:RB->metatable
3313 | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
3315 |. sdc1 f20, NODE:TMP2->val
3319 |4: // Check for __newindex if previous value is nil.
3320 | beqz TAB:TMP0, <2 // No metatable: done.
3322 | lbu TMP0, TAB:TMP0->nomm
3323 | andi TMP0, TMP0, 1<<MM_newindex
3324 | bnez TMP0, <2 // 'no __newindex' flag set: done.
3329 |5: // Follow hash chain.
3330 | bnez NODE:TMP1, <1
3331 |. move NODE:TMP2, NODE:TMP1
3332 | // End of hash chain: key not found, add a new one
3334 | // But check for __newindex first.
3335 | lw TAB:TMP2, TAB:RB->metatable
3336 | beqz TAB:TMP2, >6 // No metatable: continue.
3337 |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
3338 | lbu TMP0, TAB:TMP2->nomm
3339 | andi TMP0, TMP0, 1<<MM_newindex
3340 | beqz TMP0, ->vmeta_tsets // 'no __newindex' flag NOT set: check.
3343 | load_got lj_tab_newkey
3344 | sw STR:RC, LO(CARG3)
3347 | move CARG2, TAB:RB
3349 | call_intern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k
3351 | // Returns TValue *.
3353 | b <3 // No 2nd write barrier needed.
3354 |. sdc1 f20, 0(CRET1)
3356 |7: // Possible table write barrier for the value. Skip valiswhite check.
3357 | barrierback TAB:RB, TMP3, TMP0, <3
3360 | // RA = src*8, RB = table*8, RC = index*8
3361 | decode_RB8a RB, INS
3363 | addu CARG2, BASE, RB
3364 | decode_RDtoRC8 RC, RD
3365 | lw CARG1, HI(CARG2)
3367 | lw TAB:RB, LO(CARG2)
3369 | bne CARG1, AT, ->vmeta_tsetb
3371 | lw TMP1, TAB:RB->asize
3372 | lw TMP2, TAB:RB->array
3373 | sltu AT, TMP0, TMP1
3374 | beqz AT, ->vmeta_tsetb
3375 |. addu RC, TMP2, RC
3377 | lbu TMP3, TAB:RB->marked
3378 | beq TMP1, TISNIL, >5
3381 | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
3387 |5: // Check for __newindex if previous value is nil.
3388 | lw TAB:TMP2, TAB:RB->metatable
3389 | beqz TAB:TMP2, <1 // No metatable: done.
3391 | lbu TMP1, TAB:TMP2->nomm
3392 | andi TMP1, TMP1, 1<<MM_newindex
3393 | bnez TMP1, <1 // 'no __newindex' flag set: done.
3395 | b ->vmeta_tsetb // Caveat: preserve TMP0!
3398 |7: // Possible table write barrier for the value. Skip valiswhite check.
3399 | barrierback TAB:RB, TMP3, TMP0, <2
3403 | // RA = base*8 (table at base-1), RD = num_const*8 (start index)
3406 | addu TMP3, KBASE, RD
3407 | lw TAB:CARG2, -8+LO(RA) // Guaranteed to be a table.
3408 | addiu TMP0, MULTRES, -8
3409 | lw TMP3, LO(TMP3) // Integer constant is in lo-word.
3410 | beqz TMP0, >4 // Nothing to copy?
3411 |. srl CARG3, TMP0, 3
3412 | addu CARG3, CARG3, TMP3
3413 | lw TMP2, TAB:CARG2->asize
3415 | lbu TMP3, TAB:CARG2->marked
3416 | lw CARG1, TAB:CARG2->array
3417 | sltu AT, TMP2, CARG3
3419 |. addu TMP2, RA, TMP0
3420 | addu TMP1, TMP1, CARG1
3421 | andi TMP0, TMP3, LJ_GC_BLACK // isblack(table)
3422 |3: // Copy result slots to table.
3428 |. addiu TMP1, TMP1, 8
3434 |5: // Need to resize array part.
3435 | load_got lj_tab_reasize
3439 | call_intern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
3441 | // Must not reallocate the stack.
3444 |. lw BASE, L->base // Reload BASE for lack of a saved register.
3446 |7: // Possible table write barrier for any value. Skip valiswhite check.
3447 | barrierback TAB:CARG2, TMP3, TMP0, <4
3450 /* -- Calls and vararg handling ----------------------------------------- */
3453 | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
3454 | decode_RDtoRC8 NARGS8:RC, RD
3456 |. addu NARGS8:RC, NARGS8:RC, MULTRES
3459 | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
3460 | decode_RDtoRC8 NARGS8:RC, RD
3463 | addu BASE, BASE, RA
3466 | lw LFUNC:RB, LO(BASE)
3467 | addiu BASE, BASE, 8
3468 | bne TMP0, AT, ->vmeta_call
3469 |. addiu NARGS8:RC, NARGS8:RC, -8
3474 | // RA = base*8, (RB = 0,) RC = extra_nargs*8
3475 | addu NARGS8:RD, NARGS8:RD, MULTRES // BC_CALLT gets RC from RD.
3476 | // Fall through. Assumes BC_CALLT follows.
3479 | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
3483 | lw LFUNC:RB, LO(RA)
3484 | move NARGS8:RC, RD
3485 | lw TMP1, FRAME_PC(BASE)
3487 | bne TMP0, AT, ->vmeta_callt
3488 |. addiu NARGS8:RC, NARGS8:RC, -8
3490 | andi TMP0, TMP1, FRAME_TYPE // Caveat: preserve TMP0 until the 'or'.
3491 | lbu TMP3, LFUNC:RB->ffid
3493 |. xori TMP2, TMP1, FRAME_VARG
3495 | sw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC.
3496 | sltiu AT, TMP3, 2 // (> FF_C) Calling a fast function?
3498 | beqz NARGS8:RC, >3
3499 |. move TMP3, NARGS8:RC
3503 | addiu TMP3, TMP3, -8
3506 |. addiu TMP2, TMP2, 8
3514 |5: // Tailcall to a fast function with a Lua frame below.
3516 | decode_RA8a RA, INS
3518 | subu TMP1, BASE, RA
3519 | lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1)
3520 | lw TMP1, LFUNC:TMP1->pc
3522 |. lw KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE.
3524 |7: // Tailcall from a vararg function.
3525 | andi AT, TMP2, FRAME_TYPEP
3526 | bnez AT, <1 // Vararg frame below?
3527 |. subu TMP2, BASE, TMP2 // Relocate BASE down.
3529 | lw TMP1, FRAME_PC(TMP2)
3531 |. andi TMP0, TMP1, FRAME_TYPE
3535 | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
3537 | addu BASE, BASE, RA
3539 | lw TMP1, -24+HI(BASE)
3540 | lw LFUNC:RB, -24+LO(BASE)
3542 | ldc1 f0, -16(BASE)
3543 | sw TMP1, HI(BASE) // Copy callable.
3544 | sw LFUNC:RB, LO(BASE)
3545 | sdc1 f2, 16(BASE) // Copy control var.
3546 | sdc1 f0, 8(BASE) // Copy state.
3547 | addiu BASE, BASE, 8
3548 | bne TMP1, AT, ->vmeta_call
3549 |. li NARGS8:RC, 16 // Iterators get 2 arguments.
3554 | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
3556 | // NYI: add hotloop, record BC_ITERN.
3559 | lw TAB:RB, -16+LO(RA)
3560 | lw RC, -8+LO(RA) // Get index from control var.
3561 | lw TMP0, TAB:RB->asize
3562 | lw TMP1, TAB:RB->array
3564 |1: // Traverse array part.
3566 | beqz AT, >5 // Index points after array part?
3568 | addu TMP3, TMP1, TMP3
3572 | lhu RD, -4+OFS_RD(PC)
3573 | beq TMP2, TISNIL, <1 // Skip holes in array part.
3576 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
3580 | sw RC, -8+LO(RA) // Update control var.
3586 |5: // Traverse hash part.
3587 | lw TMP1, TAB:RB->hmask
3589 | lw TMP2, TAB:RB->node
3591 | sltu AT, TMP1, RC // End of iteration? Branch to ITERL+1.
3595 | subu TMP3, TMP3, RB
3596 | addu NODE:TMP3, TMP3, TMP2
3597 | lw RB, HI(NODE:TMP3)
3598 | ldc1 f0, 0(NODE:TMP3)
3599 | lhu RD, -4+OFS_RD(PC)
3600 | beq RB, TISNIL, <6 // Skip holes in hash part.
3602 | ldc1 f2, NODE:TMP3->key
3603 | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
3611 |. sw RC, -8+LO(RA) // Update control var.
3615 | // RA = base*8, RD = target (points to ITERN)
3617 | lw TMP0, -24+HI(RA)
3618 | lw CFUNC:TMP1, -24+LO(RA)
3619 | lw TMP2, -16+HI(RA)
3620 | lw TMP3, -8+HI(RA)
3623 |. addiu TMP2, TMP2, -LJ_TTAB
3624 | lbu TMP1, CFUNC:TMP1->ffid
3625 | addiu TMP3, TMP3, -LJ_TNIL
3627 | or TMP2, TMP2, TMP3
3628 | addiu TMP1, TMP1, -FF_next_N
3629 | addu TMP0, PC, TMP0
3630 | or TMP1, TMP1, TMP2
3632 |. lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)
3633 | addu PC, TMP0, TMP2
3635 | ori TMP1, TMP1, 0x7fff
3636 | sw r0, -8+LO(RA) // Initialize control var.
3637 | sw TMP1, -8+HI(RA)
3640 |5: // Despecialize bytecode if any of the checks fail.
3643 | sb TMP3, -4+OFS_OP(PC)
3644 | addu PC, TMP0, TMP2
3646 |. sb TMP1, OFS_OP(PC)
3650 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
3651 | lw TMP0, FRAME_PC(BASE)
3652 | decode_RDtoRC8 RC, RD
3653 | decode_RB8a RB, INS
3657 | addiu RC, RC, FRAME_VARG
3659 | addiu TMP3, BASE, -8 // TMP3 = vtop
3660 | subu RC, RC, TMP0 // RC = vbase
3661 | // Note: RC may now be even _above_ BASE if nargs was < numparams.
3662 | beqz RB, >5 // Copy all varargs?
3663 |. subu TMP1, TMP3, RC
3664 | addiu TMP2, TMP2, -16
3665 |1: // Copy vararg slots to destination slots.
3670 | movz CARG1, TISNIL, AT
3679 |5: // Copy all varargs.
3680 | lw TMP0, L->maxstack
3681 | blez TMP1, <3 // No vararg slots?
3682 |. li MULTRES, 8 // MULTRES = (0+1)*8
3683 | addu TMP2, RA, TMP1
3684 | sltu AT, TMP0, TMP2
3686 |. addiu MULTRES, TMP1, 8
3692 | bnez AT, <6 // More vararg slots?
3697 |7: // Grow stack for varargs.
3698 | load_got lj_state_growstack
3702 | subu BASE, RC, BASE // Need delta, because BASE may change.
3704 | srl CARG2, TMP1, 3
3705 | call_intern lj_state_growstack // (lua_State *L, int n)
3712 |. addiu TMP3, BASE, -8
3715 /* -- Returns ----------------------------------------------------------- */
3718 | // RA = results*8, RD = extra_nresults*8
3719 | addu RD, RD, MULTRES // MULTRES >= 8, so RD >= 8.
3720 | // Fall through. Assumes BC_RET follows.
3724 | // RA = results*8, RD = (nresults+1)*8
3725 | lw PC, FRAME_PC(BASE)
3729 | andi TMP0, PC, FRAME_TYPE
3730 | bnez TMP0, ->BC_RETV_Z
3731 |. xori TMP1, PC, FRAME_VARG
3734 | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
3736 | addiu TMP2, BASE, -8
3738 | decode_RA8a TMP0, INS
3739 | decode_RB8a RB, INS
3742 | addu TMP3, TMP2, RB
3744 |. subu BASE, TMP2, TMP0
3751 |. addiu TMP2, TMP2, 8
3753 | addiu TMP3, TMP3, -8
3755 | sltu AT, TMP2, TMP3
3757 |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
3759 | lw TMP1, LFUNC:TMP1->pc
3760 | lw KBASE, PC2PROTO(k)(TMP1)
3763 |6: // Fill up results with nil.
3764 | sw TISNIL, HI(TMP2)
3766 |. addiu TMP2, TMP2, 8
3768 |->BC_RETV_Z: // Non-standard return case.
3769 | andi TMP2, TMP1, FRAME_TYPEP
3770 | bnez TMP2, ->vm_return
3772 | // Return from vararg function: relocate BASE down.
3773 | subu BASE, BASE, TMP1
3775 |. lw PC, FRAME_PC(BASE)
3778 case BC_RET0: case BC_RET1:
3779 | // RA = results*8, RD = (nresults+1)*8
3780 | lw PC, FRAME_PC(BASE)
3783 | andi TMP0, PC, FRAME_TYPE
3784 | bnez TMP0, ->BC_RETV_Z
3785 |. xori TMP1, PC, FRAME_VARG
3788 | addiu TMP2, BASE, -8
3789 if (op == BC_RET1) {
3792 | decode_RB8a RB, INS
3793 | decode_RA8a RA, INS
3796 if (op == BC_RET1) {
3799 | subu BASE, TMP2, RA
3803 |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
3805 | lw TMP1, LFUNC:TMP1->pc
3806 | lw KBASE, PC2PROTO(k)(TMP1)
3809 |6: // Fill up results with nil.
3810 | addiu TMP2, TMP2, 8
3813 if (op == BC_RET1) {
3814 |. sw TISNIL, HI(TMP2)
3816 |. sw TISNIL, -8+HI(TMP2)
3820 /* -- Loops and branches ------------------------------------------------ */
3826 | // Fall through. Assumes BC_IFORL follows.
3836 | // RA = base*8, RD = target (after end of loop or start of loop)
3837 vk = (op == BC_IFORL || op == BC_JFORL);
3840 | ldc1 f0, FORL_IDX*8(RA)
3841 | ldc1 f4, FORL_STEP*8(RA)
3842 | ldc1 f2, FORL_STOP*8(RA)
3843 | lw TMP3, FORL_STEP*8+HI(RA)
3845 | sdc1 f0, FORL_IDX*8(RA)
3847 | lw TMP1, FORL_IDX*8+HI(RA)
3848 | lw TMP3, FORL_STEP*8+HI(RA)
3849 | lw TMP2, FORL_STOP*8+HI(RA)
3850 | sltiu TMP1, TMP1, LJ_TISNUM
3851 | sltiu TMP0, TMP3, LJ_TISNUM
3852 | sltiu TMP2, TMP2, LJ_TISNUM
3853 | and TMP1, TMP1, TMP0
3854 | and TMP1, TMP1, TMP2
3855 | ldc1 f0, FORL_IDX*8(RA)
3856 | beqz TMP1, ->vmeta_for
3857 |. ldc1 f2, FORL_STOP*8(RA)
3859 if (op != BC_JFORL) {
3861 | lui TMP0, (-(BCBIAS_J*4 >> 16) & 65535)
3865 | sdc1 f0, FORL_EXT*8(RA)
3866 if (op == BC_JFORI) {
3869 | addu TMP0, RD, TMP0
3870 | slt TMP3, TMP3, r0
3874 | lhu RD, -4+OFS_RD(PC)
3875 | movn TMP1, TMP2, TMP3
3876 | bnez TMP1, =>BC_JLOOP
3878 } else if (op == BC_JFORL) {
3881 | slt TMP3, TMP3, r0
3884 | movn TMP1, TMP2, TMP3
3885 | bnez TMP1, =>BC_JLOOP
3888 | addu TMP1, RD, TMP0
3889 | slt TMP3, TMP3, r0
3891 if (op == BC_FORI) {
3898 | movn TMP1, TMP2, TMP3
3908 | // Fall through. Assumes BC_IITERL follows.
3916 | // RA = base*8, RD = target
3919 | beq TMP1, TISNIL, >1 // Stop if iterator returned nil.
3921 if (op == BC_JITERL) {
3922 | sw TMP1, -8+HI(RA)
3924 |. sw TMP2, -8+LO(RA)
3926 | branch_RD // Otherwise save control var + branch.
3927 | sw TMP1, -8+HI(RA)
3928 | sw TMP2, -8+LO(RA)
3935 | // RA = base*8, RD = target (loop extent)
3936 | // Note: RA/RD is only used by trace recorder to determine scope/extent
3937 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
3941 | // Fall through. Assumes BC_ILOOP follows.
3945 | // RA = base*8, RD = target (loop extent)
3951 | // RA = base*8 (ignored), RD = traceno*8
3952 | lw TMP1, DISPATCH_J(trace)(DISPATCH)
3955 | addu TMP1, TMP1, RD
3956 | // Traces on MIPS don't store the trace number, so use 0.
3957 | sw AT, DISPATCH_GL(vmstate)(DISPATCH)
3958 | lw TRACE:TMP2, 0(TMP1)
3959 | sw BASE, DISPATCH_GL(jit_base)(DISPATCH)
3960 | sw L, DISPATCH_GL(jit_L)(DISPATCH)
3961 | lw TMP2, TRACE:TMP2->mcode
3963 |. addiu JGL, DISPATCH, GG_DISP2G+32768
3968 | // RA = base*8 (only used by trace recorder), RD = target
3973 /* -- Function headers -------------------------------------------------- */
3979 case BC_FUNCV: /* NYI: compiled vararg functions. */
3980 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
3988 | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
3989 | lw TMP2, L->maxstack
3990 | lbu TMP1, -4+PC2PROTO(numparams)(PC)
3991 | lw KBASE, -4+PC2PROTO(k)(PC)
3993 | bnez AT, ->vm_growstack_l
3994 |. sll TMP1, TMP1, 3
3995 if (op != BC_JFUNCF) {
3999 | sltu AT, NARGS8:RC, TMP1 // Check for missing parameters.
4001 |. addu AT, BASE, NARGS8:RC
4002 if (op == BC_JFUNCF) {
4003 | decode_RD8a RD, INS
4010 |3: // Clear missing parameters.
4013 |. addiu NARGS8:RC, NARGS8:RC, 8
4020 | NYI // NYI: compiled vararg functions
4021 break; /* NYI: compiled vararg functions. */
4024 | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
4025 | addu TMP1, BASE, RC
4026 | lw TMP2, L->maxstack
4028 | sw LFUNC:RB, LO(TMP1) // Store copy of LFUNC.
4029 | addiu TMP3, RC, 8+FRAME_VARG
4030 | sltu AT, TMP0, TMP2
4031 | lw KBASE, -4+PC2PROTO(k)(PC)
4032 | beqz AT, ->vm_growstack_l
4033 |. sw TMP3, HI(TMP1) // Store delta + FRAME_VARG.
4034 | lbu TMP2, -4+PC2PROTO(numparams)(PC)
4039 |. addiu BASE, TMP1, 8
4043 | sltu AT, RA, RC // Less args than parameters?
4045 | movz TMP0, TISNIL, AT // Clear missing parameters.
4046 | movn CARG1, TISNIL, AT // Clear old fixarg slot (help the GC).
4047 | sw TMP3, 8+LO(TMP1)
4048 | addiu TMP2, TMP2, -1
4049 | sw TMP0, 8+HI(TMP1)
4050 | addiu TMP1, TMP1, 8
4060 | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
4061 if (op == BC_FUNCC) {
4062 | lw CFUNCADDR, CFUNC:RB->f
4064 | lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)
4066 | addu TMP1, RA, NARGS8:RC
4067 | lw TMP2, L->maxstack
4068 | addu RC, BASE, NARGS8:RC
4070 | sltu AT, TMP2, TMP1
4073 if (op == BC_FUNCCW) {
4074 | lw CARG2, CFUNC:RB->f
4076 | bnez AT, ->vm_growstack_c // Need to grow stack.
4078 | jalr CFUNCADDR // (lua_State *L [, lua_CFunction f])
4080 | // Returns nresults.
4085 | lw PC, FRAME_PC(BASE) // Fetch PC of caller.
4086 | subu RA, TMP1, RD // RA = L->top - nresults*8
4091 /* ---------------------------------------------------------------------- */
4094 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
4100 static int build_backend(BuildCtx *ctx)
4104 dasm_growpc(Dst, BC__MAX);
4106 build_subroutines(ctx);
4109 for (op = 0; op < BC__MAX; op++)
4110 build_ins(ctx, (BCOp)op, op);
4115 /* Emit pseudo frame-info for all assembler functions. */
4116 static void emit_asm_debug(BuildCtx *ctx)
4118 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
4120 switch (ctx->mode) {
4122 fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
4125 "\t.4byte .LECIE0-.LSCIE0\n"
4127 "\t.4byte 0xffffffff\n"
4133 "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
4138 "\t.4byte .LEFDE0-.LASFDE0\n"
4140 "\t.4byte .Lframe0\n"
4141 "\t.4byte .Lbegin\n"
4143 "\t.byte 0xe\n\t.uleb128 %d\n"
4144 "\t.byte 0x9f\n\t.sleb128 1\n"
4145 "\t.byte 0x9e\n\t.sleb128 2\n",
4146 fcofs, CFRAME_SIZE);
4147 for (i = 23; i >= 16; i--)
4148 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i);
4149 for (i = 30; i >= 20; i -= 2)
4150 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i);
4157 "\t.4byte .LEFDE1-.LASFDE1\n"
4159 "\t.4byte .Lframe0\n"
4160 "\t.4byte lj_vm_ffi_call\n"
4162 "\t.byte 0x9f\n\t.uleb128 1\n"
4163 "\t.byte 0x90\n\t.uleb128 2\n"
4164 "\t.byte 0xd\n\t.uleb128 0x10\n"
4166 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
4168 fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
4170 "\t.globl lj_err_unwind_dwarf\n"
4172 "\t.4byte .LECIE1-.LSCIE1\n"
4176 "\t.string \"zPR\"\n"
4180 "\t.uleb128 6\n" /* augmentation length */
4182 "\t.4byte lj_err_unwind_dwarf\n"
4184 "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
4189 "\t.4byte .LEFDE2-.LASFDE2\n"
4191 "\t.4byte .LASFDE2-.Lframe1\n"
4192 "\t.4byte .Lbegin\n"
4194 "\t.uleb128 0\n" /* augmentation length */
4195 "\t.byte 0xe\n\t.uleb128 %d\n"
4196 "\t.byte 0x9f\n\t.sleb128 1\n"
4197 "\t.byte 0x9e\n\t.sleb128 2\n",
4198 fcofs, CFRAME_SIZE);
4199 for (i = 23; i >= 16; i--)
4200 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i);
4201 for (i = 30; i >= 20; i -= 2)
4202 fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i);
4209 "\t.4byte .LECIE2-.LSCIE2\n"
4213 "\t.string \"zR\"\n"
4217 "\t.uleb128 1\n" /* augmentation length */
4219 "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
4224 "\t.4byte .LEFDE3-.LASFDE3\n"
4226 "\t.4byte .LASFDE3-.Lframe2\n"
4227 "\t.4byte lj_vm_ffi_call\n"
4229 "\t.uleb128 0\n" /* augmentation length */
4230 "\t.byte 0x9f\n\t.uleb128 1\n"
4231 "\t.byte 0x90\n\t.uleb128 2\n"
4232 "\t.byte 0xd\n\t.uleb128 0x10\n"
4234 ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);