- simplify some code

This commit is contained in:
Magnus Norddahl 2018-09-14 23:38:57 +02:00 committed by drfrag
parent b342dbc8db
commit 378e58731a
3 changed files with 14 additions and 48 deletions

View file

@ -164,14 +164,7 @@ bool JitCompiler::CanJit(VMScriptFunction *sfunc)
// Partially implemented functions: // Partially implemented functions:
auto pc = sfunc->Code + i; auto pc = sfunc->Code + i;
if (sfunc->Code[i].op == OP_RET) if (sfunc->Code[i].op == OP_CAST)
{
if (B != REGT_NIL)
{
int regtype = B;
}
}
else if (sfunc->Code[i].op == OP_CAST)
{ {
switch (C) switch (C)
{ {
@ -193,12 +186,6 @@ bool JitCompiler::CanJit(VMScriptFunction *sfunc)
{ {
if (!!(B & REGT_MULTIREG3) || !!(B & REGT_MULTIREG2)) if (!!(B & REGT_MULTIREG3) || !!(B & REGT_MULTIREG2))
return false; return false;
switch (B)
{
default:
break;
}
} }
else if (sfunc->Code[i].op == OP_RESULT) else if (sfunc->Code[i].op == OP_RESULT)
{ {

View file

@ -33,40 +33,19 @@ void JitCompiler::EmitPARAM()
cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT); cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT);
break; break;
case REGT_STRING: case REGT_STRING:
{ cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, sp)), regS[C]);
auto setStringLambda = [](VMValue* val, FString* str) -> void { cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_STRING);
::new(val) VMValue(str);
};
auto ptr = cc.newIntPtr();
cc.mov(ptr, params);
cc.add(ptr, index * sizeof(VMValue));
auto call = cc.call(ToMemAddress(reinterpret_cast<void*>(static_cast<void(*)(VMValue*, FString*)>(setStringLambda))),
asmjit::FuncSignature2<void, VMValue*, FString*>(asmjit::CallConv::kIdHostCDecl));
call->setArg(0, ptr);
call->setArg(1, regS[C]);
break; break;
}
case REGT_STRING | REGT_ADDROF: case REGT_STRING | REGT_ADDROF:
stackPtr = cc.newIntPtr(); cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, a)), regS[C]);
cc.mov(stackPtr, frameS);
cc.add(stackPtr, C * sizeof(FString));
cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, a)), stackPtr);
cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER); cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
break; break;
case REGT_STRING | REGT_KONST: case REGT_STRING | REGT_KONST:
{ tmp = cc.newIntPtr();
auto setStringLambda = [](VMValue* val, FString* str) -> void { cc.mov(tmp, ToMemAddress(&konsts[C]));
::new(val) VMValue(str); cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, sp)), tmp);
}; cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_STRING);
auto ptr = cc.newIntPtr();
cc.mov(ptr, params);
cc.add(ptr, index * sizeof(VMValue));
auto call = cc.call(ToMemAddress(reinterpret_cast<void*>(static_cast<void(*)(VMValue*, FString*)>(setStringLambda))),
asmjit::FuncSignature2<void, VMValue*, FString*>(asmjit::CallConv::kIdHostCDecl));
call->setArg(0, ptr);
call->setArg(1, asmjit::imm_ptr(&konsts[C]));
break; break;
}
case REGT_POINTER: case REGT_POINTER:
cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, a)), regA[C]); cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, a)), regA[C]);
cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER); cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER);
@ -232,8 +211,9 @@ void JitCompiler::StoreInOuts(int b)
cc.add(stackPtr, (int)(C * sizeof(int32_t))); cc.add(stackPtr, (int)(C * sizeof(int32_t)));
cc.mov(x86::dword_ptr(stackPtr), regD[C]); cc.mov(x86::dword_ptr(stackPtr), regD[C]);
break; break;
//case REGT_STRING | REGT_ADDROF: case REGT_STRING | REGT_ADDROF:
// break; // We don't have to do anything in this case. String values are never moved to virtual registers.
break;
case REGT_POINTER | REGT_ADDROF: case REGT_POINTER | REGT_ADDROF:
stackPtr = cc.newIntPtr(); stackPtr = cc.newIntPtr();
cc.mov(stackPtr, frameA); cc.mov(stackPtr, frameA);
@ -278,8 +258,7 @@ void JitCompiler::LoadReturns(const VMOP *retval, int numret, bool inout)
cc.movsd(regF[regnum], asmjit::x86::qword_ptr(frameF, regnum * sizeof(double))); cc.movsd(regF[regnum], asmjit::x86::qword_ptr(frameF, regnum * sizeof(double)));
break; break;
case REGT_STRING: case REGT_STRING:
cc.mov(regS[regnum], frameS); // We don't have to do anything in this case. String values are never moved to virtual registers.
cc.add(regS[regnum], regnum * sizeof(FString));
break; break;
case REGT_POINTER: case REGT_POINTER:
cc.mov(regA[regnum], asmjit::x86::ptr(frameA, regnum * sizeof(void*))); cc.mov(regA[regnum], asmjit::x86::ptr(frameA, regnum * sizeof(void*)));
@ -324,7 +303,7 @@ void JitCompiler::FillReturns(const VMOP *retval, int numret)
break; break;
case REGT_STRING: case REGT_STRING:
cc.mov(regPtr, frameS); cc.mov(regPtr, frameS);
cc.add(regPtr, regnum * sizeof(FString)); cc.add(regPtr, (int)(regnum * sizeof(FString)));
break; break;
case REGT_POINTER: case REGT_POINTER:
cc.mov(regPtr, frameA); cc.mov(regPtr, frameA);

View file

@ -174,7 +174,7 @@ void JitCompiler::EmitRET()
}; };
auto ptr = cc.newIntPtr(); auto ptr = cc.newIntPtr();
cc.mov(ptr, ret); cc.mov(ptr, ret);
cc.add(ptr, retnum * sizeof(VMReturn)); cc.add(ptr, (int)(retnum * sizeof(VMReturn)));
auto call = cc.call(ToMemAddress(reinterpret_cast<void*>(static_cast<void(*)(VMReturn*, FString*)>(setRetStringLamdba))), auto call = cc.call(ToMemAddress(reinterpret_cast<void*>(static_cast<void(*)(VMReturn*, FString*)>(setRetStringLamdba))),
asmjit::FuncSignature2<void, VMReturn*, FString*>(asmjit::CallConv::kIdHostCDecl)); asmjit::FuncSignature2<void, VMReturn*, FString*>(asmjit::CallConv::kIdHostCDecl));
call->setArg(0, ptr); call->setArg(0, ptr);