diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 9bc4b1d97f..c2fb7918b8 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -50,7 +50,8 @@ static Common::FifoQueue tsQueue; // event pools static Event *eventPool = nullptr; -float g_lastOCFactor; +static float s_lastOCFactor; +float g_lastOCFactor_inverted; int g_slicelength; static int maxslicelength = MAX_SLICE_LENGTH; @@ -94,12 +95,12 @@ static void EmptyTimedCallback(u64 userdata, int cyclesLate) {} // but the effect is largely the same. static int DowncountToCycles(int downcount) { - return (int)(downcount / g_lastOCFactor); + return (int)(downcount * g_lastOCFactor_inverted); } static int CyclesToDowncount(int cycles) { - return (int)(cycles * g_lastOCFactor); + return (int)(cycles * s_lastOCFactor); } int RegisterEvent(const std::string& name, TimedCallback callback) @@ -135,7 +136,8 @@ void UnregisterAllEvents() void Init() { - g_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f; + s_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f; + g_lastOCFactor_inverted = 1.0f / s_lastOCFactor; PowerPC::ppcState.downcount = CyclesToDowncount(maxslicelength); g_slicelength = maxslicelength; g_globalTimer = 0; @@ -204,7 +206,10 @@ void DoState(PointerWrap &p) p.Do(fakeDecStartTicks); p.Do(g_fakeTBStartValue); p.Do(g_fakeTBStartTicks); - p.Do(g_lastOCFactor); + p.Do(s_lastOCFactor); + if (p.GetMode() == PointerWrap::MODE_READ) + g_lastOCFactor_inverted = 1.0f / s_lastOCFactor; + p.DoMarker("CoreTimingData"); MoveEvents(); @@ -418,7 +423,8 @@ void Advance() int cyclesExecuted = g_slicelength - DowncountToCycles(PowerPC::ppcState.downcount); g_globalTimer += cyclesExecuted; - g_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f; + s_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f; + g_lastOCFactor_inverted = 1.0f / s_lastOCFactor; PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength); globalTimerIsSane = true; diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h index 566e0ee757..ab369bc2b3 100644 --- a/Source/Core/Core/CoreTiming.h +++ b/Source/Core/Core/CoreTiming.h @@ -30,7 +30,7 @@ extern s64 g_globalTimer; extern u64 g_fakeTBStartValue; extern u64 g_fakeTBStartTicks; extern int g_slicelength; -extern float g_lastOCFactor; +extern float g_lastOCFactor_inverted; void Init(); void Shutdown(); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp index acbb5f7e26..224b4501ad 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp @@ -285,7 +285,7 @@ void Jit64::mfspr(UGeckoInstruction inst) // cost of calling out to C for this is actually significant. // Scale downcount by the CPU overclocking factor. CVTSI2SS(XMM0, PPCSTATE(downcount)); - DIVSS(XMM0, M(&CoreTiming::g_lastOCFactor)); + MULSS(XMM0, M(&CoreTiming::g_lastOCFactor_inverted)); CVTSS2SI(RDX, R(XMM0)); // RDX is downcount scaled by the overclocking factor MOV(32, R(RAX), M(&CoreTiming::g_slicelength)); SUB(64, R(RAX), R(RDX)); // cycles since the last CoreTiming::Advance() event is (slicelength - Scaled_downcount)