2018-09-13 00:29:04 +00:00
|
|
|
|
|
|
|
#include "jitintern.h"
|
|
|
|
|
|
|
|
void JitCompiler::EmitPARAM()
|
|
|
|
{
|
|
|
|
using namespace asmjit;
|
|
|
|
|
|
|
|
int index = NumParam++;
|
|
|
|
ParamOpcodes.Push(pc);
|
|
|
|
|
|
|
|
X86Gp stackPtr, tmp;
|
|
|
|
X86Xmm tmp2;
|
|
|
|
|
2018-10-14 21:13:30 +00:00
|
|
|
switch (A)
|
2018-09-13 00:29:04 +00:00
|
|
|
{
|
|
|
|
case REGT_NIL:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), (int64_t)0);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_NIL);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_INT:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(x86::dword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, i)), regD[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_INT | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetD + (int)(BC * sizeof(int32_t))));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), stackPtr);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_INT | REGT_KONST:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(x86::dword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, i)), konstd[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
2018-09-14 17:20:31 +00:00
|
|
|
case REGT_STRING:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, sp)), regS[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_STRING);
|
2018-09-14 17:20:31 +00:00
|
|
|
break;
|
|
|
|
case REGT_STRING | REGT_ADDROF:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), regS[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-14 17:20:31 +00:00
|
|
|
break;
|
|
|
|
case REGT_STRING | REGT_KONST:
|
2018-10-07 07:02:28 +00:00
|
|
|
tmp = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(tmp, asmjit::imm_ptr(&konsts[BC]));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, sp)), tmp);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_STRING);
|
2018-09-14 17:20:31 +00:00
|
|
|
break;
|
2018-09-13 00:29:04 +00:00
|
|
|
case REGT_POINTER:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), regA[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_POINTER | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetA + (int)(BC * sizeof(void*))));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), stackPtr);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_POINTER | REGT_KONST:
|
2018-10-07 07:02:28 +00:00
|
|
|
tmp = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(tmp, asmjit::imm_ptr(konsta[BC].v));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), tmp);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT | REGT_MULTIREG2:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
index = NumParam++;
|
|
|
|
ParamOpcodes.Push(pc);
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC + 1]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT | REGT_MULTIREG3:
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
index = NumParam++;
|
|
|
|
ParamOpcodes.Push(pc);
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC + 1]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
index = NumParam++;
|
|
|
|
ParamOpcodes.Push(pc);
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), regF[BC + 2]);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetF + (int)(BC * sizeof(double))));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(x86::ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, a)), stackPtr);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT | REGT_KONST:
|
2018-10-07 07:02:28 +00:00
|
|
|
tmp = newTempIntPtr();
|
|
|
|
tmp2 = newTempXmmSd();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.mov(tmp, asmjit::imm_ptr(konstf + BC));
|
2018-09-13 00:29:04 +00:00
|
|
|
cc.movsd(tmp2, asmjit::x86::qword_ptr(tmp));
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(x86::qword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, f)), tmp2);
|
|
|
|
cc.mov(x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_FLOAT);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
I_FatalError("Unknown REGT value passed to EmitPARAM\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JitCompiler::EmitPARAMI()
|
|
|
|
{
|
|
|
|
int index = NumParam++;
|
|
|
|
ParamOpcodes.Push(pc);
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(asmjit::x86::dword_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, i)), (int)ABCs);
|
|
|
|
cc.mov(asmjit::x86::byte_ptr(vmframe, offsetParams + index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT);
|
2018-09-13 00:29:04 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 00:56:02 +00:00
|
|
|
void JitCompiler::EmitRESULT()
|
|
|
|
{
|
|
|
|
// This instruction is just a placeholder to indicate where a return
|
|
|
|
// value should be stored. It does nothing on its own and should not
|
|
|
|
// be executed.
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:29:04 +00:00
|
|
|
void JitCompiler::EmitCALL()
|
|
|
|
{
|
2018-10-10 21:47:56 +00:00
|
|
|
EmitDoCall(regA[A]);
|
2018-09-13 00:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JitCompiler::EmitCALL_K()
|
|
|
|
{
|
2018-10-07 07:02:28 +00:00
|
|
|
auto ptr = newTempIntPtr();
|
2018-10-10 21:47:56 +00:00
|
|
|
cc.mov(ptr, asmjit::imm_ptr(konsta[A].o));
|
|
|
|
EmitDoCall(ptr);
|
2018-09-13 00:29:04 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 21:47:56 +00:00
|
|
|
void JitCompiler::EmitDoCall(asmjit::X86Gp vmfunc)
|
2018-09-13 00:29:04 +00:00
|
|
|
{
|
|
|
|
using namespace asmjit;
|
|
|
|
|
|
|
|
if (NumParam < B)
|
|
|
|
I_FatalError("OP_CALL parameter count does not match the number of preceding OP_PARAM instructions");
|
|
|
|
|
|
|
|
StoreInOuts(B);
|
|
|
|
FillReturns(pc + 1, C);
|
|
|
|
|
2018-10-12 05:41:16 +00:00
|
|
|
X86Gp paramsptr = newTempIntPtr();
|
|
|
|
cc.lea(paramsptr, x86::ptr(vmframe, offsetParams + (int)((NumParam - B) * sizeof(VMValue))));
|
2018-09-13 00:29:04 +00:00
|
|
|
|
2018-10-10 21:47:56 +00:00
|
|
|
EmitScriptCall(vmfunc, paramsptr);
|
2018-09-13 00:29:04 +00:00
|
|
|
|
2018-09-16 22:31:25 +00:00
|
|
|
LoadInOuts(B);
|
|
|
|
LoadReturns(pc + 1, C);
|
2018-09-13 00:29:04 +00:00
|
|
|
|
|
|
|
NumParam -= B;
|
|
|
|
ParamOpcodes.Resize(ParamOpcodes.Size() - B);
|
2018-10-12 04:25:51 +00:00
|
|
|
|
|
|
|
pc += C; // Skip RESULTs
|
2018-09-13 00:29:04 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 20:08:26 +00:00
|
|
|
void JitCompiler::EmitScriptCall(asmjit::X86Gp vmfunc, asmjit::X86Gp paramsptr)
|
|
|
|
{
|
|
|
|
using namespace asmjit;
|
|
|
|
|
|
|
|
auto scriptcall = newTempIntPtr();
|
|
|
|
cc.mov(scriptcall, x86::ptr(vmfunc, offsetof(VMScriptFunction, ScriptCall)));
|
|
|
|
|
|
|
|
auto result = newResultInt32();
|
|
|
|
auto call = cc.call(scriptcall, FuncSignature5<int, VMFunction *, VMValue*, int, VMReturn*, int>());
|
|
|
|
call->setRet(0, result);
|
|
|
|
call->setArg(0, vmfunc);
|
|
|
|
call->setArg(1, paramsptr);
|
|
|
|
call->setArg(2, Imm(B));
|
|
|
|
call->setArg(3, callReturns);
|
|
|
|
call->setArg(4, Imm(C));
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:29:04 +00:00
|
|
|
void JitCompiler::StoreInOuts(int b)
|
|
|
|
{
|
|
|
|
using namespace asmjit;
|
|
|
|
|
|
|
|
for (unsigned int i = ParamOpcodes.Size() - b; i < ParamOpcodes.Size(); i++)
|
|
|
|
{
|
|
|
|
asmjit::X86Gp stackPtr;
|
2018-10-14 21:13:30 +00:00
|
|
|
auto bc = ParamOpcodes[i]->i16u;
|
|
|
|
switch (ParamOpcodes[i]->a)
|
2018-09-13 00:29:04 +00:00
|
|
|
{
|
|
|
|
case REGT_INT | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetD + (int)(bc * sizeof(int32_t))));
|
|
|
|
cc.mov(x86::dword_ptr(stackPtr), regD[bc]);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
2018-09-14 21:38:57 +00:00
|
|
|
case REGT_STRING | REGT_ADDROF:
|
|
|
|
// We don't have to do anything in this case. String values are never moved to virtual registers.
|
|
|
|
break;
|
2018-09-13 00:29:04 +00:00
|
|
|
case REGT_POINTER | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetA + (int)(bc * sizeof(void*))));
|
|
|
|
cc.mov(x86::ptr(stackPtr), regA[bc]);
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT | REGT_ADDROF:
|
2018-10-07 07:02:28 +00:00
|
|
|
stackPtr = newTempIntPtr();
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.lea(stackPtr, x86::ptr(vmframe, offsetF + (int)(bc * sizeof(double))));
|
|
|
|
cc.movsd(x86::qword_ptr(stackPtr), regF[bc]);
|
2018-10-07 20:21:48 +00:00
|
|
|
|
|
|
|
// When passing the address to a float we don't know if the receiving function will treat it as float, vec2 or vec3.
|
2018-10-14 21:13:30 +00:00
|
|
|
if ((unsigned int)bc + 1 < regF.Size())
|
2018-10-07 20:21:48 +00:00
|
|
|
{
|
|
|
|
cc.add(stackPtr, (int)sizeof(double));
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(stackPtr), regF[bc + 1]);
|
2018-10-07 20:21:48 +00:00
|
|
|
}
|
2018-10-14 21:13:30 +00:00
|
|
|
if ((unsigned int)bc + 2 < regF.Size())
|
2018-10-07 20:21:48 +00:00
|
|
|
{
|
|
|
|
cc.add(stackPtr, (int)sizeof(double));
|
2018-10-14 21:13:30 +00:00
|
|
|
cc.movsd(x86::qword_ptr(stackPtr), regF[bc + 2]);
|
2018-10-07 20:21:48 +00:00
|
|
|
}
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 22:31:25 +00:00
|
|
|
void JitCompiler::LoadInOuts(int b)
|
|
|
|
{
|
|
|
|
for (unsigned int i = ParamOpcodes.Size() - b; i < ParamOpcodes.Size(); i++)
|
|
|
|
{
|
|
|
|
const VMOP ¶m = *ParamOpcodes[i];
|
2018-10-14 21:13:30 +00:00
|
|
|
if (param.op == OP_PARAM && (param.a & REGT_ADDROF))
|
2018-09-16 22:31:25 +00:00
|
|
|
{
|
2018-10-14 21:13:30 +00:00
|
|
|
LoadCallResult(param.a, param.i16u, true);
|
2018-09-16 22:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JitCompiler::LoadReturns(const VMOP *retval, int numret)
|
2018-09-13 00:29:04 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < numret; ++i)
|
|
|
|
{
|
2018-09-16 22:31:25 +00:00
|
|
|
if (retval[i].op != OP_RESULT)
|
2018-09-13 00:29:04 +00:00
|
|
|
I_FatalError("Expected OP_RESULT to follow OP_CALL\n");
|
|
|
|
|
2018-10-14 21:13:30 +00:00
|
|
|
LoadCallResult(retval[i].b, retval[i].c, false);
|
2018-09-16 22:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-13 00:29:04 +00:00
|
|
|
|
2018-10-14 21:13:30 +00:00
|
|
|
void JitCompiler::LoadCallResult(int type, int regnum, bool addrof)
|
2018-09-16 22:31:25 +00:00
|
|
|
{
|
|
|
|
switch (type & REGT_TYPE)
|
|
|
|
{
|
|
|
|
case REGT_INT:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(regD[regnum], asmjit::x86::dword_ptr(vmframe, offsetD + regnum * sizeof(int32_t)));
|
2018-09-16 22:31:25 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(regF[regnum], asmjit::x86::qword_ptr(vmframe, offsetF + regnum * sizeof(double)));
|
2018-10-07 20:21:48 +00:00
|
|
|
if (addrof)
|
|
|
|
{
|
|
|
|
// When passing the address to a float we don't know if the receiving function will treat it as float, vec2 or vec3.
|
|
|
|
if ((unsigned int)regnum + 1 < regF.Size())
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(regF[regnum + 1], asmjit::x86::qword_ptr(vmframe, offsetF + (regnum + 1) * sizeof(double)));
|
2018-10-07 20:21:48 +00:00
|
|
|
if ((unsigned int)regnum + 2 < regF.Size())
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(regF[regnum + 2], asmjit::x86::qword_ptr(vmframe, offsetF + (regnum + 2) * sizeof(double)));
|
2018-10-07 20:21:48 +00:00
|
|
|
}
|
|
|
|
else if (type & REGT_MULTIREG2)
|
|
|
|
{
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(regF[regnum + 1], asmjit::x86::qword_ptr(vmframe, offsetF + (regnum + 1) * sizeof(double)));
|
2018-10-07 20:21:48 +00:00
|
|
|
}
|
|
|
|
else if (type & REGT_MULTIREG3)
|
|
|
|
{
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.movsd(regF[regnum + 1], asmjit::x86::qword_ptr(vmframe, offsetF + (regnum + 1) * sizeof(double)));
|
|
|
|
cc.movsd(regF[regnum + 2], asmjit::x86::qword_ptr(vmframe, offsetF + (regnum + 2) * sizeof(double)));
|
2018-10-07 20:21:48 +00:00
|
|
|
}
|
2018-09-16 22:31:25 +00:00
|
|
|
break;
|
|
|
|
case REGT_STRING:
|
|
|
|
// We don't have to do anything in this case. String values are never moved to virtual registers.
|
|
|
|
break;
|
|
|
|
case REGT_POINTER:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.mov(regA[regnum], asmjit::x86::ptr(vmframe, offsetA + regnum * sizeof(void*)));
|
2018-09-16 22:31:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
I_FatalError("Unknown OP_RESULT/OP_PARAM type encountered in LoadCallResult\n");
|
|
|
|
break;
|
2018-09-13 00:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JitCompiler::FillReturns(const VMOP *retval, int numret)
|
|
|
|
{
|
|
|
|
using namespace asmjit;
|
|
|
|
|
|
|
|
for (int i = 0; i < numret; ++i)
|
|
|
|
{
|
|
|
|
if (retval[i].op != OP_RESULT)
|
|
|
|
{
|
|
|
|
I_FatalError("Expected OP_RESULT to follow OP_CALL\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int type = retval[i].b;
|
|
|
|
int regnum = retval[i].c;
|
|
|
|
|
|
|
|
if (type & REGT_KONST)
|
|
|
|
{
|
|
|
|
I_FatalError("OP_RESULT with REGT_KONST is not allowed\n");
|
|
|
|
}
|
|
|
|
|
2018-10-07 07:02:28 +00:00
|
|
|
auto regPtr = newTempIntPtr();
|
2018-09-13 00:29:04 +00:00
|
|
|
|
|
|
|
switch (type & REGT_TYPE)
|
|
|
|
{
|
|
|
|
case REGT_INT:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.lea(regPtr, x86::ptr(vmframe, offsetD + (int)(regnum * sizeof(int32_t))));
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
case REGT_FLOAT:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.lea(regPtr, x86::ptr(vmframe, offsetF + (int)(regnum * sizeof(double))));
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
2018-09-14 17:20:31 +00:00
|
|
|
case REGT_STRING:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.lea(regPtr, x86::ptr(vmframe, offsetS + (int)(regnum * sizeof(FString))));
|
2018-09-14 17:20:31 +00:00
|
|
|
break;
|
2018-09-13 00:29:04 +00:00
|
|
|
case REGT_POINTER:
|
2018-10-12 05:41:16 +00:00
|
|
|
cc.lea(regPtr, x86::ptr(vmframe, offsetA + (int)(regnum * sizeof(void*))));
|
2018-09-13 00:29:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
I_FatalError("Unknown OP_RESULT type encountered in FillReturns\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cc.mov(x86::ptr(callReturns, i * sizeof(VMReturn) + offsetof(VMReturn, Location)), regPtr);
|
|
|
|
cc.mov(x86::byte_ptr(callReturns, i * sizeof(VMReturn) + offsetof(VMReturn, RegType)), type);
|
|
|
|
}
|
|
|
|
}
|