From 433a56636b84e72eaa24417787656a8a56ad9cfc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 21:31:19 -0400 Subject: [PATCH 1/5] PPCAnalyst: Move public interface above private interface --- Source/Core/Core/PowerPC/PPCAnalyst.h | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.h b/Source/Core/Core/PowerPC/PPCAnalyst.h index 564e73b9c4..ca286d8f4b 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/PowerPC/PPCAnalyst.h @@ -166,21 +166,6 @@ struct CodeBlock class PPCAnalyzer { -private: - enum ReorderType - { - REORDER_CARRY, - REORDER_CMP, - REORDER_CROR - }; - - void ReorderInstructionsCore(u32 instructions, CodeOp* code, bool reverse, ReorderType type); - void ReorderInstructions(u32 instructions, CodeOp* code); - void SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, u32 index); - - // Options - u32 m_options; - public: enum AnalystOption { @@ -226,6 +211,21 @@ public: void ClearOption(AnalystOption option) { m_options &= ~(option); } bool HasOption(AnalystOption option) const { return !!(m_options & option); } u32 Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32 blockSize); + +private: + enum ReorderType + { + REORDER_CARRY, + REORDER_CMP, + REORDER_CROR + }; + + void ReorderInstructionsCore(u32 instructions, CodeOp* code, bool reverse, ReorderType type); + void ReorderInstructions(u32 instructions, CodeOp* code); + void SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, u32 index); + + // Options + u32 m_options; }; void LogFunctionCall(u32 addr); From 4bd3b28823648a8290d88a69d1e1ecd5cb0b5037 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 21:32:13 -0400 Subject: [PATCH 2/5] PPCAnalyst: in-class initialize PPCAnalyzer's members Eliminates the need to assign in the constructor initializer list. --- Source/Core/Core/PowerPC/PPCAnalyst.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.h b/Source/Core/Core/PowerPC/PPCAnalyst.h index ca286d8f4b..55e0045938 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/PowerPC/PPCAnalyst.h @@ -205,7 +205,6 @@ public: OPTION_CROR_MERGE = (1 << 6), }; - PPCAnalyzer() : m_options(0) {} // Option setting/getting void SetOption(AnalystOption option) { m_options |= option; } void ClearOption(AnalystOption option) { m_options &= ~(option); } @@ -225,7 +224,7 @@ private: void SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, u32 index); // Options - u32 m_options; + u32 m_options = 0; }; void LogFunctionCall(u32 addr); From 5e5a56bd9b57ba75d63f47658eabdb00deb12d29 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 21:34:12 -0400 Subject: [PATCH 3/5] PPCAnalyst: Remove unnecessary includes from header --- Source/Core/Core/PowerPC/PPCAnalyst.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.h b/Source/Core/Core/PowerPC/PPCAnalyst.h index 55e0045938..c625e80097 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/PowerPC/PPCAnalyst.h @@ -5,11 +5,7 @@ #pragma once #include -#include -#include #include -#include -#include #include "Common/BitSet.h" #include "Common/CommonTypes.h" From f2b2f5b4c726bc1651ebcdc7a5d769d6d0c83729 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 21:38:16 -0400 Subject: [PATCH 4/5] PPCAnalyst: Make ReorderType an enum class Makes the values strongly typed and doesn't dump them into the class itself. --- Source/Core/Core/PowerPC/PPCAnalyst.cpp | 15 ++++++++------- Source/Core/Core/PowerPC/PPCAnalyst.h | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/PowerPC/PPCAnalyst.cpp index bd6cf88014..ba75fe5ab9 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/PowerPC/PPCAnalyst.cpp @@ -479,11 +479,12 @@ void PPCAnalyzer::ReorderInstructionsCore(u32 instructions, CodeOp* code, bool r CodeOp& b = code[i + increment]; // Reorder integer compares, rlwinm., and carry-affecting ops // (if we add more merged branch instructions, add them here!) - if ((type == REORDER_CROR && isCror(a)) || (type == REORDER_CARRY && isCarryOp(a)) || - (type == REORDER_CMP && (isCmp(a) || a.outputCR0))) + if ((type == ReorderType::CROR && isCror(a)) || + (type == ReorderType::Carry && isCarryOp(a)) || + (type == ReorderType::CMP && (isCmp(a) || a.outputCR0))) { // once we're next to a carry instruction, don't move away! - if (type == REORDER_CARRY && i != start) + if (type == ReorderType::Carry && i != start) { // if we read the CA flag, and the previous instruction sets it, don't move away. if (!reverse && (a.opinfo->flags & FL_READ_CA) && @@ -514,16 +515,16 @@ void PPCAnalyzer::ReorderInstructions(u32 instructions, CodeOp* code) // picky about this, but cror seems to almost solely be used for this purpose in real code. // Additionally, the other boolean ops seem to almost never be used. if (HasOption(OPTION_CROR_MERGE)) - ReorderInstructionsCore(instructions, code, true, REORDER_CROR); + ReorderInstructionsCore(instructions, code, true, ReorderType::CROR); // For carry, bubble instructions *towards* each other; one direction often isn't enough // to get pairs like addc/adde next to each other. if (HasOption(OPTION_CARRY_MERGE)) { - ReorderInstructionsCore(instructions, code, false, REORDER_CARRY); - ReorderInstructionsCore(instructions, code, true, REORDER_CARRY); + ReorderInstructionsCore(instructions, code, false, ReorderType::Carry); + ReorderInstructionsCore(instructions, code, true, ReorderType::Carry); } if (HasOption(OPTION_BRANCH_MERGE)) - ReorderInstructionsCore(instructions, code, false, REORDER_CMP); + ReorderInstructionsCore(instructions, code, false, ReorderType::CMP); } void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const GekkoOPInfo* opinfo, diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.h b/Source/Core/Core/PowerPC/PPCAnalyst.h index c625e80097..e5e84a69f6 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.h +++ b/Source/Core/Core/PowerPC/PPCAnalyst.h @@ -208,11 +208,11 @@ public: u32 Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer, u32 blockSize); private: - enum ReorderType + enum class ReorderType { - REORDER_CARRY, - REORDER_CMP, - REORDER_CROR + Carry, + CMP, + CROR }; void ReorderInstructionsCore(u32 instructions, CodeOp* code, bool reverse, ReorderType type); From 9c5115a62739387f34d0139fed3680aa1af97174 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 21:42:40 -0400 Subject: [PATCH 5/5] PPCAnalyst: Simplify boolean assignments in SetInstructionStats() Ternaries here aren't necessary if all we're checking against is if something is non-zero --- Source/Core/Core/PowerPC/PPCAnalyst.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/PowerPC/PPCAnalyst.cpp index ba75fe5ab9..a3416e3631 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/PowerPC/PPCAnalyst.cpp @@ -545,7 +545,7 @@ void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const Gekk else if ((opinfo->flags & FL_SET_CRn) && code->inst.CRFD == 0) code->outputCR0 = true; else - code->outputCR0 = (opinfo->flags & FL_SET_CR0) ? true : false; + code->outputCR0 = (opinfo->flags & FL_SET_CR0) != 0; // Does the instruction output CR1? if (opinfo->flags & FL_RC_BIT_F) @@ -553,14 +553,14 @@ void PPCAnalyzer::SetInstructionStats(CodeBlock* block, CodeOp* code, const Gekk else if ((opinfo->flags & FL_SET_CRn) && code->inst.CRFD == 1) code->outputCR1 = true; else - code->outputCR1 = (opinfo->flags & FL_SET_CR1) ? true : false; + code->outputCR1 = (opinfo->flags & FL_SET_CR1) != 0; - code->wantsFPRF = (opinfo->flags & FL_READ_FPRF) ? true : false; - code->outputFPRF = (opinfo->flags & FL_SET_FPRF) ? true : false; - code->canEndBlock = (opinfo->flags & FL_ENDBLOCK) ? true : false; + code->wantsFPRF = (opinfo->flags & FL_READ_FPRF) != 0; + code->outputFPRF = (opinfo->flags & FL_SET_FPRF) != 0; + code->canEndBlock = (opinfo->flags & FL_ENDBLOCK) != 0; - code->wantsCA = (opinfo->flags & FL_READ_CA) ? true : false; - code->outputCA = (opinfo->flags & FL_SET_CA) ? true : false; + code->wantsCA = (opinfo->flags & FL_READ_CA) != 0; + code->outputCA = (opinfo->flags & FL_SET_CA) != 0; // We're going to try to avoid storing carry in XER if we can avoid it -- keep it in the x86 carry // flag!