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.
This commit is contained in:
parent
407f86e01a
commit
27beef1ff4
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue