Inline-Lua
view release on metacpan or search on metacpan
ffi/target/release/build/mlua-sys-6a99a2ae50f12319/out/luajit-build/build/src/vm_x64.dasc view on Meta::CPAN
| mov TMPR, TAB:RB
| checktab TAB:RB, ->fff_fallback
#if LJ_52
| cmp aword TAB:RB->metatable, 0; jne ->fff_fallback
#endif
| mov CFUNC:RD, [BASE-16]
| cleartp CFUNC:RD
| mov CFUNC:RD, CFUNC:RD->upvalue[0]
| settp CFUNC:RD, LJ_TFUNC
| mov PC, [BASE-8]
| mov [BASE-16], CFUNC:RD
| mov [BASE-8], TMPR
|.if DUALNUM
| mov64 RD, ((uint64_t)LJ_TISNUM<<47)
| mov [BASE], RD
|.else
| mov qword [BASE], 0
|.endif
| mov RDd, 1+3
| jmp ->fff_res
|
|//-- Base library: catch errors ----------------------------------------
|
|.ffunc_1 pcall
| mov L:RB, SAVE_L
| lea RA, [BASE+NARGS:RD*8]
| cmp RA, L:RB->maxstack; ja ->fff_fallback
| lea RA, [BASE+16]
| sub NARGS:RDd, 1
| mov PCd, 16+FRAME_PCALL
|1:
| movzx RBd, byte [DISPATCH+DISPATCH_GL(hookmask)]
| shr RB, HOOK_ACTIVE_SHIFT
| and RB, 1
| add PC, RB // Remember active hook before pcall.
| // Note: this does a (harmless) copy of the function to the PC slot, too.
| mov KBASE, RD
|2:
| mov RB, [RA+KBASE*8-24]
| mov [RA+KBASE*8-16], RB
| sub KBASE, 1
| ja <2
| jmp ->vm_call_dispatch
|
|.ffunc_2 xpcall
| mov L:RB, SAVE_L
| lea RA, [BASE+NARGS:RD*8]
| cmp RA, L:RB->maxstack; ja ->fff_fallback
| mov LFUNC:RA, [BASE+8]
| checktp_nc LFUNC:RA, LJ_TFUNC, ->fff_fallback
| mov LFUNC:RB, [BASE] // Swap function and traceback.
| mov [BASE], LFUNC:RA
| mov [BASE+8], LFUNC:RB
| lea RA, [BASE+24]
| sub NARGS:RDd, 2
| mov PCd, 24+FRAME_PCALL
| jmp <1
|
|//-- Coroutine library --------------------------------------------------
|
|.macro coroutine_resume_wrap, resume
|.if resume
|.ffunc_1 coroutine_resume
| mov L:RB, [BASE]
| cleartp L:RB
|.else
|.ffunc coroutine_wrap_aux
| mov CFUNC:RB, [BASE-16]
| cleartp CFUNC:RB
| mov L:RB, CFUNC:RB->upvalue[0].gcr
| cleartp L:RB
|.endif
| mov PC, [BASE-8]
| mov SAVE_PC, PC
| mov TMP1, L:RB
|.if resume
| checktptp [BASE], LJ_TTHREAD, ->fff_fallback
|.endif
| cmp aword L:RB->cframe, 0; jne ->fff_fallback
| cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback
| mov RA, L:RB->top
| je >1 // Status != LUA_YIELD (i.e. 0)?
| cmp RA, L:RB->base // Check for presence of initial func.
| je ->fff_fallback
| mov PC, [RA-8] // Move initial function up.
| mov [RA], PC
| add RA, 8
|1:
|.if resume
| lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread).
|.else
| lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1).
|.endif
| cmp PC, L:RB->maxstack; ja ->fff_fallback
| mov L:RB->top, PC
|
| mov L:RB, SAVE_L
| mov L:RB->base, BASE
|.if resume
| add BASE, 8 // Keep resumed thread in stack for GC.
|.endif
| mov L:RB->top, BASE
|.if resume
| lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move.
|.else
| lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move.
|.endif
| sub RB, PC // Relative to PC.
|
| cmp PC, RA
| je >3
|2: // Move args to coroutine.
| mov RC, [PC+RB]
| mov [PC-8], RC
| sub PC, 8
| cmp PC, RA
| jne <2
|3:
| mov CARG2, RA
| mov CARG1, TMP1
| call ->vm_resume // (lua_State *L, TValue *base, 0, 0)
|
| mov L:RB, SAVE_L
| mov L:PC, TMP1
| mov BASE, L:RB->base
| mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB
| set_vmstate INTERP
|
| cmp eax, LUA_YIELD
| ja >8
|4:
| mov RA, L:PC->base
| mov KBASE, L:PC->top
| mov L:PC->top, RA // Clear coroutine stack.
| mov PC, KBASE
| sub PC, RA
| je >6 // No results?
| lea RD, [BASE+PC]
| shr PCd, 3
| cmp RD, L:RB->maxstack
| ja >9 // Need to grow stack?
|
| mov RB, BASE
| sub RB, RA
|5: // Move results from coroutine.
| mov RD, [RA]
| mov [RA+RB], RD
| add RA, 8
| cmp RA, KBASE
| jne <5
|6:
|.if resume
| lea RDd, [PCd+2] // nresults+1 = 1 + true + results.
| mov_true ITYPE // Prepend true to results.
| mov [BASE-8], ITYPE
|.else
| lea RDd, [PCd+1] // nresults+1 = 1 + results.
|.endif
|7:
| mov PC, SAVE_PC
| mov MULTRES, RDd
|.if resume
| mov RA, -8
|.else
| xor RAd, RAd
|.endif
| test PCd, FRAME_TYPE
| jz ->BC_RET_Z
| jmp ->vm_return
|
|8: // Coroutine returned with error (at co->top-1).
|.if resume
| mov_false ITYPE // Prepend false to results.
| mov [BASE-8], ITYPE
| mov RA, L:PC->top
| sub RA, 8
| mov L:PC->top, RA // Clear error from coroutine stack.
| // Copy error message.
| mov RD, [RA]
| mov [BASE], RD
| mov RDd, 1+2 // nresults+1 = 1 + false + error.
| jmp <7
|.else
| mov CARG2, L:PC
| mov CARG1, L:RB
| call extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
| // Error function does not return.
|.endif
|
|9: // Handle stack expansion on return from yield.
| mov L:RA, TMP1
| mov L:RA->top, KBASE // Undo coroutine stack clearing.
| mov CARG2, PC
| mov CARG1, L:RB
| call extern lj_state_growstack // (lua_State *L, int n)
| mov L:PC, TMP1
| mov BASE, L:RB->base
| jmp <4 // Retry the stack move.
|.endmacro
|
| coroutine_resume_wrap 1 // coroutine.resume
| coroutine_resume_wrap 0 // coroutine.wrap
|
|.ffunc coroutine_yield
| mov L:RB, SAVE_L
| test aword L:RB->cframe, CFRAME_RESUME
| jz ->fff_fallback
| mov L:RB->base, BASE
| lea RD, [BASE+NARGS:RD*8-8]
| mov L:RB->top, RD
| xor RDd, RDd
| mov aword L:RB->cframe, RD
| mov al, LUA_YIELD
| mov byte L:RB->status, al
| jmp ->vm_leave_unw
|
|//-- Math library -------------------------------------------------------
|
| .ffunc_1 math_abs
| mov RB, [BASE]
|.if DUALNUM
| checkint RB, >3
| cmp RBd, 0; jns ->fff_resi
| neg RBd; js >2
|->fff_resbit:
|->fff_resi:
| setint RB
|->fff_resRB:
| mov PC, [BASE-8]
| mov [BASE-16], RB
| jmp ->fff_res1
|2:
| mov64 RB, U64x(41e00000,00000000) // 2^31.
| jmp ->fff_resRB
|3:
| ja ->fff_fallback
|.else
| checknum RB, ->fff_fallback
|.endif
| shl RB, 1
| shr RB, 1
| mov PC, [BASE-8]
| mov [BASE-16], RB
| jmp ->fff_res1
|
|.ffunc_n math_sqrt, sqrtsd
|->fff_resxmm0:
| mov PC, [BASE-8]
| movsd qword [BASE-16], xmm0
| // fallthrough
|
|->fff_res1:
| mov RDd, 1+1
|->fff_res:
| mov MULTRES, RDd
|->fff_res_:
| test PCd, FRAME_TYPE
| jnz >7
|5:
| cmp PC_RB, RDL // More results expected?
| ja >6
| // Adjust BASE. KBASE is assumed to be set for the calling frame.
| movzx RAd, PC_RA
| neg RA
( run in 0.540 second using v1.01-cache-2.11-cpan-39bf76dae61 )