1 |// Low-level VM code for x86 CPUs.
2 |// Bytecode interpreter, fast functions and helper functions.
3 |// Copyright (C) 2005-2017 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
228 | sub rsp, CFRAME_SPACE
231 | push rbp; saveregs_
234 | add rsp, CFRAME_SPACE
238 | pop r14; pop r15; pop rbx; pop rbp
241 |//----- 16 byte aligned,
243 |.define SAVE_RET, aword [rsp+aword*11] //<-- rsp entering interpreter.
244 |.define SAVE_R4, aword [rsp+aword*10]
245 |.define SAVE_R3, aword [rsp+aword*9]
246 |.define SAVE_R2, aword [rsp+aword*8]
247 |.define SAVE_R1, aword [rsp+aword*7]
248 |.define SAVE_RU2, aword [rsp+aword*6]
249 |.define SAVE_RU1, aword [rsp+aword*5] //<-- rsp after register saves.
251 |.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter.
252 |.define SAVE_R4, aword [rsp+aword*8]
253 |.define SAVE_R3, aword [rsp+aword*7]
254 |.define SAVE_R2, aword [rsp+aword*6]
255 |.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves.
257 |.define SAVE_CFRAME, aword [rsp+aword*4]
258 |.define SAVE_PC, dword [rsp+dword*7]
259 |.define SAVE_L, dword [rsp+dword*6]
260 |.define SAVE_ERRF, dword [rsp+dword*5]
261 |.define SAVE_NRES, dword [rsp+dword*4]
262 |.define TMPa, aword [rsp+aword*1]
263 |.define TMP2, dword [rsp+dword*1]
264 |.define TMP1, dword [rsp] //<-- rsp while in interpreter.
265 |//----- 16 byte aligned
267 |// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).
268 |.define TMPQ, qword [rsp]
269 |.define TMP3, dword [rsp+aword*1]
270 |.define MULTRES, TMP2
274 |//-----------------------------------------------------------------------
276 |// Instruction headers.
277 |.macro ins_A; .endmacro
278 |.macro ins_AD; .endmacro
279 |.macro ins_AJ; .endmacro
280 |.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro
281 |.macro ins_AB_; movzx RB, RCH; .endmacro
282 |.macro ins_A_C; movzx RC, RCL; .endmacro
283 |.macro ins_AND; not RDa; .endmacro
285 |// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).
293 | jmp aword [DISPATCH+OP*8]
295 | jmp aword [DISPATCH+OP*4]
299 |// Instruction footer.
301 | // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
302 | .define ins_next, ins_NEXT
303 | .define ins_next_, ins_NEXT
305 | // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
306 | // Affects only certain kinds of benchmarks (and only with -j off).
307 | // Around 10%-30% slower on Core2, a lot more slower on P4.
317 |// Call decode and dispatch.
319 | // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC
320 | mov PC, LFUNC:RB->pc
326 | jmp aword [DISPATCH+OP*8]
328 | jmp aword [DISPATCH+OP*4]
333 | // BASE = new base, RB = LFUNC, RD = nargs+1
338 |//-----------------------------------------------------------------------
340 |// Macros to test operand types.
341 |.macro checktp, reg, tp; cmp dword [BASE+reg*8+4], tp; .endmacro
342 |.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro
343 |.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro
344 |.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro
345 |.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro
347 |// These operands must be used with movzx.
348 |.define PC_OP, byte [PC-4]
349 |.define PC_RA, byte [PC-3]
350 |.define PC_RB, byte [PC-1]
351 |.define PC_RC, byte [PC-2]
352 |.define PC_RD, word [PC-2]
354 |.macro branchPC, reg
355 | lea PC, [PC+reg*4-BCBIAS_J*4]
358 |// Assumes DISPATCH is relative to GL.
359 #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
360 #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
362 #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
364 |// Decrement hashed hotcount and trigger trace recorder if zero.
368 | and reg, HOTCOUNT_PCMASK
369 | sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP
376 | and reg, HOTCOUNT_PCMASK
377 | sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL
381 |// Set current VM state.
382 |.macro set_vmstate, st
383 | mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st
387 |.macro fcomparepp // Compare and pop st0 >< st1.
392 |.macro fdup; fld st0; .endmacro
393 |.macro fpop1; fstp st1; .endmacro
395 |// Synthesize SSE FP constants.
396 |.macro sseconst_abs, reg, tmp // Synthesize abs mask.
398 | mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp
400 | pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1
404 |.macro sseconst_hi, reg, tmp, val // Synthesize hi-32 bit const.
406 | mov64 tmp, U64x(val,00000000); movd reg, tmp
408 | mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51
412 |.macro sseconst_sign, reg, tmp // Synthesize sign mask.
413 | sseconst_hi reg, tmp, 80000000
415 |.macro sseconst_1, reg, tmp // Synthesize 1.0.
416 | sseconst_hi reg, tmp, 3ff00000
418 |.macro sseconst_m1, reg, tmp // Synthesize -1.0.
419 | sseconst_hi reg, tmp, bff00000
421 |.macro sseconst_2p52, reg, tmp // Synthesize 2^52.
422 | sseconst_hi reg, tmp, 43300000
424 |.macro sseconst_tobit, reg, tmp // Synthesize 2^52 + 2^51.
425 | sseconst_hi reg, tmp, 43380000
428 |// Move table write barrier back. Overwrites reg.
429 |.macro barrierback, tab, reg
430 | and byte tab->marked, (uint8_t)~LJ_GC_BLACK // black2gray(tab)
431 | mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]
432 | mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab
433 | mov tab->gclist, reg
436 |//-----------------------------------------------------------------------
438 /* Generate subroutines used by opcodes and other parts of the VM. */
439 /* The .code_sub section should be last to help static branch prediction. */
440 static void build_subroutines(BuildCtx *ctx)
444 |//-----------------------------------------------------------------------
445 |//-- Return handling ----------------------------------------------------
446 |//-----------------------------------------------------------------------
452 | // Return from pcall or xpcall fast func.
454 | sub BASE, PC // Restore caller base.
455 | lea RAa, [RA+PC-8] // Rebase RA and prepend one result.
456 | mov PC, [BASE-4] // Fetch PC of previous frame.
457 | // Prepending may overwrite the pcall frame, so do it at the end.
458 | mov dword [BASE+RA+4], LJ_TTRUE // Prepend true to results.
461 | add RD, 1 // RD = nresults+1
462 | jz ->vm_unwind_yield
464 | test PC, FRAME_TYPE
465 | jz ->BC_RET_Z // Handle regular return to Lua.
468 | // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return
470 | test PC, FRAME_TYPE
477 | neg PC // Previous base = BASE - delta.
481 |1: // Move results down.
488 | mov RB, [BASE+RA+4]
499 | mov RA, SAVE_NRES // RA = wanted nresults+1
502 | jne >6 // More/less results wanted?
505 | mov L:RB->top, BASE
508 | mov RAa, SAVE_CFRAME // Restore previous C frame.
509 | mov L:RB->cframe, RAa
510 | xor eax, eax // Ok return status for vm_pcall.
517 | jb >7 // Less results wanted?
518 | // More results wanted. Check stack size and fill up results with nil.
519 | cmp BASE, L:RB->maxstack
521 | mov dword [BASE-4], LJ_TNIL
526 |7: // Less results wanted.
528 | jz <5 // But check for LUA_MULTRET+1.
529 | sub RA, RD // Negative result!
530 | lea BASE, [BASE+RA*8] // Correct top.
533 |8: // Corner case: need to grow stack for filling up results.
534 | // This can happen if:
535 | // - A C function grows the stack (a lot).
536 | // - The GC shrinks the stack in between.
537 | // - A return back from a lua_call() with (high) nresults adjustment.
538 | mov L:RB->top, BASE // Save current top held in BASE (yes).
539 | mov MULTRES, RD // Need to fill only remainder with nil.
542 | call extern lj_state_growstack@8 // (lua_State *L, int n)
543 | mov BASE, L:RB->top // Need the (realloced) L->top in BASE.
548 | jmp ->vm_unwind_c_eh
550 |->vm_unwind_c@8: // Unwind C stack, return from vm_pcall.
551 | // (void *cframe, int errcode)
553 | mov eax, CARG2d // Error return status for vm_pcall.
556 | mov eax, FCARG2 // Error return status for vm_pcall.
559 |->vm_unwind_c_eh: // Landing pad for external unwinder.
561 | mov GL:RB, L:RB->glref
562 | mov dword GL:RB->vmstate, ~LJ_VMST_C
565 |->vm_unwind_rethrow:
566 |.if X64 and not X64WIN
570 | jmp extern lj_err_throw@8 // (lua_State *L, int errcode)
573 |->vm_unwind_ff@4: // Unwind C stack, return from ff pcall.
576 | and CARG1, CFRAME_RAWMASK
579 | and FCARG1, CFRAME_RAWMASK
582 |->vm_unwind_ff_eh: // Landing pad for external unwinder.
584 | mov RAa, -8 // Results start at BASE+RA = BASE-8.
585 | mov RD, 1+1 // Really 1+2 results, incr. later.
586 | mov BASE, L:RB->base
587 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
588 | add DISPATCH, GG_G2DISP
589 | mov PC, [BASE-4] // Fetch PC of previous frame.
590 | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message.
592 | jmp ->vm_returnc // Increments RD/MULTRES and returns.
594 |//-----------------------------------------------------------------------
595 |//-- Grow stack for calls -----------------------------------------------
596 |//-----------------------------------------------------------------------
598 |->vm_growstack_c: // Grow stack for C function.
599 | mov FCARG2, LUA_MINSTACK
602 |->vm_growstack_v: // Grow stack for vararg Lua function.
606 |->vm_growstack_f: // Grow stack for fixarg Lua function.
607 | // BASE = new base, RD = nargs+1, RB = L, PC = first PC
608 | lea RD, [BASE+NARGS:RD*8-8]
610 | movzx RA, byte [PC-4+PC2PROTO(framesize)]
611 | add PC, 4 // Must point after first instruction.
612 | mov L:RB->base, BASE
617 | // RB = L, L->base = new base, L->top = top
619 | call extern lj_state_growstack@8 // (lua_State *L, int n)
620 | mov BASE, L:RB->base
622 | mov LFUNC:RB, [BASE-8]
626 | // BASE = new base, RB = LFUNC, RD = nargs+1
627 | ins_callt // Just retry the call.
629 |//-----------------------------------------------------------------------
630 |//-- Entry points into the assembler VM ---------------------------------
631 |//-----------------------------------------------------------------------
633 |->vm_resume: // Setup C frame and resume thread.
634 | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
637 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
642 | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
646 | lea KBASEa, [esp+CFRAME_RESUME]
647 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
648 | add DISPATCH, GG_G2DISP
649 | mov L:RB->cframe, KBASEa
650 | mov SAVE_PC, RD // Any value outside of bytecode is ok.
651 | mov SAVE_CFRAME, RDa
656 | cmp byte L:RB->status, RDL
657 | je >3 // Initial resume (like a call).
659 | // Resume after yield (like a return).
661 | mov byte L:RB->status, RDL
662 | mov BASE, L:RB->base
666 | add RD, 1 // RD = nresults+1
667 | sub RA, BASE // RA = resultofs
670 | test PC, FRAME_TYPE
674 |->vm_pcall: // Setup protected C frame and enter VM.
675 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
679 | mov SAVE_ERRF, CARG4d
683 |->vm_call: // Setup C frame and enter VM.
684 | // (lua_State *L, TValue *base, int nres1)
688 |1: // Entry point for vm_pcall above (PC = ftype).
690 | mov SAVE_NRES, CARG3d
691 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
696 | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
699 | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
700 | mov SAVE_CFRAME, KBASEa
701 | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
703 | mov L:RB->cframe, rsp
705 | mov L:RB->cframe, esp
708 |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype).
709 | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
710 | add DISPATCH, GG_G2DISP
712 |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype).
714 | mov BASE, L:RB->base // BASE = old base (used in vmeta_call).
716 | sub PC, BASE // PC = frame delta + frame type
721 | add NARGS:RD, 1 // RD = nargs+1
724 | mov LFUNC:RB, [RA-8]
725 | cmp dword [RA-4], LJ_TFUNC
726 | jne ->vmeta_call // Ensure KBASE defined and != BASE.
728 |->vm_call_dispatch_f:
731 | // BASE = new base, RB = func, RD = nargs+1, PC = caller PC
733 |->vm_cpcall: // Setup protected C frame, call C.
734 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
737 | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
741 | // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap!
742 | mov RC, INARG_CP_UD // Get args before they are overwritten.
743 | mov RA, INARG_CP_FUNC
744 | mov BASE, INARG_CP_CALL
746 | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
748 | mov KBASE, L:RB->stack // Compute -savestack(L, L->top).
749 | sub KBASE, L:RB->top
750 | mov SAVE_ERRF, 0 // No error function.
751 | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame.
752 | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).
755 | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
756 | mov SAVE_CFRAME, KBASEa
757 | mov L:RB->cframe, rsp
759 | call CARG4 // (lua_State *L, lua_CFunction func, void *ud)
761 | mov ARG3, RC // Have to copy args downwards.
765 | mov KBASE, L:RB->cframe // Add our C frame to cframe chain.
766 | mov SAVE_CFRAME, KBASE
767 | mov L:RB->cframe, esp
769 | call BASE // (lua_State *L, lua_CFunction func, void *ud)
771 | // TValue * (new base) or NULL returned in eax (RC).
773 | jz ->vm_leave_cp // No base? Just remove C frame.
776 | jmp <2 // Else continue with the call.
778 |//-----------------------------------------------------------------------
779 |//-- Metamethod handling ------------------------------------------------
780 |//-----------------------------------------------------------------------
782 |//-- Continuation dispatch ----------------------------------------------
785 | // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)
789 | sub BASE, PC // Restore caller BASE.
790 | mov dword [RA+RD*8-4], LJ_TNIL // Ensure one valid arg.
791 | mov RC, RA // ... in [RC]
792 | mov PC, [RB-12] // Restore PC from [cont|PC].
794 | movsxd RAa, dword [RB-16] // May be negative on WIN64 with debug.
799 | lea KBASEa, qword [=>0]
802 | mov RA, dword [RB-16]
808 | mov LFUNC:KBASE, [BASE-8]
809 | mov KBASE, LFUNC:KBASE->pc
810 | mov KBASE, [KBASE+PC2PROTO(k)]
811 | // BASE = base, RC = result, RB = meta base
812 | jmp RAa // Jump to continuation.
816 | je ->cont_ffi_callback // cont = 1: return from FFI callback.
817 | // cont = 0: Tail call from C function.
824 |->cont_cat: // BASE = base, RC = result, RB = mbase
827 | lea RA, [BASE+RA*8]
834 | mov L:CARG1d, SAVE_L
835 | mov L:CARG1d->base, BASE
840 | mov L:CARG1d, SAVE_L
841 | mov L:CARG1d->base, BASE
856 |//-- Table indexing metamethods -----------------------------------------
859 | mov TMP1, RC // RC = GCstr *
861 | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
864 | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
865 | mov [RA], TAB:RB // RB = GCtab *
866 | mov dword [RA+4], LJ_TTAB
873 | mov TMP2, LJ_TISNUM
883 | lea RCa, TMPQ // Store temp. TValue in TMPQ.
887 | movzx RC, PC_RC // Reload TValue *k from RC.
888 | lea RC, [BASE+RC*8]
890 | movzx RB, PC_RB // Reload TValue *t from RB.
891 | lea RB, [BASE+RB*8]
894 | mov L:CARG1d, SAVE_L
895 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
897 | mov CARG3, RCa // May be 64 bit ptr to stack.
904 | mov L:RB->base, BASE
907 | call extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
908 | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
909 | mov BASE, L:RB->base
912 |->cont_ra: // BASE = base, RC = result
916 | mov [BASE+RA*8], RBa
920 | mov [BASE+RA*8+4], RB
921 | mov [BASE+RA*8], RC
925 |3: // Call __index metamethod.
926 | // BASE = base, L->top = new base, stack = cont/func/t/k
928 | mov [RA-12], PC // [cont|PC]
929 | lea PC, [RA+FRAME_CONT]
931 | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
932 | mov NARGS:RD, 2+1 // 2 args for func(t, k).
933 | jmp ->vm_call_dispatch_f
935 |//-----------------------------------------------------------------------
938 | mov TMP1, RC // RC = GCstr *
940 | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
943 | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
944 | mov [RA], TAB:RB // RB = GCtab *
945 | mov dword [RA+4], LJ_TTAB
952 | mov TMP2, LJ_TISNUM
962 | lea RCa, TMPQ // Store temp. TValue in TMPQ.
966 | movzx RC, PC_RC // Reload TValue *k from RC.
967 | lea RC, [BASE+RC*8]
969 | movzx RB, PC_RB // Reload TValue *t from RB.
970 | lea RB, [BASE+RB*8]
973 | mov L:CARG1d, SAVE_L
974 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
976 | mov CARG3, RCa // May be 64 bit ptr to stack.
983 | mov L:RB->base, BASE
986 | call extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
987 | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
988 | mov BASE, L:RB->base
991 | // NOBARRIER: lj_meta_tset ensures the table is not black.
994 | mov RBa, [BASE+RA*8]
997 | mov RB, [BASE+RA*8+4]
998 | mov RA, [BASE+RA*8]
1002 |->cont_nop: // BASE = base, (RC = result)
1005 |3: // Call __newindex metamethod.
1006 | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
1008 | mov [RA-12], PC // [cont|PC]
1010 | // Copy value to third argument.
1012 | mov RBa, [BASE+RC*8]
1015 | mov RB, [BASE+RC*8+4]
1016 | mov RC, [BASE+RC*8]
1020 | lea PC, [RA+FRAME_CONT]
1022 | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
1023 | mov NARGS:RD, 3+1 // 3 args for func(t, k, v).
1024 | jmp ->vm_call_dispatch_f
1026 |//-- Comparison metamethods ---------------------------------------------
1031 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d == BASE.
1033 | lea CARG3d, [BASE+RD*8]
1034 | lea CARG2d, [BASE+RA*8]
1036 | lea CARG2d, [BASE+RA*8]
1037 | lea CARG3d, [BASE+RD*8]
1039 | mov CARG1d, L:RB // Caveat: CARG1d/CARG4d == RA.
1040 | movzx CARG4d, PC_OP
1043 | lea RD, [BASE+RD*8]
1044 | lea RA, [BASE+RA*8]
1050 | mov L:RB->base, BASE
1053 | call extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
1054 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1056 | mov BASE, L:RB->base
1068 |->cont_condt: // BASE = base, RC = result
1070 | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is true.
1074 |->cont_condf: // BASE = base, RC = result
1075 | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is false.
1084 | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
1086 | mov CARG1d, L:RB // Caveat: CARG1d == RA.
1089 | mov CARG4d, RB // Caveat: CARG4d == RA.
1091 | mov L:RB->base, BASE // Caveat: CARG3d == BASE.
1100 | mov L:RB->base, BASE
1103 | call extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
1104 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1111 | mov L:RB->base, BASE
1113 | mov FCARG2, dword [PC-4]
1115 | call extern lj_meta_equal_cd@8 // (lua_State *L, BCIns ins)
1116 | // 0/1 or TValue * (metamethod) returned in eax (RC).
1120 |//-- Arithmetic metamethods ---------------------------------------------
1127 | lea RC, [KBASE+RC*8]
1135 | lea RC, [KBASE+RC*8]
1136 | lea RB, [BASE+RB*8]
1141 | lea RC, [BASE+RD*8]
1150 | lea RC, [BASE+RC*8]
1152 | lea RB, [BASE+RB*8]
1154 | lea RA, [BASE+RA*8]
1161 | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
1163 | mov CARG1d, L:RB // Caveat: CARG1d == RA.
1165 | movzx CARG5d, PC_OP
1167 | mov CARG4d, RC // Caveat: CARG4d == RA.
1168 | mov L:CARG1d, SAVE_L
1169 | mov L:CARG1d->base, BASE // Caveat: CARG3d == BASE.
1171 | mov L:RB, L:CARG1d
1180 | mov L:RB->base, BASE
1183 | call extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
1184 | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
1185 | mov BASE, L:RB->base
1189 | // Call metamethod for binary op.
1191 | // BASE = base, RC = new base, stack = cont/func/o1/o2
1194 | mov [RA-12], PC // [cont|PC]
1195 | lea PC, [RC+FRAME_CONT]
1196 | mov NARGS:RD, 2+1 // 2 args for func(o1, o2).
1197 | jmp ->vm_call_dispatch
1201 | mov L:RB->base, BASE
1202 | lea FCARG2, [BASE+RD*8] // Caveat: FCARG2 == BASE
1203 | mov L:FCARG1, L:RB
1205 | call extern lj_meta_len@8 // (lua_State *L, TValue *o)
1206 | // NULL (retry) or TValue * (metamethod) returned in eax (RC).
1207 | mov BASE, L:RB->base
1210 | jne ->vmeta_binop // Binop call for compatibility.
1212 | mov TAB:FCARG1, [BASE+RD*8]
1215 | jmp ->vmeta_binop // Binop call for compatibility.
1218 |//-- Call metamethod ----------------------------------------------------
1221 | lea RA, [BASE+RA*8+8]
1222 |->vmeta_call: // Resolve and call __call metamethod.
1223 | // BASE = old base, RA = new base, RC = nargs+1, PC = return
1224 | mov TMP2, RA // Save RA, RC for us.
1225 | mov TMP1, NARGS:RD
1229 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
1231 | lea CARG3d, [RA+NARGS:RD*8]
1232 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
1234 | lea RC, [RA+NARGS:RD*8]
1239 | mov L:RB->base, BASE // This is the callers base!
1242 | call extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
1243 | mov BASE, L:RB->base
1245 | mov NARGS:RD, TMP1
1246 | mov LFUNC:RB, [RA-8]
1248 | // This is fragile. L->base must not move, KBASE must always be defined.
1249 | cmp KBASE, BASE // Continue with CALLT if flag set.
1252 | ins_call // Otherwise call resolved metamethod.
1254 |//-- Argument coercion for 'for' statement ------------------------------
1258 | mov L:RB->base, BASE
1259 | mov FCARG2, RA // Caveat: FCARG2 == BASE
1260 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
1262 | call extern lj_meta_for@8 // (lua_State *L, TValue *base)
1263 | mov BASE, L:RB->base
1269 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Retry FORI or JFORI.
1271 | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Retry FORI or JFORI.
1274 |//-----------------------------------------------------------------------
1275 |//-- Fast functions -----------------------------------------------------
1276 |//-----------------------------------------------------------------------
1278 |.macro .ffunc, name
1282 |.macro .ffunc_1, name
1284 | cmp NARGS:RD, 1+1; jb ->fff_fallback
1287 |.macro .ffunc_2, name
1289 | cmp NARGS:RD, 2+1; jb ->fff_fallback
1292 |.macro .ffunc_n, name
1294 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1298 |.macro .ffunc_n, name, op
1300 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1305 |.macro .ffunc_nsse, name, op
1307 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1308 | op xmm0, qword [BASE]
1311 |.macro .ffunc_nsse, name
1312 | .ffunc_nsse name, movsd
1315 |.macro .ffunc_nn, name
1317 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1318 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1320 | fld qword [BASE+8]
1323 |.macro .ffunc_nnsse, name
1325 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1326 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1327 | movsd xmm0, qword [BASE]
1328 | movsd xmm1, qword [BASE+8]
1331 |.macro .ffunc_nnr, name
1333 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1334 | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
1335 | fld qword [BASE+8]
1339 |// Inlined GC threshold check. Caveat: uses label 1.
1341 | mov RB, [DISPATCH+DISPATCH_GL(gc.total)]
1342 | cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]
1348 |//-- Base library: checks -----------------------------------------------
1352 | cmp RB, LJ_TISTRUECOND; jae ->fff_fallback
1391 | mov CFUNC:RB, [BASE-8]
1392 | mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]
1394 | mov dword [BASE-4], LJ_TSTR
1395 | mov [BASE-8], STR:RC
1399 | mov RC, ~LJ_TLIGHTUD
1403 |//-- Base library: getters and setters ---------------------------------
1405 |.ffunc_1 getmetatable
1408 | cmp RB, LJ_TTAB; jne >6
1409 |1: // Field metatable must be at same offset for GCtab and GCudata!
1410 | mov TAB:RB, [BASE]
1411 | mov TAB:RB, TAB:RB->metatable
1413 | test TAB:RB, TAB:RB
1414 | mov dword [BASE-4], LJ_TNIL
1416 | mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)]
1417 | mov dword [BASE-4], LJ_TTAB // Store metatable as default result.
1418 | mov [BASE-8], TAB:RB
1419 | mov RA, TAB:RB->hmask
1420 | and RA, STR:RC->hash
1422 | add NODE:RA, TAB:RB->node
1423 |3: // Rearranged logic, because we expect _not_ to find the key.
1424 | cmp dword NODE:RA->key.it, LJ_TSTR
1426 | cmp dword NODE:RA->key.gcr, STR:RC
1429 | mov NODE:RA, NODE:RA->next
1430 | test NODE:RA, NODE:RA
1432 | jmp ->fff_res1 // Not found, keep default result.
1435 | cmp RB, LJ_TNIL; je ->fff_res1 // Ditto for nil value.
1437 | mov [BASE-4], RB // Return value of mt.__metatable.
1442 | cmp RB, LJ_TUDATA; je <1
1444 | cmp RB, LJ_TNUMX; ja >8
1445 | cmp RB, LJ_TISNUM; jbe >7
1446 | mov RB, LJ_TLIGHTUD
1450 | cmp RB, LJ_TISNUM; ja >8
1455 | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]
1458 |.ffunc_2 setmetatable
1459 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1460 | // Fast path: no mt for table yet and not clearing the mt.
1461 | mov TAB:RB, [BASE]
1462 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1463 | cmp dword [BASE+12], LJ_TTAB; jne ->fff_fallback
1464 | mov TAB:RC, [BASE+8]
1465 | mov TAB:RB->metatable, TAB:RC
1467 | mov dword [BASE-4], LJ_TTAB // Return original table.
1468 | mov [BASE-8], TAB:RB
1469 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
1471 | // Possible write barrier. Table is black, but skip iswhite(mt) check.
1472 | barrierback TAB:RB, RC
1477 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1479 | mov RB, BASE // Save BASE.
1480 | lea CARG3d, [BASE+8]
1481 | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
1482 | mov CARG1d, SAVE_L
1484 | mov RB, BASE // Save BASE.
1485 | mov CARG2d, [BASE]
1486 | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
1487 | mov CARG1d, SAVE_L
1489 | mov TAB:RD, [BASE]
1493 | mov RB, BASE // Save BASE.
1497 | call extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
1498 | // cTValue * returned in eax (RD).
1499 | mov BASE, RB // Restore BASE.
1500 | // Copy table slot.
1514 |//-- Base library: conversions ------------------------------------------
1517 | // Only handles the number case inline (without a base argument).
1518 | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
1519 | cmp dword [BASE+4], LJ_TISNUM
1522 | mov RB, dword [BASE]; jmp ->fff_resi
1526 | jae ->fff_fallback
1529 | movsd xmm0, qword [BASE]; jmp ->fff_resxmm0
1531 | fld qword [BASE]; jmp ->fff_resn
1535 | // Only handles the string or number case inline.
1537 | cmp dword [BASE+4], LJ_TSTR; jne >3
1538 | // A __tostring method in the string base metatable is ignored.
1539 | mov STR:RD, [BASE]
1541 | mov dword [BASE-4], LJ_TSTR
1542 | mov [BASE-8], STR:RD
1544 |3: // Handle numbers inline, unless a number base metatable is present.
1545 | cmp dword [BASE+4], LJ_TISNUM; ja ->fff_fallback
1546 | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0
1547 | jne ->fff_fallback
1548 | ffgccheck // Caveat: uses label 1.
1550 | mov L:RB->base, BASE // Add frame since C call can throw.
1551 | mov SAVE_PC, PC // Redundant (but a defined value).
1552 |.if X64 and not X64WIN
1553 | mov FCARG2, BASE // Otherwise: FCARG2 == BASE
1555 | mov L:FCARG1, L:RB
1557 | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o)
1559 | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np)
1561 | // GCstr returned in eax (RD).
1562 | mov BASE, L:RB->base
1565 |//-- Base library: iterators -------------------------------------------
1568 | je >2 // Missing 2nd arg?
1570 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1572 | mov L:RB->base, BASE // Add frame since C call can throw.
1573 | mov L:RB->top, BASE // Dummy frame length is ok.
1576 | lea CARG3d, [BASE+8]
1577 | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
1580 | mov CARG2d, [BASE]
1581 | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
1584 | mov TAB:RD, [BASE]
1590 | mov SAVE_PC, PC // Needed for ITERN fallback.
1591 | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
1592 | // Flag returned in eax (RD).
1593 | mov BASE, L:RB->base
1594 | test RD, RD; jz >3 // End of traversal?
1595 | // Copy key and value to results.
1598 | mov RDa, [BASE+16]
1614 |2: // Set missing 2nd arg to nil.
1615 | mov dword [BASE+12], LJ_TNIL
1617 |3: // End of traversal: return nil.
1618 | mov dword [BASE-4], LJ_TNIL
1622 | mov TAB:RB, [BASE]
1623 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1625 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1627 | mov CFUNC:RB, [BASE-8]
1628 | mov CFUNC:RD, CFUNC:RB->upvalue[0]
1630 | mov dword [BASE-4], LJ_TFUNC
1631 | mov [BASE-8], CFUNC:RD
1632 | mov dword [BASE+12], LJ_TNIL
1636 |.ffunc_2 ipairs_aux
1637 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1638 | cmp dword [BASE+12], LJ_TISNUM
1640 | jne ->fff_fallback
1642 | jae ->fff_fallback
1646 | mov RD, dword [BASE+8]
1648 | mov dword [BASE-4], LJ_TISNUM
1649 | mov dword [BASE-8], RD
1651 | movsd xmm0, qword [BASE+8]
1652 | sseconst_1 xmm1, RBa
1655 | movsd qword [BASE-8], xmm0
1657 | fld qword [BASE+8]
1661 | fstp qword [BASE-8]
1664 | mov TAB:RB, [BASE]
1665 | cmp RD, TAB:RB->asize; jae >2 // Not in array part?
1667 | add RD, TAB:RB->array
1669 | cmp dword [RD+4], LJ_TNIL; je ->fff_res0
1670 | // Copy array slot.
1681 |2: // Check for empty hash part first. Otherwise call C function.
1682 | cmp dword TAB:RB->hmask, 0; je ->fff_res0
1683 | mov FCARG1, TAB:RB
1684 | mov RB, BASE // Save BASE.
1685 | mov FCARG2, RD // Caveat: FCARG2 == BASE
1686 | call extern lj_tab_getinth@8 // (GCtab *t, int32_t key)
1687 | // cTValue * or NULL returned in eax (RD).
1696 | mov TAB:RB, [BASE]
1697 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
1699 | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
1701 | mov CFUNC:RB, [BASE-8]
1702 | mov CFUNC:RD, CFUNC:RB->upvalue[0]
1704 | mov dword [BASE-4], LJ_TFUNC
1705 | mov [BASE-8], CFUNC:RD
1707 | mov dword [BASE+12], LJ_TISNUM
1708 | mov dword [BASE+8], 0
1711 | movsd qword [BASE+8], xmm0
1714 | fstp qword [BASE+8]
1719 |//-- Base library: catch errors ----------------------------------------
1724 | mov PC, 8+FRAME_PCALL
1726 | movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)]
1727 | shr RB, HOOK_ACTIVE_SHIFT
1729 | add PC, RB // Remember active hook before pcall.
1730 | jmp ->vm_call_dispatch
1733 | cmp dword [BASE+12], LJ_TFUNC; jne ->fff_fallback
1734 | mov RB, [BASE+4] // Swap function and traceback.
1736 | mov dword [BASE+4], LJ_TFUNC
1737 | mov LFUNC:RB, [BASE]
1739 | mov [BASE+8], LFUNC:RB
1743 | mov PC, 16+FRAME_PCALL
1746 |//-- Coroutine library --------------------------------------------------
1748 |.macro coroutine_resume_wrap, resume
1750 |.ffunc_1 coroutine_resume
1753 |.ffunc coroutine_wrap_aux
1754 | mov CFUNC:RB, [BASE-8]
1755 | mov L:RB, CFUNC:RB->upvalue[0].gcr
1765 | cmp dword [BASE+4], LJ_TTHREAD; jne ->fff_fallback
1767 | cmp aword L:RB->cframe, 0; jne ->fff_fallback
1768 | cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback
1770 | je >1 // Status != LUA_YIELD (i.e. 0)?
1771 | cmp RA, L:RB->base // Check for presence of initial func.
1775 | lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread).
1777 | lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1).
1779 | cmp PC, L:RB->maxstack; ja ->fff_fallback
1783 | mov L:RB->base, BASE
1785 | add BASE, 8 // Keep resumed thread in stack for GC.
1787 | mov L:RB->top, BASE
1789 | lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move.
1791 | lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move.
1793 | sub RBa, PCa // Relative to PC.
1797 |2: // Move args to coroutine.
1820 | call ->vm_resume // (lua_State *L, TValue *base, 0, 0)
1821 | set_vmstate INTERP
1827 | mov L:PC, ARG1 // The callee doesn't modify SAVE_L.
1829 | mov BASE, L:RB->base
1830 | cmp eax, LUA_YIELD
1833 | mov RA, L:PC->base
1834 | mov KBASE, L:PC->top
1835 | mov L:PC->top, RA // Clear coroutine stack.
1838 | je >6 // No results?
1841 | cmp RD, L:RB->maxstack
1842 | ja >9 // Need to grow stack?
1846 |5: // Move results from coroutine.
1861 | lea RD, [PC+2] // nresults+1 = 1 + true + results.
1862 | mov dword [BASE-4], LJ_TTRUE // Prepend true to results.
1864 | lea RD, [PC+1] // nresults+1 = 1 + results.
1874 | test PC, FRAME_TYPE
1878 |8: // Coroutine returned with error (at co->top-1).
1880 | mov dword [BASE-4], LJ_TFALSE // Prepend false to results.
1883 | mov L:PC->top, RA // Clear error from coroutine stack.
1884 | // Copy error message.
1894 | mov RD, 1+2 // nresults+1 = 1 + false + error.
1899 | call extern lj_ffh_coroutine_wrap_err@8 // (lua_State *L, lua_State *co)
1900 | // Error function does not return.
1903 |9: // Handle stack expansion on return from yield.
1907 | mov L:RA, ARG1 // The callee doesn't modify SAVE_L.
1909 | mov L:RA->top, KBASE // Undo coroutine stack clearing.
1912 | call extern lj_state_growstack@8 // (lua_State *L, int n)
1918 | mov BASE, L:RB->base
1919 | jmp <4 // Retry the stack move.
1922 | coroutine_resume_wrap 1 // coroutine.resume
1923 | coroutine_resume_wrap 0 // coroutine.wrap
1925 |.ffunc coroutine_yield
1927 | test aword L:RB->cframe, CFRAME_RESUME
1929 | mov L:RB->base, BASE
1930 | lea RD, [BASE+NARGS:RD*8-8]
1933 | mov aword L:RB->cframe, RDa
1935 | mov byte L:RB->status, al
1936 | jmp ->vm_leave_unw
1938 |//-- Math library -------------------------------------------------------
1941 |->fff_resi: // Dummy.
1947 | fstp qword [BASE-8]
1953 | cmp dword [BASE+4], LJ_TISNUM; jne >2
1954 | mov RB, dword [BASE]
1955 | cmp RB, 0; jns ->fff_resi
1960 | mov dword [BASE-4], LJ_TISNUM
1961 | mov dword [BASE-8], RB
1965 | mov dword [BASE-4], 0x41e00000 // 2^31.
1966 | mov dword [BASE-8], 0
1971 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
1975 | movsd xmm0, qword [BASE]
1976 | sseconst_abs xmm1, RDa
1980 | movsd qword [BASE-8], xmm0
1986 |->fff_resxmm0: // Dummy.
1989 | fstp qword [BASE-8]
1997 | test PC, FRAME_TYPE
2000 | cmp PC_RB, RDL // More results expected?
2002 | // Adjust BASE. KBASE is assumed to be set for the calling frame.
2004 | not RAa // Note: ~RA = -(RA+1)
2005 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
2008 |6: // Fill up results with nil.
2009 | mov dword [BASE+RD*8-12], LJ_TNIL
2013 |7: // Non-standard return case.
2014 | mov RAa, -8 // Results start at BASE+RA = BASE-8.
2017 |.macro math_round, func
2018 | .ffunc math_ .. func
2020 | cmp dword [BASE+4], LJ_TISNUM; jne >1
2021 | mov RB, dword [BASE]; jmp ->fff_resi
2025 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
2028 | movsd xmm0, qword [BASE]
2029 | call ->vm_ .. func
2032 | cmp RB, 0x80000000
2035 | ucomisd xmm0, xmm1
2042 | call ->vm_ .. func
2046 | cmp RB, 0x80000000; jne >2
2065 |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0
2067 |.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn
2071 | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
2072 | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
2073 | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn
2075 |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn
2076 |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn
2078 |.ffunc_n math_sin; fsin; jmp ->fff_resn
2079 |.ffunc_n math_cos; fcos; jmp ->fff_resn
2080 |.ffunc_n math_tan; fptan; fpop; jmp ->fff_resn
2083 | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fpatan
2086 | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fxch; fpatan
2088 |.ffunc_n math_atan; fld1; fpatan; jmp ->fff_resn
2090 |.macro math_extern, func
2092 | .ffunc_nsse math_ .. func
2094 | movsd FPARG1, xmm0
2097 | .ffunc_n math_ .. func
2101 | call extern lj_vm_ .. func
2116 |.ffunc_nsse math_rad
2117 | mov CFUNC:RB, [BASE-8]
2118 | mulsd xmm0, qword CFUNC:RB->upvalue[0]
2122 | mov CFUNC:RB, [BASE-8]
2123 | fmul qword CFUNC:RB->upvalue[0]
2127 |.ffunc_nn math_atan2; fpatan; jmp ->fff_resn
2128 |.ffunc_nnr math_ldexp; fscale; fpop1; jmp ->fff_resn
2130 |.ffunc_1 math_frexp
2132 | cmp RB, LJ_TISNUM; jae ->fff_fallback
2135 | mov [BASE-4], RB; mov [BASE-8], RC
2136 | shl RB, 1; cmp RB, 0xffe00000; jae >3
2139 | cmp RB, 0x00200000; jb >4
2141 | shr RB, 21; sub RB, RC // Extract and unbias exponent.
2145 | mov TMP1, RB; fild TMP1
2148 | and RB, 0x800fffff // Mask off exponent.
2149 | or RB, 0x3fe00000 // Put mantissa in range [0.5,1) or 0.
2153 | movsd qword [BASE], xmm0
2159 |3: // Return +-0, +-Inf, NaN unmodified and an exponent of 0.
2161 | xorps xmm0, xmm0; jmp <2
2165 |4: // Handle denormals by multiplying with 2^54 and adjusting the bias.
2167 | movsd xmm0, qword [BASE]
2168 | sseconst_hi xmm1, RBa, 43500000 // 2^54.
2170 | movsd qword [BASE-8], xmm0
2173 | mov TMP1, 0x5a800000; fmul TMP1 // x = x*2^54
2174 | fstp qword [BASE-8]
2176 | mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1
2179 |.ffunc_nsse math_modf
2185 | shl RB, 1; cmp RB, 0xffe00000; je >4 // +-Inf?
2191 | movsd qword [BASE-8], xmm0
2192 | movsd qword [BASE], xmm4
2198 | fstp qword [BASE-8]
2201 | mov RC, [BASE-4]; mov RB, [BASE+4]
2202 | xor RC, RB; js >3 // Need to adjust sign?
2207 | xor RB, 0x80000000; mov [BASE+4], RB // Flip sign of fraction.
2211 | xorps xmm4, xmm4; jmp <1 // Return +-Inf and +-0.
2213 | fldz; fxch; jmp <1 // Return +-Inf and +-0.
2216 |.ffunc_nnr math_fmod
2217 |1: ; fprem; fnstsw ax; and ax, 0x400; jnz <1
2222 |.ffunc_nnsse math_pow; call ->vm_pow; jmp ->fff_resxmm0
2224 |.ffunc_nn math_pow; call ->vm_pow; jmp ->fff_resn
2227 |.macro math_minmax, name, cmovop, fcmovop, sseop
2230 | cmp dword [BASE+4], LJ_TISNUM
2233 | mov RB, dword [BASE]
2234 |1: // Handle integers.
2235 | cmp RA, RD; jae ->fff_resi
2236 | cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3
2237 | cmp RB, dword [BASE+RA*8-8]
2238 | cmovop RB, dword [BASE+RA*8-8]
2243 | // Convert intermediate result to number and continue below.
2254 | jae ->fff_fallback
2258 | movsd xmm0, qword [BASE]
2259 |5: // Handle numbers or integers.
2260 | cmp RA, RD; jae ->fff_resxmm0
2261 | cmp dword [BASE+RA*8-4], LJ_TISNUM
2265 | cvtsi2sd xmm1, dword [BASE+RA*8-8]
2268 | jae ->fff_fallback
2271 | movsd xmm1, qword [BASE+RA*8-8]
2278 |5: // Handle numbers or integers.
2279 | cmp RA, RD; jae ->fff_resn
2280 | cmp dword [BASE+RA*8-4], LJ_TISNUM
2284 | fild dword [BASE+RA*8-8]
2290 | fld qword [BASE+RA*8-8]
2292 | fucomi st1; fcmovop st1; fpop1
2298 | math_minmax math_min, cmovg, fcmovnbe, minsd
2299 | math_minmax math_max, cmovl, fcmovbe, maxsd
2302 | fpop; jmp ->fff_fallback
2305 |//-- String library -----------------------------------------------------
2307 |.ffunc_1 string_len
2308 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2309 | mov STR:RB, [BASE]
2311 | mov RB, dword STR:RB->len; jmp ->fff_resi
2313 | cvtsi2sd xmm0, dword STR:RB->len; jmp ->fff_resxmm0
2315 | fild dword STR:RB->len; jmp ->fff_resn
2318 |.ffunc string_byte // Only handle the 1-arg case here.
2319 | cmp NARGS:RD, 1+1; jne ->fff_fallback
2320 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2321 | mov STR:RB, [BASE]
2323 | cmp dword STR:RB->len, 1
2324 | jb ->fff_res0 // Return no results for empty string.
2325 | movzx RB, byte STR:RB[1]
2329 | cvtsi2sd xmm0, RB; jmp ->fff_resxmm0
2331 | mov TMP1, RB; fild TMP1; jmp ->fff_resn
2334 |.ffunc string_char // Only handle the 1-arg case here.
2336 | cmp NARGS:RD, 1+1; jne ->fff_fallback // *Exactly* 1 arg.
2337 | cmp dword [BASE+4], LJ_TISNUM
2339 | jne ->fff_fallback
2340 | mov RB, dword [BASE]
2341 | cmp RB, 255; ja ->fff_fallback
2344 | jae ->fff_fallback
2345 | cvttsd2si RB, qword [BASE]
2346 | cmp RB, 255; ja ->fff_fallback
2349 | jae ->fff_fallback
2352 | cmp TMP2, 255; ja ->fff_fallback
2359 | lea RDa, TMP2 // Points to stack. Little-endian.
2362 | mov L:RB->base, BASE
2364 | mov CARG3d, TMP3 // Zero-extended to size_t.
2365 | mov CARG2, RDa // May be 64 bit ptr to stack.
2372 | call extern lj_str_new // (lua_State *L, char *str, size_t l)
2373 | // GCstr * returned in eax (RD).
2374 | mov BASE, L:RB->base
2376 | mov dword [BASE-4], LJ_TSTR
2377 | mov [BASE-8], STR:RD
2383 | cmp NARGS:RD, 1+2; jb ->fff_fallback
2385 | cmp dword [BASE+20], LJ_TISNUM
2387 | jne ->fff_fallback
2388 | mov RB, dword [BASE+16]
2391 | jae ->fff_fallback
2392 | cvttsd2si RB, qword [BASE+16]
2395 | jae ->fff_fallback
2396 | fld qword [BASE+16]
2400 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2401 | cmp dword [BASE+12], LJ_TISNUM
2403 | jne ->fff_fallback
2405 | jae ->fff_fallback
2407 | mov STR:RB, [BASE]
2409 | mov RB, STR:RB->len
2411 | mov RA, dword [BASE+8]
2413 | cvttsd2si RA, qword [BASE+8]
2415 | fld qword [BASE+8]
2420 | cmp RB, RC // len < end? (unsigned compare)
2423 | test RA, RA // start <= 0?
2427 | sub RC, RA // start > end?
2429 | lea RB, [STR:RB+RA+#STR-1]
2440 |5: // Negative end or overflow.
2442 | lea RC, [RC+RB+1] // end = end+(len+1)
2445 | mov RC, RB // end = len
2448 |7: // Negative start or underflow.
2450 | add RA, RB // start = start+(len+1)
2452 | jg <3 // start > 0?
2454 | mov RA, 1 // start = 1
2457 |->fff_emptystr: // Range underflow.
2458 | xor RC, RC // Zero length. Any ptr in RB is ok.
2461 |.ffunc string_rep // Only handle the 1-char case inline.
2463 | cmp NARGS:RD, 2+1; jne ->fff_fallback // Exactly 2 arguments.
2464 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2465 | cmp dword [BASE+12], LJ_TISNUM
2466 | mov STR:RB, [BASE]
2468 | jne ->fff_fallback
2469 | mov RC, dword [BASE+8]
2471 | jae ->fff_fallback
2472 | cvttsd2si RC, qword [BASE+8]
2474 | jae ->fff_fallback
2475 | fld qword [BASE+8]
2480 | jle ->fff_emptystr // Count <= 0? (or non-int)
2481 | cmp dword STR:RB->len, 1
2482 | jb ->fff_emptystr // Zero length string?
2483 | jne ->fff_fallback_2 // Fallback for > 1-char strings.
2484 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_2
2485 | movzx RA, byte STR:RB[1]
2486 | mov RB, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2492 |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
2497 | mov RD, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2500 |.ffunc_1 string_reverse
2502 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2503 | mov STR:RB, [BASE]
2504 | mov RC, STR:RB->len
2506 | jz ->fff_emptystr // Zero length string?
2507 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
2509 | mov TMP2, PC // Need another temp register.
2515 | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2517 | movzx RA, byte [RB]
2526 |.macro ffstring_case, name, lo, hi
2529 | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
2530 | mov STR:RB, [BASE]
2531 | mov RC, STR:RB->len
2532 | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
2534 | mov TMP2, PC // Need another temp register.
2540 | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
2542 |1: // ASCII case conversion. Yes, this is suboptimal code (do you care?).
2543 | movzx RA, byte [RB+RC]
2559 |ffstring_case string_lower, 0x41, 0x5a
2560 |ffstring_case string_upper, 0x61, 0x7a
2562 |//-- Table library ------------------------------------------------------
2564 |.ffunc_1 table_getn
2565 | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
2566 | mov RB, BASE // Save BASE.
2567 | mov TAB:FCARG1, [BASE]
2568 | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t)
2569 | // Length of table returned in eax (RD).
2570 | mov BASE, RB // Restore BASE.
2572 | mov RB, RD; jmp ->fff_resi
2574 | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0
2576 | mov ARG1, RD; fild ARG1; jmp ->fff_resn
2579 |//-- Bit library --------------------------------------------------------
2581 |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!).
2583 |.macro .ffunc_bit, name, kind, fdef
2587 | sseconst_tobit xmm1, RBa
2589 | mov TMP1, TOBIT_BIAS
2592 | cmp dword [BASE+4], LJ_TISNUM
2595 | mov RB, dword [BASE]
2604 | jae ->fff_fallback
2607 | movsd xmm0, qword [BASE]
2609 | sseconst_tobit xmm1, RBa
2616 | mov TMP1, TOBIT_BIAS
2627 |.macro .ffunc_bit, name, kind
2628 | .ffunc_bit name, kind, .ffunc_1
2631 |.ffunc_bit bit_tobit, 0
2642 |.macro .ffunc_bit_op, name, ins
2643 | .ffunc_bit name, 2
2644 | mov TMP2, NARGS:RD // Save for fallback.
2645 | lea RD, [BASE+NARGS:RD*8-16]
2649 | cmp dword [RD+4], LJ_TISNUM
2652 | ins RB, dword [RD]
2656 | ja ->fff_fallback_bit_op
2658 | jae ->fff_fallback_bit_op
2661 | movsd xmm0, qword [RD]
2675 |.ffunc_bit_op bit_band, and
2676 |.ffunc_bit_op bit_bor, or
2677 |.ffunc_bit_op bit_bxor, xor
2679 |.ffunc_bit bit_bswap, 1
2683 |.ffunc_bit bit_bnot, 1
2698 |->fff_fallback_bit_op:
2699 | mov NARGS:RD, TMP2 // Restore for fallback
2700 | jmp ->fff_fallback
2702 |.macro .ffunc_bit_sh, name, ins
2704 | .ffunc_bit name, 1, .ffunc_2
2705 | // Note: no inline conversion from number for 2nd argument!
2706 | cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback
2707 | mov RA, dword [BASE+8]
2710 | sseconst_tobit xmm2, RBa
2717 | mov TMP1, TOBIT_BIAS
2725 | ins RB, cl // Assumes RA is ecx.
2729 |.ffunc_bit_sh bit_lshift, shl
2730 |.ffunc_bit_sh bit_rshift, shr
2731 |.ffunc_bit_sh bit_arshift, sar
2732 |.ffunc_bit_sh bit_rol, rol
2733 |.ffunc_bit_sh bit_ror, ror
2735 |//-----------------------------------------------------------------------
2738 | mov NARGS:RD, 1+2 // Other args are ignored, anyway.
2739 | jmp ->fff_fallback
2741 | mov NARGS:RD, 1+1 // Other args are ignored, anyway.
2742 |->fff_fallback: // Call fast function fallback handler.
2743 | // BASE = new base, RD = nargs+1
2745 | mov PC, [BASE-4] // Fallback may overwrite PC.
2746 | mov SAVE_PC, PC // Redundant (but a defined value).
2747 | mov L:RB->base, BASE
2748 | lea RD, [BASE+NARGS:RD*8-8]
2749 | lea RA, [RD+8*LUA_MINSTACK] // Ensure enough space for handler.
2751 | mov CFUNC:RD, [BASE-8]
2752 | cmp RA, L:RB->maxstack
2753 | ja >5 // Need to grow stack.
2759 | call aword CFUNC:RD->f // (lua_State *L)
2760 | mov BASE, L:RB->base
2761 | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
2762 | test RD, RD; jg ->fff_res // Returned nresults+1?
2768 | lea NARGS:RD, [RA+1]
2769 | mov LFUNC:RB, [BASE-8]
2770 | jne ->vm_call_tail // Returned -1?
2771 | ins_callt // Returned 0: retry fast path.
2773 |// Reconstruct previous base for vmeta_call during tailcall.
2776 | test PC, FRAME_TYPE
2779 | not RBa // Note: ~RB = -(RB+1)
2780 | lea BASE, [BASE+RB*8] // base = base - (RB+1)*8
2781 | jmp ->vm_call_dispatch // Resolve again for tailcall.
2786 | jmp ->vm_call_dispatch // Resolve again for tailcall.
2788 |5: // Grow stack for fallback handler.
2789 | mov FCARG2, LUA_MINSTACK
2791 | call extern lj_state_growstack@8 // (lua_State *L, int n)
2792 | mov BASE, L:RB->base
2793 | xor RD, RD // Simulate a return 0.
2794 | jmp <1 // Dumb retry (goes through ff first).
2796 |->fff_gcstep: // Call GC step function.
2797 | // BASE = new base, RD = nargs+1
2798 | pop RBa // Must keep stack at same level.
2799 | mov TMPa, RBa // Save return address
2801 | mov SAVE_PC, PC // Redundant (but a defined value).
2802 | mov L:RB->base, BASE
2803 | lea RD, [BASE+NARGS:RD*8-8]
2806 | call extern lj_gc_step@4 // (lua_State *L)
2807 | mov BASE, L:RB->base
2813 | push RBa // Restore return address.
2816 |//-----------------------------------------------------------------------
2817 |//-- Special dispatch targets -------------------------------------------
2818 |//-----------------------------------------------------------------------
2820 |->vm_record: // Dispatch target for recording phase.
2822 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2823 | test RDL, HOOK_VMEVENT // No recording while in vmevent.
2825 | // Decrement the hookcount for consistency, but always do the call.
2826 | test RDL, HOOK_ACTIVE
2828 | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
2830 | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
2834 |->vm_rethook: // Dispatch target for return hooks.
2835 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2836 | test RDL, HOOK_ACTIVE // Hook already active?
2840 |->vm_inshook: // Dispatch target for instr/line hooks.
2841 | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
2842 | test RDL, HOOK_ACTIVE // Hook already active?
2845 | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
2847 | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
2849 | test RDL, LUA_MASKLINE
2853 | mov L:RB->base, BASE
2854 | mov FCARG2, PC // Caveat: FCARG2 == BASE
2856 | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
2857 | call extern lj_dispatch_ins@8 // (lua_State *L, BCIns *pc)
2859 | mov BASE, L:RB->base
2866 | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins.
2868 | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Re-dispatch to static ins.
2871 |->cont_hook: // Continue from hook yield.
2874 | mov MULTRES, RA // Restore MULTRES for *M ins.
2877 |->vm_hotloop: // Hot loop counter underflow.
2879 | mov LFUNC:RB, [BASE-8] // Same as curr_topL(L).
2880 | mov RB, LFUNC:RB->pc
2881 | movzx RD, byte [RB+PC2PROTO(framesize)]
2882 | lea RD, [BASE+RD*8]
2884 | mov L:RB->base, BASE
2887 | lea FCARG1, [DISPATCH+GG_DISP2J]
2888 | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
2890 | call extern lj_trace_hot@8 // (jit_State *J, const BCIns *pc)
2894 |->vm_callhook: // Dispatch target for call hooks.
2900 |->vm_hotcall: // Hot call counter underflow.
2903 | or PC, 1 // Marker for hot call.
2906 | lea RD, [BASE+NARGS:RD*8-8]
2908 | mov L:RB->base, BASE
2912 | call extern lj_dispatch_call@8 // (lua_State *L, const BCIns *pc)
2913 | // ASMFunction returned in eax/rax (RDa).
2914 | mov SAVE_PC, 0 // Invalidate for subsequent line hook.
2918 | mov BASE, L:RB->base
2928 |//-----------------------------------------------------------------------
2929 |//-- Trace exit handler -------------------------------------------------
2930 |//-----------------------------------------------------------------------
2932 |// Called from an exit stub with the exit number on the stack.
2933 |// The 16 bit exit number is stored with two (sign-extended) push imm8.
2937 | push r13; push r12
2938 | push r11; push r10; push r9; push r8
2939 | push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp
2940 | push rbx; push rdx; push rcx; push rax
2941 | movzx RC, byte [rbp-8] // Reconstruct exit number.
2942 | mov RCH, byte [rbp-16]
2943 | mov [rbp-8], r15; mov [rbp-16], r14
2945 | push ebp; lea ebp, [esp+12]; push ebp
2946 | push ebx; push edx; push ecx; push eax
2947 | movzx RC, byte [ebp-4] // Reconstruct exit number.
2948 | mov RCH, byte [ebp-8]
2949 | mov [ebp-4], edi; mov [ebp-8], esi
2951 | // Caveat: DISPATCH is ebx.
2952 | mov DISPATCH, [ebp]
2953 | mov RA, [DISPATCH+DISPATCH_GL(vmstate)] // Get trace number.
2955 | mov [DISPATCH+DISPATCH_J(exitno)], RC
2956 | mov [DISPATCH+DISPATCH_J(parent)], RA
2959 | sub rsp, 16*8+4*8 // Room for SSE regs + save area.
2961 | sub rsp, 16*8 // Room for SSE regs.
2964 | movsd qword [rbp-8], xmm15; movsd qword [rbp-16], xmm14
2965 | movsd qword [rbp-24], xmm13; movsd qword [rbp-32], xmm12
2966 | movsd qword [rbp-40], xmm11; movsd qword [rbp-48], xmm10
2967 | movsd qword [rbp-56], xmm9; movsd qword [rbp-64], xmm8
2968 | movsd qword [rbp-72], xmm7; movsd qword [rbp-80], xmm6
2969 | movsd qword [rbp-88], xmm5; movsd qword [rbp-96], xmm4
2970 | movsd qword [rbp-104], xmm3; movsd qword [rbp-112], xmm2
2971 | movsd qword [rbp-120], xmm1; movsd qword [rbp-128], xmm0
2973 | sub esp, 8*8+16 // Room for SSE regs + args.
2974 | movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6
2975 | movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4
2976 | movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2
2977 | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0
2979 | // Caveat: RB is ebp.
2980 | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)]
2981 | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]
2982 | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
2983 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
2984 | mov L:RB->base, BASE
2986 | lea CARG2, [rsp+4*8]
2990 | lea FCARG2, [esp+16]
2992 | lea FCARG1, [DISPATCH+GG_DISP2J]
2993 | call extern lj_trace_exit@8 // (jit_State *J, ExitState *ex)
2994 | // MULTRES or negated error code returned in eax (RD).
2995 | mov RAa, L:RB->cframe
2996 | and RAa, CFRAME_RAWMASK
2998 | // Reposition stack later.
3000 | mov rsp, RAa // Reposition stack to C frame.
3002 | mov esp, RAa // Reposition stack to C frame.
3004 | mov [RAa+CFRAME_OFS_L], L:RB // Set SAVE_L (on-trace resume/yield).
3005 | mov BASE, L:RB->base
3006 | mov PC, [RAa+CFRAME_OFS_PC] // Get SAVE_PC.
3012 | // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.
3015 | // Restore additional callee-save registers only used in compiled code.
3017 | lea RAa, [rsp+9*16+4*8]
3019 | movdqa xmm15, [RAa-9*16]
3020 | movdqa xmm14, [RAa-8*16]
3021 | movdqa xmm13, [RAa-7*16]
3022 | movdqa xmm12, [RAa-6*16]
3023 | movdqa xmm11, [RAa-5*16]
3024 | movdqa xmm10, [RAa-4*16]
3025 | movdqa xmm9, [RAa-3*16]
3026 | movdqa xmm8, [RAa-2*16]
3027 | movdqa xmm7, [RAa-1*16]
3028 | mov rsp, RAa // Reposition stack to C frame.
3029 | movdqa xmm6, [RAa]
3033 | add rsp, 16 // Reposition stack to C frame.
3039 | test RD, RD; js >3 // Check for error from exit.
3041 | mov LFUNC:KBASE, [BASE-8]
3042 | mov KBASE, LFUNC:KBASE->pc
3043 | mov KBASE, [KBASE+PC2PROTO(k)]
3044 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
3045 | set_vmstate INTERP
3046 | // Modified copy of ins_next which handles function header dispatch, too.
3052 | cmp OP, BC_FUNCF // Function header?
3054 | mov RC, MULTRES // RC/RD holds nres+1.
3057 | jmp aword [DISPATCH+OP*8]
3059 | jmp aword [DISPATCH+OP*4]
3062 |3: // Rethrow error from the right C frame.
3066 | call extern lj_err_throw@8 // (lua_State *L, int errcode)
3069 |//-----------------------------------------------------------------------
3070 |//-- Math helper functions ----------------------------------------------
3071 |//-----------------------------------------------------------------------
3073 |// FP value rounding. Called by math.floor/math.ceil fast functions
3074 |// and from JIT code.
3076 |// x87 variant: Arg/ret on x87 stack. No int/xmm registers modified.
3077 |.macro vm_round_x87, mode1, mode2
3078 | fnstcw word [esp+4] // Caveat: overwrites ARG1 and ARG2.
3082 |.if mode2 ~= 0xffff
3086 | fldcw word [esp+6]
3088 | fldcw word [esp+4]
3093 |// SSE variant: arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.
3094 |.macro vm_round_sse, mode
3095 | sseconst_abs xmm2, RDa
3096 | sseconst_2p52 xmm3, RDa
3098 | andpd xmm1, xmm2 // |x|
3099 | ucomisd xmm3, xmm1 // No truncation if 2^52 <= |x|.
3101 | andnpd xmm2, xmm0 // Isolate sign bit.
3102 |.if mode == 2 // trunc(x)?
3104 | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
3106 | sseconst_1 xmm3, RDa
3107 | cmpsd xmm0, xmm1, 1 // |x| < result?
3109 | subsd xmm1, xmm0 // If yes, subtract -1.
3110 | orpd xmm1, xmm2 // Merge sign bit back in.
3112 | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
3114 | orpd xmm1, xmm2 // Merge sign bit back in.
3115 | .if mode == 1 // ceil(x)?
3116 | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0.
3117 | cmpsd xmm0, xmm1, 6 // x > result?
3118 | .else // floor(x)?
3119 | sseconst_1 xmm2, RDa
3120 | cmpsd xmm0, xmm1, 1 // x < result?
3123 | subsd xmm1, xmm0 // If yes, subtract +-1.
3130 |.macro vm_round, name, ssemode, mode1, mode2
3133 | vm_round_x87 mode1, mode2
3136 | vm_round_sse ssemode
3139 | vm_round vm_floor, 0, 0x0400, 0xf7ff
3140 | vm_round vm_ceil, 1, 0x0800, 0xfbff
3141 | vm_round vm_trunc, 2, 0x0c00, 0xffff
3143 |// FP modulo x%y. Called by BC_MOD* and vm_arith.
3146 |// Args in xmm0/xmm1, return value in xmm0.
3147 |// Caveat: xmm0-xmm5 and RC (eax) modified!
3150 | sseconst_abs xmm2, RDa
3151 | sseconst_2p52 xmm3, RDa
3153 | andpd xmm4, xmm2 // |x/y|
3154 | ucomisd xmm3, xmm4 // No truncation if 2^52 <= |x/y|.
3156 | andnpd xmm2, xmm0 // Isolate sign bit.
3157 | addsd xmm4, xmm3 // (|x/y| + 2^52) - 2^52
3159 | orpd xmm4, xmm2 // Merge sign bit back in.
3160 | sseconst_1 xmm2, RDa
3161 | cmpsd xmm0, xmm4, 1 // x/y < result?
3163 | subsd xmm4, xmm0 // If yes, subtract 1.0.
3174 |// Args/ret on x87 stack (y on top). No xmm registers modified.
3175 |// Caveat: needs 3 slots on x87 stack! RC (eax) modified!
3178 | fnstcw word [esp+4]
3183 | fldcw word [esp+6]
3185 | fldcw word [esp+4]
3191 |// FP log2(x). Called by math.log(x, base).
3194 | movsd qword [rsp+8], xmm0 // Use scratch area.
3198 | fstp qword [rsp+8]
3199 | movsd xmm0, qword [rsp+8]
3201 | movsd qword [rsp-8], xmm0 // Use red zone.
3205 | fstp qword [rsp-8]
3206 | movsd xmm0, qword [rsp-8]
3214 |// FP exponentiation e^x and 2^x. Called by math.exp fast function and
3215 |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified.
3216 |// Caveat: needs 3 slots on x87 stack!
3218 | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e))
3221 | .define expscratch, dword [rsp+8] // Use scratch area.
3223 | .define expscratch, dword [rsp-8] // Use red zone.
3225 | .define expscratch, dword [esp+4] // Needs 4 byte scratch area.
3227 | fst expscratch // Caveat: overwrites ARG1.
3228 | cmp expscratch, 0x7f800000; je >1 // Special case: e^+Inf = +Inf
3229 | cmp expscratch, 0xff800000; je >2 // Special case: e^-Inf = 0
3230 |->vm_exp2raw: // Entry point for vm_pow. Without +-Inf check.
3231 | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
3232 | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
3238 |// Generic power function x^y. Called by BC_POW, math.pow fast function,
3240 |// Args/ret on x87 stack (y on top). RC (eax) modified.
3241 |// Caveat: needs 3 slots on x87 stack!
3244 | fist dword [esp+4] // Store/reload int before comparison.
3245 | fild dword [esp+4] // Integral exponent used in vm_powi.
3247 | jnz >8 // Branch for FP exponents.
3248 | jp >9 // Branch for NaN exponent.
3249 | fpop // Pop y and fallthrough to vm_powi.
3251 |// FP/int power function x^i. Arg1/ret on x87 stack.
3252 |// Arg2 (int) on C stack. RC (eax) modified.
3253 |// Caveat: needs 2 slots on x87 stack!
3255 | cmp eax, 1; jle >6 // i<=1?
3256 | // Now 1 < (unsigned)i <= 0x80000000.
3257 |1: // Handle leading zeros.
3258 | test eax, 1; jnz >2
3265 |3: // Handle trailing bits.
3276 | je <5 // x^1 ==> x
3280 | cmp eax, 1; je <5 // x^-1 ==> 1/x
3281 | jmp <1 // x^-i ==> (1/x)^i
3283 | fpop; fld1 // x^0 ==> 1
3286 |8: // FP/FP power function x^y.
3290 | mov eax, [esp+4]; shl eax, 1
3291 | cmp eax, 0xff000000; je >2 // x^+-Inf?
3292 | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
3293 | cmp eax, 0xff000000; je >4 // +-Inf^y?
3297 |9: // Handle x^NaN.
3300 | je >1 // 1^NaN ==> 1
3301 | fxch // x^NaN ==> NaN
3306 |2: // Handle x^+-Inf.
3310 | je >3 // +-1^+-Inf ==> 1
3311 | fpop; fabs; fldz; mov eax, 0; setc al
3312 | ror eax, 1; xor eax, [esp+4]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0
3318 |4: // Handle +-0^y or +-Inf^y.
3319 | cmp dword [esp+4], 0; jge <3 // y >= 0, x^y ==> |x|
3321 | test eax, eax; jz >5 // y < 0, +-0^y ==> +Inf
3322 | fldz // y < 0, +-Inf^y ==> 0
3325 | mov dword [esp+4], 0x7f800000 // Return +Inf.
3330 |// Args in xmm0/xmm1. Ret in xmm0. xmm0-xmm2 and RC (eax) modified.
3331 |// Needs 16 byte scratch area for x86. Also called from JIT code.
3333 | cvtsd2si eax, xmm1
3334 | cvtsi2sd xmm2, eax
3335 | ucomisd xmm1, xmm2
3336 | jnz >8 // Branch for FP exponents.
3337 | jp >9 // Branch for NaN exponent.
3338 | // Fallthrough to vm_powi_sse.
3340 |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.
3342 | cmp eax, 1; jle >6 // i<=1?
3343 | // Now 1 < (unsigned)i <= 0x80000000.
3344 |1: // Handle leading zeros.
3345 | test eax, 1; jnz >2
3352 |3: // Handle trailing bits.
3363 | je <5 // x^1 ==> x
3364 | jb >7 // x^0 ==> 1
3367 | sseconst_1 xmm1, RDa
3372 | sseconst_1 xmm0, RDa
3375 |8: // FP/FP power function x^y.
3377 | movd rax, xmm1; shl rax, 1
3378 | rol rax, 12; cmp rax, 0xffe; je >2 // x^+-Inf?
3379 | movd rax, xmm0; shl rax, 1; je >4 // +-0^y?
3380 | rol rax, 12; cmp rax, 0xffe; je >5 // +-Inf^y?
3382 | movsd qword [rsp+16], xmm1 // Use scratch area.
3383 | movsd qword [rsp+8], xmm0
3384 | fld qword [rsp+16]
3387 | movsd qword [rsp-16], xmm1 // Use red zone.
3388 | movsd qword [rsp-8], xmm0
3389 | fld qword [rsp-16]
3393 | movsd qword [esp+12], xmm1 // Needs 16 byte scratch area.
3394 | movsd qword [esp+4], xmm0
3395 | cmp dword [esp+12], 0; jne >1
3396 | mov eax, [esp+16]; shl eax, 1
3397 | cmp eax, 0xffe00000; je >2 // x^+-Inf?
3399 | cmp dword [esp+4], 0; jne >1
3400 | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
3401 | cmp eax, 0xffe00000; je >5 // +-Inf^y?
3403 | fld qword [esp+12]
3406 | fyl2x // y*log2(x)
3407 | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
3408 | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
3410 | fstp qword [rsp+8] // Use scratch area.
3411 | movsd xmm0, qword [rsp+8]
3413 | fstp qword [rsp-8] // Use red zone.
3414 | movsd xmm0, qword [rsp-8]
3416 | fstp qword [esp+4] // Needs 8 byte scratch area.
3417 | movsd xmm0, qword [esp+4]
3421 |9: // Handle x^NaN.
3422 | sseconst_1 xmm2, RDa
3423 | ucomisd xmm0, xmm2; je >1 // 1^NaN ==> 1
3424 | movaps xmm0, xmm1 // x^NaN ==> NaN
3428 |2: // Handle x^+-Inf.
3429 | sseconst_abs xmm2, RDa
3430 | andpd xmm0, xmm2 // |x|
3431 | sseconst_1 xmm2, RDa
3432 | ucomisd xmm0, xmm2; je <1 // +-1^+-Inf ==> 1
3433 | movmskpd eax, xmm1
3435 | mov ah, al; setc al; xor al, ah; jne <1 // |x|<>1, x^+-Inf ==> +Inf/0
3437 | sseconst_hi xmm0, RDa, 7ff00000 // +Inf
3440 |4: // Handle +-0^y.
3441 | movmskpd eax, xmm1; test eax, eax; jnz <3 // y < 0, +-0^y ==> +Inf
3442 | xorps xmm0, xmm0 // y >= 0, +-0^y ==> 0
3445 |5: // Handle +-Inf^y.
3446 | movmskpd eax, xmm1; test eax, eax; jz <3 // y >= 0, +-Inf^y ==> +Inf
3447 | xorps xmm0, xmm0 // y < 0, +-Inf^y ==> 0
3450 |// Callable from C: double lj_vm_foldfpm(double x, int fpm)
3451 |// Computes fpm(x) for extended math functions. ORDER FPM.
3456 | .define fpmop, CARG2d
3458 | .define fpmop, CARG1d
3460 | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
3461 | cmp fpmop, 3; jb ->vm_trunc; ja >2
3462 | sqrtsd xmm0, xmm0; ret
3465 | movsd qword [rsp+8], xmm0 // Use scratch area.
3468 | movsd qword [rsp-8], xmm0 // Use red zone.
3471 | cmp fpmop, 5; ja >2
3472 | .if X64WIN; pop rax; .endif
3475 | .if X64WIN; push rax; .endif
3478 | call ->vm_exp2_x87
3479 | .if X64WIN; push rax; .endif
3481 |2: ; cmp fpmop, 7; je >1; ja >2
3482 | fldln2; fxch; fyl2x; jmp >7
3483 |1: ; fld1; fxch; fyl2x; jmp >7
3484 |2: ; cmp fpmop, 9; je >1; ja >2
3485 | fldlg2; fxch; fyl2x; jmp >7
3487 |2: ; cmp fpmop, 11; je >1; ja >9
3492 | fstp qword [rsp+8] // Use scratch area.
3493 | movsd xmm0, qword [rsp+8]
3495 | fstp qword [rsp-8] // Use red zone.
3496 | movsd xmm0, qword [rsp-8]
3499 |.else // x86 calling convention.
3500 | .define fpmop, eax
3502 | mov fpmop, [esp+12]
3503 | movsd xmm0, qword [esp+4]
3504 | cmp fpmop, 1; je >1; ja >2
3505 | call ->vm_floor; jmp >7
3506 |1: ; call ->vm_ceil; jmp >7
3507 |2: ; cmp fpmop, 3; je >1; ja >2
3508 | call ->vm_trunc; jmp >7
3512 | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
3515 |2: ; fld qword [esp+4]
3516 | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
3517 |2: ; cmp fpmop, 7; je >1; ja >2
3518 | fldln2; fxch; fyl2x; ret
3519 |1: ; fld1; fxch; fyl2x; ret
3520 |2: ; cmp fpmop, 9; je >1; ja >2
3521 | fldlg2; fxch; fyl2x; ret
3523 |2: ; cmp fpmop, 11; je >1; ja >9
3525 |1: ; fptan; fpop; ret
3527 | mov fpmop, [esp+12]
3529 | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
3530 | cmp fpmop, 3; jb ->vm_trunc; ja >2
3532 |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
3533 | cmp fpmop, 7; je >1; ja >2
3534 | fldln2; fxch; fyl2x; ret
3535 |1: ; fld1; fxch; fyl2x; ret
3536 |2: ; cmp fpmop, 9; je >1; ja >2
3537 | fldlg2; fxch; fyl2x; ret
3539 |2: ; cmp fpmop, 11; je >1; ja >9
3541 |1: ; fptan; fpop; ret
3544 |9: ; int3 // Bad fpm.
3547 |// Callable from C: double lj_vm_foldarith(double x, double y, int op)
3548 |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -)
3549 |// and basic math functions. ORDER ARITH
3554 | .define foldop, CARG3d
3556 | .define foldop, CARG1d
3558 | cmp foldop, 1; je >1; ja >2
3559 | addsd xmm0, xmm1; ret
3560 |1: ; subsd xmm0, xmm1; ret
3561 |2: ; cmp foldop, 3; je >1; ja >2
3562 | mulsd xmm0, xmm1; ret
3563 |1: ; divsd xmm0, xmm1; ret
3564 |2: ; cmp foldop, 5; jb ->vm_mod; je ->vm_pow
3565 | cmp foldop, 7; je >1; ja >2
3566 | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; ret
3567 |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; ret
3568 |2: ; cmp foldop, 9; ja >2
3570 | movsd qword [rsp+8], xmm0 // Use scratch area.
3571 | movsd qword [rsp+16], xmm1
3573 | fld qword [rsp+16]
3575 | movsd qword [rsp-8], xmm0 // Use red zone.
3576 | movsd qword [rsp-16], xmm1
3578 | fld qword [rsp-16]
3584 | fstp qword [rsp+8] // Use scratch area.
3585 | movsd xmm0, qword [rsp+8]
3587 | fstp qword [rsp-8] // Use red zone.
3588 | movsd xmm0, qword [rsp-8]
3591 |1: ; fxch; fscale; fpop1; jmp <7
3592 |2: ; cmp foldop, 11; je >1; ja >9
3593 | minsd xmm0, xmm1; ret
3594 |1: ; maxsd xmm0, xmm1; ret
3595 |9: ; int3 // Bad op.
3597 |.elif SSE // x86 calling convention with SSE ops.
3599 | .define foldop, eax
3600 | mov foldop, [esp+20]
3601 | movsd xmm0, qword [esp+4]
3602 | movsd xmm1, qword [esp+12]
3603 | cmp foldop, 1; je >1; ja >2
3606 | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
3609 |1: ; subsd xmm0, xmm1; jmp <7
3610 |2: ; cmp foldop, 3; je >1; ja >2
3611 | mulsd xmm0, xmm1; jmp <7
3612 |1: ; divsd xmm0, xmm1; jmp <7
3615 | call ->vm_mod; jmp <7
3616 |1: ; pop edx; call ->vm_pow; push edx; jmp <7 // Writes to scratch area.
3617 |2: ; cmp foldop, 7; je >1; ja >2
3618 | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; jmp <7
3619 |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; jmp <7
3620 |2: ; cmp foldop, 9; ja >2
3621 | fld qword [esp+4] // Reload from stack
3622 | fld qword [esp+12]
3625 |1: ; fxch; fscale; fpop1; ret
3626 |2: ; cmp foldop, 11; je >1; ja >9
3627 | minsd xmm0, xmm1; jmp <7
3628 |1: ; maxsd xmm0, xmm1; jmp <7
3629 |9: ; int3 // Bad op.
3631 |.else // x86 calling convention with x87 ops.
3635 | fld qword [esp+12]
3636 | cmp eax, 1; je >1; ja >2
3638 |1: ; fsubp st1; ret
3639 |2: ; cmp eax, 3; je >1; ja >2
3641 |1: ; fdivp st1; ret
3642 |2: ; cmp eax, 5; jb ->vm_mod; je ->vm_pow
3643 | cmp eax, 7; je >1; ja >2
3645 |1: ; fpop; fabs; ret
3646 |2: ; cmp eax, 9; je >1; ja >2
3648 |1: ; fxch; fscale; fpop1; ret
3649 |2: ; cmp eax, 11; je >1; ja >9
3650 | fucomi st1; fcmovnbe st1; fpop1; ret
3651 |1: ; fucomi st1; fcmovbe st1; fpop1; ret
3652 |9: ; int3 // Bad op.
3656 |//-----------------------------------------------------------------------
3657 |//-- Miscellaneous functions --------------------------------------------
3658 |//-----------------------------------------------------------------------
3660 |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])
3664 | .if X64WIN; push rsi; mov rsi, CARG2; .endif
3672 | .if X64WIN; pop rsi; .endif
3678 | xor edx, 0x00200000 // Toggle ID bit in flags.
3683 | xor eax, eax // Zero means no features supported.
3685 | jz >1 // No ID toggle means no CPUID support.
3686 | mov eax, [esp+4] // Argument 1 is function number.
3690 | mov edi, [esp+16] // Argument 2 is result area.
3701 |//-----------------------------------------------------------------------
3702 |//-- Assertions ---------------------------------------------------------
3703 |//-----------------------------------------------------------------------
3705 |->assert_bad_for_arg_type:
3706 #ifdef LUA_USE_ASSERT
3711 |//-----------------------------------------------------------------------
3712 |//-- FFI helper functions -----------------------------------------------
3713 |//-----------------------------------------------------------------------
3715 |// Handler for callback functions. Callback slot number in ah/al.
3718 |.type CTSTATE, CTState, PC
3720 | sub esp, 16 // Leave room for SAVE_ERRF etc.
3722 | saveregs_ // ebp/rbp already saved. ebp now holds global_State *.
3723 | lea DISPATCH, [ebp+GG_G2DISP]
3724 | mov CTSTATE, GL:ebp->ctype_state
3726 | mov CTSTATE->cb.slot, eax
3728 | mov CTSTATE->cb.gpr[0], CARG1
3729 | mov CTSTATE->cb.gpr[1], CARG2
3730 | mov CTSTATE->cb.gpr[2], CARG3
3731 | mov CTSTATE->cb.gpr[3], CARG4
3732 | movsd qword CTSTATE->cb.fpr[0], xmm0
3733 | movsd qword CTSTATE->cb.fpr[1], xmm1
3734 | movsd qword CTSTATE->cb.fpr[2], xmm2
3735 | movsd qword CTSTATE->cb.fpr[3], xmm3
3737 | lea rax, [rsp+CFRAME_SIZE+4*8]
3739 | lea rax, [rsp+CFRAME_SIZE]
3740 | mov CTSTATE->cb.gpr[4], CARG5
3741 | mov CTSTATE->cb.gpr[5], CARG6
3742 | movsd qword CTSTATE->cb.fpr[4], xmm4
3743 | movsd qword CTSTATE->cb.fpr[5], xmm5
3744 | movsd qword CTSTATE->cb.fpr[6], xmm6
3745 | movsd qword CTSTATE->cb.fpr[7], xmm7
3747 | mov CTSTATE->cb.stack, rax
3750 | lea eax, [esp+CFRAME_SIZE+16]
3751 | mov CTSTATE->cb.gpr[0], FCARG1
3752 | mov CTSTATE->cb.gpr[1], FCARG2
3753 | mov CTSTATE->cb.stack, eax
3754 | mov FCARG1, [esp+CFRAME_SIZE+12] // Move around misplaced retaddr/ebp.
3755 | mov FCARG2, [esp+CFRAME_SIZE+8]
3756 | mov SAVE_RET, FCARG1
3757 | mov SAVE_R4, FCARG2
3760 | mov SAVE_PC, CTSTATE // Any value outside of bytecode is ok.
3761 | mov FCARG1, CTSTATE
3762 | call extern lj_ccallback_enter@8 // (CTState *cts, void *cf)
3763 | // lua_State * returned in eax (RD).
3764 | set_vmstate INTERP
3765 | mov BASE, L:RD->base
3768 | mov LFUNC:RB, [BASE-8]
3774 |->cont_ffi_callback: // Return from FFI callback.
3777 | mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]
3778 | mov aword CTSTATE->L, L:RAa
3779 | mov L:RA->base, BASE
3781 | mov FCARG1, CTSTATE
3783 | call extern lj_ccallback_leave@8 // (CTState *cts, TValue *o)
3785 | mov rax, CTSTATE->cb.gpr[0]
3786 | movsd xmm0, qword CTSTATE->cb.fpr[0]
3787 | jmp ->vm_leave_unw
3790 | mov eax, CTSTATE->cb.gpr[0]
3791 | mov edx, CTSTATE->cb.gpr[1]
3792 | cmp dword CTSTATE->cb.gpr[2], 1
3795 | fld qword CTSTATE->cb.fpr[0].d
3798 | fld dword CTSTATE->cb.fpr[0].f
3800 | mov ecx, L:RB->top
3801 | movzx ecx, word [ecx+6] // Get stack adjustment and copy up.
3802 | mov SAVE_L, ecx // Must be one slot above SAVE_RET
3804 | pop ecx // Move return addr from SAVE_RET.
3805 | add esp, [esp] // Adjust stack.
3812 |->vm_ffi_call@4: // Call C function via FFI.
3813 | // Caveat: needs special frame unwinding, see below.
3816 | .type CCSTATE, CCallState, rbx
3817 | push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1
3819 | .type CCSTATE, CCallState, ebx
3820 | push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1
3823 | // Readjust stack.
3825 | mov eax, CCSTATE->spadj
3828 | sub esp, CCSTATE->spadj
3830 | mov CCSTATE->spadj, esp
3834 | // Copy stack slots.
3835 | movzx ecx, byte CCSTATE->nsp
3840 | mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]
3841 | mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax
3843 | mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)]
3844 | mov [esp+ecx*4], eax
3851 | movzx eax, byte CCSTATE->nfpr
3852 | mov CARG1, CCSTATE->gpr[0]
3853 | mov CARG2, CCSTATE->gpr[1]
3854 | mov CARG3, CCSTATE->gpr[2]
3855 | mov CARG4, CCSTATE->gpr[3]
3857 | mov CARG5, CCSTATE->gpr[4]
3858 | mov CARG6, CCSTATE->gpr[5]
3860 | test eax, eax; jz >5
3861 | movaps xmm0, CCSTATE->fpr[0]
3862 | movaps xmm1, CCSTATE->fpr[1]
3863 | movaps xmm2, CCSTATE->fpr[2]
3864 | movaps xmm3, CCSTATE->fpr[3]
3866 | cmp eax, 4; jbe >5
3867 | movaps xmm4, CCSTATE->fpr[4]
3868 | movaps xmm5, CCSTATE->fpr[5]
3869 | movaps xmm6, CCSTATE->fpr[6]
3870 | movaps xmm7, CCSTATE->fpr[7]
3874 | mov FCARG1, CCSTATE->gpr[0]
3875 | mov FCARG2, CCSTATE->gpr[1]
3878 | call aword CCSTATE->func
3881 | mov CCSTATE->gpr[0], rax
3882 | movaps CCSTATE->fpr[0], xmm0
3884 | mov CCSTATE->gpr[1], rdx
3885 | movaps CCSTATE->fpr[1], xmm1
3888 | mov CCSTATE->gpr[0], eax
3889 | mov CCSTATE->gpr[1], edx
3890 | cmp byte CCSTATE->resx87, 1
3893 | fstp qword CCSTATE->fpr[0].d[0]
3896 | fstp dword CCSTATE->fpr[0].f[0]
3899 | sub CCSTATE->spadj, esp
3904 | mov rbx, [rbp-8]; leave; ret
3906 | mov ebx, [ebp-4]; leave; ret
3909 |// Note: vm_ffi_call must be the last function in this object file!
3911 |//-----------------------------------------------------------------------
3914 /* Generate the code for a single instruction. */
3915 static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3918 |// Note: aligning all instructions does not pay off.
3923 /* -- Comparison ops ---------------------------------------------------- */
3925 /* Remember: all ops branch for a true comparison, fall through otherwise. */
3927 |.macro jmp_comp, lt, ge, le, gt, target
3941 ||default: break; /* Shut up GCC. */
3945 case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
3946 | // RA = src1, RD = src2, JMP with RD = target
3951 | mov RB, dword [BASE+RA*8]
3953 | cmp RB, dword [BASE+RD*8]
3954 | jmp_comp jge, jl, jg, jle, >9
3961 |7: // RA is not an integer.
3963 | // RA is a number.
3964 | cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp
3965 | // RA is a number, RD is an integer.
3967 | cvtsi2sd xmm0, dword [BASE+RD*8]
3970 | fld qword [BASE+RA*8]
3971 | fild dword [BASE+RD*8]
3975 |8: // RA is an integer, RD is not an integer.
3977 | // RA is an integer, RD is a number.
3979 | cvtsi2sd xmm1, dword [BASE+RA*8]
3980 | movsd xmm0, qword [BASE+RD*8]
3982 | ucomisd xmm0, xmm1
3983 | jmp_comp jbe, ja, jb, jae, <9
3986 | fild dword [BASE+RA*8]
3990 | checknum RA, ->vmeta_comp
3991 | checknum RD, ->vmeta_comp
3995 | movsd xmm0, qword [BASE+RD*8]
3998 | ucomisd xmm0, qword [BASE+RA*8]
4002 | fld qword [BASE+RA*8] // Reverse order, i.e like cmp D, A.
4004 | fld qword [BASE+RD*8]
4009 | // Unordered: all of ZF CF PF set, ordered: PF clear.
4010 | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
4012 | jmp_comp jbe, ja, jb, jae, <9
4015 | jmp_comp jbe, ja, jb, jae, >1
4023 case BC_ISEQV: case BC_ISNEV:
4024 vk = op == BC_ISEQV;
4025 | ins_AD // RA = src1, RD = src2, JMP with RD = target
4026 | mov RB, [BASE+RD*8+4]
4029 | cmp RB, LJ_TISNUM; jne >7
4031 | mov RB, dword [BASE+RD*8]
4032 | cmp RB, dword [BASE+RA*8]
4043 |7: // RD is not an integer.
4045 | // RD is a number.
4046 | cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5
4047 | // RD is a number, RA is an integer.
4049 | cvtsi2sd xmm0, dword [BASE+RA*8]
4051 | fild dword [BASE+RA*8]
4055 |8: // RD is an integer, RA is not an integer.
4057 | // RD is an integer, RA is a number.
4059 | cvtsi2sd xmm0, dword [BASE+RD*8]
4060 | ucomisd xmm0, qword [BASE+RA*8]
4062 | fild dword [BASE+RD*8]
4063 | fld qword [BASE+RA*8]
4068 | cmp RB, LJ_TISNUM; jae >5
4073 | movsd xmm0, qword [BASE+RA*8]
4075 | ucomisd xmm0, qword [BASE+RD*8]
4079 | fld qword [BASE+RA*8]
4081 | fld qword [BASE+RD*8]
4087 | jp >2 // Unordered means not equal.
4090 | jp >2 // Unordered means not equal.
4095 |1: // EQ: Branch to the target.
4098 |2: // NE: Fallthrough to next instruction.
4106 |2: // NE: Branch to the target.
4109 |1: // EQ: Fallthrough to next instruction.
4111 if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||
4112 op == BC_ISEQN || op == BC_ISNEN)) {
4118 if (op == BC_ISEQV || op == BC_ISNEV) {
4119 |5: // Either or both types are not numbers.
4121 | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
4122 | checktp RA, LJ_TCDATA; je ->vmeta_equal_cd
4124 | checktp RA, RB // Compare types.
4125 | jne <2 // Not the same type?
4127 | jae <1 // Same type and primitive type?
4129 | // Same types and not a primitive type. Compare GCobj or pvalue.
4130 | mov RA, [BASE+RA*8]
4131 | mov RD, [BASE+RD*8]
4133 | je <1 // Same GCobjs or pvalues?
4134 | cmp RB, LJ_TISTABUD
4135 | ja <2 // Different objects and not table/ud?
4137 | cmp RB, LJ_TUDATA // And not 64 bit lightuserdata.
4141 | // Different tables or userdatas. Need to check __eq metamethod.
4142 | // Field metatable must be at same offset for GCtab and GCudata!
4143 | mov TAB:RB, TAB:RA->metatable
4144 | test TAB:RB, TAB:RB
4145 | jz <2 // No metatable?
4146 | test byte TAB:RB->nomm, 1<<MM_eq
4147 | jnz <2 // Or 'no __eq' flag set?
4149 | xor RB, RB // ne = 0
4151 | mov RB, 1 // ne = 1
4153 | jmp ->vmeta_equal // Handle __eq metamethod.
4158 if (LJ_DUALNUM && vk) {
4163 | jmp ->vmeta_equal_cd
4167 case BC_ISEQS: case BC_ISNES:
4168 vk = op == BC_ISEQS;
4169 | ins_AND // RA = src, RD = str const, JMP with RD = target
4170 | mov RB, [BASE+RA*8+4]
4172 | cmp RB, LJ_TSTR; jne >3
4173 | mov RA, [BASE+RA*8]
4174 | cmp RA, [KBASE+RD*4]
4182 case BC_ISEQN: case BC_ISNEN:
4183 vk = op == BC_ISEQN;
4184 | ins_AD // RA = src, RD = num const, JMP with RD = target
4185 | mov RB, [BASE+RA*8+4]
4188 | cmp RB, LJ_TISNUM; jne >7
4189 | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8
4190 | mov RB, dword [KBASE+RD*8]
4191 | cmp RB, dword [BASE+RA*8]
4202 |7: // RA is not an integer.
4204 | // RA is a number.
4205 | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1
4206 | // RA is a number, RD is an integer.
4208 | cvtsi2sd xmm0, dword [KBASE+RD*8]
4210 | fild dword [KBASE+RD*8]
4214 |8: // RA is an integer, RD is a number.
4216 | cvtsi2sd xmm0, dword [BASE+RA*8]
4217 | ucomisd xmm0, qword [KBASE+RD*8]
4219 | fild dword [BASE+RA*8]
4220 | fld qword [KBASE+RD*8]
4224 | cmp RB, LJ_TISNUM; jae >3
4228 | movsd xmm0, qword [KBASE+RD*8]
4230 | ucomisd xmm0, qword [BASE+RA*8]
4234 | fld qword [KBASE+RD*8]
4236 | fld qword [BASE+RA*8]
4241 case BC_ISEQP: case BC_ISNEP:
4242 vk = op == BC_ISEQP;
4243 | ins_AND // RA = src, RD = primitive type (~), JMP with RD = target
4244 | mov RB, [BASE+RA*8+4]
4247 if (!LJ_HASFFI) goto iseqne_test;
4255 | cmp RB, LJ_TCDATA; jne <2
4256 | jmp ->vmeta_equal_cd
4259 | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
4267 /* -- Unary test and copy ops ------------------------------------------- */
4269 case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
4270 | ins_AD // RA = dst or unused, RD = src, JMP with RD = target
4271 | mov RB, [BASE+RD*8+4]
4273 | cmp RB, LJ_TISTRUECOND
4274 if (op == BC_IST || op == BC_ISTC) {
4279 if (op == BC_ISTC || op == BC_ISFC) {
4280 | mov [BASE+RA*8+4], RB
4281 | mov RB, [BASE+RD*8]
4282 | mov [BASE+RA*8], RB
4286 |1: // Fallthrough to the next instruction.
4290 /* -- Unary ops --------------------------------------------------------- */
4293 | ins_AD // RA = dst, RD = src
4295 | mov RBa, [BASE+RD*8]
4296 | mov [BASE+RA*8], RBa
4298 | mov RB, [BASE+RD*8+4]
4299 | mov RD, [BASE+RD*8]
4300 | mov [BASE+RA*8+4], RB
4301 | mov [BASE+RA*8], RD
4306 | ins_AD // RA = dst, RD = src
4308 | checktp RD, LJ_TISTRUECOND
4310 | mov [BASE+RA*8+4], RB
4314 | ins_AD // RA = dst, RD = src
4317 | mov RB, [BASE+RD*8]
4320 | mov dword [BASE+RA*8+4], LJ_TISNUM
4321 | mov dword [BASE+RA*8], RB
4325 | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31.
4326 | mov dword [BASE+RA*8], 0
4331 | checknum RD, ->vmeta_unm
4334 | movsd xmm0, qword [BASE+RD*8]
4335 | sseconst_sign xmm1, RDa
4337 | movsd qword [BASE+RA*8], xmm0
4339 | fld qword [BASE+RD*8]
4341 | fstp qword [BASE+RA*8]
4350 | ins_AD // RA = dst, RD = src
4352 | mov STR:RD, [BASE+RD*8]
4354 | mov RD, dword STR:RD->len
4356 | mov dword [BASE+RA*8+4], LJ_TISNUM
4357 | mov dword [BASE+RA*8], RD
4360 | cvtsi2sd xmm0, dword STR:RD->len
4362 | movsd qword [BASE+RA*8], xmm0
4364 | fild dword STR:RD->len
4366 | fstp qword [BASE+RA*8]
4370 | checktab RD, ->vmeta_len
4371 | mov TAB:FCARG1, [BASE+RD*8]
4373 | mov TAB:RB, TAB:FCARG1->metatable
4379 | mov RB, BASE // Save BASE.
4380 | call extern lj_tab_len@4 // (GCtab *t)
4381 | // Length of table returned in eax (RD).
4390 | mov BASE, RB // Restore BASE.
4394 |9: // Check for __len.
4395 | test byte TAB:RB->nomm, 1<<MM_len
4397 | jmp ->vmeta_len // 'no __len' flag NOT set: check.
4401 /* -- Binary ops -------------------------------------------------------- */
4403 |.macro ins_arithpre, x87ins, sseins, ssereg
4405 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
4408 | checknum RB, ->vmeta_arith_vn
4410 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn
4413 | movsd xmm0, qword [BASE+RB*8]
4414 | sseins ssereg, qword [KBASE+RC*8]
4416 | fld qword [BASE+RB*8]
4417 | x87ins qword [KBASE+RC*8]
4421 | checknum RB, ->vmeta_arith_nv
4423 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv
4426 | movsd xmm0, qword [KBASE+RC*8]
4427 | sseins ssereg, qword [BASE+RB*8]
4429 | fld qword [KBASE+RC*8]
4430 | x87ins qword [BASE+RB*8]
4434 | checknum RB, ->vmeta_arith_vv
4435 | checknum RC, ->vmeta_arith_vv
4437 | movsd xmm0, qword [BASE+RB*8]
4438 | sseins ssereg, qword [BASE+RC*8]
4440 | fld qword [BASE+RB*8]
4441 | x87ins qword [BASE+RC*8]
4447 |.macro ins_arithdn, intins
4449 ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
4452 | checkint RB, ->vmeta_arith_vn
4453 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn
4454 | mov RB, [BASE+RB*8]
4455 | intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno
4458 | checkint RB, ->vmeta_arith_nv
4459 | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv
4460 | mov RC, [KBASE+RC*8]
4461 | intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo
4464 | checkint RB, ->vmeta_arith_vv
4465 | checkint RC, ->vmeta_arith_vv
4466 | mov RB, [BASE+RB*8]
4467 | intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo
4470 | mov dword [BASE+RA*8+4], LJ_TISNUM
4472 | mov dword [BASE+RA*8], RC
4474 | mov dword [BASE+RA*8], RB
4479 |.macro ins_arithpost
4481 | movsd qword [BASE+RA*8], xmm0
4483 | fstp qword [BASE+RA*8]
4487 |.macro ins_arith, x87ins, sseins
4488 | ins_arithpre x87ins, sseins, xmm0
4493 |.macro ins_arith, intins, x87ins, sseins
4495 | ins_arithdn intins
4497 | ins_arith, x87ins, sseins
4501 | // RA = dst, RB = src1 or num const, RC = src2 or num const
4502 case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
4503 | ins_arith add, fadd, addsd
4505 case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
4506 | ins_arith sub, fsub, subsd
4508 case BC_MULVN: case BC_MULNV: case BC_MULVV:
4509 | ins_arith imul, fmul, mulsd
4511 case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
4512 | ins_arith fdiv, divsd
4515 | ins_arithpre fld, movsd, xmm1
4521 case BC_MODNV: case BC_MODVV:
4522 | ins_arithpre fld, movsd, xmm1
4523 | jmp ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
4526 | ins_arithpre fld, movsd, xmm1
4533 | ins_ABC // RA = dst, RB = src_start, RC = src_end
4535 | mov L:CARG1d, SAVE_L
4536 | mov L:CARG1d->base, BASE
4537 | lea CARG2d, [BASE+RC*8]
4541 | mov L:RB, L:CARG1d
4543 | lea RA, [BASE+RC*8]
4550 | mov L:RB->base, BASE
4553 | call extern lj_meta_cat // (lua_State *L, TValue *top, int left)
4554 | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
4555 | mov BASE, L:RB->base
4558 | movzx RB, PC_RB // Copy result to Stk[RA] from Stk[RB].
4561 | mov RCa, [BASE+RB*8]
4562 | mov [BASE+RA*8], RCa
4564 | mov RC, [BASE+RB*8+4]
4565 | mov RB, [BASE+RB*8]
4566 | mov [BASE+RA*8+4], RC
4567 | mov [BASE+RA*8], RB
4572 /* -- Constant ops ------------------------------------------------------ */
4575 | ins_AND // RA = dst, RD = str const (~)
4576 | mov RD, [KBASE+RD*4]
4577 | mov dword [BASE+RA*8+4], LJ_TSTR
4578 | mov [BASE+RA*8], RD
4583 | ins_AND // RA = dst, RD = cdata const (~)
4584 | mov RD, [KBASE+RD*4]
4585 | mov dword [BASE+RA*8+4], LJ_TCDATA
4586 | mov [BASE+RA*8], RD
4591 | ins_AD // RA = dst, RD = signed int16 literal
4594 | mov dword [BASE+RA*8+4], LJ_TISNUM
4595 | mov dword [BASE+RA*8], RD
4597 | movsx RD, RDW // Sign-extend literal.
4599 | movsd qword [BASE+RA*8], xmm0
4601 | fild PC_RD // Refetch signed RD from instruction.
4602 | fstp qword [BASE+RA*8]
4607 | ins_AD // RA = dst, RD = num const
4609 | movsd xmm0, qword [KBASE+RD*8]
4610 | movsd qword [BASE+RA*8], xmm0
4612 | fld qword [KBASE+RD*8]
4613 | fstp qword [BASE+RA*8]
4618 | ins_AND // RA = dst, RD = primitive type (~)
4619 | mov [BASE+RA*8+4], RD
4623 | ins_AD // RA = dst_start, RD = dst_end
4624 | lea RA, [BASE+RA*8+12]
4625 | lea RD, [BASE+RD*8+4]
4627 | mov [RA-8], RB // Sets minimum 2 slots.
4636 /* -- Upvalue and function ops ------------------------------------------ */
4639 | ins_AD // RA = dst, RD = upvalue #
4640 | mov LFUNC:RB, [BASE-8]
4641 | mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)]
4642 | mov RB, UPVAL:RB->v
4645 | mov [BASE+RA*8], RDa
4649 | mov [BASE+RA*8+4], RD
4650 | mov [BASE+RA*8], RB
4655 #define TV2MARKOFS \
4656 ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
4657 | ins_AD // RA = upvalue #, RD = src
4658 | mov LFUNC:RB, [BASE-8]
4659 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4660 | cmp byte UPVAL:RB->closed, 0
4661 | mov RB, UPVAL:RB->v
4662 | mov RA, [BASE+RD*8]
4663 | mov RD, [BASE+RD*8+4]
4667 | // Check barrier for closed upvalue.
4668 | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv)
4673 |2: // Upvalue is black. Check if new value is collectable and white.
4675 | cmp RD, LJ_TNUMX - LJ_TISGCV // tvisgcv(v)
4677 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v)
4679 | // Crossed a write barrier. Move the barrier forward.
4680 |.if X64 and not X64WIN
4682 | mov RB, BASE // Save BASE.
4684 | xchg FCARG2, RB // Save BASE (FCARG2 == BASE).
4686 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
4687 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
4688 | mov BASE, RB // Restore BASE.
4693 | ins_AND // RA = upvalue #, RD = str const (~)
4694 | mov LFUNC:RB, [BASE-8]
4695 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4696 | mov GCOBJ:RA, [KBASE+RD*4]
4697 | mov RD, UPVAL:RB->v
4698 | mov [RD], GCOBJ:RA
4699 | mov dword [RD+4], LJ_TSTR
4700 | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv)
4705 |2: // Check if string is white and ensure upvalue is closed.
4706 | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str)
4708 | cmp byte UPVAL:RB->closed, 0
4710 | // Crossed a write barrier. Move the barrier forward.
4711 | mov RB, BASE // Save BASE (FCARG2 == BASE).
4713 | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
4714 | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
4715 | mov BASE, RB // Restore BASE.
4719 | ins_AD // RA = upvalue #, RD = num const
4720 | mov LFUNC:RB, [BASE-8]
4722 | movsd xmm0, qword [KBASE+RD*8]
4724 | fld qword [KBASE+RD*8]
4726 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4727 | mov RA, UPVAL:RB->v
4729 | movsd qword [RA], xmm0
4736 | ins_AND // RA = upvalue #, RD = primitive type (~)
4737 | mov LFUNC:RB, [BASE-8]
4738 | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
4739 | mov RA, UPVAL:RB->v
4744 | ins_AD // RA = level, RD = target
4745 | branchPC RD // Do this first to free RD.
4747 | cmp dword L:RB->openupval, 0
4749 | mov L:RB->base, BASE
4750 | lea FCARG2, [BASE+RA*8] // Caveat: FCARG2 == BASE
4751 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
4752 | call extern lj_func_closeuv@8 // (lua_State *L, TValue *level)
4753 | mov BASE, L:RB->base
4759 | ins_AND // RA = dst, RD = proto const (~) (holding function prototype)
4762 | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
4763 | mov CARG3d, [BASE-8]
4764 | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *.
4767 | mov LFUNC:RA, [BASE-8]
4768 | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *.
4770 | mov ARG3, LFUNC:RA
4771 | mov ARG2, PROTO:RD
4773 | mov L:RB->base, BASE
4776 | // (lua_State *L, GCproto *pt, GCfuncL *parent)
4777 | call extern lj_func_newL_gc
4778 | // GCfuncL * returned in eax (RC).
4779 | mov BASE, L:RB->base
4781 | mov [BASE+RA*8], LFUNC:RC
4782 | mov dword [BASE+RA*8+4], LJ_TFUNC
4786 /* -- Table ops --------------------------------------------------------- */
4789 | ins_AD // RA = dst, RD = hbits|asize
4791 | mov L:RB->base, BASE
4792 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
4793 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
4811 | mov L:CARG1d, L:RB
4817 | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
4818 | // Table * returned in eax (RC).
4819 | mov BASE, L:RB->base
4821 | mov [BASE+RA*8], TAB:RC
4822 | mov dword [BASE+RA*8+4], LJ_TTAB
4824 |3: // Turn 0x7ff into 0x801.
4828 | mov L:FCARG1, L:RB
4829 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
4834 | ins_AND // RA = dst, RD = table const (~) (holding template table)
4836 | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
4838 | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
4839 | mov L:RB->base, BASE
4842 | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE
4843 | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
4844 | call extern lj_tab_dup@8 // (lua_State *L, Table *kt)
4845 | // Table * returned in eax (RC).
4846 | mov BASE, L:RB->base
4848 | mov [BASE+RA*8], TAB:RC
4849 | mov dword [BASE+RA*8+4], LJ_TTAB
4852 | mov L:FCARG1, L:RB
4853 | call extern lj_gc_step_fixtop@4 // (lua_State *L)
4854 | movzx RD, PC_RD // Need to reload RD.
4860 | ins_AND // RA = dst, RD = str const (~)
4861 | mov LFUNC:RB, [BASE-8]
4862 | mov TAB:RB, LFUNC:RB->env
4863 | mov STR:RC, [KBASE+RD*4]
4867 | ins_AND // RA = src, RD = str const (~)
4868 | mov LFUNC:RB, [BASE-8]
4869 | mov TAB:RB, LFUNC:RB->env
4870 | mov STR:RC, [KBASE+RD*4]
4875 | ins_ABC // RA = dst, RB = table, RC = key
4876 | checktab RB, ->vmeta_tgetv
4877 | mov TAB:RB, [BASE+RB*8]
4882 | mov RC, dword [BASE+RC*8]
4884 | // Convert number to int and back and compare.
4887 | movsd xmm0, qword [BASE+RC*8]
4890 | ucomisd xmm0, xmm1
4892 | fld qword [BASE+RC*8]
4898 | jne ->vmeta_tgetv // Generic numeric key? Use fallback.
4900 | cmp RC, TAB:RB->asize // Takes care of unordered, too.
4901 | jae ->vmeta_tgetv // Not in array part? Use fallback.
4903 | add RC, TAB:RB->array
4904 | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4906 | // Get array slot.
4909 | mov [BASE+RA*8], RBa
4913 | mov [BASE+RA*8], RB
4914 | mov [BASE+RA*8+4], RC
4919 |2: // Check for __index if table value is nil.
4920 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
4922 | mov TAB:RA, TAB:RB->metatable
4923 | test byte TAB:RA->nomm, 1<<MM_index
4924 | jz ->vmeta_tgetv // 'no __index' flag NOT set: check.
4925 | movzx RA, PC_RA // Restore RA.
4927 | mov dword [BASE+RA*8+4], LJ_TNIL
4931 | checkstr RC, ->vmeta_tgetv
4932 | mov STR:RC, [BASE+RC*8]
4936 | ins_ABC // RA = dst, RB = table, RC = str const (~)
4938 | mov STR:RC, [KBASE+RC*4]
4939 | checktab RB, ->vmeta_tgets
4940 | mov TAB:RB, [BASE+RB*8]
4941 |->BC_TGETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
4942 | mov RA, TAB:RB->hmask
4943 | and RA, STR:RC->hash
4945 | add NODE:RA, TAB:RB->node
4947 | cmp dword NODE:RA->key.it, LJ_TSTR
4949 | cmp dword NODE:RA->key.gcr, STR:RC
4951 | // Ok, key found. Assumes: offsetof(Node, val) == 0
4952 | cmp dword [RA+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4953 | je >5 // Key found, but nil value?
4955 | // Get node value.
4958 | mov [BASE+RC*8], RBa
4962 | mov [BASE+RC*8], RB
4963 | mov [BASE+RC*8+4], RA
4970 | mov dword [BASE+RC*8+4], LJ_TNIL
4973 |4: // Follow hash chain.
4974 | mov NODE:RA, NODE:RA->next
4975 | test NODE:RA, NODE:RA
4977 | // End of hash chain: key not found, nil result.
4979 |5: // Check for __index if table value is nil.
4980 | mov TAB:RA, TAB:RB->metatable
4981 | test TAB:RA, TAB:RA
4982 | jz <3 // No metatable: done.
4983 | test byte TAB:RA->nomm, 1<<MM_index
4984 | jnz <3 // 'no __index' flag set: done.
4985 | jmp ->vmeta_tgets // Caveat: preserve STR:RC.
4988 | ins_ABC // RA = dst, RB = table, RC = byte literal
4989 | checktab RB, ->vmeta_tgetb
4990 | mov TAB:RB, [BASE+RB*8]
4991 | cmp RC, TAB:RB->asize
4994 | add RC, TAB:RB->array
4995 | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
4997 | // Get array slot.
5000 | mov [BASE+RA*8], RBa
5004 | mov [BASE+RA*8], RB
5005 | mov [BASE+RA*8+4], RC
5010 |2: // Check for __index if table value is nil.
5011 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5013 | mov TAB:RA, TAB:RB->metatable
5014 | test byte TAB:RA->nomm, 1<<MM_index
5015 | jz ->vmeta_tgetb // 'no __index' flag NOT set: check.
5016 | movzx RA, PC_RA // Restore RA.
5018 | mov dword [BASE+RA*8+4], LJ_TNIL
5023 | ins_ABC // RA = src, RB = table, RC = key
5024 | checktab RB, ->vmeta_tsetv
5025 | mov TAB:RB, [BASE+RB*8]
5030 | mov RC, dword [BASE+RC*8]
5032 | // Convert number to int and back and compare.
5035 | movsd xmm0, qword [BASE+RC*8]
5038 | ucomisd xmm0, xmm1
5040 | fld qword [BASE+RC*8]
5046 | jne ->vmeta_tsetv // Generic numeric key? Use fallback.
5048 | cmp RC, TAB:RB->asize // Takes care of unordered, too.
5051 | add RC, TAB:RB->array
5052 | cmp dword [RC+4], LJ_TNIL
5053 | je >3 // Previous value is nil?
5055 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5057 |2: // Set array slot.
5059 | mov RBa, [BASE+RA*8]
5062 | mov RB, [BASE+RA*8+4]
5063 | mov RA, [BASE+RA*8]
5069 |3: // Check for __newindex if previous value is nil.
5070 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5072 | mov TAB:RA, TAB:RB->metatable
5073 | test byte TAB:RA->nomm, 1<<MM_newindex
5074 | jz ->vmeta_tsetv // 'no __newindex' flag NOT set: check.
5075 | movzx RA, PC_RA // Restore RA.
5079 | checkstr RC, ->vmeta_tsetv
5080 | mov STR:RC, [BASE+RC*8]
5083 |7: // Possible table write barrier for the value. Skip valiswhite check.
5084 | barrierback TAB:RB, RA
5085 | movzx RA, PC_RA // Restore RA.
5089 | ins_ABC // RA = src, RB = table, RC = str const (~)
5091 | mov STR:RC, [KBASE+RC*4]
5092 | checktab RB, ->vmeta_tsets
5093 | mov TAB:RB, [BASE+RB*8]
5094 |->BC_TSETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
5095 | mov RA, TAB:RB->hmask
5096 | and RA, STR:RC->hash
5098 | mov byte TAB:RB->nomm, 0 // Clear metamethod cache.
5099 | add NODE:RA, TAB:RB->node
5101 | cmp dword NODE:RA->key.it, LJ_TSTR
5103 | cmp dword NODE:RA->key.gcr, STR:RC
5105 | // Ok, key found. Assumes: offsetof(Node, val) == 0
5106 | cmp dword [RA+4], LJ_TNIL
5107 | je >4 // Previous value is nil?
5109 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5111 |3: // Set node value.
5114 | mov RBa, [BASE+RC*8]
5117 | mov RB, [BASE+RC*8+4]
5118 | mov RC, [BASE+RC*8]
5124 |4: // Check for __newindex if previous value is nil.
5125 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5127 | mov TMP1, RA // Save RA.
5128 | mov TAB:RA, TAB:RB->metatable
5129 | test byte TAB:RA->nomm, 1<<MM_newindex
5130 | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
5131 | mov RA, TMP1 // Restore RA.
5134 |5: // Follow hash chain.
5135 | mov NODE:RA, NODE:RA->next
5136 | test NODE:RA, NODE:RA
5138 | // End of hash chain: key not found, add a new one.
5140 | // But check for __newindex first.
5141 | mov TAB:RA, TAB:RB->metatable
5142 | test TAB:RA, TAB:RA
5143 | jz >6 // No metatable: continue.
5144 | test byte TAB:RA->nomm, 1<<MM_newindex
5145 | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
5149 | mov TMP3, TAB:RB // Save TAB:RB for us.
5151 | mov L:CARG1d, SAVE_L
5152 | mov L:CARG1d->base, BASE
5154 | mov CARG2d, TAB:RB
5155 | mov L:RB, L:CARG1d
5157 | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2.
5162 | mov L:RB->base, BASE
5165 | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
5166 | // Handles write barrier for the new key. TValue * returned in eax (RC).
5167 | mov BASE, L:RB->base
5168 | mov TAB:RB, TMP3 // Need TAB:RB for barrier.
5170 | jmp <2 // Must check write barrier for value.
5172 |7: // Possible table write barrier for the value. Skip valiswhite check.
5173 | barrierback TAB:RB, RC // Destroys STR:RC.
5177 | ins_ABC // RA = src, RB = table, RC = byte literal
5178 | checktab RB, ->vmeta_tsetb
5179 | mov TAB:RB, [BASE+RB*8]
5180 | cmp RC, TAB:RB->asize
5183 | add RC, TAB:RB->array
5184 | cmp dword [RC+4], LJ_TNIL
5185 | je >3 // Previous value is nil?
5187 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5189 |2: // Set array slot.
5191 | mov RAa, [BASE+RA*8]
5194 | mov RB, [BASE+RA*8+4]
5195 | mov RA, [BASE+RA*8]
5201 |3: // Check for __newindex if previous value is nil.
5202 | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
5204 | mov TAB:RA, TAB:RB->metatable
5205 | test byte TAB:RA->nomm, 1<<MM_newindex
5206 | jz ->vmeta_tsetb // 'no __newindex' flag NOT set: check.
5207 | movzx RA, PC_RA // Restore RA.
5210 |7: // Possible table write barrier for the value. Skip valiswhite check.
5211 | barrierback TAB:RB, RA
5212 | movzx RA, PC_RA // Restore RA.
5217 | ins_AD // RA = base (table at base-1), RD = num const (start index)
5218 | mov TMP1, KBASE // Need one more free register.
5219 | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word.
5221 | lea RA, [BASE+RA*8]
5222 | mov TAB:RB, [RA-8] // Guaranteed to be a table.
5223 | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
5228 | jz >4 // Nothing to copy?
5229 | add RD, KBASE // Compute needed size.
5230 | cmp RD, TAB:RB->asize
5231 | ja >5 // Doesn't fit into array part?
5234 | add KBASE, TAB:RB->array
5235 |3: // Copy result slots to table.
5254 |5: // Need to resize array part.
5256 | mov L:CARG1d, SAVE_L
5257 | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
5258 | mov CARG2d, TAB:RB
5260 | mov L:RB, L:CARG1d
5264 | mov L:RB->base, BASE
5269 | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
5270 | mov BASE, L:RB->base
5271 | movzx RA, PC_RA // Restore RA.
5274 |7: // Possible table write barrier for any value. Skip valiswhite check.
5275 | barrierback TAB:RB, RD
5279 /* -- Calls and vararg handling ----------------------------------------- */
5281 case BC_CALL: case BC_CALLM:
5282 | ins_A_C // RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs
5283 if (op == BC_CALLM) {
5284 | add NARGS:RD, MULTRES
5286 | cmp dword [BASE+RA*8+4], LJ_TFUNC
5287 | mov LFUNC:RB, [BASE+RA*8]
5288 | jne ->vmeta_call_ra
5289 | lea BASE, [BASE+RA*8+8]
5294 | ins_AD // RA = base, RD = extra_nargs
5295 | add NARGS:RD, MULTRES
5296 | // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.
5299 | ins_AD // RA = base, RD = nargs+1
5300 | lea RA, [BASE+RA*8+8]
5301 | mov KBASE, BASE // Use KBASE for move + vmeta_call hint.
5302 | mov LFUNC:RB, [RA-8]
5303 | cmp dword [RA-4], LJ_TFUNC
5307 | test PC, FRAME_TYPE
5310 | mov [BASE-8], LFUNC:RB // Copy function down, reloaded below.
5311 | mov MULTRES, NARGS:RD
5314 |2: // Move args down.
5330 | mov LFUNC:RB, [BASE-8]
5332 | mov NARGS:RD, MULTRES
5333 | cmp byte LFUNC:RB->ffid, 1 // (> FF_C) Calling a fast function?
5338 |5: // Tailcall to a fast function.
5339 | test PC, FRAME_TYPE // Lua frame below?
5343 | mov LFUNC:KBASE, [BASE+RA*8-8] // Need to prepare KBASE.
5344 | mov KBASE, LFUNC:KBASE->pc
5345 | mov KBASE, [KBASE+PC2PROTO(k)]
5348 |7: // Tailcall from a vararg function.
5349 | sub PC, FRAME_VARG
5350 | test PC, FRAME_TYPEP
5351 | jnz >8 // Vararg frame below?
5352 | sub BASE, PC // Need to relocate BASE/KBASE down.
5357 | add PC, FRAME_VARG
5362 | ins_A // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)
5363 | lea RA, [BASE+RA*8+8] // fb = base+1
5365 | mov RBa, [RA-24] // Copy state. fb[0] = fb[-3].
5366 | mov RCa, [RA-16] // Copy control var. fb[1] = fb[-2].
5370 | mov RB, [RA-24] // Copy state. fb[0] = fb[-3].
5374 | mov RB, [RA-16] // Copy control var. fb[1] = fb[-2].
5379 | mov LFUNC:RB, [RA-32] // Copy callable. fb[-1] = fb[-4]
5381 | mov [RA-8], LFUNC:RB
5383 | cmp RC, LJ_TFUNC // Handle like a regular 2-arg call.
5391 | ins_A // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))
5393 | // NYI: add hotloop, record BC_ITERN.
5395 | mov TMP1, KBASE // Need two more free registers.
5396 | mov TMP2, DISPATCH
5397 | mov TAB:RB, [BASE+RA*8-16]
5398 | mov RC, [BASE+RA*8-8] // Get index from control var.
5399 | mov DISPATCH, TAB:RB->asize
5401 | mov KBASE, TAB:RB->array
5402 |1: // Traverse array part.
5403 | cmp RC, DISPATCH; jae >5 // Index points after array part?
5404 | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4
5406 | mov dword [BASE+RA*8+4], LJ_TISNUM
5407 | mov dword [BASE+RA*8], RC
5411 | fild dword [BASE+RA*8-8]
5413 | // Copy array slot to returned value.
5415 | mov RBa, [KBASE+RC*8]
5416 | mov [BASE+RA*8+8], RBa
5418 | mov RB, [KBASE+RC*8+4]
5419 | mov [BASE+RA*8+12], RB
5420 | mov RB, [KBASE+RC*8]
5421 | mov [BASE+RA*8+8], RB
5424 | // Return array index as a numeric key.
5428 | movsd qword [BASE+RA*8], xmm0
5430 | fstp qword [BASE+RA*8]
5432 | mov [BASE+RA*8-8], RC // Update control var.
5434 | movzx RD, PC_RD // Get target from ITERL.
5437 | mov DISPATCH, TMP2
5441 |4: // Skip holes in array part.
5443 |.if not (DUALNUM or SSE)
5444 | mov [BASE+RA*8-8], RC
5448 |5: // Traverse hash part.
5451 | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1.
5452 | imul KBASE, RC, #NODE
5453 | add NODE:KBASE, TAB:RB->node
5454 | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7
5455 | lea DISPATCH, [RC+DISPATCH+1]
5456 | // Copy key and value from hash slot.
5458 | mov RBa, NODE:KBASE->key
5459 | mov RCa, NODE:KBASE->val
5460 | mov [BASE+RA*8], RBa
5461 | mov [BASE+RA*8+8], RCa
5463 | mov RB, NODE:KBASE->key.gcr
5464 | mov RC, NODE:KBASE->key.it
5465 | mov [BASE+RA*8], RB
5466 | mov [BASE+RA*8+4], RC
5467 | mov RB, NODE:KBASE->val.gcr
5468 | mov RC, NODE:KBASE->val.it
5469 | mov [BASE+RA*8+8], RB
5470 | mov [BASE+RA*8+12], RC
5472 | mov [BASE+RA*8-8], DISPATCH
5475 |7: // Skip holes in hash part.
5481 | ins_AD // RA = base, RD = target (points to ITERN)
5482 | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5
5483 | mov CFUNC:RB, [BASE+RA*8-24]
5484 | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5
5485 | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5
5486 | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5
5488 | mov dword [BASE+RA*8-8], 0 // Initialize control var.
5489 | mov dword [BASE+RA*8-4], 0xfffe7fff
5492 |5: // Despecialize bytecode if any of the checks fail.
5495 | mov byte [PC], BC_ITERC
5500 | ins_ABC // RA = base, RB = nresults+1, RC = numparams
5501 | mov TMP1, KBASE // Need one more free register.
5502 | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
5503 | lea RA, [BASE+RA*8]
5504 | sub KBASE, [BASE-4]
5505 | // Note: KBASE may now be even _above_ BASE if nargs was < numparams.
5507 | jz >5 // Copy all varargs?
5508 | lea RB, [RA+RB*8-8]
5509 | cmp KBASE, BASE // No vararg slots?
5511 |1: // Copy vararg slots to destination slots.
5513 | mov RCa, [KBASE-8]
5524 | cmp RA, RB // All destination slots filled?
5526 | cmp KBASE, BASE // No more vararg slots?
5528 |2: // Fill up remainder with nil.
5529 | mov dword [RA+4], LJ_TNIL
5537 |5: // Copy all varargs.
5538 | mov MULTRES, 1 // MULTRES = 0+1
5541 | jbe <3 // No vararg slots?
5545 | mov MULTRES, RB // MULTRES = #varargs+1
5548 | cmp RC, L:RB->maxstack
5549 | ja >7 // Need to grow stack?
5550 |6: // Copy all vararg slots.
5552 | mov RCa, [KBASE-8]
5563 | cmp KBASE, BASE // No more vararg slots?
5567 |7: // Grow stack for varargs.
5568 | mov L:RB->base, BASE
5571 | sub KBASE, BASE // Need delta, because BASE may change.
5572 | mov FCARG2, MULTRES
5575 | call extern lj_state_growstack@8 // (lua_State *L, int n)
5576 | mov BASE, L:RB->base
5582 /* -- Returns ----------------------------------------------------------- */
5585 | ins_AD // RA = results, RD = extra_nresults
5586 | add RD, MULTRES // MULTRES >=1, so RD >=1.
5587 | // Fall through. Assumes BC_RET follows and ins_AD is a no-op.
5590 case BC_RET: case BC_RET0: case BC_RET1:
5591 | ins_AD // RA = results, RD = nresults+1
5592 if (op != BC_RET0) {
5597 | mov MULTRES, RD // Save nresults+1.
5598 | test PC, FRAME_TYPE // Check frame type marker.
5599 | jnz >7 // Not returning to a fixarg Lua func?
5603 | mov KBASE, BASE // Use KBASE for result move.
5606 |2: // Move results down.
5608 | mov RBa, [KBASE+RA]
5609 | mov [KBASE-8], RBa
5611 | mov RB, [KBASE+RA]
5613 | mov RB, [KBASE+RA+4]
5620 | mov RD, MULTRES // Note: MULTRES may be >255.
5621 | movzx RB, PC_RB // So cannot compare with RDL!
5623 | cmp RB, RD // More results expected?
5628 | mov RBa, [BASE+RA]
5631 | mov RB, [BASE+RA+4]
5639 | cmp PC_RB, RDL // More results expected?
5645 | not RAa // Note: ~RA = -(RA+1)
5646 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
5647 | mov LFUNC:KBASE, [BASE-8]
5648 | mov KBASE, LFUNC:KBASE->pc
5649 | mov KBASE, [KBASE+PC2PROTO(k)]
5652 |6: // Fill up results with nil.
5654 | mov dword [KBASE-4], LJ_TNIL // Note: relies on shifted base.
5657 | mov dword [BASE+RD*8-12], LJ_TNIL
5662 |7: // Non-standard return case.
5663 | lea RB, [PC-FRAME_VARG]
5664 | test RB, FRAME_TYPEP
5666 | // Return from vararg function: relocate BASE down and RA up.
5668 if (op != BC_RET0) {
5674 /* -- Loops and branches ------------------------------------------------ */
5676 |.define FOR_IDX, [RA]; .define FOR_TIDX, dword [RA+4]
5677 |.define FOR_STOP, [RA+8]; .define FOR_TSTOP, dword [RA+12]
5678 |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20]
5679 |.define FOR_EXT, [RA+24]; .define FOR_TEXT, dword [RA+28]
5685 | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.
5695 vk = (op == BC_IFORL || op == BC_JFORL);
5696 | ins_AJ // RA = base, RD = target (after end of loop or start of loop)
5697 | lea RA, [BASE+RA*8]
5699 | cmp FOR_TIDX, LJ_TISNUM; jne >9
5701 | cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for
5702 | cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for
5703 | mov RB, dword FOR_IDX
5704 | cmp dword FOR_STEP, 0; jl >5
5706 #ifdef LUA_USE_ASSERT
5707 | cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type
5708 | cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type
5710 | mov RB, dword FOR_STEP
5711 | test RB, RB; js >5
5712 | add RB, dword FOR_IDX; jo >1
5713 | mov dword FOR_IDX, RB
5715 | cmp RB, dword FOR_STOP
5716 | mov FOR_TEXT, LJ_TISNUM
5717 | mov dword FOR_EXT, RB
5718 if (op == BC_FORI) {
5723 } else if (op == BC_JFORI) {
5729 } else if (op == BC_IFORL) {
5742 |5: // Invert check for negative step.
5744 | add RB, dword FOR_IDX; jo <1
5745 | mov dword FOR_IDX, RB
5747 | cmp RB, dword FOR_STOP
5748 | mov FOR_TEXT, LJ_TISNUM
5749 | mov dword FOR_EXT, RB
5750 if (op == BC_FORI) {
5752 } else if (op == BC_JFORI) {
5756 } else if (op == BC_IFORL) {
5762 |9: // Fallback to FP variant.
5764 | cmp FOR_TIDX, LJ_TISNUM
5768 | cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for
5770 #ifdef LUA_USE_ASSERT
5771 | cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type
5772 | cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type
5775 | mov RB, FOR_TSTEP // Load type/hiword of for step.
5777 | cmp RB, LJ_TISNUM; jae ->vmeta_for
5780 | movsd xmm0, qword FOR_IDX
5781 | movsd xmm1, qword FOR_STOP
5783 | addsd xmm0, qword FOR_STEP
5784 | movsd qword FOR_IDX, xmm0
5785 | test RB, RB; js >3
5789 | ucomisd xmm1, xmm0
5791 | movsd qword FOR_EXT, xmm0
5793 | fld qword FOR_STOP
5796 | fadd qword FOR_STEP // nidx = idx + step
5799 | test RB, RB; js >1
5804 | fxch // Swap lim/(n)idx if step non-negative.
5808 if (op == BC_FORI) {
5815 } else if (op == BC_JFORI) {
5819 } else if (op == BC_IFORL) {
5836 |3: // Invert comparison if step is negative.
5837 | ucomisd xmm0, xmm1
5846 | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.
5854 | ins_AJ // RA = base, RD = target
5855 | lea RA, [BASE+RA*8]
5857 | cmp RB, LJ_TNIL; je >1 // Stop if iterator returned nil.
5858 if (op == BC_JITERL) {
5864 | branchPC RD // Otherwise save control var + branch.
5874 | ins_A // RA = base, RD = target (loop extent)
5875 | // Note: RA/RD is only used by trace recorder to determine scope/extent
5876 | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
5880 | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.
5884 | ins_A // RA = base, RD = target (loop extent)
5890 | ins_AD // RA = base (ignored), RD = traceno
5891 | mov RA, [DISPATCH+DISPATCH_J(trace)]
5892 | mov TRACE:RD, [RA+RD*4]
5893 | mov RDa, TRACE:RD->mcode
5895 | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE
5896 | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB
5897 | // Save additional callee-save registers only used in compiled code.
5905 | movdqa [RAa], xmm6
5906 | movdqa [RAa-1*16], xmm7
5907 | movdqa [RAa-2*16], xmm8
5908 | movdqa [RAa-3*16], xmm9
5909 | movdqa [RAa-4*16], xmm10
5910 | movdqa [RAa-5*16], xmm11
5911 | movdqa [RAa-6*16], xmm12
5912 | movdqa [RAa-7*16], xmm13
5913 | movdqa [RAa-8*16], xmm14
5914 | movdqa [RAa-9*16], xmm15
5925 | ins_AJ // RA = unused, RD = target
5930 /* -- Function headers -------------------------------------------------- */
5933 ** Reminder: A function may be called with func/args above L->maxstack,
5934 ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,
5935 ** too. This means all FUNC* ops (including fast functions) must check
5936 ** for stack overflow _before_ adding more slots!
5943 case BC_FUNCV: /* NYI: compiled vararg functions. */
5944 | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.
5952 | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
5953 | mov KBASE, [PC-4+PC2PROTO(k)]
5955 | lea RA, [BASE+RA*8] // Top of frame.
5956 | cmp RA, L:RB->maxstack
5957 | ja ->vm_growstack_f
5958 | movzx RA, byte [PC-4+PC2PROTO(numparams)]
5959 | cmp NARGS:RD, RA // Check for missing parameters.
5962 if (op == BC_JFUNCF) {
5969 |3: // Clear missing parameters.
5970 | mov dword [BASE+NARGS:RD*8-4], LJ_TNIL
5981 | int3 // NYI: compiled vararg functions
5982 break; /* NYI: compiled vararg functions. */
5985 | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
5986 | lea RB, [NARGS:RD*8+FRAME_VARG]
5987 | lea RD, [BASE+NARGS:RD*8]
5988 | mov LFUNC:KBASE, [BASE-8]
5989 | mov [RD-4], RB // Store delta + FRAME_VARG.
5990 | mov [RD-8], LFUNC:KBASE // Store copy of LFUNC.
5993 | cmp RA, L:RB->maxstack
5994 | ja ->vm_growstack_v // Need to grow stack.
5997 | movzx RB, byte [PC-4+PC2PROTO(numparams)]
6000 |1: // Copy fixarg slots up to new frame.
6003 | jnb >3 // Less args than parameters?
6009 | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC).
6013 if (op == BC_JFUNCV) {
6017 | mov KBASE, [PC-4+PC2PROTO(k)]
6021 |3: // Clear missing parameters.
6022 | mov dword [RD+4], LJ_TNIL
6031 | ins_AD // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1
6032 | mov CFUNC:RB, [BASE-8]
6033 | mov KBASEa, CFUNC:RB->f
6035 | lea RD, [BASE+NARGS:RD*8-8]
6036 | mov L:RB->base, BASE
6037 | lea RA, [RD+8*LUA_MINSTACK]
6038 | cmp RA, L:RB->maxstack
6040 if (op == BC_FUNCC) {
6042 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
6049 | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
6055 | ja ->vm_growstack_c // Need to grow stack.
6057 if (op == BC_FUNCC) {
6058 | call KBASEa // (lua_State *L)
6060 | // (lua_State *L, lua_CFunction f)
6061 | call aword [DISPATCH+DISPATCH_GL(wrapf)]
6063 | set_vmstate INTERP
6064 | // nresults returned in eax (RD).
6065 | mov BASE, L:RB->base
6066 | lea RA, [BASE+RD*8]
6068 | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8
6069 | mov PC, [BASE-4] // Fetch PC of caller.
6073 /* ---------------------------------------------------------------------- */
6076 fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
6082 static int build_backend(BuildCtx *ctx)
6085 dasm_growpc(Dst, BC__MAX);
6086 build_subroutines(ctx);
6088 for (op = 0; op < BC__MAX; op++)
6089 build_ins(ctx, (BCOp)op, op);
6093 /* Emit pseudo frame-info for all assembler functions. */
6094 static void emit_asm_debug(BuildCtx *ctx)
6096 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
6100 #define REG_SP "0x7"
6101 #define REG_RA "0x10"
6105 #define REG_SP "0x4"
6106 #define REG_RA "0x8"
6108 switch (ctx->mode) {
6110 fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
6113 "\t.long .LECIE0-.LSCIE0\n"
6115 "\t.long 0xffffffff\n"
6119 "\t.sleb128 -" SZPTR "\n"
6120 "\t.byte " REG_RA "\n"
6121 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6122 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6123 "\t.align " SZPTR "\n"
6127 "\t.long .LEFDE0-.LASFDE0\n"
6129 "\t.long .Lframe0\n"
6133 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6134 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6135 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6136 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
6137 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
6139 "\t.byte 0x8d\n\t.uleb128 0x6\n" /* offset r13 */
6140 "\t.byte 0x8c\n\t.uleb128 0x7\n" /* offset r12 */
6145 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6146 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6147 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
6148 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
6149 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6151 "\t.align " SZPTR "\n"
6152 ".LEFDE0:\n\n", fcofs, CFRAME_SIZE);
6156 "\t.long .LEFDE1-.LASFDE1\n"
6158 "\t.long .Lframe0\n"
6160 "\t.quad lj_vm_ffi_call\n"
6162 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6163 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6164 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6165 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6167 "\t.long lj_vm_ffi_call\n"
6169 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6170 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6171 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6172 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6174 "\t.align " SZPTR "\n"
6175 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
6178 #if (defined(__sun__) && defined(__svr4__))
6180 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n");
6182 fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
6185 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
6189 "\t.long .LECIE1-.LSCIE1\n"
6193 "\t.string \"zPR\"\n"
6195 "\t.sleb128 -" SZPTR "\n"
6196 "\t.byte " REG_RA "\n"
6197 "\t.uleb128 6\n" /* augmentation length */
6198 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6199 "\t.long lj_err_unwind_dwarf-.\n"
6200 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6201 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6202 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6203 "\t.align " SZPTR "\n"
6207 "\t.long .LEFDE2-.LASFDE2\n"
6209 "\t.long .LASFDE2-.Lframe1\n"
6210 "\t.long .Lbegin-.\n"
6212 "\t.uleb128 0\n" /* augmentation length */
6213 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6215 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6216 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6217 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
6218 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
6220 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6221 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
6222 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
6223 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6225 "\t.align " SZPTR "\n"
6226 ".LEFDE2:\n\n", fcofs, CFRAME_SIZE);
6230 "\t.long .LECIE2-.LSCIE2\n"
6234 "\t.string \"zR\"\n"
6236 "\t.sleb128 -" SZPTR "\n"
6237 "\t.byte " REG_RA "\n"
6238 "\t.uleb128 1\n" /* augmentation length */
6239 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6240 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6241 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6242 "\t.align " SZPTR "\n"
6246 "\t.long .LEFDE3-.LASFDE3\n"
6248 "\t.long .LASFDE3-.Lframe2\n"
6249 "\t.long lj_vm_ffi_call-.\n"
6251 "\t.uleb128 0\n" /* augmentation length */
6253 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6254 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6255 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6256 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6258 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6259 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6260 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6261 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6263 "\t.align " SZPTR "\n"
6264 ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
6269 /* Mental note: never let Apple design an assembler.
6270 ** Or a linker. Or a plastic case. But I digress.
6272 case BUILD_machasm: {
6277 fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
6280 "\t.set L$set$x,LECIEX-LSCIEX\n"
6285 "\t.ascii \"zPR\\0\"\n"
6287 "\t.byte 128-" SZPTR "\n"
6288 "\t.byte " REG_RA "\n"
6289 "\t.byte 6\n" /* augmentation length */
6290 "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */
6292 "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n"
6293 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6294 "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
6296 "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n"
6297 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6298 "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */
6300 "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
6301 "\t.align " BSZPTR "\n"
6303 for (i = 0; i < ctx->nsym; i++) {
6304 const char *name = ctx->sym[i].name;
6305 int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
6306 if (size == 0) continue;
6308 if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; }
6313 "\t.set L$set$%d,LEFDE%d-LASFDE%d\n"
6314 "\t.long L$set$%d\n"
6316 "\t.long LASFDE%d-EH_frame1\n"
6319 "\t.byte 0\n" /* augmentation length */
6320 "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */
6322 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6323 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6324 "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
6325 "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
6327 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6328 "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
6329 "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
6330 "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
6332 "\t.align " BSZPTR "\n"
6334 name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
6340 "\t.set L$set$y,LECIEY-LSCIEY\n"
6345 "\t.ascii \"zR\\0\"\n"
6347 "\t.byte 128-" SZPTR "\n"
6348 "\t.byte " REG_RA "\n"
6349 "\t.byte 1\n" /* augmentation length */
6351 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6352 "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
6354 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6355 "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */
6357 "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
6358 "\t.align " BSZPTR "\n"
6361 "_lj_vm_ffi_call.eh:\n"
6363 "\t.set L$set$yy,LEFDEY-LASFDEY\n"
6364 "\t.long L$set$yy\n"
6366 "\t.long LASFDEY-EH_frame2\n"
6367 "\t.long _lj_vm_ffi_call-.\n"
6369 "\t.byte 0\n" /* augmentation length */
6371 "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */
6372 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6373 "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */
6374 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6376 "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */
6377 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6378 "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */
6379 "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */
6381 "\t.align " BSZPTR "\n"
6382 "LEFDEY:\n\n", fcsize);
6386 fprintf(ctx->fp, "\t.subsections_via_symbols\n");
6389 "\t.non_lazy_symbol_pointer\n"
6390 "L_lj_err_unwind_dwarf$non_lazy_ptr:\n"
6391 ".indirect_symbol _lj_err_unwind_dwarf\n"
6397 default: /* Difficult for other modes. */