2023-01-27 22:28:31 +00:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "IrLoweringX64.h"
|
|
|
|
|
|
|
|
#include "Luau/CodeGen.h"
|
|
|
|
#include "Luau/DenseHash.h"
|
2023-02-10 19:40:38 +00:00
|
|
|
#include "Luau/IrAnalysis.h"
|
2023-03-31 19:42:49 +01:00
|
|
|
#include "Luau/IrCallWrapperX64.h"
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
#include "Luau/IrDump.h"
|
|
|
|
#include "Luau/IrUtils.h"
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
#include "EmitBuiltinsX64.h"
|
2023-01-27 22:28:31 +00:00
|
|
|
#include "EmitCommonX64.h"
|
|
|
|
#include "EmitInstructionX64.h"
|
|
|
|
#include "NativeState.h"
|
|
|
|
|
|
|
|
#include "lstate.h"
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
2023-03-03 20:21:14 +00:00
|
|
|
namespace X64
|
|
|
|
{
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
IrLoweringX64::IrLoweringX64(AssemblyBuilderX64& build, ModuleHelpers& helpers, NativeState& data, IrFunction& function)
|
2023-01-27 22:28:31 +00:00
|
|
|
: build(build)
|
|
|
|
, helpers(helpers)
|
|
|
|
, data(data)
|
|
|
|
, function(function)
|
2023-04-07 22:01:29 +01:00
|
|
|
, regs(build, function)
|
2023-04-21 23:14:26 +01:00
|
|
|
, valueTracker(function)
|
2023-01-27 22:28:31 +00:00
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
// In order to allocate registers during lowering, we need to know where instruction results are last used
|
|
|
|
updateLastUseLocations(function);
|
2023-04-14 19:06:22 +01:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
valueTracker.setRestoreCallack(®s, [](void* context, IrInst& inst) {
|
|
|
|
((IrRegAllocX64*)context)->restore(inst, false);
|
|
|
|
});
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
build.align(kFunctionAlignment, X64::AlignmentDataX64::Ud2);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
void IrLoweringX64::storeDoubleAsFloat(OperandX64 dst, IrOp src)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
|
|
|
|
|
|
|
if (src.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
build.vmovss(tmp.reg, build.f32(float(doubleOp(src))));
|
|
|
|
}
|
|
|
|
else if (src.kind == IrOpKind::Inst)
|
|
|
|
{
|
|
|
|
build.vcvtsd2ss(tmp.reg, regOp(src), regOp(src));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
build.vmovss(dst, tmp.reg);
|
|
|
|
}
|
|
|
|
|
2023-01-27 22:28:31 +00:00
|
|
|
void IrLoweringX64::lowerInst(IrInst& inst, uint32_t index, IrBlock& next)
|
|
|
|
{
|
2023-04-07 22:01:29 +01:00
|
|
|
regs.currInstIdx = index;
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
valueTracker.beforeInstLowering(inst);
|
|
|
|
|
2023-01-27 22:28:31 +00:00
|
|
|
switch (inst.cmd)
|
|
|
|
{
|
|
|
|
case IrCmd::LOAD_TAG:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(inst.regX64, luauRegTag(vmRegOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::VmConst)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(inst.regX64, luauConstantTag(vmConstOp(inst.a)));
|
2023-02-10 19:40:38 +00:00
|
|
|
// If we have a register, we assume it's a pointer to TValue
|
|
|
|
// We might introduce explicit operand types in the future to make this more robust
|
|
|
|
else if (inst.a.kind == IrOpKind::Inst)
|
|
|
|
build.mov(inst.regX64, dword[regOp(inst.a) + offsetof(TValue, tt)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_POINTER:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::qword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(inst.regX64, luauRegValue(vmRegOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::VmConst)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(inst.regX64, luauConstantValue(vmConstOp(inst.a)));
|
2023-03-17 19:20:37 +00:00
|
|
|
// If we have a register, we assume it's a pointer to TValue
|
|
|
|
// We might introduce explicit operand types in the future to make this more robust
|
|
|
|
else if (inst.a.kind == IrOpKind::Inst)
|
|
|
|
build.mov(inst.regX64, qword[regOp(inst.a) + offsetof(TValue, value)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_DOUBLE:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovsd(inst.regX64, luauRegValue(vmRegOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::VmConst)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovsd(inst.regX64, luauConstantValue(vmConstOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_INT:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(inst.regX64, luauRegValueInt(vmRegOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_TVALUE:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovups(inst.regX64, luauReg(vmRegOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::VmConst)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovups(inst.regX64, luauConstant(vmConstOp(inst.a)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::Inst)
|
|
|
|
build.vmovups(inst.regX64, xmmword[regOp(inst.a)]);
|
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_NODE_VALUE_TV:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.vmovups(inst.regX64, luauNodeValue(regOp(inst.a)));
|
|
|
|
break;
|
|
|
|
case IrCmd::LOAD_ENV:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::qword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(inst.regX64, sClosure);
|
|
|
|
build.mov(inst.regX64, qword[inst.regX64 + offsetof(Closure, env)]);
|
|
|
|
break;
|
|
|
|
case IrCmd::GET_ARR_ADDR:
|
|
|
|
if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::qword, index, {inst.b});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-10 19:40:38 +00:00
|
|
|
if (dwordReg(inst.regX64) != regOp(inst.b))
|
|
|
|
build.mov(dwordReg(inst.regX64), regOp(inst.b));
|
|
|
|
|
2023-01-27 22:28:31 +00:00
|
|
|
build.shl(dwordReg(inst.regX64), kTValueSizeLog2);
|
|
|
|
build.add(inst.regX64, qword[regOp(inst.a) + offsetof(Table, array)]);
|
|
|
|
}
|
|
|
|
else if (inst.b.kind == IrOpKind::Constant)
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::qword, index, {inst.a});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(inst.regX64, qword[regOp(inst.a) + offsetof(Table, array)]);
|
|
|
|
|
2023-02-17 23:41:51 +00:00
|
|
|
if (intOp(inst.b) != 0)
|
|
|
|
build.lea(inst.regX64, addr[inst.regX64 + intOp(inst.b) * sizeof(TValue)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IrCmd::GET_SLOT_NODE_ADDR:
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::qword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
getTableNodeAtCachedSlot(build, tmp.reg, inst.regX64, regOp(inst.a), uintOp(inst.b));
|
|
|
|
break;
|
|
|
|
}
|
2023-03-17 19:20:37 +00:00
|
|
|
case IrCmd::GET_HASH_NODE_ADDR:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
2023-04-07 22:01:29 +01:00
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(rcx, kInvalidInstIdx)};
|
2023-03-17 19:20:37 +00:00
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::qword, index);
|
|
|
|
|
2023-03-17 19:20:37 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
|
|
|
|
build.mov(inst.regX64, qword[regOp(inst.a) + offsetof(Table, node)]);
|
|
|
|
build.mov(dwordReg(tmp.reg), 1);
|
|
|
|
build.mov(byteReg(shiftTmp.reg), byte[regOp(inst.a) + offsetof(Table, lsizenode)]);
|
|
|
|
build.shl(dwordReg(tmp.reg), byteReg(shiftTmp.reg));
|
|
|
|
build.dec(dwordReg(tmp.reg));
|
|
|
|
build.and_(dwordReg(tmp.reg), uintOp(inst.b));
|
|
|
|
build.shl(tmp.reg, kLuaNodeSizeLog2);
|
|
|
|
build.add(inst.regX64, tmp.reg);
|
|
|
|
break;
|
|
|
|
};
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::STORE_TAG:
|
|
|
|
if (inst.b.kind == IrOpKind::Constant)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(luauRegTag(vmRegOp(inst.a)), tagOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::STORE_POINTER:
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(luauRegValue(vmRegOp(inst.a)), regOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::STORE_DOUBLE:
|
|
|
|
if (inst.b.kind == IrOpKind::Constant)
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.vmovsd(tmp.reg, build.f64(doubleOp(inst.b)));
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovsd(luauRegValue(vmRegOp(inst.a)), tmp.reg);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
{
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovsd(luauRegValue(vmRegOp(inst.a)), regOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IrCmd::STORE_INT:
|
|
|
|
if (inst.b.kind == IrOpKind::Constant)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(luauRegValueInt(vmRegOp(inst.a)), intOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.b.kind == IrOpKind::Inst)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(luauRegValueInt(vmRegOp(inst.a)), regOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
2023-04-07 22:01:29 +01:00
|
|
|
case IrCmd::STORE_VECTOR:
|
|
|
|
storeDoubleAsFloat(luauRegValueVector(vmRegOp(inst.a), 0), inst.b);
|
|
|
|
storeDoubleAsFloat(luauRegValueVector(vmRegOp(inst.a), 1), inst.c);
|
|
|
|
storeDoubleAsFloat(luauRegValueVector(vmRegOp(inst.a), 2), inst.d);
|
|
|
|
break;
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::STORE_TVALUE:
|
|
|
|
if (inst.a.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovups(luauReg(vmRegOp(inst.a)), regOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
else if (inst.a.kind == IrOpKind::Inst)
|
|
|
|
build.vmovups(xmmword[regOp(inst.a)], regOp(inst.b));
|
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
break;
|
|
|
|
case IrCmd::STORE_NODE_VALUE_TV:
|
|
|
|
build.vmovups(luauNodeValue(regOp(inst.a)), regOp(inst.b));
|
|
|
|
break;
|
|
|
|
case IrCmd::ADD_INT:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
build.lea(inst.regX64, addr[regOp(inst.a) + regOp(inst.b)]);
|
|
|
|
else if (inst.regX64 == regOp(inst.a) && intOp(inst.b) == 1)
|
2023-01-27 22:28:31 +00:00
|
|
|
build.inc(inst.regX64);
|
|
|
|
else if (inst.regX64 == regOp(inst.a))
|
|
|
|
build.add(inst.regX64, intOp(inst.b));
|
|
|
|
else
|
|
|
|
build.lea(inst.regX64, addr[regOp(inst.a) + intOp(inst.b)]);
|
|
|
|
break;
|
|
|
|
case IrCmd::SUB_INT:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.regX64 == regOp(inst.a) && intOp(inst.b) == 1)
|
|
|
|
build.dec(inst.regX64);
|
|
|
|
else if (inst.regX64 == regOp(inst.a))
|
|
|
|
build.sub(inst.regX64, intOp(inst.b));
|
|
|
|
else
|
|
|
|
build.lea(inst.regX64, addr[regOp(inst.a) - intOp(inst.b)]);
|
|
|
|
break;
|
|
|
|
case IrCmd::ADD_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-02-24 21:49:38 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vaddsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vaddsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::SUB_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-02-24 21:49:38 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vsubsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vsubsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::MUL_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
|
|
|
|
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vmulsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vmulsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::DIV_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-02-24 21:49:38 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vdivsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vdivsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::MOD_NUM:
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-03-10 20:21:07 +00:00
|
|
|
ScopedRegX64 optLhsTmp{regs};
|
|
|
|
RegisterX64 lhs;
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
optLhsTmp.alloc(SizeX64::xmmword);
|
|
|
|
|
|
|
|
build.vmovsd(optLhsTmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
lhs = optLhsTmp.reg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lhs = regOp(inst.a);
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.vdivsd(tmp.reg, lhs, memRegDoubleOp(inst.b));
|
|
|
|
build.vroundsd(tmp.reg, tmp.reg, tmp.reg, RoundingModeX64::RoundToNegativeInfinity);
|
|
|
|
build.vmulsd(tmp.reg, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
build.vsubsd(inst.regX64, lhs, tmp.reg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::xmmword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.vmovsd(tmp1.reg, memRegDoubleOp(inst.b));
|
|
|
|
build.vdivsd(tmp2.reg, lhs, tmp1.reg);
|
|
|
|
build.vroundsd(tmp2.reg, tmp2.reg, tmp2.reg, RoundingModeX64::RoundToNegativeInfinity);
|
|
|
|
build.vmulsd(tmp1.reg, tmp2.reg, tmp1.reg);
|
|
|
|
build.vsubsd(inst.regX64, lhs, tmp1.reg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::POW_NUM:
|
|
|
|
{
|
2023-03-31 19:42:49 +01:00
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::xmmword, memRegDoubleOp(inst.a), inst.a);
|
|
|
|
callWrap.addArgument(SizeX64::xmmword, memRegDoubleOp(inst.b), inst.b);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, libm_pow)]);
|
2023-04-07 22:01:29 +01:00
|
|
|
inst.regX64 = regs.takeReg(xmm0, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-03-03 20:21:14 +00:00
|
|
|
case IrCmd::MIN_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-03-03 20:21:14 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
|
|
|
|
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vminsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vminsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IrCmd::MAX_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a, inst.b});
|
2023-03-03 20:21:14 +00:00
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
|
|
|
|
|
|
|
build.vmovsd(tmp.reg, memRegDoubleOp(inst.a));
|
|
|
|
build.vmaxsd(inst.regX64, tmp.reg, memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vmaxsd(inst.regX64, regOp(inst.a), memRegDoubleOp(inst.b));
|
|
|
|
}
|
|
|
|
break;
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::UNM_NUM:
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
RegisterX64 src = regOp(inst.a);
|
|
|
|
|
|
|
|
if (inst.regX64 == src)
|
|
|
|
{
|
|
|
|
build.vxorpd(inst.regX64, inst.regX64, build.f64(-0.0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.vmovsd(inst.regX64, src, src);
|
|
|
|
build.vxorpd(inst.regX64, inst.regX64, build.f64(-0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::FLOOR_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
build.vroundsd(inst.regX64, inst.regX64, memRegDoubleOp(inst.a), RoundingModeX64::RoundToNegativeInfinity);
|
|
|
|
break;
|
|
|
|
case IrCmd::CEIL_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
build.vroundsd(inst.regX64, inst.regX64, memRegDoubleOp(inst.a), RoundingModeX64::RoundToPositiveInfinity);
|
|
|
|
break;
|
|
|
|
case IrCmd::ROUND_NUM:
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::xmmword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::xmmword};
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
if (inst.a.kind != IrOpKind::Inst)
|
2023-03-31 19:42:49 +01:00
|
|
|
build.vmovsd(inst.regX64, memRegDoubleOp(inst.a));
|
2023-04-07 22:01:29 +01:00
|
|
|
else if (regOp(inst.a) != inst.regX64)
|
|
|
|
build.vmovsd(inst.regX64, inst.regX64, regOp(inst.a));
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
build.vandpd(tmp1.reg, inst.regX64, build.f64x2(-0.0, -0.0));
|
|
|
|
build.vmovsd(tmp2.reg, build.i64(0x3fdfffffffffffff)); // 0.49999999999999994
|
|
|
|
build.vorpd(tmp1.reg, tmp1.reg, tmp2.reg);
|
|
|
|
build.vaddsd(inst.regX64, inst.regX64, tmp1.reg);
|
|
|
|
build.vroundsd(inst.regX64, inst.regX64, inst.regX64, RoundingModeX64::RoundToZero);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::SQRT_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
build.vsqrtsd(inst.regX64, inst.regX64, memRegDoubleOp(inst.a));
|
|
|
|
break;
|
|
|
|
case IrCmd::ABS_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::xmmword, index, {inst.a});
|
2023-03-31 19:42:49 +01:00
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
if (inst.a.kind != IrOpKind::Inst)
|
2023-03-31 19:42:49 +01:00
|
|
|
build.vmovsd(inst.regX64, memRegDoubleOp(inst.a));
|
2023-04-07 22:01:29 +01:00
|
|
|
else if (regOp(inst.a) != inst.regX64)
|
|
|
|
build.vmovsd(inst.regX64, inst.regX64, regOp(inst.a));
|
2023-03-31 19:42:49 +01:00
|
|
|
|
|
|
|
build.vandpd(inst.regX64, inst.regX64, build.i64(~(1LL << 63)));
|
|
|
|
break;
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::NOT_ANY:
|
|
|
|
{
|
|
|
|
// TODO: if we have a single user which is a STORE_INT, we are missing the opportunity to write directly to target
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a, inst.b});
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
Label saveone, savezero, exit;
|
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
// Other cases should've been constant folded
|
|
|
|
LUAU_ASSERT(tagOp(inst.a) == LUA_TBOOLEAN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.cmp(regOp(inst.a), LUA_TNIL);
|
|
|
|
build.jcc(ConditionX64::Equal, saveone);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
build.cmp(regOp(inst.a), LUA_TBOOLEAN);
|
|
|
|
build.jcc(ConditionX64::NotEqual, savezero);
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.cmp(regOp(inst.b), 0);
|
|
|
|
build.jcc(ConditionX64::Equal, saveone);
|
|
|
|
|
|
|
|
build.setLabel(savezero);
|
|
|
|
build.mov(inst.regX64, 0);
|
|
|
|
build.jmp(exit);
|
|
|
|
|
|
|
|
build.setLabel(saveone);
|
|
|
|
build.mov(inst.regX64, 1);
|
|
|
|
|
|
|
|
build.setLabel(exit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::JUMP:
|
|
|
|
jumpOrFallthrough(blockOp(inst.a), next);
|
|
|
|
break;
|
|
|
|
case IrCmd::JUMP_IF_TRUTHY:
|
2023-03-24 18:03:04 +00:00
|
|
|
jumpIfTruthy(build, vmRegOp(inst.a), labelOp(inst.b), labelOp(inst.c));
|
2023-01-27 22:28:31 +00:00
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
|
|
|
break;
|
|
|
|
case IrCmd::JUMP_IF_FALSY:
|
2023-03-24 18:03:04 +00:00
|
|
|
jumpIfFalsy(build, vmRegOp(inst.a), labelOp(inst.b), labelOp(inst.c));
|
2023-01-27 22:28:31 +00:00
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
|
|
|
break;
|
|
|
|
case IrCmd::JUMP_EQ_TAG:
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::Inst || inst.b.kind == IrOpKind::Constant);
|
|
|
|
OperandX64 opb = inst.b.kind == IrOpKind::Inst ? regOp(inst.b) : OperandX64(tagOp(inst.b));
|
|
|
|
|
|
|
|
build.cmp(memRegTagOp(inst.a), opb);
|
|
|
|
|
|
|
|
if (isFallthroughBlock(blockOp(inst.d), next))
|
|
|
|
{
|
|
|
|
build.jcc(ConditionX64::Equal, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
build.jcc(ConditionX64::NotEqual, labelOp(inst.d));
|
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-02-10 19:40:38 +00:00
|
|
|
case IrCmd::JUMP_EQ_INT:
|
|
|
|
build.cmp(regOp(inst.a), intOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.jcc(ConditionX64::Equal, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
|
|
|
break;
|
2023-04-21 23:14:26 +01:00
|
|
|
case IrCmd::JUMP_LT_INT:
|
|
|
|
build.cmp(regOp(inst.a), intOp(inst.b));
|
|
|
|
|
|
|
|
build.jcc(ConditionX64::Less, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
|
|
|
break;
|
|
|
|
case IrCmd::JUMP_GE_UINT:
|
|
|
|
build.cmp(regOp(inst.a), uintOp(inst.b));
|
|
|
|
|
|
|
|
build.jcc(ConditionX64::AboveEqual, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
|
|
|
break;
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::JUMP_EQ_POINTER:
|
|
|
|
build.cmp(regOp(inst.a), regOp(inst.b));
|
|
|
|
|
|
|
|
build.jcc(ConditionX64::Equal, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
|
|
|
break;
|
|
|
|
case IrCmd::JUMP_CMP_NUM:
|
|
|
|
{
|
2023-03-24 18:03:04 +00:00
|
|
|
IrCondition cond = conditionOp(inst.c);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
// TODO: jumpOnNumberCmp should work on IrCondition directly
|
2023-03-03 20:21:14 +00:00
|
|
|
jumpOnNumberCmp(build, tmp.reg, memRegDoubleOp(inst.a), memRegDoubleOp(inst.b), cond, labelOp(inst.d));
|
2023-01-27 22:28:31 +00:00
|
|
|
jumpOrFallthrough(blockOp(inst.e), next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::JUMP_CMP_ANY:
|
2023-03-31 19:42:49 +01:00
|
|
|
jumpOnAnyCmpFallback(regs, build, vmRegOp(inst.a), vmRegOp(inst.b), conditionOp(inst.c), labelOp(inst.d));
|
2023-01-27 22:28:31 +00:00
|
|
|
jumpOrFallthrough(blockOp(inst.e), next);
|
|
|
|
break;
|
2023-03-17 19:20:37 +00:00
|
|
|
case IrCmd::JUMP_SLOT_MATCH:
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
jumpIfNodeKeyNotInExpectedSlot(build, tmp.reg, regOp(inst.a), luauConstantValue(vmConstOp(inst.b)), labelOp(inst.d));
|
2023-03-17 19:20:37 +00:00
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
|
|
|
break;
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::TABLE_LEN:
|
2023-03-31 19:42:49 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, regOp(inst.a), inst.a);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaH_getn)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
build.vcvtsi2sd(inst.regX64, inst.regX64, eax);
|
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::NEW_TABLE:
|
2023-03-31 19:42:49 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
2023-04-14 19:06:22 +01:00
|
|
|
callWrap.addArgument(SizeX64::dword, int32_t(uintOp(inst.a)));
|
|
|
|
callWrap.addArgument(SizeX64::dword, int32_t(uintOp(inst.b)));
|
2023-03-31 19:42:49 +01:00
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaH_new)]);
|
2023-04-07 22:01:29 +01:00
|
|
|
inst.regX64 = regs.takeReg(rax, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::DUP_TABLE:
|
2023-03-31 19:42:49 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, regOp(inst.a), inst.a);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaH_clone)]);
|
2023-04-07 22:01:29 +01:00
|
|
|
inst.regX64 = regs.takeReg(rax, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
}
|
2023-03-17 19:20:37 +00:00
|
|
|
case IrCmd::TRY_NUM_TO_INDEX:
|
2023-01-27 22:28:31 +00:00
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
convertNumberToIndexOrJump(build, tmp.reg, regOp(inst.a), inst.regX64, labelOp(inst.b));
|
|
|
|
break;
|
|
|
|
}
|
2023-03-17 19:20:37 +00:00
|
|
|
case IrCmd::TRY_CALL_FASTGETTM:
|
|
|
|
{
|
2023-03-31 19:42:49 +01:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
|
|
|
|
build.mov(tmp.reg, qword[regOp(inst.a) + offsetof(Table, metatable)]);
|
|
|
|
regs.freeLastUseReg(function.instOp(inst.a), index); // Release before the call if it's the last use
|
2023-03-17 19:20:37 +00:00
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
build.test(tmp.reg, tmp.reg);
|
|
|
|
build.jcc(ConditionX64::Zero, labelOp(inst.c)); // No metatable
|
2023-03-17 19:20:37 +00:00
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
build.test(byte[tmp.reg + offsetof(Table, tmcache)], 1 << intOp(inst.b));
|
|
|
|
build.jcc(ConditionX64::NotZero, labelOp(inst.c)); // No tag method
|
|
|
|
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::qword};
|
|
|
|
build.mov(tmp2.reg, qword[rState + offsetof(lua_State, global)]);
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
{
|
|
|
|
ScopedSpills spillGuard(regs);
|
|
|
|
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, tmp);
|
|
|
|
callWrap.addArgument(SizeX64::qword, intOp(inst.b));
|
|
|
|
callWrap.addArgument(SizeX64::qword, qword[tmp2.release() + offsetof(global_State, tmname) + intOp(inst.b) * sizeof(TString*)]);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaT_gettm)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
inst.regX64 = regs.takeReg(rax, index);
|
2023-03-17 19:20:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-02-10 19:40:38 +00:00
|
|
|
case IrCmd::INT_TO_NUM:
|
2023-04-14 19:06:22 +01:00
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
2023-02-10 19:40:38 +00:00
|
|
|
|
|
|
|
build.vcvtsi2sd(inst.regX64, inst.regX64, regOp(inst.a));
|
|
|
|
break;
|
2023-04-21 23:14:26 +01:00
|
|
|
case IrCmd::UINT_TO_NUM:
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::xmmword, index);
|
|
|
|
|
|
|
|
build.vcvtsi2sd(inst.regX64, inst.regX64, qwordReg(regOp(inst.a)));
|
|
|
|
break;
|
|
|
|
case IrCmd::NUM_TO_INT:
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.vcvttsd2si(inst.regX64, memRegDoubleOp(inst.a));
|
|
|
|
break;
|
|
|
|
case IrCmd::NUM_TO_UINT:
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.vcvttsd2si(qwordReg(inst.regX64), memRegDoubleOp(inst.a));
|
|
|
|
break;
|
2023-02-24 21:49:38 +00:00
|
|
|
case IrCmd::ADJUST_STACK_TO_REG:
|
|
|
|
{
|
2023-04-07 22:01:29 +01:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
if (inst.b.kind == IrOpKind::Constant)
|
|
|
|
{
|
2023-03-24 18:03:04 +00:00
|
|
|
build.lea(tmp.reg, addr[rBase + (vmRegOp(inst.a) + intOp(inst.b)) * sizeof(TValue)]);
|
2023-02-24 21:49:38 +00:00
|
|
|
build.mov(qword[rState + offsetof(lua_State, top)], tmp.reg);
|
|
|
|
}
|
|
|
|
else if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
{
|
2023-04-07 22:01:29 +01:00
|
|
|
build.mov(dwordReg(tmp.reg), regOp(inst.b));
|
|
|
|
build.shl(tmp.reg, kTValueSizeLog2);
|
|
|
|
build.lea(tmp.reg, addr[rBase + tmp.reg + vmRegOp(inst.a) * sizeof(TValue)]);
|
|
|
|
build.mov(qword[rState + offsetof(lua_State, top)], tmp.reg);
|
2023-02-24 21:49:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::ADJUST_STACK_TO_TOP:
|
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
build.mov(tmp.reg, qword[rState + offsetof(lua_State, ci)]);
|
|
|
|
build.mov(tmp.reg, qword[tmp.reg + offsetof(CallInfo, top)]);
|
|
|
|
build.mov(qword[rState + offsetof(lua_State, top)], tmp.reg);
|
|
|
|
break;
|
|
|
|
}
|
2023-03-03 20:21:14 +00:00
|
|
|
|
|
|
|
case IrCmd::FASTCALL:
|
2023-03-24 18:03:04 +00:00
|
|
|
emitBuiltin(regs, build, uintOp(inst.a), vmRegOp(inst.b), vmRegOp(inst.c), inst.d, intOp(inst.e), intOp(inst.f));
|
2023-03-03 20:21:14 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::INVOKE_FASTCALL:
|
|
|
|
{
|
|
|
|
unsigned bfid = uintOp(inst.a);
|
|
|
|
|
|
|
|
OperandX64 args = 0;
|
|
|
|
|
|
|
|
if (inst.d.kind == IrOpKind::VmReg)
|
2023-03-24 18:03:04 +00:00
|
|
|
args = luauRegAddress(vmRegOp(inst.d));
|
2023-03-03 20:21:14 +00:00
|
|
|
else if (inst.d.kind == IrOpKind::VmConst)
|
2023-03-24 18:03:04 +00:00
|
|
|
args = luauConstantAddress(vmConstOp(inst.d));
|
2023-03-03 20:21:14 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(boolOp(inst.d) == false);
|
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
int ra = vmRegOp(inst.b);
|
|
|
|
int arg = vmRegOp(inst.c);
|
2023-03-03 20:21:14 +00:00
|
|
|
int nparams = intOp(inst.e);
|
|
|
|
int nresults = intOp(inst.f);
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
ScopedRegX64 func{regs, SizeX64::qword};
|
|
|
|
build.mov(func.reg, qword[rNativeContext + offsetof(NativeContext, luauF_table) + bfid * sizeof(luau_FastFunction)]);
|
2023-03-03 20:21:14 +00:00
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, luauRegAddress(ra));
|
|
|
|
callWrap.addArgument(SizeX64::qword, luauRegAddress(arg));
|
|
|
|
callWrap.addArgument(SizeX64::dword, nresults);
|
|
|
|
callWrap.addArgument(SizeX64::qword, args);
|
2023-03-03 20:21:14 +00:00
|
|
|
|
|
|
|
if (nparams == LUA_MULTRET)
|
|
|
|
{
|
2023-04-14 19:06:22 +01:00
|
|
|
RegisterX64 reg = callWrap.suggestNextArgumentRegister(SizeX64::qword);
|
2023-04-07 22:01:29 +01:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
// L->top - (ra + 1)
|
2023-03-03 20:21:14 +00:00
|
|
|
build.mov(reg, qword[rState + offsetof(lua_State, top)]);
|
2023-04-07 22:01:29 +01:00
|
|
|
build.lea(tmp.reg, addr[rBase + (ra + 1) * sizeof(TValue)]);
|
|
|
|
build.sub(reg, tmp.reg);
|
2023-03-03 20:21:14 +00:00
|
|
|
build.shr(reg, kTValueSizeLog2);
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
callWrap.addArgument(SizeX64::dword, dwordReg(reg));
|
2023-03-03 20:21:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-07 22:01:29 +01:00
|
|
|
callWrap.addArgument(SizeX64::dword, nparams);
|
2023-03-03 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
callWrap.call(func.release());
|
|
|
|
inst.regX64 = regs.takeReg(eax, index); // Result of a builtin call is returned in eax
|
2023-03-03 20:21:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::CHECK_FASTCALL_RES:
|
|
|
|
{
|
|
|
|
RegisterX64 res = regOp(inst.a);
|
|
|
|
|
|
|
|
build.test(res, res); // test here will set SF=1 for a negative number and it always sets OF to 0
|
|
|
|
build.jcc(ConditionX64::Less, labelOp(inst.b)); // jl jumps if SF != OF
|
|
|
|
break;
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::DO_ARITH:
|
|
|
|
if (inst.c.kind == IrOpKind::VmReg)
|
2023-03-31 19:42:49 +01:00
|
|
|
callArithHelper(regs, build, vmRegOp(inst.a), vmRegOp(inst.b), luauRegAddress(vmRegOp(inst.c)), TMS(intOp(inst.d)));
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
2023-03-31 19:42:49 +01:00
|
|
|
callArithHelper(regs, build, vmRegOp(inst.a), vmRegOp(inst.b), luauConstantAddress(vmConstOp(inst.c)), TMS(intOp(inst.d)));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::DO_LEN:
|
2023-03-31 19:42:49 +01:00
|
|
|
callLengthHelper(regs, build, vmRegOp(inst.a), vmRegOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::GET_TABLE:
|
|
|
|
if (inst.c.kind == IrOpKind::VmReg)
|
|
|
|
{
|
2023-03-31 19:42:49 +01:00
|
|
|
callGetTable(regs, build, vmRegOp(inst.b), luauRegAddress(vmRegOp(inst.c)), vmRegOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else if (inst.c.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
TValue n;
|
|
|
|
setnvalue(&n, uintOp(inst.c));
|
2023-03-31 19:42:49 +01:00
|
|
|
callGetTable(regs, build, vmRegOp(inst.b), build.bytes(&n, sizeof(n)), vmRegOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IrCmd::SET_TABLE:
|
|
|
|
if (inst.c.kind == IrOpKind::VmReg)
|
|
|
|
{
|
2023-03-31 19:42:49 +01:00
|
|
|
callSetTable(regs, build, vmRegOp(inst.b), luauRegAddress(vmRegOp(inst.c)), vmRegOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else if (inst.c.kind == IrOpKind::Constant)
|
|
|
|
{
|
|
|
|
TValue n;
|
|
|
|
setnvalue(&n, uintOp(inst.c));
|
2023-03-31 19:42:49 +01:00
|
|
|
callSetTable(regs, build, vmRegOp(inst.b), build.bytes(&n, sizeof(n)), vmRegOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IrCmd::GET_IMPORT:
|
2023-04-14 19:06:22 +01:00
|
|
|
{
|
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
|
|
|
|
build.mov(tmp1.reg, sClosure);
|
|
|
|
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, qword[tmp1.release() + offsetof(Closure, env)]);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rConstants);
|
|
|
|
callWrap.addArgument(SizeX64::dword, uintOp(inst.b));
|
|
|
|
callWrap.addArgument(SizeX64::dword, 0);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaV_getimport)]);
|
|
|
|
|
|
|
|
emitUpdateBase(build);
|
|
|
|
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::qword};
|
|
|
|
|
|
|
|
// setobj2s(L, ra, L->top - 1)
|
|
|
|
build.mov(tmp2.reg, qword[rState + offsetof(lua_State, top)]);
|
|
|
|
build.sub(tmp2.reg, sizeof(TValue));
|
|
|
|
|
|
|
|
ScopedRegX64 tmp3{regs, SizeX64::xmmword};
|
|
|
|
build.vmovups(tmp3.reg, xmmword[tmp2.reg]);
|
|
|
|
build.vmovups(luauReg(vmRegOp(inst.a)), tmp3.reg);
|
|
|
|
|
|
|
|
// L->top--
|
|
|
|
build.mov(qword[rState + offsetof(lua_State, top)], tmp2.reg);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-04-14 19:06:22 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::CONCAT:
|
2023-03-31 19:42:49 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::dword, int32_t(uintOp(inst.b)));
|
|
|
|
callWrap.addArgument(SizeX64::dword, int32_t(vmRegOp(inst.a) + uintOp(inst.b) - 1));
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaV_concat)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
emitUpdateBase(build);
|
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::GET_UPVALUE:
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::xmmword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(tmp1.reg, sClosure);
|
2023-03-24 18:03:04 +00:00
|
|
|
build.add(tmp1.reg, offsetof(Closure, l.uprefs) + sizeof(TValue) * vmUpvalueOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
// uprefs[] is either an actual value, or it points to UpVal object which has a pointer to value
|
|
|
|
Label skip;
|
|
|
|
build.cmp(dword[tmp1.reg + offsetof(TValue, tt)], LUA_TUPVAL);
|
|
|
|
build.jcc(ConditionX64::NotEqual, skip);
|
|
|
|
|
|
|
|
// UpVal.v points to the value (either on stack, or on heap inside each UpVal, but we can deref it unconditionally)
|
|
|
|
build.mov(tmp1.reg, qword[tmp1.reg + offsetof(TValue, value.gc)]);
|
|
|
|
build.mov(tmp1.reg, qword[tmp1.reg + offsetof(UpVal, v)]);
|
|
|
|
|
|
|
|
build.setLabel(skip);
|
|
|
|
|
|
|
|
build.vmovups(tmp2.reg, xmmword[tmp1.reg]);
|
2023-03-24 18:03:04 +00:00
|
|
|
build.vmovups(luauReg(vmRegOp(inst.a)), tmp2.reg);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::SET_UPVALUE:
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(tmp1.reg, sClosure);
|
2023-03-24 18:03:04 +00:00
|
|
|
build.mov(tmp2.reg, qword[tmp1.reg + offsetof(Closure, l.uprefs) + sizeof(TValue) * vmUpvalueOp(inst.a) + offsetof(TValue, value.gc)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(tmp1.reg, qword[tmp2.reg + offsetof(UpVal, v)]);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
{
|
|
|
|
ScopedRegX64 tmp3{regs, SizeX64::xmmword};
|
|
|
|
build.vmovups(tmp3.reg, luauReg(vmRegOp(inst.b)));
|
|
|
|
build.vmovups(xmmword[tmp1.reg], tmp3.reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp1.free();
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
callBarrierObject(regs, build, tmp2.release(), {}, vmRegOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-02-10 19:40:38 +00:00
|
|
|
case IrCmd::PREPARE_FORN:
|
2023-03-31 19:42:49 +01:00
|
|
|
callPrepareForN(regs, build, vmRegOp(inst.a), vmRegOp(inst.b), vmRegOp(inst.c));
|
2023-02-10 19:40:38 +00:00
|
|
|
break;
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::CHECK_TAG:
|
2023-04-14 19:06:22 +01:00
|
|
|
build.cmp(memRegTagOp(inst.a), tagOp(inst.b));
|
|
|
|
build.jcc(ConditionX64::NotEqual, labelOp(inst.c));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::CHECK_READONLY:
|
2023-04-14 19:06:22 +01:00
|
|
|
build.cmp(byte[regOp(inst.a) + offsetof(Table, readonly)], 0);
|
|
|
|
build.jcc(ConditionX64::NotEqual, labelOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::CHECK_NO_METATABLE:
|
2023-04-14 19:06:22 +01:00
|
|
|
build.cmp(qword[regOp(inst.a) + offsetof(Table, metatable)], 0);
|
|
|
|
build.jcc(ConditionX64::NotEqual, labelOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::CHECK_SAFE_ENV:
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
build.mov(tmp.reg, sClosure);
|
|
|
|
build.mov(tmp.reg, qword[tmp.reg + offsetof(Closure, env)]);
|
|
|
|
build.cmp(byte[tmp.reg + offsetof(Table, safeenv)], 0);
|
|
|
|
build.jcc(ConditionX64::Equal, labelOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::CHECK_ARRAY_SIZE:
|
|
|
|
if (inst.b.kind == IrOpKind::Inst)
|
|
|
|
build.cmp(dword[regOp(inst.a) + offsetof(Table, sizearray)], regOp(inst.b));
|
|
|
|
else if (inst.b.kind == IrOpKind::Constant)
|
2023-02-17 23:41:51 +00:00
|
|
|
build.cmp(dword[regOp(inst.a) + offsetof(Table, sizearray)], intOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
else
|
|
|
|
LUAU_ASSERT(!"Unsupported instruction form");
|
|
|
|
|
|
|
|
build.jcc(ConditionX64::BelowEqual, labelOp(inst.c));
|
|
|
|
break;
|
|
|
|
case IrCmd::CHECK_SLOT_MATCH:
|
|
|
|
{
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
jumpIfNodeKeyNotInExpectedSlot(build, tmp.reg, regOp(inst.a), luauConstantValue(vmConstOp(inst.b)), labelOp(inst.c));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-03-17 19:20:37 +00:00
|
|
|
case IrCmd::CHECK_NODE_NO_NEXT:
|
2023-04-14 19:06:22 +01:00
|
|
|
{
|
|
|
|
ScopedRegX64 tmp{regs, SizeX64::dword};
|
|
|
|
|
|
|
|
build.mov(tmp.reg, dword[regOp(inst.a) + offsetof(LuaNode, key) + kOffsetOfTKeyNext]);
|
|
|
|
build.shr(tmp.reg, kNextBitOffset);
|
|
|
|
build.jcc(ConditionX64::NotZero, labelOp(inst.b));
|
2023-03-17 19:20:37 +00:00
|
|
|
break;
|
2023-04-14 19:06:22 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrCmd::INTERRUPT:
|
2023-04-14 19:06:22 +01:00
|
|
|
emitInterrupt(regs, build, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::CHECK_GC:
|
2023-04-07 22:01:29 +01:00
|
|
|
callStepGc(regs, build);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::BARRIER_OBJ:
|
2023-04-07 22:01:29 +01:00
|
|
|
callBarrierObject(regs, build, regOp(inst.a), inst.a, vmRegOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::BARRIER_TABLE_BACK:
|
2023-04-07 22:01:29 +01:00
|
|
|
callBarrierTableFast(regs, build, regOp(inst.a), inst.a);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::BARRIER_TABLE_FORWARD:
|
|
|
|
{
|
|
|
|
Label skip;
|
2023-03-31 19:42:49 +01:00
|
|
|
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp{regs, SizeX64::qword};
|
2023-03-31 19:42:49 +01:00
|
|
|
checkObjectBarrierConditions(build, tmp.reg, regOp(inst.a), vmRegOp(inst.b), skip);
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
{
|
|
|
|
ScopedSpills spillGuard(regs);
|
|
|
|
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, regOp(inst.a), inst.a);
|
|
|
|
callWrap.addArgument(SizeX64::qword, tmp);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaC_barriertable)]);
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.setLabel(skip);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::SET_SAVEDPC:
|
|
|
|
{
|
|
|
|
// This is like emitSetSavedPc, but using register allocation instead of relying on rax/rdx
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.mov(tmp2.reg, sCode);
|
|
|
|
build.add(tmp2.reg, uintOp(inst.a) * sizeof(Instruction));
|
|
|
|
build.mov(tmp1.reg, qword[rState + offsetof(lua_State, ci)]);
|
|
|
|
build.mov(qword[tmp1.reg + offsetof(CallInfo, savedpc)], tmp2.reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::CLOSE_UPVALS:
|
|
|
|
{
|
|
|
|
Label next;
|
2023-02-24 21:49:38 +00:00
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::qword};
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
// L->openupval != 0
|
|
|
|
build.mov(tmp1.reg, qword[rState + offsetof(lua_State, openupval)]);
|
|
|
|
build.test(tmp1.reg, tmp1.reg);
|
|
|
|
build.jcc(ConditionX64::Zero, next);
|
|
|
|
|
|
|
|
// ra <= L->openuval->v
|
2023-03-24 18:03:04 +00:00
|
|
|
build.lea(tmp2.reg, addr[rBase + vmRegOp(inst.a) * sizeof(TValue)]);
|
2023-01-27 22:28:31 +00:00
|
|
|
build.cmp(tmp2.reg, qword[tmp1.reg + offsetof(UpVal, v)]);
|
|
|
|
build.jcc(ConditionX64::Above, next);
|
|
|
|
|
2023-03-31 19:42:49 +01:00
|
|
|
tmp1.free();
|
2023-02-10 19:40:38 +00:00
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
{
|
|
|
|
ScopedSpills spillGuard(regs);
|
|
|
|
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, tmp2);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, luaF_close)]);
|
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
build.setLabel(next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::CAPTURE:
|
|
|
|
// No-op right now
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Fallbacks to non-IR instruction implementations
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::SETLIST:
|
|
|
|
regs.assertAllFree();
|
2023-04-07 22:01:29 +01:00
|
|
|
emitInstSetList(regs, build, vmRegOp(inst.b), vmRegOp(inst.c), intOp(inst.d), uintOp(inst.e));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::CALL:
|
|
|
|
regs.assertAllFree();
|
2023-04-07 22:01:29 +01:00
|
|
|
regs.assertNoSpills();
|
2023-03-24 18:03:04 +00:00
|
|
|
emitInstCall(build, helpers, vmRegOp(inst.a), intOp(inst.b), intOp(inst.c));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::RETURN:
|
|
|
|
regs.assertAllFree();
|
2023-04-07 22:01:29 +01:00
|
|
|
regs.assertNoSpills();
|
2023-03-24 18:03:04 +00:00
|
|
|
emitInstReturn(build, helpers, vmRegOp(inst.a), intOp(inst.b));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::FORGLOOP:
|
|
|
|
regs.assertAllFree();
|
2023-04-14 19:06:22 +01:00
|
|
|
emitInstForGLoop(build, vmRegOp(inst.a), intOp(inst.b), labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::FORGLOOP_FALLBACK:
|
2023-04-14 19:06:22 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::dword, vmRegOp(inst.a));
|
|
|
|
callWrap.addArgument(SizeX64::dword, intOp(inst.b));
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, forgLoopNonTableFallback)]);
|
|
|
|
|
|
|
|
emitUpdateBase(build);
|
|
|
|
|
|
|
|
build.test(al, al);
|
|
|
|
build.jcc(ConditionX64::NotZero, labelOp(inst.c));
|
|
|
|
jumpOrFallthrough(blockOp(inst.d), next);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-04-14 19:06:22 +01:00
|
|
|
}
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::FORGPREP_XNEXT_FALLBACK:
|
2023-04-14 19:06:22 +01:00
|
|
|
{
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::qword, rState);
|
|
|
|
callWrap.addArgument(SizeX64::qword, luauRegAddress(vmRegOp(inst.b)));
|
|
|
|
callWrap.addArgument(SizeX64::dword, uintOp(inst.a) + 1);
|
|
|
|
callWrap.call(qword[rNativeContext + offsetof(NativeContext, forgPrepXnextFallback)]);
|
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-04-14 19:06:22 +01:00
|
|
|
}
|
2023-03-31 19:42:49 +01:00
|
|
|
case IrCmd::COVERAGE:
|
2023-04-14 19:06:22 +01:00
|
|
|
{
|
|
|
|
ScopedRegX64 tmp1{regs, SizeX64::qword};
|
|
|
|
ScopedRegX64 tmp2{regs, SizeX64::dword};
|
|
|
|
ScopedRegX64 tmp3{regs, SizeX64::dword};
|
|
|
|
|
|
|
|
build.mov(tmp1.reg, sCode);
|
|
|
|
build.add(tmp1.reg, uintOp(inst.a) * sizeof(Instruction));
|
|
|
|
|
|
|
|
// hits = LUAU_INSN_E(*pc)
|
|
|
|
build.mov(tmp2.reg, dword[tmp1.reg]);
|
|
|
|
build.sar(tmp2.reg, 8);
|
|
|
|
|
|
|
|
// hits = (hits < (1 << 23) - 1) ? hits + 1 : hits;
|
|
|
|
build.xor_(tmp3.reg, tmp3.reg);
|
|
|
|
build.cmp(tmp2.reg, (1 << 23) - 1);
|
|
|
|
build.setcc(ConditionX64::NotEqual, byteReg(tmp3.reg));
|
|
|
|
build.add(tmp2.reg, tmp3.reg);
|
|
|
|
|
|
|
|
// VM_PATCH_E(pc, hits);
|
|
|
|
build.sal(tmp2.reg, 8);
|
|
|
|
build.movzx(tmp3.reg, byte[tmp1.reg]);
|
|
|
|
build.or_(tmp3.reg, tmp2.reg);
|
|
|
|
build.mov(dword[tmp1.reg], tmp3.reg);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-04-14 19:06:22 +01:00
|
|
|
}
|
2023-01-27 22:28:31 +00:00
|
|
|
|
|
|
|
// Full instruction fallbacks
|
|
|
|
case IrCmd::FALLBACK_GETGLOBAL:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_GETGLOBAL, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_SETGLOBAL:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_SETGLOBAL, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_GETTABLEKS:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.d.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_GETTABLEKS, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_SETTABLEKS:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.d.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_SETTABLEKS, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_NAMECALL:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.d.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_NAMECALL, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_PREPVARARGS:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::Constant);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_PREPVARARGS, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_GETVARARGS:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::Constant);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_GETVARARGS, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_NEWCLOSURE:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::Constant);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_NEWCLOSURE, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_DUPCLOSURE:
|
2023-02-10 19:40:38 +00:00
|
|
|
LUAU_ASSERT(inst.b.kind == IrOpKind::VmReg);
|
|
|
|
LUAU_ASSERT(inst.c.kind == IrOpKind::VmConst);
|
|
|
|
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_DUPCLOSURE, uintOp(inst.a));
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
case IrCmd::FALLBACK_FORGPREP:
|
2023-04-14 19:06:22 +01:00
|
|
|
emitFallback(regs, build, data, LOP_FORGPREP, uintOp(inst.a));
|
|
|
|
jumpOrFallthrough(blockOp(inst.c), next);
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
2023-04-21 23:14:26 +01:00
|
|
|
case IrCmd::BITAND_UINT:
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.and_(inst.regX64, memRegUintOp(inst.b));
|
|
|
|
break;
|
|
|
|
case IrCmd::BITXOR_UINT:
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.xor_(inst.regX64, memRegUintOp(inst.b));
|
|
|
|
break;
|
|
|
|
case IrCmd::BITOR_UINT:
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.or_(inst.regX64, memRegUintOp(inst.b));
|
|
|
|
break;
|
|
|
|
case IrCmd::BITNOT_UINT:
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.not_(inst.regX64);
|
|
|
|
break;
|
|
|
|
case IrCmd::BITLSHIFT_UINT:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(ecx, kInvalidInstIdx)};
|
|
|
|
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.mov(shiftTmp.reg, memRegUintOp(inst.b));
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
build.mov(inst.regX64, uintOp(inst.a));
|
|
|
|
else if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.shl(inst.regX64, byteReg(shiftTmp.reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITRSHIFT_UINT:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(ecx, kInvalidInstIdx)};
|
|
|
|
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.mov(shiftTmp.reg, memRegUintOp(inst.b));
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
build.mov(inst.regX64, uintOp(inst.a));
|
|
|
|
else if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.shr(inst.regX64, byteReg(shiftTmp.reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITARSHIFT_UINT:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(ecx, kInvalidInstIdx)};
|
|
|
|
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.mov(shiftTmp.reg, memRegUintOp(inst.b));
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
build.mov(inst.regX64, uintOp(inst.a));
|
|
|
|
else if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.sar(inst.regX64, byteReg(shiftTmp.reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITLROTATE_UINT:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(ecx, kInvalidInstIdx)};
|
|
|
|
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.mov(shiftTmp.reg, memRegUintOp(inst.b));
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
build.mov(inst.regX64, uintOp(inst.a));
|
|
|
|
else if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.rol(inst.regX64, byteReg(shiftTmp.reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITRROTATE_UINT:
|
|
|
|
{
|
|
|
|
// Custom bit shift value can only be placed in cl
|
|
|
|
ScopedRegX64 shiftTmp{regs, regs.takeReg(ecx, kInvalidInstIdx)};
|
|
|
|
|
|
|
|
inst.regX64 = regs.allocReg(SizeX64::dword, index);
|
|
|
|
|
|
|
|
build.mov(shiftTmp.reg, memRegUintOp(inst.b));
|
|
|
|
|
|
|
|
if (inst.a.kind == IrOpKind::Constant)
|
|
|
|
build.mov(inst.regX64, uintOp(inst.a));
|
|
|
|
else if (inst.regX64 != regOp(inst.a))
|
|
|
|
build.mov(inst.regX64, regOp(inst.a));
|
|
|
|
|
|
|
|
build.ror(inst.regX64, byteReg(shiftTmp.reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITCOUNTLZ_UINT:
|
|
|
|
{
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
Label zero, exit;
|
|
|
|
|
|
|
|
build.test(regOp(inst.a), regOp(inst.a));
|
|
|
|
build.jcc(ConditionX64::Equal, zero);
|
|
|
|
|
|
|
|
build.bsr(inst.regX64, regOp(inst.a));
|
|
|
|
build.xor_(inst.regX64, 0x1f);
|
|
|
|
build.jmp(exit);
|
|
|
|
|
|
|
|
build.setLabel(zero);
|
|
|
|
build.mov(inst.regX64, 32);
|
|
|
|
|
|
|
|
build.setLabel(exit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::BITCOUNTRZ_UINT:
|
|
|
|
{
|
|
|
|
inst.regX64 = regs.allocRegOrReuse(SizeX64::dword, index, {inst.a});
|
|
|
|
|
|
|
|
Label zero, exit;
|
|
|
|
|
|
|
|
build.test(regOp(inst.a), regOp(inst.a));
|
|
|
|
build.jcc(ConditionX64::Equal, zero);
|
|
|
|
|
|
|
|
build.bsf(inst.regX64, regOp(inst.a));
|
|
|
|
build.jmp(exit);
|
|
|
|
|
|
|
|
build.setLabel(zero);
|
|
|
|
build.mov(inst.regX64, 32);
|
|
|
|
|
|
|
|
build.setLabel(exit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IrCmd::INVOKE_LIBM:
|
|
|
|
{
|
|
|
|
LuauBuiltinFunction bfid = LuauBuiltinFunction(uintOp(inst.a));
|
|
|
|
|
|
|
|
IrCallWrapperX64 callWrap(regs, build, index);
|
|
|
|
callWrap.addArgument(SizeX64::xmmword, memRegDoubleOp(inst.b), inst.b);
|
|
|
|
|
|
|
|
if (inst.c.kind != IrOpKind::None)
|
|
|
|
callWrap.addArgument(SizeX64::xmmword, memRegDoubleOp(inst.c), inst.c);
|
|
|
|
|
|
|
|
callWrap.call(qword[rNativeContext + getNativeContextOffset(bfid)]);
|
|
|
|
inst.regX64 = regs.takeReg(xmm0, index);
|
|
|
|
break;
|
|
|
|
}
|
2023-04-14 19:06:22 +01:00
|
|
|
|
|
|
|
// Pseudo instructions
|
|
|
|
case IrCmd::NOP:
|
|
|
|
case IrCmd::SUBSTITUTE:
|
|
|
|
LUAU_ASSERT(!"Pseudo instructions should not be lowered");
|
2023-01-27 22:28:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-03-24 18:03:04 +00:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
valueTracker.afterInstLowering(inst, index);
|
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
regs.freeLastUseRegs(inst, index);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
void IrLoweringX64::finishBlock()
|
|
|
|
{
|
|
|
|
regs.assertNoSpills();
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
bool IrLoweringX64::hasError() const
|
|
|
|
{
|
|
|
|
// If register allocator had to use more stack slots than we have available, this function can't run natively
|
|
|
|
if (regs.maxUsedSlot > kSpillSlots)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-27 22:28:31 +00:00
|
|
|
bool IrLoweringX64::isFallthroughBlock(IrBlock target, IrBlock next)
|
|
|
|
{
|
|
|
|
return target.start == next.start;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrLoweringX64::jumpOrFallthrough(IrBlock& target, IrBlock& next)
|
|
|
|
{
|
|
|
|
if (!isFallthroughBlock(target, next))
|
|
|
|
build.jmp(target.label);
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
OperandX64 IrLoweringX64::memRegDoubleOp(IrOp op)
|
2023-01-27 22:28:31 +00:00
|
|
|
{
|
|
|
|
switch (op.kind)
|
|
|
|
{
|
|
|
|
case IrOpKind::Inst:
|
|
|
|
return regOp(op);
|
|
|
|
case IrOpKind::Constant:
|
|
|
|
return build.f64(doubleOp(op));
|
|
|
|
case IrOpKind::VmReg:
|
2023-03-24 18:03:04 +00:00
|
|
|
return luauRegValue(vmRegOp(op));
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrOpKind::VmConst:
|
2023-03-24 18:03:04 +00:00
|
|
|
return luauConstantValue(vmConstOp(op));
|
2023-01-27 22:28:31 +00:00
|
|
|
default:
|
|
|
|
LUAU_ASSERT(!"Unsupported operand kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
return noreg;
|
|
|
|
}
|
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
OperandX64 IrLoweringX64::memRegUintOp(IrOp op)
|
|
|
|
{
|
|
|
|
switch (op.kind)
|
|
|
|
{
|
|
|
|
case IrOpKind::Inst:
|
|
|
|
return regOp(op);
|
|
|
|
case IrOpKind::Constant:
|
|
|
|
return OperandX64(uintOp(op));
|
|
|
|
default:
|
|
|
|
LUAU_ASSERT(!"Unsupported operand kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
return noreg;
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
OperandX64 IrLoweringX64::memRegTagOp(IrOp op)
|
2023-01-27 22:28:31 +00:00
|
|
|
{
|
|
|
|
switch (op.kind)
|
|
|
|
{
|
|
|
|
case IrOpKind::Inst:
|
|
|
|
return regOp(op);
|
|
|
|
case IrOpKind::VmReg:
|
2023-03-24 18:03:04 +00:00
|
|
|
return luauRegTag(vmRegOp(op));
|
2023-01-27 22:28:31 +00:00
|
|
|
case IrOpKind::VmConst:
|
2023-03-24 18:03:04 +00:00
|
|
|
return luauConstantTag(vmConstOp(op));
|
2023-01-27 22:28:31 +00:00
|
|
|
default:
|
|
|
|
LUAU_ASSERT(!"Unsupported operand kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
return noreg;
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:01:29 +01:00
|
|
|
RegisterX64 IrLoweringX64::regOp(IrOp op)
|
2023-01-27 22:28:31 +00:00
|
|
|
{
|
2023-03-24 18:03:04 +00:00
|
|
|
IrInst& inst = function.instOp(op);
|
2023-04-07 22:01:29 +01:00
|
|
|
|
2023-04-21 23:14:26 +01:00
|
|
|
if (inst.spilled || inst.needsReload)
|
2023-04-07 22:01:29 +01:00
|
|
|
regs.restore(inst, false);
|
|
|
|
|
2023-03-24 18:03:04 +00:00
|
|
|
LUAU_ASSERT(inst.regX64 != noreg);
|
|
|
|
return inst.regX64;
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IrConst IrLoweringX64::constOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.constOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t IrLoweringX64::tagOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.tagOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IrLoweringX64::boolOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.boolOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int IrLoweringX64::intOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.intOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned IrLoweringX64::uintOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.uintOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double IrLoweringX64::doubleOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.doubleOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IrBlock& IrLoweringX64::blockOp(IrOp op) const
|
|
|
|
{
|
2023-02-10 19:40:38 +00:00
|
|
|
return function.blockOp(op);
|
2023-01-27 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Label& IrLoweringX64::labelOp(IrOp op) const
|
|
|
|
{
|
|
|
|
return blockOp(op).label;
|
|
|
|
}
|
|
|
|
|
2023-03-03 20:21:14 +00:00
|
|
|
} // namespace X64
|
2023-01-27 22:28:31 +00:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|