From b0efcdc8ef6da6a934c1204b08a118bb302baadd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 25 Mar 2018 21:23:15 -0400 Subject: [PATCH 1/2] Interpreter: Get rid of static state within SingleStepInner() Given how the hooking operates, we may not execute an instruction. Instead of making the state a static local to the function, just make it part of the lifecycle of the Interpreter class. --- .../Core/Core/PowerPC/Interpreter/Interpreter.cpp | 15 +++++++-------- .../Core/Core/PowerPC/Interpreter/Interpreter.h | 2 ++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index a30c35247a..9d0014cc1a 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -101,7 +101,6 @@ static void Trace(UGeckoInstruction& inst) int Interpreter::SingleStepInner() { - static UGeckoInstruction instCode; u32 function = HLE::GetFirstFunctionIndex(PC); if (function != 0) { @@ -138,7 +137,7 @@ int Interpreter::SingleStepInner() #endif NPC = PC + sizeof(UGeckoInstruction); - instCode.hex = PowerPC::Read_Opcode(PC); + m_prev_inst.hex = PowerPC::Read_Opcode(PC); // Uncomment to trace the interpreter // if ((PC & 0xffffff)>=0x0ab54c && (PC & 0xffffff)<=0x0ab624) @@ -148,15 +147,15 @@ int Interpreter::SingleStepInner() if (startTrace) { - Trace(instCode); + Trace(m_prev_inst); } - if (instCode.hex != 0) + if (m_prev_inst.hex != 0) { UReg_MSR& msr = (UReg_MSR&)MSR; if (msr.FP) // If FPU is enabled, just execute { - m_op_table[instCode.OPCD](instCode); + m_op_table[m_prev_inst.OPCD](m_prev_inst); if (PowerPC::ppcState.Exceptions & EXCEPTION_DSI) { PowerPC::CheckExceptions(); @@ -166,9 +165,9 @@ int Interpreter::SingleStepInner() else { // check if we have to generate a FPU unavailable exception - if (!PPCTables::UsesFPU(instCode)) + if (!PPCTables::UsesFPU(m_prev_inst)) { - m_op_table[instCode.OPCD](instCode); + m_op_table[m_prev_inst.OPCD](m_prev_inst); if (PowerPC::ppcState.Exceptions & EXCEPTION_DSI) { PowerPC::CheckExceptions(); @@ -193,7 +192,7 @@ int Interpreter::SingleStepInner() last_pc = PC; PC = NPC; - const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(instCode); + const GekkoOPInfo* opinfo = PPCTables::GetOpInfo(m_prev_inst); return opinfo->numCycles; } diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h index b4135e3724..863dc0cb5b 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.h +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.h @@ -304,6 +304,8 @@ private: static void Helper_FloatCompareOrdered(UGeckoInstruction inst, double a, double b); static void Helper_FloatCompareUnordered(UGeckoInstruction inst, double a, double b); + UGeckoInstruction m_prev_inst{}; + static bool m_end_block; // TODO: These should really be in the save state, although it's unlikely to matter much. From 8b29997ed188bbf62ac568cf21dfed39a84c1f88 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 25 Mar 2018 21:36:37 -0400 Subject: [PATCH 2/2] Interpreter: Remove an unnecessary UReg_MSR& cast from SingleStepInner This is technically undefined behavior, but regardless of that, it's not even necessary since we can just make a temporary around the MSR value and just discard it when done with it, since all we do is query the FP bit value with it. --- Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 9d0014cc1a..fd900defe1 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -152,7 +152,7 @@ int Interpreter::SingleStepInner() if (m_prev_inst.hex != 0) { - UReg_MSR& msr = (UReg_MSR&)MSR; + const UReg_MSR msr{MSR}; if (msr.FP) // If FPU is enabled, just execute { m_op_table[m_prev_inst.OPCD](m_prev_inst);