From d1f39185dd24c90195d460965b456b841707ac83 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jan 2017 19:40:56 -0500 Subject: [PATCH 1/4] IR: Convert typedefs to using aliases --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 2321037ef8..63899b6d12 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -182,8 +182,8 @@ enum Opcode Int3 }; -typedef unsigned Inst; -typedef Inst* InstLoc; +using Inst = u32; +using InstLoc = Inst*; unsigned inline getOpcode(Inst i) { From d3aed03563c631a2a23007f408614068461a69af Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jan 2017 19:42:36 -0500 Subject: [PATCH 2/4] IR: Make trivial helper functions constexpr --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 63899b6d12..08ba3a79fc 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -185,22 +185,22 @@ enum Opcode using Inst = u32; using InstLoc = Inst*; -unsigned inline getOpcode(Inst i) +constexpr u32 getOpcode(Inst i) { return i & 255; } -unsigned inline isImm(Inst i) +constexpr bool isImm(Inst i) { return getOpcode(i) >= CInt16 && getOpcode(i) <= CInt32; } -unsigned inline isICmp(Inst i) +constexpr bool isICmp(Inst i) { return getOpcode(i) >= ICmpEq && getOpcode(i) <= ICmpSle; } -unsigned inline isFResult(Inst i) +constexpr bool isFResult(Inst i) { return getOpcode(i) > FResult_Start && getOpcode(i) < FResult_End; } From 89473d59968de9510ef3e79e699f8dd13fb474ca Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jan 2017 20:03:42 -0500 Subject: [PATCH 3/4] IR: Clean up getNumberOfOperands - Use std::array - Make arrays constexpr where their contents aren't modified. --- Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index f7348ba34e..33484da69a 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -121,6 +121,7 @@ TODO (in no particular order): #endif #include +#include #include #include #include @@ -1371,22 +1372,22 @@ unsigned IRBuilder::getComplexity(InstLoc I) const unsigned IRBuilder::getNumberOfOperands(InstLoc I) const { - static unsigned numberOfOperands[256]; + static std::array number_of_operands; static bool initialized = false; if (!initialized) { initialized = true; - std::fill_n(numberOfOperands, sizeof(numberOfOperands) / sizeof(numberOfOperands[0]), -1U); - numberOfOperands[Nop] = 0; - numberOfOperands[CInt16] = 0; - numberOfOperands[CInt32] = 0; + number_of_operands.fill(0xFFFFFFFF); + number_of_operands[Nop] = 0; + number_of_operands[CInt16] = 0; + number_of_operands[CInt32] = 0; - static unsigned ZeroOp[] = { + static constexpr std::array zero_op = { LoadCR, LoadLink, LoadMSR, LoadGReg, LoadCTR, InterpreterBranch, LoadCarry, RFIExit, LoadFReg, LoadFRegDENToZero, LoadGQR, Int3, }; - static unsigned UOp[] = { + static constexpr std::array unary_op = { StoreLink, BranchUncond, StoreCR, @@ -1427,7 +1428,7 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const FastCRGTSet, FastCRLTSet, }; - static unsigned BiOp[] = { + static constexpr std::array binary_op = { BranchCond, IdleBranch, And, @@ -1473,17 +1474,17 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const FPMerge11, FDCmpCR, }; - for (auto& op : ZeroOp) - numberOfOperands[op] = 0; + for (auto op : zero_op) + number_of_operands[op] = 0; - for (auto& op : UOp) - numberOfOperands[op] = 1; + for (auto op : unary_op) + number_of_operands[op] = 1; - for (auto& op : BiOp) - numberOfOperands[op] = 2; + for (auto op : binary_op) + number_of_operands[op] = 2; } - return numberOfOperands[getOpcode(*I)]; + return number_of_operands[getOpcode(*I)]; } // Performs a few simplifications for commutative operators From bb490124458a49c4f6d8169ffa77e9d9570b1f0a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Jan 2017 20:29:40 -0500 Subject: [PATCH 4/4] IR: Deduplicate code in Reset and FoldFallbackToInterpreter --- Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 25 +++++---------------- Source/Core/Core/PowerPC/JitILCommon/IR.h | 2 ++ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index 33484da69a..5c78ea883b 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -150,6 +150,11 @@ void IRBuilder::Reset() MarkUsed.clear(); MarkUsed.reserve(100000); + InvalidateCaches(); +} + +void IRBuilder::InvalidateCaches() +{ GRegCache = {}; GRegCacheStore = {}; @@ -1209,25 +1214,7 @@ InstLoc IRBuilder::FoldICmpCRUnsigned(InstLoc Op1, InstLoc Op2) InstLoc IRBuilder::FoldFallBackToInterpreter(InstLoc Op1, InstLoc Op2) { - for (unsigned i = 0; i < 32; i++) - { - GRegCache[i] = nullptr; - GRegCacheStore[i] = nullptr; - FRegCache[i] = nullptr; - FRegCacheStore[i] = nullptr; - } - - CarryCache = nullptr; - CarryCacheStore = nullptr; - - for (unsigned i = 0; i < 8; i++) - { - CRCache[i] = nullptr; - CRCacheStore[i] = nullptr; - } - - CTRCache = nullptr; - CTRCacheStore = nullptr; + InvalidateCaches(); return EmitBiOp(FallBackToInterpreter, Op1, Op2); } diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 08ba3a79fc..cb1297f7e4 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -388,6 +388,8 @@ public: void WriteToFile(u64 codeHash); private: + void InvalidateCaches(); + InstLoc EmitZeroOp(unsigned Opcode, unsigned extra); InstLoc EmitUOp(unsigned OpCode, InstLoc Op1, unsigned extra = 0); InstLoc EmitBiOp(unsigned OpCode, InstLoc Op1, InstLoc Op2, unsigned extra = 0);