From c86e4480b6230197d1731c33f9c790c5243ca21f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 12 Oct 2018 06:59:03 +0200 Subject: [PATCH] - give temp registers names and reuse the FString object for formatting names --- src/scripting/vm/jit.cpp | 4 ---- src/scripting/vm/jitintern.h | 30 +++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index 492b9d2a11..b18aaf1a8a 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -237,28 +237,24 @@ void JitCompiler::Setup() for (int i = 0; i < sfunc->NumRegD; i++) { - FString regname; regname.Format("regD%d", i); regD[i] = cc.newInt32(regname.GetChars()); } for (int i = 0; i < sfunc->NumRegF; i++) { - FString regname; regname.Format("regF%d", i); regF[i] = cc.newXmmSd(regname.GetChars()); } for (int i = 0; i < sfunc->NumRegS; i++) { - FString regname; regname.Format("regS%d", i); regS[i] = cc.newIntPtr(regname.GetChars()); } for (int i = 0; i < sfunc->NumRegA; i++) { - FString regname; regname.Format("regA%d", i); regA[i] = cc.newIntPtr(regname.GetChars()); } diff --git a/src/scripting/vm/jitintern.h b/src/scripting/vm/jitintern.h index 3a9e24adad..81f916a697 100644 --- a/src/scripting/vm/jitintern.h +++ b/src/scripting/vm/jitintern.h @@ -104,6 +104,7 @@ private: template asmjit::CCFuncCall *CreateCall(RetType(*func)(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)) { return cc.call(asmjit::imm_ptr(reinterpret_cast(static_cast(func))), asmjit::FuncSignature7()); } + FString regname; size_t tmpPosInt32, tmpPosInt64, tmpPosIntPtr, tmpPosXmmSd, tmpPosXmmSs, tmpPosXmmPd, resultPosInt32, resultPosIntPtr, resultPosXmmSd; std::vector regTmpInt32, regTmpInt64, regTmpIntPtr, regResultInt32, regResultIntPtr; std::vector regTmpXmmSd, regTmpXmmSs, regTmpXmmPd, regResultXmmSd; @@ -121,16 +122,27 @@ private: resultPosXmmSd = 0; } - asmjit::X86Gp newTempInt32() { if (tmpPosInt32 == regTmpInt32.size()) regTmpInt32.push_back(cc.newInt32()); return regTmpInt32[tmpPosInt32++]; } - asmjit::X86Gp newTempInt64() { if (tmpPosInt64 == regTmpInt64.size()) regTmpInt64.push_back(cc.newInt64()); return regTmpInt64[tmpPosInt64++]; } - asmjit::X86Gp newTempIntPtr() { if (tmpPosIntPtr == regTmpIntPtr.size()) regTmpIntPtr.push_back(cc.newIntPtr()); return regTmpIntPtr[tmpPosIntPtr++]; } - asmjit::X86Xmm newTempXmmSd() { if (tmpPosXmmSd == regTmpXmmSd.size()) regTmpXmmSd.push_back(cc.newXmmSd()); return regTmpXmmSd[tmpPosXmmSd++]; } - asmjit::X86Xmm newTempXmmSs() { if (tmpPosXmmSs == regTmpXmmSs.size()) regTmpXmmSs.push_back(cc.newXmmSs()); return regTmpXmmSs[tmpPosXmmSs++]; } - asmjit::X86Xmm newTempXmmPd() { if (tmpPosXmmPd == regTmpXmmPd.size()) regTmpXmmPd.push_back(cc.newXmmPd()); return regTmpXmmPd[tmpPosXmmPd++]; } + template + T newTempRegister(std::vector &tmpVector, size_t &tmpPos, const char *name, NewFunc newCallback) + { + if (tmpPos == tmpVector.size()) + { + regname.Format("%s%d", name, (int)tmpVector.size()); + tmpVector.push_back(newCallback(regname.GetChars())); + } + return tmpVector[tmpPos++]; + } - asmjit::X86Gp newResultInt32() { if (resultPosInt32 == regResultInt32.size()) regResultInt32.push_back(cc.newInt32()); return regResultInt32[resultPosInt32++]; } - asmjit::X86Gp newResultIntPtr() { if (resultPosIntPtr == regResultIntPtr.size()) regResultIntPtr.push_back(cc.newIntPtr()); return regResultIntPtr[resultPosIntPtr++]; } - asmjit::X86Xmm newResultXmmSd() { if (resultPosXmmSd == regResultXmmSd.size()) regResultXmmSd.push_back(cc.newXmmSd()); return regResultXmmSd[resultPosXmmSd++]; } + asmjit::X86Gp newTempInt32() { return newTempRegister(regTmpInt32, tmpPosInt32, "tmpDword", [&](const char *name) { return cc.newInt32(name); }); } + asmjit::X86Gp newTempInt64() { return newTempRegister(regTmpInt64, tmpPosInt64, "tmpQword", [&](const char *name) { return cc.newInt64(name); }); } + asmjit::X86Gp newTempIntPtr() { return newTempRegister(regTmpIntPtr, tmpPosIntPtr, "tmpPtr", [&](const char *name) { return cc.newIntPtr(name); }); } + asmjit::X86Xmm newTempXmmSd() { return newTempRegister(regTmpXmmSd, tmpPosXmmSd, "tmpXmmSd", [&](const char *name) { return cc.newXmmSd(name); }); } + asmjit::X86Xmm newTempXmmSs() { return newTempRegister(regTmpXmmSs, tmpPosXmmSs, "tmpXmmSs", [&](const char *name) { return cc.newXmmSs(name); }); } + asmjit::X86Xmm newTempXmmPd() { return newTempRegister(regTmpXmmPd, tmpPosXmmPd, "tmpXmmPd", [&](const char *name) { return cc.newXmmPd(name); }); } + + asmjit::X86Gp newResultInt32() { return newTempRegister(regResultInt32, resultPosInt32, "resultDword", [&](const char *name) { return cc.newInt32(name); }); } + asmjit::X86Gp newResultIntPtr() { return newTempRegister(regResultIntPtr, resultPosIntPtr, "resultPtr", [&](const char *name) { return cc.newIntPtr(name); }); } + asmjit::X86Xmm newResultXmmSd() { return newTempRegister(regResultXmmSd, resultPosXmmSd, "resultXmmSd", [&](const char *name) { return cc.newXmmSd(name); }); } void EmitNullPointerThrow(int index, EVMAbortException reason); void EmitThrowException(EVMAbortException reason);