summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2016-03-24 04:42:13 +1300
committerScott Mansell <phiren@gmail.com>2016-03-24 05:17:10 +1300
commit27beef1ff483020b6afb5fd8ea8fb0de3ed66c77 (patch)
tree1475acb50e5cb9b60e260a0d08cb489333cad3d2 /Source
parent407f86e01a297947523cdd92c536868bda8bc939 (diff)
Store an inverted copy of lastOCfactor.
The inverse operation is more common, especially when games check the timer rapidly. So we do the division once and store the inverted copy.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/CoreTiming.cpp18
-rw-r--r--Source/Core/Core/CoreTiming.h2
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp2
3 files changed, 14 insertions, 8 deletions
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<BaseEvent, false> 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)