From 378e58731af047b449c86135f87d08b4fc931bb9 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 14 Sep 2018 23:38:57 +0200 Subject: [PATCH] - simplify some code --- src/scripting/vm/jit.cpp | 15 +----------- src/scripting/vm/jit_call.cpp | 45 ++++++++++------------------------- src/scripting/vm/jit_flow.cpp | 2 +- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index 01b949c2c..b24ac7920 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -164,14 +164,7 @@ bool JitCompiler::CanJit(VMScriptFunction *sfunc) // Partially implemented functions: auto pc = sfunc->Code + i; - if (sfunc->Code[i].op == OP_RET) - { - if (B != REGT_NIL) - { - int regtype = B; - } - } - else if (sfunc->Code[i].op == OP_CAST) + if (sfunc->Code[i].op == OP_CAST) { switch (C) { @@ -193,12 +186,6 @@ bool JitCompiler::CanJit(VMScriptFunction *sfunc) { if (!!(B & REGT_MULTIREG3) || !!(B & REGT_MULTIREG2)) return false; - - switch (B) - { - default: - break; - } } else if (sfunc->Code[i].op == OP_RESULT) { diff --git a/src/scripting/vm/jit_call.cpp b/src/scripting/vm/jit_call.cpp index 5d036dcea..7596aaaa4 100644 --- a/src/scripting/vm/jit_call.cpp +++ b/src/scripting/vm/jit_call.cpp @@ -33,40 +33,19 @@ void JitCompiler::EmitPARAM() cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_INT); break; case REGT_STRING: - { - auto setStringLambda = [](VMValue* val, FString* str) -> void { - ::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(static_cast(setStringLambda))), - asmjit::FuncSignature2(asmjit::CallConv::kIdHostCDecl)); - call->setArg(0, ptr); - call->setArg(1, regS[C]); + cc.mov(x86::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, sp)), regS[C]); + cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_STRING); break; - } case REGT_STRING | REGT_ADDROF: - stackPtr = cc.newIntPtr(); - 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::ptr(params, index * sizeof(VMValue) + offsetof(VMValue, a)), regS[C]); cc.mov(x86::byte_ptr(params, index * sizeof(VMValue) + offsetof(VMValue, Type)), (int)REGT_POINTER); break; case REGT_STRING | REGT_KONST: - { - auto setStringLambda = [](VMValue* val, FString* str) -> void { - ::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(static_cast(setStringLambda))), - asmjit::FuncSignature2(asmjit::CallConv::kIdHostCDecl)); - call->setArg(0, ptr); - call->setArg(1, asmjit::imm_ptr(&konsts[C])); + tmp = cc.newIntPtr(); + cc.mov(tmp, ToMemAddress(&konsts[C])); + 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); break; - } case REGT_POINTER: 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); @@ -232,8 +211,9 @@ void JitCompiler::StoreInOuts(int b) cc.add(stackPtr, (int)(C * sizeof(int32_t))); cc.mov(x86::dword_ptr(stackPtr), regD[C]); break; - //case REGT_STRING | REGT_ADDROF: - // break; + case REGT_STRING | REGT_ADDROF: + // We don't have to do anything in this case. String values are never moved to virtual registers. + break; case REGT_POINTER | REGT_ADDROF: stackPtr = cc.newIntPtr(); 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))); break; case REGT_STRING: - cc.mov(regS[regnum], frameS); - cc.add(regS[regnum], regnum * sizeof(FString)); + // We don't have to do anything in this case. String values are never moved to virtual registers. break; case REGT_POINTER: cc.mov(regA[regnum], asmjit::x86::ptr(frameA, regnum * sizeof(void*))); @@ -324,7 +303,7 @@ void JitCompiler::FillReturns(const VMOP *retval, int numret) break; case REGT_STRING: cc.mov(regPtr, frameS); - cc.add(regPtr, regnum * sizeof(FString)); + cc.add(regPtr, (int)(regnum * sizeof(FString))); break; case REGT_POINTER: cc.mov(regPtr, frameA); diff --git a/src/scripting/vm/jit_flow.cpp b/src/scripting/vm/jit_flow.cpp index f5d76d575..91240ea97 100644 --- a/src/scripting/vm/jit_flow.cpp +++ b/src/scripting/vm/jit_flow.cpp @@ -174,7 +174,7 @@ void JitCompiler::EmitRET() }; auto ptr = cc.newIntPtr(); cc.mov(ptr, ret); - cc.add(ptr, retnum * sizeof(VMReturn)); + cc.add(ptr, (int)(retnum * sizeof(VMReturn))); auto call = cc.call(ToMemAddress(reinterpret_cast(static_cast(setRetStringLamdba))), asmjit::FuncSignature2(asmjit::CallConv::kIdHostCDecl)); call->setArg(0, ptr);