1 |// Low-level VM code for x86 CPUs.
2 |// Bytecode interpreter, fast functions and helper functions.
3 |// Copyright (C) 2005-2013 Mike Pall. See Copyright Notice in luajit.h
10 |.section code_op, code_sub
12 |.actionlist build_actionlist
14 |.globalnames globnames
15 |.externnames extnames
17 |//-----------------------------------------------------------------------
27 |// Fixed register assignments for the interpreter.
28 |// This is very fragile and has many dependencies. Caveat emptor.
29 |.define BASE, edx // Not C callee-save, refetched anyway.
31 |.define KBASE, edi // Must be C callee-save.
32 |.define KBASEa, KBASE
33 |.define PC, esi // Must be C callee-save.
35 |.define DISPATCH, ebx // Must be C callee-save.
37 |.define KBASE, edi // Must be C callee-save.
39 |.define PC, esi // Must be C callee-save.
41 |.define DISPATCH, ebx // Must be C callee-save.
43 |.define KBASE, r15d // Must be C callee-save.
45 |.define PC, ebx // Must be C callee-save.
47 |.define DISPATCH, r14d // Must be C callee-save.
53 |.define RB, ebp // Must be ebp (C callee-save).
54 |.define RC, eax // Must be eax.
75 |.define FCARG1, ecx // x86 fastcall arguments.
78 |.define CARG1, rcx // x64/WIN64 C call arguments.
86 |.define FCARG1, CARG1d // Upwards compatible to x86 fastcall.
87 |.define FCARG2, CARG2d
89 |.define CARG1, rdi // x64/POSIX C call arguments.
101 |.define FCARG1, CARG1d // Simulate x86 fastcall.
102 |.define FCARG2, CARG2d
105 |// Type definitions. Some of these are only used for documentation.
107 |.type GL, global_State
108 |.type TVALUE, TValue
112 |.type LFUNC, GCfuncL
113 |.type CFUNC, GCfuncC
114 |.type PROTO, GCproto
115 |.type UPVAL, GCupval
118 |.type TRACE, GCtrace
120 |// Stack layout while in interpreter. Must match with lj_frame.h.
121 |//-----------------------------------------------------------------------
122 |.if not X64 // x86 stack layout.
124 |.define CFRAME_SPACE, aword*7 // Delta for esp (see <--).
126 | push edi; push esi; push ebx
127 | sub esp, CFRAME_SPACE
130 | push ebp; saveregs_
133 | add esp, CFRAME_SPACE
134 | pop ebx; pop esi; pop edi; pop ebp
137 |.define SAVE_ERRF, aword [esp+aword*15] // vm_pcall/vm_cpcall only.
138 |.define SAVE_NRES, aword [esp+aword*14]
139 |.define SAVE_CFRAME, aword [esp+aword*13]
140 |.define SAVE_L, aword [esp+aword*12]
141 |//----- 16 byte aligned, ^^^ arguments from C caller
142 |.define SAVE_RET, aword [esp+aword*11] //<-- esp entering interpreter.
143 |.define SAVE_R4, aword [esp+aword*10]
144 |.define SAVE_R3, aword [esp+aword*9]
145 |.define SAVE_R2, aword [esp+aword*8]
146 |//----- 16 byte aligned
147 |.define SAVE_R1, aword [esp+aword*7] //<-- esp after register saves.
148 |.define SAVE_PC, aword [esp+aword*6]
149 |.define TMP2, aword [esp+aword*5]
150 |.define TMP1, aword [esp+aword*4]
151 |//----- 16 byte aligned
152 |.define ARG4, aword [esp+aword*3]
153 |.define ARG3, aword [esp+aword*2]
154 |.define ARG2, aword [esp+aword*1]
155 |.define ARG1, aword [esp] //<-- esp while in interpreter.
156 |//----- 16 byte aligned, ^^^ arguments for C callee
158 |// FPARGx overlaps ARGx and ARG(x+1) on x86.
159 |.define FPARG3, qword [esp+qword*1]
160 |.define FPARG1, qword [esp]
161 |// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ).
162 |.define TMPQ, qword [esp+aword*4]
166 |.define MULTRES, TMP2
168 |// Arguments for vm_call and vm_pcall.
169 |.define INARG_BASE, SAVE_CFRAME // Overwritten by SAVE_CFRAME!
171 |// Arguments for vm_cpcall.
172 |.define INARG_CP_CALL, SAVE_ERRF
173 |.define INARG_CP_UD, SAVE_NRES
174 |.define INARG_CP_FUNC, SAVE_CFRAME
176 |//-----------------------------------------------------------------------
177 |.elif X64WIN // x64/Windows stack layout
179 |.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--).
181 | push rdi; push rsi; push rbx
182 | sub rsp, CFRAME_SPACE
185 | push rbp; saveregs_
188 | add rsp, CFRAME_SPACE
189 | pop rbx; pop rsi; pop rdi; pop rbp
192 |.define SAVE_CFRAME, aword [rsp+aword*13]
193 |.define SAVE_PC, dword [rsp+dword*25]
194 |.define SAVE_L, dword [rsp+dword*24]
195 |.define SAVE_ERRF, dword [rsp+dword*23]
196 |.define SAVE_NRES, dword [rsp+dword*22]
197 |.define TMP2, dword [rsp+dword*21]
198 |.define TMP1, dword [rsp+dword*20]
199 |//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter
200 |.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter.
201 |.define SAVE_R4, aword [rsp+aword*8]
202 |.define SAVE_R3, aword [rsp+aword*7]
203 |.define SAVE_R2, aword [rsp+aword*6]
204 |.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves.
205 |.define ARG5, aword [rsp+aword*4]
206 |.define CSAVE_4, aword [rsp+aword*3]
207 |.define CSAVE_3, aword [rsp+aword*2]
208 |.define CSAVE_2, aword [rsp+aword*1]
209 |.define CSAVE_1, aword [rsp] //<-- rsp while in interpreter.
210 |//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee
212 |// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).
213 |.define TMPQ, qword [rsp+aword*10]
214 |.define MULTRES, TMP2
216 |.define ARG5d, dword [rsp+aword*4]
219 |//-----------------------------------------------------------------------
220 |.else // x64/POSIX stack layout
222 |.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--).
224 | push rbx; push r15; push r14
225 | sub rsp, CFRAME_SPACE
228 | push rbp; saveregs_
231 | add rsp, CFRAME_SPACE
232 | pop r14; pop r15; pop rbx; pop rbp
235 |//----- 16 byte aligned,
236 |.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter.
237 |.define SAVE_R4, aword [rsp+aword*8]
238 |.define SAVE_R3, aword [rsp+aword*7]
239 |.define SAVE_R2, aword [rsp+aword*6]
240 |.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves.
241 |.define SAVE_CFRAME, aword [rsp+aword*4]
242 |.define SAVE_PC, dword [rsp+dword*7]
243 |.define SAVE_L, dword [rsp+dword*6]
244 |.define SAVE_ERRF, dword [rsp+dword*5]
245 |.define SAVE_NRES, dword [rsp+dword*4]
246 |.define TMPa, aword [rsp+aword*1]
247 |.define TMP2, dword [rsp+dword*1]
248 |.define TMP1, dword [rsp] //<-- rsp while in interpreter.
249 |//----- 16 byte aligned
251 |// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).
252 |.define TMPQ, qword [rsp]
253 |.define TMP3, dword [rsp+aword*1]
254 |.define MULTRES, TMP2
258 |//-----------------------------------------------------------------------
260 |// Instruction headers.
261 |.macro ins_A; .endmacro
262 |.macro ins_AD; .endmacro
263 |.macro ins_AJ; .endmacro
264 |.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro
265 |.macro ins_AB_; movzx RB, RCH; .endmacro
266 |.macro ins_A_C; movzx RC, RCL; .endmacro
267 |.macro ins_AND; not RDa; .endmacro
269 |// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).
277 | jmp aword [DISPATCH+OP*8]
279 | jmp aword [DISPATCH+OP*4]
283 |// Instruction footer.
285 | // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
286 | .define ins_next, ins_NEXT
287 | .define ins_next_, ins_NEXT
289 | // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
290 | // Affects only certain kinds of benchmarks (and only with -j off).
291 | // Around 10%-30% slower on Core2, a lot more slower on P4.
301 |// Call decode and dispatch.
303 | // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC
304 | mov PC, LFUNC:RB->pc
310 | jmp aword [DISPATCH+OP*8]
312 | jmp aword [DISPATCH+OP*4]
317 | // BASE = new base, RB = LFUNC, RD = nargs+1
322 |//-----------------------------------------------------------------------
324 |// Macros to test operand types.
325 |.macro checktp, reg, tp; cmp dword [BASE+reg*8+4], tp; .endmacro
326 |.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro
327 |.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro
328 |.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro
329 |.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro
331 |// These operands must be used with movzx.
332 |.define PC_OP, byte [PC-4]
333 |.define PC_RA, byte [PC-3]
334 |.define PC_RB, byte [PC-1]
335 |.define PC_RC, byte [PC-2]
336 |.define PC_RD, word [PC-2]
338 |.macro branchPC, reg
339 | lea PC, [PC+reg*4-BCBIAS_J*4]
342 |// Assumes DISPATCH is relative to GL.
343 #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
344 #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
346 #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
348 |// Decrement hashed hotcount and trigger trace recorder if zero.
352 | and reg, HOTCOUNT_PCMASK
353 | sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP
360 | and reg, HOTCOUNT_PCMASK
361 | sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL
365 |// Set current VM state.
366 |.macro set_vmstate, st
367 | mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st
371 |.macro fcomparepp // Compare and pop st0 >< st1.
376 |.macro fdup; fld st0; .endmacro
377 |.macro fpop1; fstp st1; .endmacro
379 |// Synthesize SSE FP constants.
380 |.macro sseconst_abs, reg, tmp // Synthesize abs mask.
382 | mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp
384 | pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1
388 |.macro sseconst_hi, reg, tmp, val // Synthesize hi-32 bit const.
390 | mov64 tmp, U64x(val,00000000); movd reg, tmp
392 | mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51
396 |.macro sseconst_sign, reg, tmp // Synthesize sign mask.
397 | sseconst_hi reg, tmp, 80000000
399 |.macro sseconst_1, reg, tmp // Synthesize 1.0.
400 | sseconst_hi reg, tmp, 3ff00000
402 |.macro sseconst_m1, reg, tmp // Synthesize -1.0.
403 | sseconst_hi reg, tmp, bff00000
405 |.macro sseconst_2p52, reg, tmp // Synthesize 2^52.
406 | sseconst_hi reg, tmp, 43300000
408 |.macro sseconst_tobit, reg, tmp // Synthesize 2^52 + 2^51.
409 | sseconst_hi reg, tmp, 43380000
412 |// Move table write barrier back. Overwrites reg.
413 |.macro barrierback, tab, reg
414 | and byte tab->marked, (uint8_t)~LJ_GC_BLACK // black2gray(tab)
415 | mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]
416 | mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab
417 | mov tab->gclist, reg
420 |//-----------------------------------------------------------------------
422 /* Generate subroutines used by opcodes and other parts of the VM. */
423 /* The .code_sub section should be last to help static branch prediction. */
424 static void build_subroutines(BuildCtx *ctx)
428 |//-----------------------------------------------------------------------
429 |//-- Return handling ----------------------------------------------------
430 |//-----------------------------------------------------------------------
436 | // Return from pcall or xpcall fast func.
438 | sub BASE, PC // Restore caller base.
439 | lea RAa, [RA+PC-8] // Rebase RA and prepend one result.
440 | mov PC, [BASE-4] // Fetch PC of previous frame.
441 | // Prepending may overwrite the pcall frame, so do it at the end.
442 | mov dword [BASE+RA+4], LJ_TTRUE // Prepend true to results.
445 | add RD, 1 // RD = nresults+1
446 | jz ->vm_unwind_yield
448 | test PC, FRAME_TYPE
449 | jz ->BC_RET_Z // Handle regular return to Lua.
452 | // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return
454 | test PC, FRAME_TYPE
461 | neg PC // Previous base = BASE - delta.
465 |1: // Move results down.
472 | mov RB, [BASE+RA+4]
483 | mov RA, SAVE_NRES // RA = wanted nresults+1
486 | jne >6 // More/less results wanted?
489 | mov L:RB->top, BASE
492 | mov RAa, SAVE_CFRAME // Restore previous C frame.
493 | mov L:RB->cframe, RAa
494 | xor eax, eax // Ok return status for vm_pcall.
501 | jb >7 // Less results wanted?
502 | // More results wanted. Check stack size and fill up results with nil.
503 | cmp BASE, L:RB->maxstack
505 | mov dword [BASE-4], LJ_TNIL
510 |7: // Less results wanted.
512 | jz <5 // But check for LUA_MULTRET+1.
513 | sub RA, RD // Negative result!
514 | lea BASE, [BASE+RA*8] // Correct top.
517 |8: // Corner case: need to grow stack for filling up results.
518 | // This can happen if:
519 | // - A C function grows the stack (a lot).
520 | // - The GC shrinks the stack in between.
521 | // - A return back from a lua_call() with (high) nresults adjustment.
522 | mov L:RB->top, BASE // Save current top held in BASE (yes).
523 | mov MULTRES, RD // Need to fill only remainder with nil.
526 | call extern lj_state_growstack@8 // (lua_State *L, int n)
527 | mov BASE, L:RB->top // Need the (realloced) L->top in BASE.
532 | jmp ->vm_unwind_c_eh
534 |->vm_unwind_c@8: // Unwind C stack, return from vm_pcall.
535 | // (void *cframe, int errcode)
537 | mov eax, CARG2d // Error return status for vm_pcall.
540 | mov eax, FCARG2 // Error return status for vm_pcall.
543 |->vm_unwind_c_eh: // Landing pad for external unwinder.
545 | mov GL:RB, L:RB->glref
546 | mov dword GL:RB->vmstate, ~LJ_VMST_C
549 |->vm_unwind_rethrow:
550 |.if X64 and not X64WIN
554 | jmp extern lj_err_throw@8 // (lua_State *L, int errcode)
557 |->vm_unwind_ff@4: // Unwind C stack, return from ff pcall.
560 | and CARG1, CFRAME_RAWMASK
563 | and FCARG1, CFRAME_RAWMASK
566 |->vm_unwind_ff_eh: // Landing pad for external unwinder.
568 | mov RAa, -8 // Results start at BASE+RA = BASE-8.
569 | mov RD, 1+1 // Really 1+2 results, incr. later.
570 | mov BASE, L:RB->base
571 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
572 | add DISPATCH, GG_G2DISP
573 | mov PC, [BASE-4] // Fetch PC of previous frame.
574 | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message.
576 | jmp ->vm_returnc // Increments RD/MULTRES and returns.
578 |//-----------------------------------------------------------------------
579 |//-- Grow stack for calls -----------------------------------------------
580 |//-----------------------------------------------------------------------
582 |->vm_growstack_c: // Grow stack for C function.
583 | mov FCARG2, LUA_MINSTACK
586 |->vm_growstack_v: // Grow stack for vararg Lua function.
590 |->vm_growstack_f: // Grow stack for fixarg Lua function.
591 | // BASE = new base, RD = nargs+1, RB = L, PC = first PC
592 | lea RD, [BASE+NARGS:RD*8-8]
594 | movzx RA, byte [PC-4+PC2PROTO(framesize)]
595 | add PC, 4 // Must point after first instruction.
596 | mov L:RB->base, BASE
601 | // RB = L, L->base = new base, L->top = top
603 | call extern lj_state_growstack@8 // (lua_State *L, int n)
604 | mov BASE, L:RB->base
606 | mov LFUNC:RB, [BASE-8]
610 | // BASE = new base, RB = LFUNC, RD = nargs+1
611 | ins_callt // Just retry the call.
613 |//-----------------------------------------------------------------------
614 |//-- Entry points into the assembler VM ---------------------------------
615 |//-----------------------------------------------------------------------
617 |->vm_resume: // Setup C frame and resume thread.
618 | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
621 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
626 | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
630 | lea KBASEa, [esp+CFRAME_RESUME]
631 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
632 | add DISPATCH, GG_G2DISP
633 | mov L:RB->cframe, KBASEa
634 | mov SAVE_PC, RD // Any value outside of bytecode is ok.
635 | mov SAVE_CFRAME, RDa
640 | cmp byte L:RB->status, RDL
641 | je >3 // Initial resume (like a call).
643 | // Resume after yield (like a return).
645 | mov byte L:RB->status, RDL
646 | mov BASE, L:RB->base
650 | add RD, 1 // RD = nresults+1
651 | sub RA, BASE // RA = resultofs
654 | test PC, FRAME_TYPE
658 |->vm_pcall: // Setup protected C frame and enter VM.
659 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
663 | mov SAVE_ERRF, CARG4d
667 |->vm_call: // Setup C frame and enter VM.
668 | // (lua_State *L, TValue *base, int nres1)
672 |1: // Entry point for vm_pcall above (PC = ftype).
674 | mov SAVE_NRES, CARG3d
675 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
680 | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
683 | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
684 | mov SAVE_CFRAME, KBASEa
685 | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
687 | mov L:RB->cframe, rsp
689 | mov L:RB->cframe, esp
692 |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype).
693 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
694 | add DISPATCH, GG_G2DISP
696 |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype).
698 | mov BASE, L:RB->base // BASE = old base (used in vmeta_call).
700 | sub PC, BASE // PC = frame delta + frame type
705 | add NARGS:RD, 1 // RD = nargs+1
708 | mov LFUNC:RB, [RA-8]
709 | cmp dword [RA-4], LJ_TFUNC
710 | jne ->vmeta_call // Ensure KBASE defined and != BASE.
712 |->vm_call_dispatch_f:
715 | // BASE = new base, RB = func, RD = nargs+1, PC = caller PC
717 |->vm_cpcall: // Setup protected C frame, call C.
718 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
721 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
725 | // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap!
726 | mov RC, INARG_CP_UD // Get args before they are overwritten.
727 | mov RA, INARG_CP_FUNC
728 | mov BASE, INARG_CP_CALL
730 | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
732 | mov KBASE, L:RB->stack // Compute -savestack(L, L->top).
733 | sub KBASE, L:RB->top
734 | mov SAVE_ERRF, 0 // No error function.
735 | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame.
736 | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).
739 | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
740 | mov SAVE_CFRAME, KBASEa
741 | mov L:RB->cframe, rsp
743 | call CARG4 // (lua_State *L, lua_CFunction func, void *ud)
745 | mov ARG3, RC // Have to copy args downwards.
749 | mov KBASE, L:RB->cframe // Add our C frame to cframe chain.
750 | mov SAVE_CFRAME, KBASE
751 | mov L:RB->cframe, esp
753 | call BASE // (lua_State *L, lua_CFunction func, void *ud)
755 | // TValue * (new base) or NULL returned in eax (RC).
757 | jz ->vm_leave_cp // No base? Just remove C frame.
760 | jmp <2 // Else continue with the call.
762 |//-----------------------------------------------------------------------
763 |//-- Metamethod handling ------------------------------------------------
764 |//-----------------------------------------------------------------------
766 |//-- Continuation dispatch ----------------------------------------------
769 | // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)
773 | sub BASE, PC // Restore caller BASE.
774 | mov dword [RA+RD*8-4], LJ_TNIL // Ensure one valid arg.
775 | mov RC, RA // ... in [RC]
776 | mov PC, [RB-12] // Restore PC from [cont|PC].
778 | movsxd RAa, dword [RB-16] // May be negative on WIN64 with debug.
783 | lea KBASEa, qword [=>0]
786 | mov RA, dword [RB-16]
792 | mov LFUNC:KBASE, [BASE-8]
793 | mov KBASE, LFUNC:KBASE->pc
794 | mov KBASE, [KBASE+PC2PROTO(k)]
795 | // BASE = base, RC = result, RB = meta base
796 | jmp RAa // Jump to continuation.
800 | je ->cont_ffi_callback // cont = 1: return from FFI callback.
801 | // cont = 0: Tail call from C function.
808 |->cont_cat: // BASE = base, RC = result, RB = mbase
811 | lea RA, [BASE+RA*8]
818 | mov L:CARG1d, SAVE_L
819 | mov L:CARG1d->base, BASE
824 | mov L:CARG1d, SAVE_L
825 | mov L:CARG1d->base, BASE
840 |//-- Table indexing metamethods -----------------------------------------
843 | mov TMP1, RC // RC = GCstr *
845 | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
848 | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
849 | mov [RA], TAB:RB // RB = GCtab *
850 | mov dword [RA+4], LJ_TTAB
857 | mov TMP2, LJ_TISNUM
867 | lea RCa, TMPQ // Store temp. TValue in TMPQ.
871 | movzx RC, PC_RC // Reload TValue *k from RC.
872 | lea RC, [BASE+RC*8]
874 | movzx RB, PC_RB // Reload TValue *t from RB.
875 | lea RB, [BASE+RB*8]
878 | mov L:CARG1d, SAVE_L
879 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
881 | mov CARG3, RCa // May be 64 bit ptr to stack.
888 | mov L:RB->base, BASE
891 | call extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
892 | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
893 | mov BASE, L:RB->base
896 |->cont_ra: // BASE = base, RC = result
900 | mov [BASE+RA*8], RBa
904 | mov [BASE+RA*8+4], RB
905 | mov [BASE+RA*8], RC
909 |3: // Call __index metamethod.
910 | // BASE = base, L->top = new base, stack = cont/func/t/k
912 | mov [RA-12], PC // [cont|PC]
913 | lea PC, [RA+FRAME_CONT]
915 | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
916 | mov NARGS:RD, 2+1 // 2 args for func(t, k).
917 | jmp ->vm_call_dispatch_f
919 |//-----------------------------------------------------------------------
922 | mov TMP1, RC // RC = GCstr *
924 | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
927 | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
928 | mov [RA], TAB:RB // RB = GCtab *
929 | mov dword [RA+4], LJ_TTAB
936 | mov TMP2, LJ_TISNUM
946 | lea RCa, TMPQ // Store temp. TValue in TMPQ.
950 | movzx RC, PC_RC // Reload TValue *k from RC.
951 | lea RC, [BASE+RC*8]
953 | movzx RB, PC_RB // Reload TValue *t from RB.
954 | lea RB, [BASE+RB*8]
957 | mov L:CARG1d, SAVE_L
958 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
960 | mov CARG3, RCa // May be 64 bit ptr to stack.
967 | mov L:RB->base, BASE
970 | call extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
971 | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
972 | mov BASE, L:RB->base
975 | // NOBARRIER: lj_meta_tset ensures the table is not black.
978 | mov RBa, [BASE+RA*8]
981 | mov RB, [BASE+RA*8+4]
982 | mov RA, [BASE+RA*8]
986 |->cont_nop: // BASE = base, (RC = result)
989 |3: // Call __newindex metamethod.
990 | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
992 | mov [RA-12], PC // [cont|PC]
994 | // Copy value to third argument.
996 | mov RBa, [BASE+RC*8]
999 | mov RB, [BASE+RC*8+4]
1000 | mov RC, [BASE+RC*8]
1004 | lea PC, [RA+FRAME_CONT]
1006 | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
1007 | mov NARGS:RD, 3+1 // 3 args for func(t, k, v).
1008 | jmp ->vm_call_dispatch_f
1010 |//-- Comparison metamethods ---------------------------------------------
1015 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d == BASE.
1017 | lea CARG3d, [BASE+RD*8]
1018 | lea CARG2d, [BASE+RA*8]
1020 | lea CARG2d, [BASE+RA*8]
1021 | lea CARG3d, [BASE+RD*8]
1023 | mov CARG1d, L:RB // Caveat: CARG1d/CARG4d == RA.
1024 | movzx CARG4d, PC_OP
1027 | lea RD, [BASE+RD*8]
1028 | lea RA, [BASE+RA*8]
1034 | mov L:RB->base, BASE
1037 | call extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
1038 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1040 | mov BASE, L:RB->base
1052 |->cont_condt: // BASE = base, RC = result
1054 | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is true.
1058 |->cont_condf: // BASE = base, RC = result
1059 | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is false.
1068 | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
1070 | mov CARG1d, L:RB // Caveat: CARG1d == RA.
1073 | mov CARG4d, RB // Caveat: CARG4d == RA.
1075 | mov L:RB->base, BASE // Caveat: CARG3d == BASE.
1084 | mov L:RB->base, BASE
1087 | call extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
1088 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1095 | mov L:RB->base, BASE
1097 | mov FCARG2, dword [PC-4]
1099 | call extern lj_meta_equal_cd@8 // (lua_State *L, BCIns ins)
1100 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1104 |//-- Arithmetic metamethods ---------------------------------------------
1111 | lea RC, [KBASE+RC*8]
1119 | lea RC, [KBASE+RC*8]
1120 | lea RB, [BASE+RB*8]
1125 | lea RC, [BASE+RD*8]
1134 | lea RC, [BASE+RC*8]
1136 | lea RB, [BASE+RB*8]
1138 | lea RA, [BASE+RA*8]
1145 | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
1147 | mov CARG1d, L:RB // Caveat: CARG1d == RA.
1149 | movzx CARG5d, PC_OP
1151 | mov CARG4d, RC // Caveat: CARG4d == RA.
1152 | mov L:CARG1d, SAVE_L
1153 | mov L:CARG1d->base, BASE // Caveat: CARG3d == BASE.
1155 | mov L:RB, L:CARG1d
1164 | mov L:RB->base, BASE
1167 | call extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
1168 | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
1169 | mov BASE, L:RB->base
1173 | // Call metamethod for binary op.
1175 | // BASE = base, RC = new base, stack = cont/func/o1/o2
1178 | mov [RA-12], PC // [cont|PC]
1179 | lea PC, [RC+FRAME_CONT]
1180 | mov NARGS:RD, 2+1 // 2 args for func(o1, o2).
1181 | jmp ->vm_call_dispatch
1185 | mov L:RB->base, BASE
1186 | lea FCARG2, [BASE+RD*8] // Caveat: FCARG2 == BASE
1187 | mov L:FCARG1, L:RB
1189 | call extern lj_meta_len@8 // (lua_State *L, TValue *o)
1190 | // NULL (retry) or TValue * (metamethod) returned in eax (RC).
1191 | mov BASE, L:RB->base
1194 | jne ->vmeta_binop // Binop call for compatibility.
1196 | mov TAB:FCARG1, [BASE+RD*8]
1199 | jmp ->vmeta_binop // Binop call for compatibility.
1202 |//-- Call metamethod ----------------------------------------------------
1205 | lea RA, [BASE+RA*8+8]
1206 |->vmeta_call: // Resolve and call __call metamethod.
1207 | // BASE = old base, RA = new base, RC = nargs+1, PC = return
1208 | mov TMP2, RA // Save RA, RC for us.
1209 | mov TMP1, NARGS:RD
1213 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
1215 | lea CARG3d, [RA+NARGS:RD*8]
1216 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
1218 | lea RC, [RA+NARGS:RD*8]
1223 | mov L:RB->base, BASE // This is the callers base!
1226 | call extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
1227 | mov BASE, L:RB->base
1229 | mov NARGS:RD, TMP1
1230 | mov LFUNC:RB, [RA-8]
1232 | // This is fragile. L->base must not move, KBASE must always be defined.
1233 | cmp KBASE, BASE // Continue with CALLT if flag set.
1236 | ins_call // Otherwise call resolved metamethod.
1238 |//-- Argument coercion for 'for' statement ------------------------------
1242 | mov L:RB->base, BASE
1243 | mov FCARG2, RA // Caveat: FCARG2 == BASE
1244 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
1246 | call extern lj_meta_for@8 // (lua_State *L, TValue *base)
1247 | mov BASE, L:RB->base
1253 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Retry FORI or JFORI.
1255 | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Retry FORI or JFORI.
1258 |//-----------------------------------------------------------------------
1259 |//-- Fast functions -----------------------------------------------------
1260 |//-----------------------------------------------------------------------
1262 |.macro .ffunc, name
1266 |.macro .ffunc_1, name
1268 | cmp NARGS:RD, 1+1; jb ->fff_fallback
1271 |.macro .ffunc_2, name
1273 | cmp NARGS:RD, 2+1; jb ->fff_fallback
1276 |.macro .ffunc_n, name
1278 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1282 |.macro .ffunc_n, name, op
1284 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1289 |.macro .ffunc_nsse, name, op
1291 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1292 | op xmm0, qword [BASE]
1295 |.macro .ffunc_nsse, name
1296 | .ffunc_nsse name, movsd
1299 |.macro .ffunc_nn, name
1301 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1302 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1304 | fld qword [BASE+8]
1307 |.macro .ffunc_nnsse, name
1309 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1310 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1311 | movsd xmm0, qword [BASE]
1312 | movsd xmm1, qword [BASE+8]
1315 |.macro .ffunc_nnr, name
1317 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1318 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1319 | fld qword [BASE+8]
1323 |// Inlined GC threshold check. Caveat: uses label 1.
1325 | mov RB, [DISPATCH+DISPATCH_GL(gc.total)]
1326 | cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]
1332 |//-- Base library: checks -----------------------------------------------
1336 | cmp RB, LJ_TISTRUECOND; jae ->fff_fallback
1375 | mov CFUNC:RB, [BASE-8]
1376 | mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]
1378 | mov dword [BASE-4], LJ_TSTR
1379 | mov [BASE-8], STR:RC
1383 | mov RC, ~LJ_TLIGHTUD
1387 |//-- Base library: getters and setters ---------------------------------
1389 |.ffunc_1 getmetatable
1392 | cmp RB, LJ_TTAB; jne >6
1393 |1: // Field metatable must be at same offset for GCtab and GCudata!
1394 | mov TAB:RB, [BASE]
1395 | mov TAB:RB, TAB:RB->metatable
1397 | test TAB:RB, TAB:RB
1398 | mov dword [BASE-4], LJ_TNIL
1400 | mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)]
1401 | mov dword [BASE-4], LJ_TTAB // Store metatable as default result.
1402 | mov [BASE-8], TAB:RB
1403 | mov RA, TAB:RB->hmask
1404 | and RA, STR:RC->hash
1406 | add NODE:RA, TAB:RB->node
1407 |3: // Rearranged logic, because we expect _not_ to find the key.
1408 | cmp dword NODE:RA->key.it, LJ_TSTR
1410 | cmp dword NODE:RA->key.gcr, STR:RC
1413 | mov NODE:RA, NODE:RA->next
1414 | test NODE:RA, NODE:RA
1416 | jmp ->fff_res1 // Not found, keep default result.
1419 | cmp RB, LJ_TNIL; je ->fff_res1 // Ditto for nil value.
1421 | mov [BASE-4], RB // Return value of mt.__metatable.
1426 | cmp RB, LJ_TUDATA; je <1
1428 | cmp RB, LJ_TNUMX; ja >8
1429 | cmp RB, LJ_TISNUM; jbe >7
1430 | mov RB, LJ_TLIGHTUD
1434 | cmp RB, LJ_TISNUM; ja >8
1439 | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]
1442 |.ffunc_2 setmetatable
1443 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1444 | // Fast path: no mt for table yet and not clearing the mt.
1445 | mov TAB:RB, [BASE]
1446 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1447 | cmp dword [BASE+12], LJ_TTAB; jne ->fff_fallback
1448 | mov TAB:RC, [BASE+8]
1449 | mov TAB:RB->metatable, TAB:RC
1451 | mov dword [BASE-4], LJ_TTAB // Return original table.
1452 | mov [BASE-8], TAB:RB
1453 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
1455 | // Possible write barrier. Table is black, but skip iswhite(mt) check.
1456 | barrierback TAB:RB, RC
1461 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1463 | mov RB, BASE // Save BASE.
1464 | lea CARG3d, [BASE+8]
1465 | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
1466 | mov CARG1d, SAVE_L
1468 | mov RB, BASE // Save BASE.
1469 | mov CARG2d, [BASE]
1470 | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
1471 | mov CARG1d, SAVE_L
1473 | mov TAB:RD, [BASE]
1477 | mov RB, BASE // Save BASE.
1481 | call extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
1482 | // cTValue * returned in eax (RD).
1483 | mov BASE, RB // Restore BASE.
1484 | // Copy table slot.
1498 |//-- Base library: conversions ------------------------------------------
1501 | // Only handles the number case inline (without a base argument).
1502 | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
1503 | cmp dword [BASE+4], LJ_TISNUM
1506 | mov RB, dword [BASE]; jmp ->fff_resi
1510 | jae ->fff_fallback
1513 | movsd xmm0, qword [BASE]; jmp ->fff_resxmm0
1515 | fld qword [BASE]; jmp ->fff_resn
1519 | // Only handles the string or number case inline.
1521 | cmp dword [BASE+4], LJ_TSTR; jne >3
1522 | // A __tostring method in the string base metatable is ignored.
1523 | mov STR:RD, [BASE]
1525 | mov dword [BASE-4], LJ_TSTR
1526 | mov [BASE-8], STR:RD
1528 |3: // Handle numbers inline, unless a number base metatable is present.
1529 | cmp dword [BASE+4], LJ_TISNUM; ja ->fff_fallback
1530 | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0
1531 | jne ->fff_fallback
1532 | ffgccheck // Caveat: uses label 1.
1534 | mov L:RB->base, BASE // Add frame since C call can throw.
1535 | mov SAVE_PC, PC // Redundant (but a defined value).
1536 |.if X64 and not X64WIN
1537 | mov FCARG2, BASE // Otherwise: FCARG2 == BASE
1539 | mov L:FCARG1, L:RB
1541 | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o)
1543 | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np)
1545 | // GCstr returned in eax (RD).
1546 | mov BASE, L:RB->base
1549 |//-- Base library: iterators -------------------------------------------
1552 | je >2 // Missing 2nd arg?
1554 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1556 | mov L:RB->base, BASE // Add frame since C call can throw.
1557 | mov L:RB->top, BASE // Dummy frame length is ok.
1560 | lea CARG3d, [BASE+8]
1561 | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
1564 | mov CARG2d, [BASE]
1565 | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
1568 | mov TAB:RD, [BASE]
1574 | mov SAVE_PC, PC // Needed for ITERN fallback.
1575 | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
1576 | // Flag returned in eax (RD).
1577 | mov BASE, L:RB->base
1578 | test RD, RD; jz >3 // End of traversal?
1579 | // Copy key and value to results.
1582 | mov RDa, [BASE+16]
1598 |2: // Set missing 2nd arg to nil.
1599 | mov dword [BASE+12], LJ_TNIL
1601 |3: // End of traversal: return nil.
1602 | mov dword [BASE-4], LJ_TNIL
1606 | mov TAB:RB, [BASE]
1607 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1609 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1611 | mov CFUNC:RB, [BASE-8]
1612 | mov CFUNC:RD, CFUNC:RB->upvalue[0]
1614 | mov dword [BASE-4], LJ_TFUNC
1615 | mov [BASE-8], CFUNC:RD
1616 | mov dword [BASE+12], LJ_TNIL
1620 |.ffunc_1 ipairs_aux
1621 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1622 | cmp dword [BASE+12], LJ_TISNUM
1624 | jne ->fff_fallback
1626 | jae ->fff_fallback
1630 | mov RD, dword [BASE+8]
1632 | mov dword [BASE-4], LJ_TISNUM
1633 | mov dword [BASE-8], RD
1635 | movsd xmm0, qword [BASE+8]
1636 | sseconst_1 xmm1, RBa
1639 | movsd qword [BASE-8], xmm0
1641 | fld qword [BASE+8]
1645 | fstp qword [BASE-8]
1648 | mov TAB:RB, [BASE]
1649 | cmp RD, TAB:RB->asize; jae >2 // Not in array part?
1651 | add RD, TAB:RB->array
1653 | cmp dword [RD+4], LJ_TNIL; je ->fff_res0
1654 | // Copy array slot.
1665 |2: // Check for empty hash part first. Otherwise call C function.
1666 | cmp dword TAB:RB->hmask, 0; je ->fff_res0
1667 | mov FCARG1, TAB:RB
1668 | mov RB, BASE // Save BASE.
1669 | mov FCARG2, RD // Caveat: FCARG2 == BASE
1670 | call extern lj_tab_getinth@8 // (GCtab *t, int32_t key)
1671 | // cTValue * or NULL returned in eax (RD).
1680 | mov TAB:RB, [BASE]
1681 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1683 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1685 | mov CFUNC:RB, [BASE-8]
1686 | mov CFUNC:RD, CFUNC:RB->upvalue[0]
1688 | mov dword [BASE-4], LJ_TFUNC
1689 | mov [BASE-8], CFUNC:RD
1691 | mov dword [BASE+12], LJ_TISNUM
1692 | mov dword [BASE+8], 0
1695 | movsd qword [BASE+8], xmm0
1698 | fstp qword [BASE+8]
1703 |//-- Base library: catch errors ----------------------------------------
1708 | mov PC, 8+FRAME_PCALL
1710 | movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)]
1711 | shr RB, HOOK_ACTIVE_SHIFT
1713 | add PC, RB // Remember active hook before pcall.
1714 | jmp ->vm_call_dispatch
1717 | cmp dword [BASE+12], LJ_TFUNC; jne ->fff_fallback
1718 | mov RB, [BASE+4] // Swap function and traceback.
1720 | mov dword [BASE+4], LJ_TFUNC
1721 | mov LFUNC:RB, [BASE]
1723 | mov [BASE+8], LFUNC:RB
1727 | mov PC, 16+FRAME_PCALL
1730 |//-- Coroutine library --------------------------------------------------
1732 |.macro coroutine_resume_wrap, resume
1734 |.ffunc_1 coroutine_resume
1737 |.ffunc coroutine_wrap_aux
1738 | mov CFUNC:RB, [BASE-8]
1739 | mov L:RB, CFUNC:RB->upvalue[0].gcr
1749 | cmp dword [BASE+4], LJ_TTHREAD; jne ->fff_fallback
1751 | cmp aword L:RB->cframe, 0; jne ->fff_fallback
1752 | cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback
1754 | je >1 // Status != LUA_YIELD (i.e. 0)?
1755 | cmp RA, L:RB->base // Check for presence of initial func.
1759 | lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread).
1761 | lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1).
1763 | cmp PC, L:RB->maxstack; ja ->fff_fallback
1767 | mov L:RB->base, BASE
1769 | add BASE, 8 // Keep resumed thread in stack for GC.
1771 | mov L:RB->top, BASE
1773 | lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move.
1775 | lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move.
1777 | sub RBa, PCa // Relative to PC.
1781 |2: // Move args to coroutine.
1804 | call ->vm_resume // (lua_State *L, TValue *base, 0, 0)
1805 | set_vmstate INTERP
1811 | mov L:PC, ARG1 // The callee doesn't modify SAVE_L.
1813 | mov BASE, L:RB->base
1814 | cmp eax, LUA_YIELD
1817 | mov RA, L:PC->base
1818 | mov KBASE, L:PC->top
1819 | mov L:PC->top, RA // Clear coroutine stack.
1822 | je >6 // No results?
1825 | cmp RD, L:RB->maxstack
1826 | ja >9 // Need to grow stack?
1830 |5: // Move results from coroutine.
1845 | lea RD, [PC+2] // nresults+1 = 1 + true + results.
1846 | mov dword [BASE-4], LJ_TTRUE // Prepend true to results.
1848 | lea RD, [PC+1] // nresults+1 = 1 + results.
1858 | test PC, FRAME_TYPE
1862 |8: // Coroutine returned with error (at co->top-1).
1864 | mov dword [BASE-4], LJ_TFALSE // Prepend false to results.
1867 | mov L:PC->top, RA // Clear error from coroutine stack.
1868 | // Copy error message.
1878 | mov RD, 1+2 // nresults+1 = 1 + false + error.
1883 | call extern lj_ffh_coroutine_wrap_err@8 // (lua_State *L, lua_State *co)
1884 | // Error function does not return.
1887 |9: // Handle stack expansion on return from yield.
1891 | mov L:RA, ARG1 // The callee doesn't modify SAVE_L.
1893 | mov L:RA->top, KBASE // Undo coroutine stack clearing.
1896 | call extern lj_state_growstack@8 // (lua_State *L, int n)
1902 | mov BASE, L:RB->base
1903 | jmp <4 // Retry the stack move.
1906 | coroutine_resume_wrap 1 // coroutine.resume
1907 | coroutine_resume_wrap 0 // coroutine.wrap
1909 |.ffunc coroutine_yield
1911 | test aword L:RB->cframe, CFRAME_RESUME
1913 | mov L:RB->base, BASE
1914 | lea RD, [BASE+NARGS:RD*8-8]
1917 | mov aword L:RB->cframe, RDa
1919 | mov byte L:RB->status, al
1920 | jmp ->vm_leave_unw
1922 |//-- Math library -------------------------------------------------------
1925 |->fff_resi: // Dummy.
1931 | fstp qword [BASE-8]
1937 | cmp dword [BASE+4], LJ_TISNUM; jne >2
1938 | mov RB, dword [BASE]
1939 | cmp RB, 0; jns ->fff_resi
1944 | mov dword [BASE-4], LJ_TISNUM
1945 | mov dword [BASE-8], RB
1949 | mov dword [BASE-4], 0x41e00000 // 2^31.
1950 | mov dword [BASE-8], 0
1955 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1959 | movsd xmm0, qword [BASE]
1960 | sseconst_abs xmm1, RDa
1964 | movsd qword [BASE-8], xmm0
1970 |->fff_resxmm0: // Dummy.
1973 | fstp qword [BASE-8]
1981 | test PC, FRAME_TYPE
1984 | cmp PC_RB, RDL // More results expected?
1986 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
1988 | not RAa // Note: ~RA = -(RA+1)
1989 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
1992 |6: // Fill up results with nil.
1993 | mov dword [BASE+RD*8-12], LJ_TNIL
1997 |7: // Non-standard return case.
1998 | mov RAa, -8 // Results start at BASE+RA = BASE-8.
2001 |.macro math_round, func
2002 | .ffunc math_ .. func
2004 | cmp dword [BASE+4], LJ_TISNUM; jne >1
2005 | mov RB, dword [BASE]; jmp ->fff_resi
2009 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
2012 | movsd xmm0, qword [BASE]
2013 | call ->vm_ .. func
2016 | cmp RB, 0x80000000
2019 | ucomisd xmm0, xmm1
2026 | call ->vm_ .. func
2030 | cmp RB, 0x80000000; jne >2
2049 |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0
2051 |.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn
2055 | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
2056 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
2057 | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn
2059 |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn
2060 |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn
2062 |.ffunc_n math_sin; fsin; jmp ->fff_resn
2063 |.ffunc_n math_cos; fcos; jmp ->fff_resn
2064 |.ffunc_n math_tan; fptan; fpop; jmp ->fff_resn
2067 | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fpatan
2070 | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fxch; fpatan
2072 |.ffunc_n math_atan; fld1; fpatan; jmp ->fff_resn
2074 |.macro math_extern, func
2076 | .ffunc_nsse math_ .. func
2078 | movsd FPARG1, xmm0
2081 | .ffunc_n math_ .. func
2085 | call extern lj_vm_ .. func
2100 |.ffunc_nsse math_rad
2101 | mov CFUNC:RB, [BASE-8]
2102 | mulsd xmm0, qword CFUNC:RB->upvalue[0]
2106 | mov CFUNC:RB, [BASE-8]
2107 | fmul qword CFUNC:RB->upvalue[0]
2111 |.ffunc_nn math_atan2; fpatan; jmp ->fff_resn
2112 |.ffunc_nnr math_ldexp; fscale; fpop1; jmp ->fff_resn
2114 |.ffunc_1 math_frexp
2116 | cmp RB, LJ_TISNUM; jae ->fff_fallback
2119 | mov [BASE-4], RB; mov [BASE-8], RC
2120 | shl RB, 1; cmp RB, 0xffe00000; jae >3
2123 | cmp RB, 0x00200000; jb >4
2125 | shr RB, 21; sub RB, RC // Extract and unbias exponent.
2129 | mov TMP1, RB; fild TMP1
2132 | and RB, 0x800fffff // Mask off exponent.
2133 | or RB, 0x3fe00000 // Put mantissa in range [0.5,1) or 0.
2137 | movsd qword [BASE], xmm0
2143 |3: // Return +-0, +-Inf, NaN unmodified and an exponent of 0.
2145 | xorps xmm0, xmm0; jmp <2
2149 |4: // Handle denormals by multiplying with 2^54 and adjusting the bias.
2151 | movsd xmm0, qword [BASE]
2152 | sseconst_hi xmm1, RBa, 43500000 // 2^54.
2154 | movsd qword [BASE-8], xmm0
2157 | mov TMP1, 0x5a800000; fmul TMP1 // x = x*2^54
2158 | fstp qword [BASE-8]
2160 | mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1
2163 |.ffunc_nsse math_modf
2169 | shl RB, 1; cmp RB, 0xffe00000; je >4 // +-Inf?
2175 | movsd qword [BASE-8], xmm0
2176 | movsd qword [BASE], xmm4
2182 | fstp qword [BASE-8]
2185 | mov RC, [BASE-4]; mov RB, [BASE+4]
2186 | xor RC, RB; js >3 // Need to adjust sign?
2191 | xor RB, 0x80000000; mov [BASE+4], RB // Flip sign of fraction.
2195 | xorps xmm4, xmm4; jmp <1 // Return +-Inf and +-0.
2197 | fldz; fxch; jmp <1 // Return +-Inf and +-0.
2200 |.ffunc_nnr math_fmod
2201 |1: ; fprem; fnstsw ax; sahf; jp <1
2206 |.ffunc_nnsse math_pow; call ->vm_pow; jmp ->fff_resxmm0
2208 |.ffunc_nn math_pow; call ->vm_pow; jmp ->fff_resn
2211 |.macro math_minmax, name, cmovop, fcmovop, sseop
2214 | cmp dword [BASE+4], LJ_TISNUM
2217 | mov RB, dword [BASE]
2218 |1: // Handle integers.
2219 | cmp RA, RD; jae ->fff_resi
2220 | cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3
2221 | cmp RB, dword [BASE+RA*8-8]
2222 | cmovop RB, dword [BASE+RA*8-8]
2227 | // Convert intermediate result to number and continue below.
2238 | jae ->fff_fallback
2242 | movsd xmm0, qword [BASE]
2243 |5: // Handle numbers or integers.
2244 | cmp RA, RD; jae ->fff_resxmm0
2245 | cmp dword [BASE+RA*8-4], LJ_TISNUM
2249 | cvtsi2sd xmm1, dword [BASE+RA*8-8]
2252 | jae ->fff_fallback
2255 | movsd xmm1, qword [BASE+RA*8-8]
2262 |5: // Handle numbers or integers.
2263 | cmp RA, RD; jae ->fff_resn
2264 | cmp dword [BASE+RA*8-4], LJ_TISNUM
2268 | fild dword [BASE+RA*8-8]
2274 | fld qword [BASE+RA*8-8]
2276 | fucomi st1; fcmovop st1; fpop1
2282 | math_minmax math_min, cmovg, fcmovnbe, minsd
2283 | math_minmax math_max, cmovl, fcmovbe, maxsd
2286 | fpop; jmp ->fff_fallback
2289 |//-- String library -----------------------------------------------------
2291 |.ffunc_1 string_len
2292 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2293 | mov STR:RB, [BASE]
2295 | mov RB, dword STR:RB->len; jmp ->fff_resi
2297 | cvtsi2sd xmm0, dword STR:RB->len; jmp ->fff_resxmm0
2299 | fild dword STR:RB->len; jmp ->fff_resn
2302 |.ffunc string_byte // Only handle the 1-arg case here.
2303 | cmp NARGS:RD, 1+1; jne ->fff_fallback
2304 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2305 | mov STR:RB, [BASE]
2307 | cmp dword STR:RB->len, 1
2308 | jb ->fff_res0 // Return no results for empty string.
2309 | movzx RB, byte STR:RB[1]
2313 | cvtsi2sd xmm0, RB; jmp ->fff_resxmm0
2315 | mov TMP1, RB; fild TMP1; jmp ->fff_resn
2318 |.ffunc string_char // Only handle the 1-arg case here.
2320 | cmp NARGS:RD, 1+1; jne ->fff_fallback // *Exactly* 1 arg.
2321 | cmp dword [BASE+4], LJ_TISNUM
2323 | jne ->fff_fallback
2324 | mov RB, dword [BASE]
2325 | cmp RB, 255; ja ->fff_fallback
2328 | jae ->fff_fallback
2329 | cvttsd2si RB, qword [BASE]
2330 | cmp RB, 255; ja ->fff_fallback
2333 | jae ->fff_fallback
2336 | cmp TMP2, 255; ja ->fff_fallback
2343 | lea RDa, TMP2 // Points to stack. Little-endian.
2346 | mov L:RB->base, BASE
2348 | mov CARG3d, TMP3 // Zero-extended to size_t.
2349 | mov CARG2, RDa // May be 64 bit ptr to stack.
2356 | call extern lj_str_new // (lua_State *L, char *str, size_t l)
2357 | // GCstr * returned in eax (RD).
2358 | mov BASE, L:RB->base
2360 | mov dword [BASE-4], LJ_TSTR
2361 | mov [BASE-8], STR:RD
2367 | cmp NARGS:RD, 1+2; jb ->fff_fallback
2369 | cmp dword [BASE+20], LJ_TISNUM
2371 | jne ->fff_fallback
2372 | mov RB, dword [BASE+16]
2375 | jae ->fff_fallback
2376 | cvttsd2si RB, qword [BASE+16]
2379 | jae ->fff_fallback
2380 | fld qword [BASE+16]
2384 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2385 | cmp dword [BASE+12], LJ_TISNUM
2387 | jne ->fff_fallback
2389 | jae ->fff_fallback
2391 | mov STR:RB, [BASE]
2393 | mov RB, STR:RB->len
2395 | mov RA, dword [BASE+8]
2397 | cvttsd2si RA, qword [BASE+8]
2399 | fld qword [BASE+8]
2404 | cmp RB, RC // len < end? (unsigned compare)
2407 | test RA, RA // start <= 0?
2411 | sub RC, RA // start > end?
2413 | lea RB, [STR:RB+RA+#STR-1]
2424 |5: // Negative end or overflow.
2426 | lea RC, [RC+RB+1] // end = end+(len+1)
2429 | mov RC, RB // end = len
2432 |7: // Negative start or underflow.
2434 | add RA, RB // start = start+(len+1)
2436 | jg <3 // start > 0?
2438 | mov RA, 1 // start = 1
2441 |->fff_emptystr: // Range underflow.
2442 | xor RC, RC // Zero length. Any ptr in RB is ok.
2445 |.ffunc string_rep // Only handle the 1-char case inline.
2447 | cmp NARGS:RD, 2+1; jne ->fff_fallback // Exactly 2 arguments.
2448 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2449 | cmp dword [BASE+12], LJ_TISNUM
2450 | mov STR:RB, [BASE]
2452 | jne ->fff_fallback
2453 | mov RC, dword [BASE+8]
2455 | jae ->fff_fallback
2456 | cvttsd2si RC, qword [BASE+8]
2458 | jae ->fff_fallback
2459 | fld qword [BASE+8]
2464 | jle ->fff_emptystr // Count <= 0? (or non-int)
2465 | cmp dword STR:RB->len, 1
2466 | jb ->fff_emptystr // Zero length string?
2467 | jne ->fff_fallback_2 // Fallback for > 1-char strings.
2468 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_2
2469 | movzx RA, byte STR:RB[1]
2470 | mov RB, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2476 |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
2481 | mov RD, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2484 |.ffunc_1 string_reverse
2486 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2487 | mov STR:RB, [BASE]
2488 | mov RC, STR:RB->len
2490 | jz ->fff_emptystr // Zero length string?
2491 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
2493 | mov TMP2, PC // Need another temp register.
2499 | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2501 | movzx RA, byte [RB]
2510 |.macro ffstring_case, name, lo, hi
2513 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2514 | mov STR:RB, [BASE]
2515 | mov RC, STR:RB->len
2516 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
2518 | mov TMP2, PC // Need another temp register.
2524 | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2526 |1: // ASCII case conversion. Yes, this is suboptimal code (do you care?).
2527 | movzx RA, byte [RB+RC]
2543 |ffstring_case string_lower, 0x41, 0x5a
2544 |ffstring_case string_upper, 0x61, 0x7a
2546 |//-- Table library ------------------------------------------------------
2548 |.ffunc_1 table_getn
2549 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
2550 | mov RB, BASE // Save BASE.
2551 | mov TAB:FCARG1, [BASE]
2552 | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t)
2553 | // Length of table returned in eax (RD).
2554 | mov BASE, RB // Restore BASE.
2556 | mov RB, RD; jmp ->fff_resi
2558 | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0
2560 | mov ARG1, RD; fild ARG1; jmp ->fff_resn
2563 |//-- Bit library --------------------------------------------------------
2565 |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!).
2567 |.macro .ffunc_bit, name, kind
2571 | sseconst_tobit xmm1, RBa
2573 | mov TMP1, TOBIT_BIAS
2576 | cmp dword [BASE+4], LJ_TISNUM
2579 | mov RB, dword [BASE]
2588 | jae ->fff_fallback
2591 | movsd xmm0, qword [BASE]
2593 | sseconst_tobit xmm1, RBa
2600 | mov TMP1, TOBIT_BIAS
2611 |.ffunc_bit bit_tobit, 0
2622 |.macro .ffunc_bit_op, name, ins
2623 | .ffunc_bit name, 2
2624 | mov TMP2, NARGS:RD // Save for fallback.
2625 | lea RD, [BASE+NARGS:RD*8-16]
2629 | cmp dword [RD+4], LJ_TISNUM
2632 | ins RB, dword [RD]
2636 | ja ->fff_fallback_bit_op
2638 | jae ->fff_fallback_bit_op
2641 | movsd xmm0, qword [RD]
2655 |.ffunc_bit_op bit_band, and
2656 |.ffunc_bit_op bit_bor, or
2657 |.ffunc_bit_op bit_bxor, xor
2659 |.ffunc_bit bit_bswap, 1
2663 |.ffunc_bit bit_bnot, 1
2678 |->fff_fallback_bit_op:
2679 | mov NARGS:RD, TMP2 // Restore for fallback
2680 | jmp ->fff_fallback
2682 |.macro .ffunc_bit_sh, name, ins
2684 | .ffunc_bit name, 1
2685 | // Note: no inline conversion from number for 2nd argument!
2686 | cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback
2687 | mov RA, dword [BASE+8]
2690 | sseconst_tobit xmm2, RBa
2697 | mov TMP1, TOBIT_BIAS
2705 | ins RB, cl // Assumes RA is ecx.
2709 |.ffunc_bit_sh bit_lshift, shl
2710 |.ffunc_bit_sh bit_rshift, shr
2711 |.ffunc_bit_sh bit_arshift, sar
2712 |.ffunc_bit_sh bit_rol, rol
2713 |.ffunc_bit_sh bit_ror, ror
2715 |//-----------------------------------------------------------------------
2718 | mov NARGS:RD, 1+2 // Other args are ignored, anyway.
2719 | jmp ->fff_fallback
2721 | mov NARGS:RD, 1+1 // Other args are ignored, anyway.
2722 |->fff_fallback: // Call fast function fallback handler.
2723 | // BASE = new base, RD = nargs+1
2725 | mov PC, [BASE-4] // Fallback may overwrite PC.
2726 | mov SAVE_PC, PC // Redundant (but a defined value).
2727 | mov L:RB->base, BASE
2728 | lea RD, [BASE+NARGS:RD*8-8]
2729 | lea RA, [RD+8*LUA_MINSTACK] // Ensure enough space for handler.
2731 | mov CFUNC:RD, [BASE-8]
2732 | cmp RA, L:RB->maxstack
2733 | ja >5 // Need to grow stack.
2739 | call aword CFUNC:RD->f // (lua_State *L)
2740 | mov BASE, L:RB->base
2741 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
2742 | test RD, RD; jg ->fff_res // Returned nresults+1?
2748 | lea NARGS:RD, [RA+1]
2749 | mov LFUNC:RB, [BASE-8]
2750 | jne ->vm_call_tail // Returned -1?
2751 | ins_callt // Returned 0: retry fast path.
2753 |// Reconstruct previous base for vmeta_call during tailcall.
2756 | test PC, FRAME_TYPE
2759 | not RBa // Note: ~RB = -(RB+1)
2760 | lea BASE, [BASE+RB*8] // base = base - (RB+1)*8
2761 | jmp ->vm_call_dispatch // Resolve again for tailcall.
2766 | jmp ->vm_call_dispatch // Resolve again for tailcall.
2768 |5: // Grow stack for fallback handler.
2769 | mov FCARG2, LUA_MINSTACK
2771 | call extern lj_state_growstack@8 // (lua_State *L, int n)
2772 | mov BASE, L:RB->base
2773 | xor RD, RD // Simulate a return 0.
2774 | jmp <1 // Dumb retry (goes through ff first).
2776 |->fff_gcstep: // Call GC step function.
2777 | // BASE = new base, RD = nargs+1
2778 | pop RBa // Must keep stack at same level.
2779 | mov TMPa, RBa // Save return address
2781 | mov SAVE_PC, PC // Redundant (but a defined value).
2782 | mov L:RB->base, BASE
2783 | lea RD, [BASE+NARGS:RD*8-8]
2786 | call extern lj_gc_step@4 // (lua_State *L)
2787 | mov BASE, L:RB->base
2793 | push RBa // Restore return address.
2796 |//-----------------------------------------------------------------------
2797 |//-- Special dispatch targets -------------------------------------------
2798 |//-----------------------------------------------------------------------
2800 |->vm_record: // Dispatch target for recording phase.
2802 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2803 | test RDL, HOOK_VMEVENT // No recording while in vmevent.
2805 | // Decrement the hookcount for consistency, but always do the call.
2806 | test RDL, HOOK_ACTIVE
2808 | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
2810 | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
2814 |->vm_rethook: // Dispatch target for return hooks.
2815 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2816 | test RDL, HOOK_ACTIVE // Hook already active?
2820 |->vm_inshook: // Dispatch target for instr/line hooks.
2821 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2822 | test RDL, HOOK_ACTIVE // Hook already active?
2825 | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
2827 | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
2829 | test RDL, LUA_MASKLINE
2833 | mov L:RB->base, BASE
2834 | mov FCARG2, PC // Caveat: FCARG2 == BASE
2836 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
2837 | call extern lj_dispatch_ins@8 // (lua_State *L, BCIns *pc)
2839 | mov BASE, L:RB->base
2846 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins.
2848 | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Re-dispatch to static ins.
2851 |->cont_hook: // Continue from hook yield.
2854 | mov MULTRES, RA // Restore MULTRES for *M ins.
2857 |->vm_hotloop: // Hot loop counter underflow.
2859 | mov LFUNC:RB, [BASE-8] // Same as curr_topL(L).
2860 | mov RB, LFUNC:RB->pc
2861 | movzx RD, byte [RB+PC2PROTO(framesize)]
2862 | lea RD, [BASE+RD*8]
2864 | mov L:RB->base, BASE
2867 | lea FCARG1, [DISPATCH+GG_DISP2J]
2868 | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
2870 | call extern lj_trace_hot@8 // (jit_State *J, const BCIns *pc)
2874 |->vm_callhook: // Dispatch target for call hooks.
2880 |->vm_hotcall: // Hot call counter underflow.
2883 | or PC, 1 // Marker for hot call.
2886 | lea RD, [BASE+NARGS:RD*8-8]
2888 | mov L:RB->base, BASE
2892 | call extern lj_dispatch_call@8 // (lua_State *L, const BCIns *pc)
2893 | // ASMFunction returned in eax/rax (RDa).
2894 | mov SAVE_PC, 0 // Invalidate for subsequent line hook.
2898 | mov BASE, L:RB->base
2908 |//-----------------------------------------------------------------------
2909 |//-- Trace exit handler -------------------------------------------------
2910 |//-----------------------------------------------------------------------
2912 |// Called from an exit stub with the exit number on the stack.
2913 |// The 16 bit exit number is stored with two (sign-extended) push imm8.
2917 | push r13; push r12
2918 | push r11; push r10; push r9; push r8
2919 | push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp
2920 | push rbx; push rdx; push rcx; push rax
2921 | movzx RC, byte [rbp-8] // Reconstruct exit number.
2922 | mov RCH, byte [rbp-16]
2923 | mov [rbp-8], r15; mov [rbp-16], r14
2925 | push ebp; lea ebp, [esp+12]; push ebp
2926 | push ebx; push edx; push ecx; push eax
2927 | movzx RC, byte [ebp-4] // Reconstruct exit number.
2928 | mov RCH, byte [ebp-8]
2929 | mov [ebp-4], edi; mov [ebp-8], esi
2931 | // Caveat: DISPATCH is ebx.
2932 | mov DISPATCH, [ebp]
2933 | mov RA, [DISPATCH+DISPATCH_GL(vmstate)] // Get trace number.
2935 | mov [DISPATCH+DISPATCH_J(exitno)], RC
2936 | mov [DISPATCH+DISPATCH_J(parent)], RA
2939 | sub rsp, 16*8+4*8 // Room for SSE regs + save area.
2941 | sub rsp, 16*8 // Room for SSE regs.
2944 | movsd qword [rbp-8], xmm15; movsd qword [rbp-16], xmm14
2945 | movsd qword [rbp-24], xmm13; movsd qword [rbp-32], xmm12
2946 | movsd qword [rbp-40], xmm11; movsd qword [rbp-48], xmm10
2947 | movsd qword [rbp-56], xmm9; movsd qword [rbp-64], xmm8
2948 | movsd qword [rbp-72], xmm7; movsd qword [rbp-80], xmm6
2949 | movsd qword [rbp-88], xmm5; movsd qword [rbp-96], xmm4
2950 | movsd qword [rbp-104], xmm3; movsd qword [rbp-112], xmm2
2951 | movsd qword [rbp-120], xmm1; movsd qword [rbp-128], xmm0
2953 | sub esp, 8*8+16 // Room for SSE regs + args.
2954 | movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6
2955 | movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4
2956 | movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2
2957 | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0
2959 | // Caveat: RB is ebp.
2960 | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)]
2961 | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]
2962 | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
2963 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
2964 | mov L:RB->base, BASE
2966 | lea CARG2, [rsp+4*8]
2970 | lea FCARG2, [esp+16]
2972 | lea FCARG1, [DISPATCH+GG_DISP2J]
2973 | call extern lj_trace_exit@8 // (jit_State *J, ExitState *ex)
2974 | // MULTRES or negated error code returned in eax (RD).
2975 | mov RAa, L:RB->cframe
2976 | and RAa, CFRAME_RAWMASK
2978 | // Reposition stack later.
2980 | mov rsp, RAa // Reposition stack to C frame.
2982 | mov esp, RAa // Reposition stack to C frame.
2984 | mov [RAa+CFRAME_OFS_L], L:RB // Set SAVE_L (on-trace resume/yield).
2985 | mov BASE, L:RB->base
2986 | mov PC, [RAa+CFRAME_OFS_PC] // Get SAVE_PC.
2992 | // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.
2995 | // Restore additional callee-save registers only used in compiled code.
2997 | lea RAa, [rsp+9*16+4*8]
2999 | movdqa xmm15, [RAa-9*16]
3000 | movdqa xmm14, [RAa-8*16]
3001 | movdqa xmm13, [RAa-7*16]
3002 | movdqa xmm12, [RAa-6*16]
3003 | movdqa xmm11, [RAa-5*16]
3004 | movdqa xmm10, [RAa-4*16]
3005 | movdqa xmm9, [RAa-3*16]
3006 | movdqa xmm8, [RAa-2*16]
3007 | movdqa xmm7, [RAa-1*16]
3008 | mov rsp, RAa // Reposition stack to C frame.
3009 | movdqa xmm6, [RAa]
3013 | add rsp, 16 // Reposition stack to C frame.
3019 | test RD, RD; js >3 // Check for error from exit.
3021 | mov LFUNC:KBASE, [BASE-8]
3022 | mov KBASE, LFUNC:KBASE->pc
3023 | mov KBASE, [KBASE+PC2PROTO(k)]
3024 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
3025 | set_vmstate INTERP
3026 | // Modified copy of ins_next which handles function header dispatch, too.
3032 | cmp OP, BC_FUNCF // Function header?
3034 | mov RC, MULTRES // RC/RD holds nres+1.
3037 | jmp aword [DISPATCH+OP*8]
3039 | jmp aword [DISPATCH+OP*4]
3042 |3: // Rethrow error from the right C frame.
3046 | call extern lj_err_throw@8 // (lua_State *L, int errcode)
3049 |//-----------------------------------------------------------------------
3050 |//-- Math helper functions ----------------------------------------------
3051 |//-----------------------------------------------------------------------
3053 |// FP value rounding. Called by math.floor/math.ceil fast functions
3054 |// and from JIT code.
3056 |// x87 variant: Arg/ret on x87 stack. No int/xmm registers modified.
3057 |.macro vm_round_x87, mode1, mode2
3058 | fnstcw word [esp+4] // Caveat: overwrites ARG1 and ARG2.
3062 |.if mode2 ~= 0xffff
3066 | fldcw word [esp+6]
3068 | fldcw word [esp+4]
3073 |// SSE variant: arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.
3074 |.macro vm_round_sse, mode
3075 | sseconst_abs xmm2, RDa
3076 | sseconst_2p52 xmm3, RDa
3078 | andpd xmm1, xmm2 // |x|
3079 | ucomisd xmm3, xmm1 // No truncation if 2^52 <= |x|.
3081 | andnpd xmm2, xmm0 // Isolate sign bit.
3082 |.if mode == 2 // trunc(x)?
3084 | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
3086 | sseconst_1 xmm3, RDa
3087 | cmpsd xmm0, xmm1, 1 // |x| < result?
3089 | subsd xmm1, xmm0 // If yes, subtract -1.
3090 | orpd xmm1, xmm2 // Merge sign bit back in.
3092 | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
3094 | orpd xmm1, xmm2 // Merge sign bit back in.
3095 | .if mode == 1 // ceil(x)?
3096 | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0.
3097 | cmpsd xmm0, xmm1, 6 // x > result?
3098 | .else // floor(x)?
3099 | sseconst_1 xmm2, RDa
3100 | cmpsd xmm0, xmm1, 1 // x < result?
3103 | subsd xmm1, xmm0 // If yes, subtract +-1.
3110 |.macro vm_round, name, ssemode, mode1, mode2
3113 | vm_round_x87 mode1, mode2
3116 | vm_round_sse ssemode
3119 | vm_round vm_floor, 0, 0x0400, 0xf7ff
3120 | vm_round vm_ceil, 1, 0x0800, 0xfbff
3121 | vm_round vm_trunc, 2, 0x0c00, 0xffff
3123 |// FP modulo x%y. Called by BC_MOD* and vm_arith.
3126 |// Args in xmm0/xmm1, return value in xmm0.
3127 |// Caveat: xmm0-xmm5 and RC (eax) modified!
3130 | sseconst_abs xmm2, RDa
3131 | sseconst_2p52 xmm3, RDa
3133 | andpd xmm4, xmm2 // |x/y|
3134 | ucomisd xmm3, xmm4 // No truncation if 2^52 <= |x/y|.
3136 | andnpd xmm2, xmm0 // Isolate sign bit.
3137 | addsd xmm4, xmm3 // (|x/y| + 2^52) - 2^52
3139 | orpd xmm4, xmm2 // Merge sign bit back in.
3140 | sseconst_1 xmm2, RDa
3141 | cmpsd xmm0, xmm4, 1 // x/y < result?
3143 | subsd xmm4, xmm0 // If yes, subtract 1.0.
3154 |// Args/ret on x87 stack (y on top). No xmm registers modified.
3155 |// Caveat: needs 3 slots on x87 stack! RC (eax) modified!
3158 | fnstcw word [esp+4]
3163 | fldcw word [esp+6]
3165 | fldcw word [esp+4]
3171 |// FP log2(x). Called by math.log(x, base).
3174 | movsd qword [rsp+8], xmm0 // Use scratch area.
3178 | fstp qword [rsp+8]
3179 | movsd xmm0, qword [rsp+8]
3181 | movsd qword [rsp-8], xmm0 // Use red zone.
3185 | fstp qword [rsp-8]
3186 | movsd xmm0, qword [rsp-8]
3194 |// FP exponentiation e^x and 2^x. Called by math.exp fast function and
3195 |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified.
3196 |// Caveat: needs 3 slots on x87 stack!
3198 | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e))
3201 | .define expscratch, dword [rsp+8] // Use scratch area.
3203 | .define expscratch, dword [rsp-8] // Use red zone.
3205 | .define expscratch, dword [esp+4] // Needs 4 byte scratch area.
3207 | fst expscratch // Caveat: overwrites ARG1.
3208 | cmp expscratch, 0x7f800000; je >1 // Special case: e^+Inf = +Inf
3209 | cmp expscratch, 0xff800000; je >2 // Special case: e^-Inf = 0
3210 |->vm_exp2raw: // Entry point for vm_pow. Without +-Inf check.
3211 | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
3212 | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
3218 |// Generic power function x^y. Called by BC_POW, math.pow fast function,
3220 |// Args/ret on x87 stack (y on top). RC (eax) modified.
3221 |// Caveat: needs 3 slots on x87 stack!
3224 | fist dword [esp+4] // Store/reload int before comparison.
3225 | fild dword [esp+4] // Integral exponent used in vm_powi.
3227 | jnz >8 // Branch for FP exponents.
3228 | jp >9 // Branch for NaN exponent.
3229 | fpop // Pop y and fallthrough to vm_powi.
3231 |// FP/int power function x^i. Arg1/ret on x87 stack.
3232 |// Arg2 (int) on C stack. RC (eax) modified.
3233 |// Caveat: needs 2 slots on x87 stack!
3235 | cmp eax, 1; jle >6 // i<=1?
3236 | // Now 1 < (unsigned)i <= 0x80000000.
3237 |1: // Handle leading zeros.
3238 | test eax, 1; jnz >2
3245 |3: // Handle trailing bits.
3256 | je <5 // x^1 ==> x
3260 | cmp eax, 1; je <5 // x^-1 ==> 1/x
3261 | jmp <1 // x^-i ==> (1/x)^i
3263 | fpop; fld1 // x^0 ==> 1
3266 |8: // FP/FP power function x^y.
3270 | mov eax, [esp+4]; shl eax, 1
3271 | cmp eax, 0xff000000; je >2 // x^+-Inf?
3272 | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
3273 | cmp eax, 0xff000000; je >4 // +-Inf^y?
3277 |9: // Handle x^NaN.
3280 | je >1 // 1^NaN ==> 1
3281 | fxch // x^NaN ==> NaN
3286 |2: // Handle x^+-Inf.
3290 | je >3 // +-1^+-Inf ==> 1
3291 | fpop; fabs; fldz; mov eax, 0; setc al
3292 | ror eax, 1; xor eax, [esp+4]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0
3298 |4: // Handle +-0^y or +-Inf^y.
3299 | cmp dword [esp+4], 0; jge <3 // y >= 0, x^y ==> |x|
3301 | test eax, eax; jz >5 // y < 0, +-0^y ==> +Inf
3302 | fldz // y < 0, +-Inf^y ==> 0
3305 | mov dword [esp+4], 0x7f800000 // Return +Inf.
3310 |// Args in xmm0/xmm1. Ret in xmm0. xmm0-xmm2 and RC (eax) modified.
3311 |// Needs 16 byte scratch area for x86. Also called from JIT code.
3313 | cvtsd2si eax, xmm1
3314 | cvtsi2sd xmm2, eax
3315 | ucomisd xmm1, xmm2
3316 | jnz >8 // Branch for FP exponents.
3317 | jp >9 // Branch for NaN exponent.
3318 | // Fallthrough to vm_powi_sse.
3320 |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.
3322 | cmp eax, 1; jle >6 // i<=1?
3323 | // Now 1 < (unsigned)i <= 0x80000000.
3324 |1: // Handle leading zeros.
3325 | test eax, 1; jnz >2
3332 |3: // Handle trailing bits.
3343 | je <5 // x^1 ==> x
3344 | jb >7 // x^0 ==> 1
3347 | sseconst_1 xmm1, RDa
3352 | sseconst_1 xmm0, RDa
3355 |8: // FP/FP power function x^y.
3357 | movd rax, xmm1; shl rax, 1
3358 | rol rax, 12; cmp rax, 0xffe; je >2 // x^+-Inf?
3359 | movd rax, xmm0; shl rax, 1; je >4 // +-0^y?
3360 | rol rax, 12; cmp rax, 0xffe; je >5 // +-Inf^y?
3362 | movsd qword [rsp+16], xmm1 // Use scratch area.
3363 | movsd qword [rsp+8], xmm0
3364 | fld qword [rsp+16]
3367 | movsd qword [rsp-16], xmm1 // Use red zone.
3368 | movsd qword [rsp-8], xmm0
3369 | fld qword [rsp-16]
3373 | movsd qword [esp+12], xmm1 // Needs 16 byte scratch area.
3374 | movsd qword [esp+4], xmm0
3375 | cmp dword [esp+12], 0; jne >1
3376 | mov eax, [esp+16]; shl eax, 1
3377 | cmp eax, 0xffe00000; je >2 // x^+-Inf?
3379 | cmp dword [esp+4], 0; jne >1
3380 | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
3381 | cmp eax, 0xffe00000; je >5 // +-Inf^y?
3383 | fld qword [esp+12]
3386 | fyl2x // y*log2(x)
3387 | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
3388 | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
3390 | fstp qword [rsp+8] // Use scratch area.
3391 | movsd xmm0, qword [rsp+8]
3393 | fstp qword [rsp-8] // Use red zone.
3394 | movsd xmm0, qword [rsp-8]
3396 | fstp qword [esp+4] // Needs 8 byte scratch area.
3397 | movsd xmm0, qword [esp+4]
3401 |9: // Handle x^NaN.
3402 | sseconst_1 xmm2, RDa
3403 | ucomisd xmm0, xmm2; je >1 // 1^NaN ==> 1
3404 | movaps xmm0, xmm1 // x^NaN ==> NaN
3408 |2: // Handle x^+-Inf.
3409 | sseconst_abs xmm2, RDa
3410 | andpd xmm0, xmm2 // |x|
3411 | sseconst_1 xmm2, RDa
3412 | ucomisd xmm0, xmm2; je <1 // +-1^+-Inf ==> 1
3413 | movmskpd eax, xmm1
3415 | mov ah, al; setc al; xor al, ah; jne <1 // |x|<>1, x^+-Inf ==> +Inf/0
3417 | sseconst_hi xmm0, RDa, 7ff00000 // +Inf
3420 |4: // Handle +-0^y.
3421 | movmskpd eax, xmm1; test eax, eax; jnz <3 // y < 0, +-0^y ==> +Inf
3422 | xorps xmm0, xmm0 // y >= 0, +-0^y ==> 0
3425 |5: // Handle +-Inf^y.
3426 | movmskpd eax, xmm1; test eax, eax; jz <3 // y >= 0, +-Inf^y ==> +Inf
3427 | xorps xmm0, xmm0 // y < 0, +-Inf^y ==> 0
3430 |// Callable from C: double lj_vm_foldfpm(double x, int fpm)
3431 |// Computes fpm(x) for extended math functions. ORDER FPM.
3436 | .define fpmop, CARG2d
3438 | .define fpmop, CARG1d
3440 | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
3441 | cmp fpmop, 3; jb ->vm_trunc; ja >2
3442 | sqrtsd xmm0, xmm0; ret
3445 | movsd qword [rsp+8], xmm0 // Use scratch area.
3448 | movsd qword [rsp-8], xmm0 // Use red zone.
3451 | cmp fpmop, 5; ja >2
3452 | .if X64WIN; pop rax; .endif
3455 | .if X64WIN; push rax; .endif
3458 | call ->vm_exp2_x87
3459 | .if X64WIN; push rax; .endif
3461 |2: ; cmp fpmop, 7; je >1; ja >2
3462 | fldln2; fxch; fyl2x; jmp >7
3463 |1: ; fld1; fxch; fyl2x; jmp >7
3464 |2: ; cmp fpmop, 9; je >1; ja >2
3465 | fldlg2; fxch; fyl2x; jmp >7
3467 |2: ; cmp fpmop, 11; je >1; ja >9
3472 | fstp qword [rsp+8] // Use scratch area.
3473 | movsd xmm0, qword [rsp+8]
3475 | fstp qword [rsp-8] // Use red zone.
3476 | movsd xmm0, qword [rsp-8]
3479 |.else // x86 calling convention.
3480 | .define fpmop, eax
3482 | mov fpmop, [esp+12]
3483 | movsd xmm0, qword [esp+4]
3484 | cmp fpmop, 1; je >1; ja >2
3485 | call ->vm_floor; jmp >7
3486 |1: ; call ->vm_ceil; jmp >7
3487 |2: ; cmp fpmop, 3; je >1; ja >2
3488 | call ->vm_trunc; jmp >7
3492 | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
3495 |2: ; fld qword [esp+4]
3496 | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
3497 |2: ; cmp fpmop, 7; je >1; ja >2
3498 | fldln2; fxch; fyl2x; ret
3499 |1: ; fld1; fxch; fyl2x; ret
3500 |2: ; cmp fpmop, 9; je >1; ja >2
3501 | fldlg2; fxch; fyl2x; ret
3503 |2: ; cmp fpmop, 11; je >1; ja >9
3505 |1: ; fptan; fpop; ret
3507 | mov fpmop, [esp+12]
3509 | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
3510 | cmp fpmop, 3; jb ->vm_trunc; ja >2
3512 |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
3513 | cmp fpmop, 7; je >1; ja >2
3514 | fldln2; fxch; fyl2x; ret
3515 |1: ; fld1; fxch; fyl2x; ret
3516 |2: ; cmp fpmop, 9; je >1; ja >2
3517 | fldlg2; fxch; fyl2x; ret
3519 |2: ; cmp fpmop, 11; je >1; ja >9
3521 |1: ; fptan; fpop; ret
3524 |9: ; int3 // Bad fpm.
3527 |// Callable from C: double lj_vm_foldarith(double x, double y, int op)
3528 |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -)
3529 |// and basic math functions. ORDER ARITH
3534 | .define foldop, CARG3d
3536 | .define foldop, CARG1d
3538 | cmp foldop, 1; je >1; ja >2
3539 | addsd xmm0, xmm1; ret
3540 |1: ; subsd xmm0, xmm1; ret
3541 |2: ; cmp foldop, 3; je >1; ja >2
3542 | mulsd xmm0, xmm1; ret
3543 |1: ; divsd xmm0, xmm1; ret
3544 |2: ; cmp foldop, 5; jb ->vm_mod; je ->vm_pow
3545 | cmp foldop, 7; je >1; ja >2
3546 | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; ret
3547 |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; ret
3548 |2: ; cmp foldop, 9; ja >2
3550 | movsd qword [rsp+8], xmm0 // Use scratch area.
3551 | movsd qword [rsp+16], xmm1
3553 | fld qword [rsp+16]
3555 | movsd qword [rsp-8], xmm0 // Use red zone.
3556 | movsd qword [rsp-16], xmm1
3558 | fld qword [rsp-16]
3564 | fstp qword [rsp+8] // Use scratch area.
3565 | movsd xmm0, qword [rsp+8]
3567 | fstp qword [rsp-8] // Use red zone.
3568 | movsd xmm0, qword [rsp-8]
3571 |1: ; fxch; fscale; fpop1; jmp <7
3572 |2: ; cmp foldop, 11; je >1; ja >9
3573 | minsd xmm0, xmm1; ret
3574 |1: ; maxsd xmm0, xmm1; ret
3575 |9: ; int3 // Bad op.
3577 |.elif SSE // x86 calling convention with SSE ops.
3579 | .define foldop, eax
3580 | mov foldop, [esp+20]
3581 | movsd xmm0, qword [esp+4]
3582 | movsd xmm1, qword [esp+12]
3583 | cmp foldop, 1; je >1; ja >2
3586 | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
3589 |1: ; subsd xmm0, xmm1; jmp <7
3590 |2: ; cmp foldop, 3; je >1; ja >2
3591 | mulsd xmm0, xmm1; jmp <7
3592 |1: ; divsd xmm0, xmm1; jmp <7
3595 | call ->vm_mod; jmp <7
3596 |1: ; pop edx; call ->vm_pow; push edx; jmp <7 // Writes to scratch area.
3597 |2: ; cmp foldop, 7; je >1; ja >2
3598 | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; jmp <7
3599 |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; jmp <7
3600 |2: ; cmp foldop, 9; ja >2
3601 | fld qword [esp+4] // Reload from stack
3602 | fld qword [esp+12]
3605 |1: ; fxch; fscale; fpop1; ret
3606 |2: ; cmp foldop, 11; je >1; ja >9
3607 | minsd xmm0, xmm1; jmp <7
3608 |1: ; maxsd xmm0, xmm1; jmp <7
3609 |9: ; int3 // Bad op.
3611 |.else // x86 calling convention with x87 ops.
3615 | fld qword [esp+12]
3616 | cmp eax, 1; je >1; ja >2
3618 |1: ; fsubp st1; ret
3619 |2: ; cmp eax, 3; je >1; ja >2
3621 |1: ; fdivp st1; ret
3622 |2: ; cmp eax, 5; jb ->vm_mod; je ->vm_pow
3623 | cmp eax, 7; je >1; ja >2
3625 |1: ; fpop; fabs; ret
3626 |2: ; cmp eax, 9; je >1; ja >2
3628 |1: ; fxch; fscale; fpop1; ret
3629 |2: ; cmp eax, 11; je >1; ja >9
3630 | fucomi st1; fcmovnbe st1; fpop1; ret
3631 |1: ; fucomi st1; fcmovbe st1; fpop1; ret
3632 |9: ; int3 // Bad op.
3636 |//-----------------------------------------------------------------------
3637 |//-- Miscellaneous functions --------------------------------------------
3638 |//-----------------------------------------------------------------------
3640 |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])
3644 | .if X64WIN; push rsi; mov rsi, CARG2; .endif
3652 | .if X64WIN; pop rsi; .endif
3658 | xor edx, 0x00200000 // Toggle ID bit in flags.
3663 | xor eax, eax // Zero means no features supported.
3665 | jz >1 // No ID toggle means no CPUID support.
3666 | mov eax, [esp+4] // Argument 1 is function number.
3670 | mov edi, [esp+16] // Argument 2 is result area.
3681 |//-----------------------------------------------------------------------
3682 |//-- Assertions ---------------------------------------------------------
3683 |//-----------------------------------------------------------------------
3685 |->assert_bad_for_arg_type:
3686 #ifdef LUA_USE_ASSERT
3691 |//-----------------------------------------------------------------------
3692 |//-- FFI helper functions -----------------------------------------------
3693 |//-----------------------------------------------------------------------
3695 |// Handler for callback functions. Callback slot number in ah/al.
3698 |.type CTSTATE, CTState, PC
3700 | sub esp, 16 // Leave room for SAVE_ERRF etc.
3702 | saveregs_ // ebp/rbp already saved. ebp now holds global_State *.
3703 | lea DISPATCH, [ebp+GG_G2DISP]
3704 | mov CTSTATE, GL:ebp->ctype_state
3706 | mov CTSTATE->cb.slot, eax
3708 | mov CTSTATE->cb.gpr[0], CARG1
3709 | mov CTSTATE->cb.gpr[1], CARG2
3710 | mov CTSTATE->cb.gpr[2], CARG3
3711 | mov CTSTATE->cb.gpr[3], CARG4
3712 | movsd qword CTSTATE->cb.fpr[0], xmm0
3713 | movsd qword CTSTATE->cb.fpr[1], xmm1
3714 | movsd qword CTSTATE->cb.fpr[2], xmm2
3715 | movsd qword CTSTATE->cb.fpr[3], xmm3
3717 | lea rax, [rsp+CFRAME_SIZE+4*8]
3719 | lea rax, [rsp+CFRAME_SIZE]
3720 | mov CTSTATE->cb.gpr[4], CARG5
3721 | mov CTSTATE->cb.gpr[5], CARG6
3722 | movsd qword CTSTATE->cb.fpr[4], xmm4
3723 | movsd qword CTSTATE->cb.fpr[5], xmm5
3724 | movsd qword CTSTATE->cb.fpr[6], xmm6
3725 | movsd qword CTSTATE->cb.fpr[7], xmm7
3727 | mov CTSTATE->cb.stack, rax
3730 | lea eax, [esp+CFRAME_SIZE+16]
3731 | mov CTSTATE->cb.gpr[0], FCARG1
3732 | mov CTSTATE->cb.gpr[1], FCARG2
3733 | mov CTSTATE->cb.stack, eax
3734 | mov FCARG1, [esp+CFRAME_SIZE+12] // Move around misplaced retaddr/ebp.
3735 | mov FCARG2, [esp+CFRAME_SIZE+8]
3736 | mov SAVE_RET, FCARG1
3737 | mov SAVE_R4, FCARG2
3740 | mov SAVE_PC, CTSTATE // Any value outside of bytecode is ok.
3741 | mov FCARG1, CTSTATE
3742 | call extern lj_ccallback_enter@8 // (CTState *cts, void *cf)
3743 | // lua_State * returned in eax (RD).
3744 | set_vmstate INTERP
3745 | mov BASE, L:RD->base
3748 | mov LFUNC:RB, [BASE-8]
3754 |->cont_ffi_callback: // Return from FFI callback.
3757 | mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]
3758 | mov aword CTSTATE->L, L:RAa
3759 | mov L:RA->base, BASE
3761 | mov FCARG1, CTSTATE
3763 | call extern lj_ccallback_leave@8 // (CTState *cts, TValue *o)
3765 | mov rax, CTSTATE->cb.gpr[0]
3766 | movsd xmm0, qword CTSTATE->cb.fpr[0]
3767 | jmp ->vm_leave_unw
3770 | mov eax, CTSTATE->cb.gpr[0]
3771 | mov edx, CTSTATE->cb.gpr[1]
3772 | cmp dword CTSTATE->cb.gpr[2], 1
3775 | fld qword CTSTATE->cb.fpr[0].d
3778 | fld dword CTSTATE->cb.fpr[0].f
3780 | mov ecx, L:RB->top
3781 | movzx ecx, word [ecx+6] // Get stack adjustment and copy up.
3782 | mov SAVE_L, ecx // Must be one slot above SAVE_RET
3784 | pop ecx // Move return addr from SAVE_RET.
3785 | add esp, [esp] // Adjust stack.
3792 |->vm_ffi_call@4: // Call C function via FFI.
3793 | // Caveat: needs special frame unwinding, see below.
3796 | .type CCSTATE, CCallState, rbx
3797 | push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1
3799 | .type CCSTATE, CCallState, ebx
3800 | push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1
3803 | // Readjust stack.
3805 | mov eax, CCSTATE->spadj
3808 | sub esp, CCSTATE->spadj
3810 | mov CCSTATE->spadj, esp
3814 | // Copy stack slots.
3815 | movzx ecx, byte CCSTATE->nsp
3820 | mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]
3821 | mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax
3823 | mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)]
3824 | mov [esp+ecx*4], eax
3831 | movzx eax, byte CCSTATE->nfpr
3832 | mov CARG1, CCSTATE->gpr[0]
3833 | mov CARG2, CCSTATE->gpr[1]
3834 | mov CARG3, CCSTATE->gpr[2]
3835 | mov CARG4, CCSTATE->gpr[3]
3837 | mov CARG5, CCSTATE->gpr[4]
3838 | mov CARG6, CCSTATE->gpr[5]
3840 | test eax, eax; jz >5
3841 | movaps xmm0, CCSTATE->fpr[0]
3842 | movaps xmm1, CCSTATE->fpr[1]
3843 | movaps xmm2, CCSTATE->fpr[2]
3844 | movaps xmm3, CCSTATE->fpr[3]
3846 | cmp eax, 4; jbe >5
3847 | movaps xmm4, CCSTATE->fpr[4]
3848 | movaps xmm5, CCSTATE->fpr[5]
3849 | movaps xmm6, CCSTATE->fpr[6]
3850 | movaps xmm7, CCSTATE->fpr[7]
3854 | mov FCARG1, CCSTATE->gpr[0]
3855 | mov FCARG2, CCSTATE->gpr[1]
3858 | call aword CCSTATE->func
3861 | mov CCSTATE->gpr[0], rax
3862 | movaps CCSTATE->fpr[0], xmm0
3864 | mov CCSTATE->gpr[1], rdx
3865 | movaps CCSTATE->fpr[1], xmm1
3868 | mov CCSTATE->gpr[0], eax
3869 | mov CCSTATE->gpr[1], edx
3870 | cmp byte CCSTATE->resx87, 1
3873 | fstp qword CCSTATE->fpr[0].d[0]
3876 | fstp dword CCSTATE->fpr[0].f[0]
3879 | sub CCSTATE->spadj, esp
3884 | mov rbx, [rbp-8]; leave; ret
3886 | mov ebx, [ebp-4]; leave; ret
3889 |// Note: vm_ffi_call must be the last function in this object file!
3891 |//-----------------------------------------------------------------------
3894 /* Generate the code for a single instruction. */
3895 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3898 |// Note: aligning all instructions does not pay off.
3903 /* -- Comparison ops ---------------------------------------------------- */
3905 /* Remember: all ops branch for a true comparison, fall through otherwise. */
3907 |.macro jmp_comp, lt, ge, le, gt, target
3921 ||default: break; /* Shut up GCC. */
3925 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
3926 | // RA = src1, RD = src2, JMP with RD = target
3931 | mov RB, dword [BASE+RA*8]
3933 | cmp RB, dword [BASE+RD*8]
3934 | jmp_comp jge, jl, jg, jle, >9
3941 |7: // RA is not an integer.
3943 | // RA is a number.
3944 | cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp
3945 | // RA is a number, RD is an integer.
3947 | cvtsi2sd xmm0, dword [BASE+RD*8]
3950 | fld qword [BASE+RA*8]
3951 | fild dword [BASE+RD*8]
3955 |8: // RA is an integer, RD is not an integer.
3957 | // RA is an integer, RD is a number.
3959 | cvtsi2sd xmm1, dword [BASE+RA*8]
3960 | movsd xmm0, qword [BASE+RD*8]
3962 | ucomisd xmm0, xmm1
3963 | jmp_comp jbe, ja, jb, jae, <9
3966 | fild dword [BASE+RA*8]
3970 | checknum RA, ->vmeta_comp
3971 | checknum RD, ->vmeta_comp
3975 | movsd xmm0, qword [BASE+RD*8]
3978 | ucomisd xmm0, qword [BASE+RA*8]
3982 | fld qword [BASE+RA*8] // Reverse order, i.e like cmp D, A.
3984 | fld qword [BASE+RD*8]
3989 | // Unordered: all of ZF CF PF set, ordered: PF clear.
3990 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
3992 | jmp_comp jbe, ja, jb, jae, <9
3995 | jmp_comp jbe, ja, jb, jae, >1
4003 case BC_ISEQV: case BC_ISNEV:
4004 vk = op == BC_ISEQV;
4005 | ins_AD // RA = src1, RD = src2, JMP with RD = target
4006 | mov RB, [BASE+RD*8+4]
4009 | cmp RB, LJ_TISNUM; jne >7
4011 | mov RB, dword [BASE+RD*8]
4012 | cmp RB, dword [BASE+RA*8]
4023 |7: // RD is not an integer.
4025 | // RD is a number.
4026 | cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5
4027 | // RD is a number, RA is an integer.
4029 | cvtsi2sd xmm0, dword [BASE+RA*8]
4031 | fild dword [BASE+RA*8]
4035 |8: // RD is an integer, RA is not an integer.
4037 | // RD is an integer, RA is a number.
4039 | cvtsi2sd xmm0, dword [BASE+RD*8]
4040 | ucomisd xmm0, qword [BASE+RA*8]
4042 | fild dword [BASE+RD*8]
4043 | fld qword [BASE+RA*8]
4048 | cmp RB, LJ_TISNUM; jae >5
4053 | movsd xmm0, qword [BASE+RA*8]
4055 | ucomisd xmm0, qword [BASE+RD*8]
4059 | fld qword [BASE+RA*8]
4061 | fld qword [BASE+RD*8]
4067 | jp >2 // Unordered means not equal.
4070 | jp >2 // Unordered means not equal.
4075 |1: // EQ: Branch to the target.
4078 |2: // NE: Fallthrough to next instruction.
4086 |2: // NE: Branch to the target.
4089 |1: // EQ: Fallthrough to next instruction.
4091 if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||
4092 op == BC_ISEQN || op == BC_ISNEN)) {
4098 if (op == BC_ISEQV || op == BC_ISNEV) {
4099 |5: // Either or both types are not numbers.
4101 | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
4102 | checktp RA, LJ_TCDATA; je ->vmeta_equal_cd
4104 | checktp RA, RB // Compare types.
4105 | jne <2 // Not the same type?
4107 | jae <1 // Same type and primitive type?
4109 | // Same types and not a primitive type. Compare GCobj or pvalue.
4110 | mov RA, [BASE+RA*8]
4111 | mov RD, [BASE+RD*8]
4113 | je <1 // Same GCobjs or pvalues?
4114 | cmp RB, LJ_TISTABUD
4115 | ja <2 // Different objects and not table/ud?
4117 | cmp RB, LJ_TUDATA // And not 64 bit lightuserdata.
4121 | // Different tables or userdatas. Need to check __eq metamethod.
4122 | // Field metatable must be at same offset for GCtab and GCudata!
4123 | mov TAB:RB, TAB:RA->metatable
4124 | test TAB:RB, TAB:RB
4125 | jz <2 // No metatable?
4126 | test byte TAB:RB->nomm, 1<<MM_eq
4127 | jnz <2 // Or 'no __eq' flag set?
4129 | xor RB, RB // ne = 0
4131 | mov RB, 1 // ne = 1
4133 | jmp ->vmeta_equal // Handle __eq metamethod.
4138 if (LJ_DUALNUM && vk) {
4143 | jmp ->vmeta_equal_cd
4147 case BC_ISEQS: case BC_ISNES:
4148 vk = op == BC_ISEQS;
4149 | ins_AND // RA = src, RD = str const, JMP with RD = target
4150 | mov RB, [BASE+RA*8+4]
4152 | cmp RB, LJ_TSTR; jne >3
4153 | mov RA, [BASE+RA*8]
4154 | cmp RA, [KBASE+RD*4]
4162 case BC_ISEQN: case BC_ISNEN:
4163 vk = op == BC_ISEQN;
4164 | ins_AD // RA = src, RD = num const, JMP with RD = target
4165 | mov RB, [BASE+RA*8+4]
4168 | cmp RB, LJ_TISNUM; jne >7
4169 | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8
4170 | mov RB, dword [KBASE+RD*8]
4171 | cmp RB, dword [BASE+RA*8]
4182 |7: // RA is not an integer.
4184 | // RA is a number.
4185 | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1
4186 | // RA is a number, RD is an integer.
4188 | cvtsi2sd xmm0, dword [KBASE+RD*8]
4190 | fild dword [KBASE+RD*8]
4194 |8: // RA is an integer, RD is a number.
4196 | cvtsi2sd xmm0, dword [BASE+RA*8]
4197 | ucomisd xmm0, qword [KBASE+RD*8]
4199 | fild dword [BASE+RA*8]
4200 | fld qword [KBASE+RD*8]
4204 | cmp RB, LJ_TISNUM; jae >3
4208 | movsd xmm0, qword [KBASE+RD*8]
4210 | ucomisd xmm0, qword [BASE+RA*8]
4214 | fld qword [KBASE+RD*8]
4216 | fld qword [BASE+RA*8]
4221 case BC_ISEQP: case BC_ISNEP:
4222 vk = op == BC_ISEQP;
4223 | ins_AND // RA = src, RD = primitive type (~), JMP with RD = target
4224 | mov RB, [BASE+RA*8+4]
4227 if (!LJ_HASFFI) goto iseqne_test;
4235 | cmp RB, LJ_TCDATA; jne <2
4236 | jmp ->vmeta_equal_cd
4239 | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
4247 /* -- Unary test and copy ops ------------------------------------------- */
4249 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
4250 | ins_AD // RA = dst or unused, RD = src, JMP with RD = target
4251 | mov RB, [BASE+RD*8+4]
4253 | cmp RB, LJ_TISTRUECOND
4254 if (op == BC_IST || op == BC_ISTC) {
4259 if (op == BC_ISTC || op == BC_ISFC) {
4260 | mov [BASE+RA*8+4], RB
4261 | mov RB, [BASE+RD*8]
4262 | mov [BASE+RA*8], RB
4266 |1: // Fallthrough to the next instruction.
4270 /* -- Unary ops --------------------------------------------------------- */
4273 | ins_AD // RA = dst, RD = src
4275 | mov RBa, [BASE+RD*8]
4276 | mov [BASE+RA*8], RBa
4278 | mov RB, [BASE+RD*8+4]
4279 | mov RD, [BASE+RD*8]
4280 | mov [BASE+RA*8+4], RB
4281 | mov [BASE+RA*8], RD
4286 | ins_AD // RA = dst, RD = src
4288 | checktp RD, LJ_TISTRUECOND
4290 | mov [BASE+RA*8+4], RB
4294 | ins_AD // RA = dst, RD = src
4297 | mov RB, [BASE+RD*8]
4300 | mov dword [BASE+RA*8+4], LJ_TISNUM
4301 | mov dword [BASE+RA*8], RB
4305 | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31.
4306 | mov dword [BASE+RA*8], 0
4311 | checknum RD, ->vmeta_unm
4314 | movsd xmm0, qword [BASE+RD*8]
4315 | sseconst_sign xmm1, RDa
4317 | movsd qword [BASE+RA*8], xmm0
4319 | fld qword [BASE+RD*8]
4321 | fstp qword [BASE+RA*8]
4330 | ins_AD // RA = dst, RD = src
4332 | mov STR:RD, [BASE+RD*8]
4334 | mov RD, dword STR:RD->len
4336 | mov dword [BASE+RA*8+4], LJ_TISNUM
4337 | mov dword [BASE+RA*8], RD
4340 | cvtsi2sd xmm0, dword STR:RD->len
4342 | movsd qword [BASE+RA*8], xmm0
4344 | fild dword STR:RD->len
4346 | fstp qword [BASE+RA*8]
4350 | checktab RD, ->vmeta_len
4351 | mov TAB:FCARG1, [BASE+RD*8]
4353 | mov TAB:RB, TAB:FCARG1->metatable
4359 | mov RB, BASE // Save BASE.
4360 | call extern lj_tab_len@4 // (GCtab *t)
4361 | // Length of table returned in eax (RD).
4370 | mov BASE, RB // Restore BASE.
4374 |9: // Check for __len.
4375 | test byte TAB:RB->nomm, 1<<MM_len
4377 | jmp ->vmeta_len // 'no __len' flag NOT set: check.
4381 /* -- Binary ops -------------------------------------------------------- */
4383 |.macro ins_arithpre, x87ins, sseins, ssereg
4385 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
4388 | checknum RB, ->vmeta_arith_vn
4390 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn
4393 | movsd xmm0, qword [BASE+RB*8]
4394 | sseins ssereg, qword [KBASE+RC*8]
4396 | fld qword [BASE+RB*8]
4397 | x87ins qword [KBASE+RC*8]
4401 | checknum RB, ->vmeta_arith_nv
4403 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv
4406 | movsd xmm0, qword [KBASE+RC*8]
4407 | sseins ssereg, qword [BASE+RB*8]
4409 | fld qword [KBASE+RC*8]
4410 | x87ins qword [BASE+RB*8]
4414 | checknum RB, ->vmeta_arith_vv
4415 | checknum RC, ->vmeta_arith_vv
4417 | movsd xmm0, qword [BASE+RB*8]
4418 | sseins ssereg, qword [BASE+RC*8]
4420 | fld qword [BASE+RB*8]
4421 | x87ins qword [BASE+RC*8]
4427 |.macro ins_arithdn, intins
4429 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
4432 | checkint RB, ->vmeta_arith_vn
4433 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn
4434 | mov RB, [BASE+RB*8]
4435 | intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno
4438 | checkint RB, ->vmeta_arith_nv
4439 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv
4440 | mov RC, [KBASE+RC*8]
4441 | intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo
4444 | checkint RB, ->vmeta_arith_vv
4445 | checkint RC, ->vmeta_arith_vv
4446 | mov RB, [BASE+RB*8]
4447 | intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo
4450 | mov dword [BASE+RA*8+4], LJ_TISNUM
4452 | mov dword [BASE+RA*8], RC
4454 | mov dword [BASE+RA*8], RB
4459 |.macro ins_arithpost
4461 | movsd qword [BASE+RA*8], xmm0
4463 | fstp qword [BASE+RA*8]
4467 |.macro ins_arith, x87ins, sseins
4468 | ins_arithpre x87ins, sseins, xmm0
4473 |.macro ins_arith, intins, x87ins, sseins
4475 | ins_arithdn intins
4477 | ins_arith, x87ins, sseins
4481 | // RA = dst, RB = src1 or num const, RC = src2 or num const
4482 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
4483 | ins_arith add, fadd, addsd
4485 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
4486 | ins_arith sub, fsub, subsd
4488 case BC_MULVN: case BC_MULNV: case BC_MULVV:
4489 | ins_arith imul, fmul, mulsd
4491 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
4492 | ins_arith fdiv, divsd
4495 | ins_arithpre fld, movsd, xmm1
4501 case BC_MODNV: case BC_MODVV:
4502 | ins_arithpre fld, movsd, xmm1
4503 | jmp ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
4506 | ins_arithpre fld, movsd, xmm1
4513 | ins_ABC // RA = dst, RB = src_start, RC = src_end
4515 | mov L:CARG1d, SAVE_L
4516 | mov L:CARG1d->base, BASE
4517 | lea CARG2d, [BASE+RC*8]
4521 | mov L:RB, L:CARG1d
4523 | lea RA, [BASE+RC*8]
4530 | mov L:RB->base, BASE
4533 | call extern lj_meta_cat // (lua_State *L, TValue *top, int left)
4534 | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
4535 | mov BASE, L:RB->base
4538 | movzx RB, PC_RB // Copy result to Stk[RA] from Stk[RB].
4541 | mov RCa, [BASE+RB*8]
4542 | mov [BASE+RA*8], RCa
4544 | mov RC, [BASE+RB*8+4]
4545 | mov RB, [BASE+RB*8]
4546 | mov [BASE+RA*8+4], RC
4547 | mov [BASE+RA*8], RB
4552 /* -- Constant ops ------------------------------------------------------ */
4555 | ins_AND // RA = dst, RD = str const (~)
4556 | mov RD, [KBASE+RD*4]
4557 | mov dword [BASE+RA*8+4], LJ_TSTR
4558 | mov [BASE+RA*8], RD
4563 | ins_AND // RA = dst, RD = cdata const (~)
4564 | mov RD, [KBASE+RD*4]
4565 | mov dword [BASE+RA*8+4], LJ_TCDATA
4566 | mov [BASE+RA*8], RD
4571 | ins_AD // RA = dst, RD = signed int16 literal
4574 | mov dword [BASE+RA*8+4], LJ_TISNUM
4575 | mov dword [BASE+RA*8], RD
4577 | movsx RD, RDW // Sign-extend literal.
4579 | movsd qword [BASE+RA*8], xmm0
4581 | fild PC_RD // Refetch signed RD from instruction.
4582 | fstp qword [BASE+RA*8]
4587 | ins_AD // RA = dst, RD = num const
4589 | movsd xmm0, qword [KBASE+RD*8]
4590 | movsd qword [BASE+RA*8], xmm0
4592 | fld qword [KBASE+RD*8]
4593 | fstp qword [BASE+RA*8]
4598 | ins_AND // RA = dst, RD = primitive type (~)
4599 | mov [BASE+RA*8+4], RD
4603 | ins_AD // RA = dst_start, RD = dst_end
4604 | lea RA, [BASE+RA*8+12]
4605 | lea RD, [BASE+RD*8+4]
4607 | mov [RA-8], RB // Sets minimum 2 slots.
4616 /* -- Upvalue and function ops ------------------------------------------ */
4619 | ins_AD // RA = dst, RD = upvalue #
4620 | mov LFUNC:RB, [BASE-8]
4621 | mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)]
4622 | mov RB, UPVAL:RB->v
4625 | mov [BASE+RA*8], RDa
4629 | mov [BASE+RA*8+4], RD
4630 | mov [BASE+RA*8], RB
4635 #define TV2MARKOFS \
4636 ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
4637 | ins_AD // RA = upvalue #, RD = src
4638 | mov LFUNC:RB, [BASE-8]
4639 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4640 | cmp byte UPVAL:RB->closed, 0
4641 | mov RB, UPVAL:RB->v
4642 | mov RA, [BASE+RD*8]
4643 | mov RD, [BASE+RD*8+4]
4647 | // Check barrier for closed upvalue.
4648 | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv)
4653 |2: // Upvalue is black. Check if new value is collectable and white.
4655 | cmp RD, LJ_TNUMX - LJ_TISGCV // tvisgcv(v)
4657 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v)
4659 | // Crossed a write barrier. Move the barrier forward.
4660 |.if X64 and not X64WIN
4662 | mov RB, BASE // Save BASE.
4664 | xchg FCARG2, RB // Save BASE (FCARG2 == BASE).
4666 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
4667 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
4668 | mov BASE, RB // Restore BASE.
4673 | ins_AND // RA = upvalue #, RD = str const (~)
4674 | mov LFUNC:RB, [BASE-8]
4675 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4676 | mov GCOBJ:RA, [KBASE+RD*4]
4677 | mov RD, UPVAL:RB->v
4678 | mov [RD], GCOBJ:RA
4679 | mov dword [RD+4], LJ_TSTR
4680 | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv)
4685 |2: // Check if string is white and ensure upvalue is closed.
4686 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str)
4688 | cmp byte UPVAL:RB->closed, 0
4690 | // Crossed a write barrier. Move the barrier forward.
4691 | mov RB, BASE // Save BASE (FCARG2 == BASE).
4693 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
4694 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
4695 | mov BASE, RB // Restore BASE.
4699 | ins_AD // RA = upvalue #, RD = num const
4700 | mov LFUNC:RB, [BASE-8]
4702 | movsd xmm0, qword [KBASE+RD*8]
4704 | fld qword [KBASE+RD*8]
4706 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4707 | mov RA, UPVAL:RB->v
4709 | movsd qword [RA], xmm0
4716 | ins_AND // RA = upvalue #, RD = primitive type (~)
4717 | mov LFUNC:RB, [BASE-8]
4718 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4719 | mov RA, UPVAL:RB->v
4724 | ins_AD // RA = level, RD = target
4725 | branchPC RD // Do this first to free RD.
4727 | cmp dword L:RB->openupval, 0
4729 | mov L:RB->base, BASE
4730 | lea FCARG2, [BASE+RA*8] // Caveat: FCARG2 == BASE
4731 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
4732 | call extern lj_func_closeuv@8 // (lua_State *L, TValue *level)
4733 | mov BASE, L:RB->base
4739 | ins_AND // RA = dst, RD = proto const (~) (holding function prototype)
4742 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
4743 | mov CARG3d, [BASE-8]
4744 | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *.
4747 | mov LFUNC:RA, [BASE-8]
4748 | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *.
4750 | mov ARG3, LFUNC:RA
4751 | mov ARG2, PROTO:RD
4753 | mov L:RB->base, BASE
4756 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
4757 | call extern lj_func_newL_gc
4758 | // GCfuncL * returned in eax (RC).
4759 | mov BASE, L:RB->base
4761 | mov [BASE+RA*8], LFUNC:RC
4762 | mov dword [BASE+RA*8+4], LJ_TFUNC
4766 /* -- Table ops --------------------------------------------------------- */
4769 | ins_AD // RA = dst, RD = hbits|asize
4771 | mov L:RB->base, BASE
4772 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
4773 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
4791 | mov L:CARG1d, L:RB
4797 | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
4798 | // Table * returned in eax (RC).
4799 | mov BASE, L:RB->base
4801 | mov [BASE+RA*8], TAB:RC
4802 | mov dword [BASE+RA*8+4], LJ_TTAB
4804 |3: // Turn 0x7ff into 0x801.
4808 | mov L:FCARG1, L:RB
4809 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
4814 | ins_AND // RA = dst, RD = table const (~) (holding template table)
4816 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
4818 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
4819 | mov L:RB->base, BASE
4822 | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE
4823 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
4824 | call extern lj_tab_dup@8 // (lua_State *L, Table *kt)
4825 | // Table * returned in eax (RC).
4826 | mov BASE, L:RB->base
4828 | mov [BASE+RA*8], TAB:RC
4829 | mov dword [BASE+RA*8+4], LJ_TTAB
4832 | mov L:FCARG1, L:RB
4833 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
4834 | movzx RD, PC_RD // Need to reload RD.
4840 | ins_AND // RA = dst, RD = str const (~)
4841 | mov LFUNC:RB, [BASE-8]
4842 | mov TAB:RB, LFUNC:RB->env
4843 | mov STR:RC, [KBASE+RD*4]
4847 | ins_AND // RA = src, RD = str const (~)
4848 | mov LFUNC:RB, [BASE-8]
4849 | mov TAB:RB, LFUNC:RB->env
4850 | mov STR:RC, [KBASE+RD*4]
4855 | ins_ABC // RA = dst, RB = table, RC = key
4856 | checktab RB, ->vmeta_tgetv
4857 | mov TAB:RB, [BASE+RB*8]
4862 | mov RC, dword [BASE+RC*8]
4864 | // Convert number to int and back and compare.
4867 | movsd xmm0, qword [BASE+RC*8]
4870 | ucomisd xmm0, xmm1
4872 | fld qword [BASE+RC*8]
4878 | jne ->vmeta_tgetv // Generic numeric key? Use fallback.
4880 | cmp RC, TAB:RB->asize // Takes care of unordered, too.
4881 | jae ->vmeta_tgetv // Not in array part? Use fallback.
4883 | add RC, TAB:RB->array
4884 | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4886 | // Get array slot.
4889 | mov [BASE+RA*8], RBa
4893 | mov [BASE+RA*8], RB
4894 | mov [BASE+RA*8+4], RC
4899 |2: // Check for __index if table value is nil.
4900 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
4902 | mov TAB:RA, TAB:RB->metatable
4903 | test byte TAB:RA->nomm, 1<<MM_index
4904 | jz ->vmeta_tgetv // 'no __index' flag NOT set: check.
4905 | movzx RA, PC_RA // Restore RA.
4907 | mov dword [BASE+RA*8+4], LJ_TNIL
4911 | checkstr RC, ->vmeta_tgetv
4912 | mov STR:RC, [BASE+RC*8]
4916 | ins_ABC // RA = dst, RB = table, RC = str const (~)
4918 | mov STR:RC, [KBASE+RC*4]
4919 | checktab RB, ->vmeta_tgets
4920 | mov TAB:RB, [BASE+RB*8]
4921 |->BC_TGETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
4922 | mov RA, TAB:RB->hmask
4923 | and RA, STR:RC->hash
4925 | add NODE:RA, TAB:RB->node
4927 | cmp dword NODE:RA->key.it, LJ_TSTR
4929 | cmp dword NODE:RA->key.gcr, STR:RC
4931 | // Ok, key found. Assumes: offsetof(Node, val) == 0
4932 | cmp dword [RA+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4933 | je >5 // Key found, but nil value?
4935 | // Get node value.
4938 | mov [BASE+RC*8], RBa
4942 | mov [BASE+RC*8], RB
4943 | mov [BASE+RC*8+4], RA
4950 | mov dword [BASE+RC*8+4], LJ_TNIL
4953 |4: // Follow hash chain.
4954 | mov NODE:RA, NODE:RA->next
4955 | test NODE:RA, NODE:RA
4957 | // End of hash chain: key not found, nil result.
4959 |5: // Check for __index if table value is nil.
4960 | mov TAB:RA, TAB:RB->metatable
4961 | test TAB:RA, TAB:RA
4962 | jz <3 // No metatable: done.
4963 | test byte TAB:RA->nomm, 1<<MM_index
4964 | jnz <3 // 'no __index' flag set: done.
4965 | jmp ->vmeta_tgets // Caveat: preserve STR:RC.
4968 | ins_ABC // RA = dst, RB = table, RC = byte literal
4969 | checktab RB, ->vmeta_tgetb
4970 | mov TAB:RB, [BASE+RB*8]
4971 | cmp RC, TAB:RB->asize
4974 | add RC, TAB:RB->array
4975 | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4977 | // Get array slot.
4980 | mov [BASE+RA*8], RBa
4984 | mov [BASE+RA*8], RB
4985 | mov [BASE+RA*8+4], RC
4990 |2: // Check for __index if table value is nil.
4991 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
4993 | mov TAB:RA, TAB:RB->metatable
4994 | test byte TAB:RA->nomm, 1<<MM_index
4995 | jz ->vmeta_tgetb // 'no __index' flag NOT set: check.
4996 | movzx RA, PC_RA // Restore RA.
4998 | mov dword [BASE+RA*8+4], LJ_TNIL
5003 | ins_ABC // RA = src, RB = table, RC = key
5004 | checktab RB, ->vmeta_tsetv
5005 | mov TAB:RB, [BASE+RB*8]
5010 | mov RC, dword [BASE+RC*8]
5012 | // Convert number to int and back and compare.
5015 | movsd xmm0, qword [BASE+RC*8]
5018 | ucomisd xmm0, xmm1
5020 | fld qword [BASE+RC*8]
5026 | jne ->vmeta_tsetv // Generic numeric key? Use fallback.
5028 | cmp RC, TAB:RB->asize // Takes care of unordered, too.
5031 | add RC, TAB:RB->array
5032 | cmp dword [RC+4], LJ_TNIL
5033 | je >3 // Previous value is nil?
5035 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5037 |2: // Set array slot.
5039 | mov RBa, [BASE+RA*8]
5042 | mov RB, [BASE+RA*8+4]
5043 | mov RA, [BASE+RA*8]
5049 |3: // Check for __newindex if previous value is nil.
5050 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5052 | mov TAB:RA, TAB:RB->metatable
5053 | test byte TAB:RA->nomm, 1<<MM_newindex
5054 | jz ->vmeta_tsetv // 'no __newindex' flag NOT set: check.
5055 | movzx RA, PC_RA // Restore RA.
5059 | checkstr RC, ->vmeta_tsetv
5060 | mov STR:RC, [BASE+RC*8]
5063 |7: // Possible table write barrier for the value. Skip valiswhite check.
5064 | barrierback TAB:RB, RA
5065 | movzx RA, PC_RA // Restore RA.
5069 | ins_ABC // RA = src, RB = table, RC = str const (~)
5071 | mov STR:RC, [KBASE+RC*4]
5072 | checktab RB, ->vmeta_tsets
5073 | mov TAB:RB, [BASE+RB*8]
5074 |->BC_TSETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
5075 | mov RA, TAB:RB->hmask
5076 | and RA, STR:RC->hash
5078 | mov byte TAB:RB->nomm, 0 // Clear metamethod cache.
5079 | add NODE:RA, TAB:RB->node
5081 | cmp dword NODE:RA->key.it, LJ_TSTR
5083 | cmp dword NODE:RA->key.gcr, STR:RC
5085 | // Ok, key found. Assumes: offsetof(Node, val) == 0
5086 | cmp dword [RA+4], LJ_TNIL
5087 | je >4 // Previous value is nil?
5089 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5091 |3: // Set node value.
5094 | mov RBa, [BASE+RC*8]
5097 | mov RB, [BASE+RC*8+4]
5098 | mov RC, [BASE+RC*8]
5104 |4: // Check for __newindex if previous value is nil.
5105 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5107 | mov TMP1, RA // Save RA.
5108 | mov TAB:RA, TAB:RB->metatable
5109 | test byte TAB:RA->nomm, 1<<MM_newindex
5110 | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
5111 | mov RA, TMP1 // Restore RA.
5114 |5: // Follow hash chain.
5115 | mov NODE:RA, NODE:RA->next
5116 | test NODE:RA, NODE:RA
5118 | // End of hash chain: key not found, add a new one.
5120 | // But check for __newindex first.
5121 | mov TAB:RA, TAB:RB->metatable
5122 | test TAB:RA, TAB:RA
5123 | jz >6 // No metatable: continue.
5124 | test byte TAB:RA->nomm, 1<<MM_newindex
5125 | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
5129 | mov TMP3, TAB:RB // Save TAB:RB for us.
5131 | mov L:CARG1d, SAVE_L
5132 | mov L:CARG1d->base, BASE
5134 | mov CARG2d, TAB:RB
5135 | mov L:RB, L:CARG1d
5137 | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2.
5142 | mov L:RB->base, BASE
5145 | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
5146 | // Handles write barrier for the new key. TValue * returned in eax (RC).
5147 | mov BASE, L:RB->base
5148 | mov TAB:RB, TMP3 // Need TAB:RB for barrier.
5150 | jmp <2 // Must check write barrier for value.
5152 |7: // Possible table write barrier for the value. Skip valiswhite check.
5153 | barrierback TAB:RB, RC // Destroys STR:RC.
5157 | ins_ABC // RA = src, RB = table, RC = byte literal
5158 | checktab RB, ->vmeta_tsetb
5159 | mov TAB:RB, [BASE+RB*8]
5160 | cmp RC, TAB:RB->asize
5163 | add RC, TAB:RB->array
5164 | cmp dword [RC+4], LJ_TNIL
5165 | je >3 // Previous value is nil?
5167 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5169 |2: // Set array slot.
5171 | mov RAa, [BASE+RA*8]
5174 | mov RB, [BASE+RA*8+4]
5175 | mov RA, [BASE+RA*8]
5181 |3: // Check for __newindex if previous value is nil.
5182 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5184 | mov TAB:RA, TAB:RB->metatable
5185 | test byte TAB:RA->nomm, 1<<MM_newindex
5186 | jz ->vmeta_tsetb // 'no __newindex' flag NOT set: check.
5187 | movzx RA, PC_RA // Restore RA.
5190 |7: // Possible table write barrier for the value. Skip valiswhite check.
5191 | barrierback TAB:RB, RA
5192 | movzx RA, PC_RA // Restore RA.
5197 | ins_AD // RA = base (table at base-1), RD = num const (start index)
5198 | mov TMP1, KBASE // Need one more free register.
5199 | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word.
5201 | lea RA, [BASE+RA*8]
5202 | mov TAB:RB, [RA-8] // Guaranteed to be a table.
5203 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5208 | jz >4 // Nothing to copy?
5209 | add RD, KBASE // Compute needed size.
5210 | cmp RD, TAB:RB->asize
5211 | ja >5 // Doesn't fit into array part?
5214 | add KBASE, TAB:RB->array
5215 |3: // Copy result slots to table.
5234 |5: // Need to resize array part.
5236 | mov L:CARG1d, SAVE_L
5237 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
5238 | mov CARG2d, TAB:RB
5240 | mov L:RB, L:CARG1d
5244 | mov L:RB->base, BASE
5249 | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
5250 | mov BASE, L:RB->base
5251 | movzx RA, PC_RA // Restore RA.
5254 |7: // Possible table write barrier for any value. Skip valiswhite check.
5255 | barrierback TAB:RB, RD
5259 /* -- Calls and vararg handling ----------------------------------------- */
5261 case BC_CALL: case BC_CALLM:
5262 | ins_A_C // RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs
5263 if (op == BC_CALLM) {
5264 | add NARGS:RD, MULTRES
5266 | cmp dword [BASE+RA*8+4], LJ_TFUNC
5267 | mov LFUNC:RB, [BASE+RA*8]
5268 | jne ->vmeta_call_ra
5269 | lea BASE, [BASE+RA*8+8]
5274 | ins_AD // RA = base, RD = extra_nargs
5275 | add NARGS:RD, MULTRES
5276 | // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.
5279 | ins_AD // RA = base, RD = nargs+1
5280 | lea RA, [BASE+RA*8+8]
5281 | mov KBASE, BASE // Use KBASE for move + vmeta_call hint.
5282 | mov LFUNC:RB, [RA-8]
5283 | cmp dword [RA-4], LJ_TFUNC
5287 | test PC, FRAME_TYPE
5290 | mov [BASE-8], LFUNC:RB // Copy function down, reloaded below.
5291 | mov MULTRES, NARGS:RD
5294 |2: // Move args down.
5310 | mov LFUNC:RB, [BASE-8]
5312 | mov NARGS:RD, MULTRES
5313 | cmp byte LFUNC:RB->ffid, 1 // (> FF_C) Calling a fast function?
5318 |5: // Tailcall to a fast function.
5319 | test PC, FRAME_TYPE // Lua frame below?
5323 | lea RA, [BASE+RA*8]
5324 | mov LFUNC:KBASE, [RA-8] // Need to prepare KBASE.
5325 | mov KBASE, LFUNC:KBASE->pc
5326 | mov KBASE, [KBASE+PC2PROTO(k)]
5329 |7: // Tailcall from a vararg function.
5330 | sub PC, FRAME_VARG
5331 | test PC, FRAME_TYPEP
5332 | jnz >8 // Vararg frame below?
5333 | sub BASE, PC // Need to relocate BASE/KBASE down.
5338 | add PC, FRAME_VARG
5343 | ins_A // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)
5344 | lea RA, [BASE+RA*8+8] // fb = base+1
5346 | mov RBa, [RA-24] // Copy state. fb[0] = fb[-3].
5347 | mov RCa, [RA-16] // Copy control var. fb[1] = fb[-2].
5351 | mov RB, [RA-24] // Copy state. fb[0] = fb[-3].
5355 | mov RB, [RA-16] // Copy control var. fb[1] = fb[-2].
5360 | mov LFUNC:RB, [RA-32] // Copy callable. fb[-1] = fb[-4]
5362 | mov [RA-8], LFUNC:RB
5364 | cmp RC, LJ_TFUNC // Handle like a regular 2-arg call.
5372 | ins_A // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))
5374 | // NYI: add hotloop, record BC_ITERN.
5376 | mov TMP1, KBASE // Need two more free registers.
5377 | mov TMP2, DISPATCH
5378 | mov TAB:RB, [BASE+RA*8-16]
5379 | mov RC, [BASE+RA*8-8] // Get index from control var.
5380 | mov DISPATCH, TAB:RB->asize
5382 | mov KBASE, TAB:RB->array
5383 |1: // Traverse array part.
5384 | cmp RC, DISPATCH; jae >5 // Index points after array part?
5385 | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4
5387 | mov dword [BASE+RA*8+4], LJ_TISNUM
5388 | mov dword [BASE+RA*8], RC
5392 | fild dword [BASE+RA*8-8]
5394 | // Copy array slot to returned value.
5396 | mov RBa, [KBASE+RC*8]
5397 | mov [BASE+RA*8+8], RBa
5399 | mov RB, [KBASE+RC*8+4]
5400 | mov [BASE+RA*8+12], RB
5401 | mov RB, [KBASE+RC*8]
5402 | mov [BASE+RA*8+8], RB
5405 | // Return array index as a numeric key.
5409 | movsd qword [BASE+RA*8], xmm0
5411 | fstp qword [BASE+RA*8]
5413 | mov [BASE+RA*8-8], RC // Update control var.
5415 | movzx RD, PC_RD // Get target from ITERL.
5418 | mov DISPATCH, TMP2
5422 |4: // Skip holes in array part.
5424 |.if not (DUALNUM or SSE)
5425 | mov [BASE+RA*8-8], RC
5429 |5: // Traverse hash part.
5432 | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1.
5433 | imul KBASE, RC, #NODE
5434 | add NODE:KBASE, TAB:RB->node
5435 | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7
5436 | lea DISPATCH, [RC+DISPATCH+1]
5437 | // Copy key and value from hash slot.
5439 | mov RBa, NODE:KBASE->key
5440 | mov RCa, NODE:KBASE->val
5441 | mov [BASE+RA*8], RBa
5442 | mov [BASE+RA*8+8], RCa
5444 | mov RB, NODE:KBASE->key.gcr
5445 | mov RC, NODE:KBASE->key.it
5446 | mov [BASE+RA*8], RB
5447 | mov [BASE+RA*8+4], RC
5448 | mov RB, NODE:KBASE->val.gcr
5449 | mov RC, NODE:KBASE->val.it
5450 | mov [BASE+RA*8+8], RB
5451 | mov [BASE+RA*8+12], RC
5453 | mov [BASE+RA*8-8], DISPATCH
5456 |7: // Skip holes in hash part.
5462 | ins_AD // RA = base, RD = target (points to ITERN)
5463 | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5
5464 | mov CFUNC:RB, [BASE+RA*8-24]
5465 | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5
5466 | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5
5467 | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5
5469 | mov dword [BASE+RA*8-8], 0 // Initialize control var.
5470 | mov dword [BASE+RA*8-4], 0xfffe7fff
5473 |5: // Despecialize bytecode if any of the checks fail.
5476 | mov byte [PC], BC_ITERC
5481 | ins_ABC // RA = base, RB = nresults+1, RC = numparams
5482 | mov TMP1, KBASE // Need one more free register.
5483 | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
5484 | lea RA, [BASE+RA*8]
5485 | sub KBASE, [BASE-4]
5486 | // Note: KBASE may now be even _above_ BASE if nargs was < numparams.
5488 | jz >5 // Copy all varargs?
5489 | lea RB, [RA+RB*8-8]
5490 | cmp KBASE, BASE // No vararg slots?
5492 |1: // Copy vararg slots to destination slots.
5494 | mov RCa, [KBASE-8]
5505 | cmp RA, RB // All destination slots filled?
5507 | cmp KBASE, BASE // No more vararg slots?
5509 |2: // Fill up remainder with nil.
5510 | mov dword [RA+4], LJ_TNIL
5518 |5: // Copy all varargs.
5519 | mov MULTRES, 1 // MULTRES = 0+1
5522 | jbe <3 // No vararg slots?
5526 | mov MULTRES, RB // MULTRES = #varargs+1
5529 | cmp RC, L:RB->maxstack
5530 | ja >7 // Need to grow stack?
5531 |6: // Copy all vararg slots.
5533 | mov RCa, [KBASE-8]
5544 | cmp KBASE, BASE // No more vararg slots?
5548 |7: // Grow stack for varargs.
5549 | mov L:RB->base, BASE
5552 | sub KBASE, BASE // Need delta, because BASE may change.
5553 | mov FCARG2, MULTRES
5556 | call extern lj_state_growstack@8 // (lua_State *L, int n)
5557 | mov BASE, L:RB->base
5563 /* -- Returns ----------------------------------------------------------- */
5566 | ins_AD // RA = results, RD = extra_nresults
5567 | add RD, MULTRES // MULTRES >=1, so RD >=1.
5568 | // Fall through. Assumes BC_RET follows and ins_AD is a no-op.
5571 case BC_RET: case BC_RET0: case BC_RET1:
5572 | ins_AD // RA = results, RD = nresults+1
5573 if (op != BC_RET0) {
5578 | mov MULTRES, RD // Save nresults+1.
5579 | test PC, FRAME_TYPE // Check frame type marker.
5580 | jnz >7 // Not returning to a fixarg Lua func?
5584 | mov KBASE, BASE // Use KBASE for result move.
5587 |2: // Move results down.
5589 | mov RBa, [KBASE+RA]
5590 | mov [KBASE-8], RBa
5592 | mov RB, [KBASE+RA]
5594 | mov RB, [KBASE+RA+4]
5601 | mov RD, MULTRES // Note: MULTRES may be >255.
5602 | movzx RB, PC_RB // So cannot compare with RDL!
5604 | cmp RB, RD // More results expected?
5609 | mov RBa, [BASE+RA]
5612 | mov RB, [BASE+RA+4]
5620 | cmp PC_RB, RDL // More results expected?
5626 | not RAa // Note: ~RA = -(RA+1)
5627 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
5628 | mov LFUNC:KBASE, [BASE-8]
5629 | mov KBASE, LFUNC:KBASE->pc
5630 | mov KBASE, [KBASE+PC2PROTO(k)]
5633 |6: // Fill up results with nil.
5635 | mov dword [KBASE-4], LJ_TNIL // Note: relies on shifted base.
5638 | mov dword [BASE+RD*8-12], LJ_TNIL
5643 |7: // Non-standard return case.
5644 | lea RB, [PC-FRAME_VARG]
5645 | test RB, FRAME_TYPEP
5647 | // Return from vararg function: relocate BASE down and RA up.
5649 if (op != BC_RET0) {
5655 /* -- Loops and branches ------------------------------------------------ */
5657 |.define FOR_IDX, [RA]; .define FOR_TIDX, dword [RA+4]
5658 |.define FOR_STOP, [RA+8]; .define FOR_TSTOP, dword [RA+12]
5659 |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20]
5660 |.define FOR_EXT, [RA+24]; .define FOR_TEXT, dword [RA+28]
5666 | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.
5676 vk = (op == BC_IFORL || op == BC_JFORL);
5677 | ins_AJ // RA = base, RD = target (after end of loop or start of loop)
5678 | lea RA, [BASE+RA*8]
5680 | cmp FOR_TIDX, LJ_TISNUM; jne >9
5682 | cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for
5683 | cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for
5684 | mov RB, dword FOR_IDX
5685 | cmp dword FOR_STEP, 0; jl >5
5687 #ifdef LUA_USE_ASSERT
5688 | cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type
5689 | cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type
5691 | mov RB, dword FOR_STEP
5692 | test RB, RB; js >5
5693 | add RB, dword FOR_IDX; jo >1
5694 | mov dword FOR_IDX, RB
5696 | cmp RB, dword FOR_STOP
5697 | mov FOR_TEXT, LJ_TISNUM
5698 | mov dword FOR_EXT, RB
5699 if (op == BC_FORI) {
5704 } else if (op == BC_JFORI) {
5710 } else if (op == BC_IFORL) {
5723 |5: // Invert check for negative step.
5725 | add RB, dword FOR_IDX; jo <1
5726 | mov dword FOR_IDX, RB
5728 | cmp RB, dword FOR_STOP
5729 | mov FOR_TEXT, LJ_TISNUM
5730 | mov dword FOR_EXT, RB
5731 if (op == BC_FORI) {
5733 } else if (op == BC_JFORI) {
5737 } else if (op == BC_IFORL) {
5743 |9: // Fallback to FP variant.
5745 | cmp FOR_TIDX, LJ_TISNUM
5749 | cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for
5751 #ifdef LUA_USE_ASSERT
5752 | cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type
5753 | cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type
5756 | mov RB, FOR_TSTEP // Load type/hiword of for step.
5758 | cmp RB, LJ_TISNUM; jae ->vmeta_for
5761 | movsd xmm0, qword FOR_IDX
5762 | movsd xmm1, qword FOR_STOP
5764 | addsd xmm0, qword FOR_STEP
5765 | movsd qword FOR_IDX, xmm0
5766 | test RB, RB; js >3
5770 | ucomisd xmm1, xmm0
5772 | movsd qword FOR_EXT, xmm0
5774 | fld qword FOR_STOP
5777 | fadd qword FOR_STEP // nidx = idx + step
5780 | test RB, RB; js >1
5785 | fxch // Swap lim/(n)idx if step non-negative.
5789 if (op == BC_FORI) {
5796 } else if (op == BC_JFORI) {
5800 } else if (op == BC_IFORL) {
5817 |3: // Invert comparison if step is negative.
5818 | ucomisd xmm0, xmm1
5827 | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.
5835 | ins_AJ // RA = base, RD = target
5836 | lea RA, [BASE+RA*8]
5838 | cmp RB, LJ_TNIL; je >1 // Stop if iterator returned nil.
5839 if (op == BC_JITERL) {
5845 | branchPC RD // Otherwise save control var + branch.
5855 | ins_A // RA = base, RD = target (loop extent)
5856 | // Note: RA/RD is only used by trace recorder to determine scope/extent
5857 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
5861 | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.
5865 | ins_A // RA = base, RD = target (loop extent)
5871 | ins_AD // RA = base (ignored), RD = traceno
5872 | mov RA, [DISPATCH+DISPATCH_J(trace)]
5873 | mov TRACE:RD, [RA+RD*4]
5874 | mov RDa, TRACE:RD->mcode
5876 | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE
5877 | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB
5878 | // Save additional callee-save registers only used in compiled code.
5886 | movdqa [RAa], xmm6
5887 | movdqa [RAa-1*16], xmm7
5888 | movdqa [RAa-2*16], xmm8
5889 | movdqa [RAa-3*16], xmm9
5890 | movdqa [RAa-4*16], xmm10
5891 | movdqa [RAa-5*16], xmm11
5892 | movdqa [RAa-6*16], xmm12
5893 | movdqa [RAa-7*16], xmm13
5894 | movdqa [RAa-8*16], xmm14
5895 | movdqa [RAa-9*16], xmm15
5906 | ins_AJ // RA = unused, RD = target
5911 /* -- Function headers -------------------------------------------------- */
5914 ** Reminder: A function may be called with func/args above L->maxstack,
5915 ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,
5916 ** too. This means all FUNC* ops (including fast functions) must check
5917 ** for stack overflow _before_ adding more slots!
5924 case BC_FUNCV: /* NYI: compiled vararg functions. */
5925 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.
5933 | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
5934 | mov KBASE, [PC-4+PC2PROTO(k)]
5936 | lea RA, [BASE+RA*8] // Top of frame.
5937 | cmp RA, L:RB->maxstack
5938 | ja ->vm_growstack_f
5939 | movzx RA, byte [PC-4+PC2PROTO(numparams)]
5940 | cmp NARGS:RD, RA // Check for missing parameters.
5943 if (op == BC_JFUNCF) {
5950 |3: // Clear missing parameters.
5951 | mov dword [BASE+NARGS:RD*8-4], LJ_TNIL
5962 | int3 // NYI: compiled vararg functions
5963 break; /* NYI: compiled vararg functions. */
5966 | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
5967 | lea RB, [NARGS:RD*8+FRAME_VARG]
5968 | lea RD, [BASE+NARGS:RD*8]
5969 | mov LFUNC:KBASE, [BASE-8]
5970 | mov [RD-4], RB // Store delta + FRAME_VARG.
5971 | mov [RD-8], LFUNC:KBASE // Store copy of LFUNC.
5974 | cmp RA, L:RB->maxstack
5975 | ja ->vm_growstack_v // Need to grow stack.
5978 | movzx RB, byte [PC-4+PC2PROTO(numparams)]
5981 |1: // Copy fixarg slots up to new frame.
5984 | jnb >3 // Less args than parameters?
5990 | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC).
5994 if (op == BC_JFUNCV) {
5998 | mov KBASE, [PC-4+PC2PROTO(k)]
6002 |3: // Clear missing parameters.
6003 | mov dword [RD+4], LJ_TNIL
6012 | ins_AD // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1
6013 | mov CFUNC:RB, [BASE-8]
6014 | mov KBASEa, CFUNC:RB->f
6016 | lea RD, [BASE+NARGS:RD*8-8]
6017 | mov L:RB->base, BASE
6018 | lea RA, [RD+8*LUA_MINSTACK]
6019 | cmp RA, L:RB->maxstack
6021 if (op == BC_FUNCC) {
6023 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
6030 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
6036 | ja ->vm_growstack_c // Need to grow stack.
6038 if (op == BC_FUNCC) {
6039 | call KBASEa // (lua_State *L)
6041 | // (lua_State *L, lua_CFunction f)
6042 | call aword [DISPATCH+DISPATCH_GL(wrapf)]
6044 | set_vmstate INTERP
6045 | // nresults returned in eax (RD).
6046 | mov BASE, L:RB->base
6047 | lea RA, [BASE+RD*8]
6049 | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8
6050 | mov PC, [BASE-4] // Fetch PC of caller.
6054 /* ---------------------------------------------------------------------- */
6057 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
6063 static int build_backend(BuildCtx *ctx)
6066 dasm_growpc(Dst, BC__MAX);
6067 build_subroutines(ctx);
6069 for (op = 0; op < BC__MAX; op++)
6070 build_ins(ctx, (BCOp)op, op);
6074 /* Emit pseudo frame-info for all assembler functions. */
6075 static void emit_asm_debug(BuildCtx *ctx)
6077 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
6081 #define REG_SP "0x7"
6082 #define REG_RA "0x10"
6086 #define REG_SP "0x4"
6087 #define REG_RA "0x8"
6089 switch (ctx->mode) {
6091 fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
6094 "\t.long .LECIE0-.LSCIE0\n"
6096 "\t.long 0xffffffff\n"
6100 "\t.sleb128 -" SZPTR "\n"
6101 "\t.byte " REG_RA "\n"
6102 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6103 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6104 "\t.align " SZPTR "\n"
6108 "\t.long .LEFDE0-.LASFDE0\n"
6110 "\t.long .Lframe0\n"
6114 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6115 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6116 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6117 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
6118 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
6122 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6123 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6124 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
6125 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
6126 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6128 "\t.align " SZPTR "\n"
6129 ".LEFDE0:\n\n", fcofs, CFRAME_SIZE);
6133 "\t.long .LEFDE1-.LASFDE1\n"
6135 "\t.long .Lframe0\n"
6137 "\t.quad lj_vm_ffi_call\n"
6139 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6140 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6141 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6142 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6144 "\t.long lj_vm_ffi_call\n"
6146 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6147 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6148 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6149 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6151 "\t.align " SZPTR "\n"
6152 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
6154 #if (defined(__sun__) && defined(__svr4__))
6156 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n");
6158 fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
6161 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
6165 "\t.long .LECIE1-.LSCIE1\n"
6169 "\t.string \"zPR\"\n"
6171 "\t.sleb128 -" SZPTR "\n"
6172 "\t.byte " REG_RA "\n"
6173 "\t.uleb128 6\n" /* augmentation length */
6174 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6175 "\t.long lj_err_unwind_dwarf-.\n"
6176 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6177 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6178 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6179 "\t.align " SZPTR "\n"
6183 "\t.long .LEFDE2-.LASFDE2\n"
6185 "\t.long .LASFDE2-.Lframe1\n"
6186 "\t.long .Lbegin-.\n"
6188 "\t.uleb128 0\n" /* augmentation length */
6189 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6191 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6192 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6193 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
6194 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
6196 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6197 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
6198 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
6199 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6201 "\t.align " SZPTR "\n"
6202 ".LEFDE2:\n\n", fcofs, CFRAME_SIZE);
6206 "\t.long .LECIE2-.LSCIE2\n"
6210 "\t.string \"zR\"\n"
6212 "\t.sleb128 -" SZPTR "\n"
6213 "\t.byte " REG_RA "\n"
6214 "\t.uleb128 1\n" /* augmentation length */
6215 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6216 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6217 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6218 "\t.align " SZPTR "\n"
6222 "\t.long .LEFDE3-.LASFDE3\n"
6224 "\t.long .LASFDE3-.Lframe2\n"
6225 "\t.long lj_vm_ffi_call-.\n"
6227 "\t.uleb128 0\n" /* augmentation length */
6229 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6230 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6231 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6232 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6234 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6235 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6236 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6237 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6239 "\t.align " SZPTR "\n"
6240 ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
6243 /* Mental note: never let Apple design an assembler.
6244 ** Or a linker. Or a plastic case. But I digress.
6246 case BUILD_machasm: {
6251 fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
6254 "\t.set L$set$x,LECIEX-LSCIEX\n"
6259 "\t.ascii \"zPR\\0\"\n"
6261 "\t.byte 128-" SZPTR "\n"
6262 "\t.byte " REG_RA "\n"
6263 "\t.byte 6\n" /* augmentation length */
6264 "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */
6266 "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n"
6267 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6268 "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
6270 "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n"
6271 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6272 "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */
6274 "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
6275 "\t.align " BSZPTR "\n"
6277 for (i = 0; i < ctx->nsym; i++) {
6278 const char *name = ctx->sym[i].name;
6279 int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
6280 if (size == 0) continue;
6282 if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; }
6287 "\t.set L$set$%d,LEFDE%d-LASFDE%d\n"
6288 "\t.long L$set$%d\n"
6290 "\t.long LASFDE%d-EH_frame1\n"
6293 "\t.byte 0\n" /* augmentation length */
6294 "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */
6296 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6297 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6298 "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
6299 "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
6301 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6302 "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
6303 "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
6304 "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
6306 "\t.align " BSZPTR "\n"
6308 name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
6314 "\t.set L$set$y,LECIEY-LSCIEY\n"
6319 "\t.ascii \"zR\\0\"\n"
6321 "\t.byte 128-" SZPTR "\n"
6322 "\t.byte " REG_RA "\n"
6323 "\t.byte 1\n" /* augmentation length */
6325 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6326 "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
6328 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6329 "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */
6331 "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
6332 "\t.align " BSZPTR "\n"
6335 "_lj_vm_ffi_call.eh:\n"
6337 "\t.set L$set$yy,LEFDEY-LASFDEY\n"
6338 "\t.long L$set$yy\n"
6340 "\t.long LASFDEY-EH_frame2\n"
6341 "\t.long _lj_vm_ffi_call-.\n"
6343 "\t.byte 0\n" /* augmentation length */
6345 "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */
6346 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6347 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6348 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6350 "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */
6351 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6352 "\t.byte 0xd\n\t.uleb128 0x4\n" /* def_cfa_register ebp */
6353 "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */
6355 "\t.align " BSZPTR "\n"
6356 "LEFDEY:\n\n", fcsize);
6360 fprintf(ctx->fp, "\t.subsections_via_symbols\n");
6363 "\t.non_lazy_symbol_pointer\n"
6364 "L_lj_err_unwind_dwarf$non_lazy_ptr:\n"
6365 ".indirect_symbol _lj_err_unwind_dwarf\n"
6370 default: /* Difficult for other modes. */