Mark global variables with g_ prefix
This commit is contained in:
parent
67dc26cf1d
commit
407f86e01a
|
@ -50,20 +50,20 @@ static Common::FifoQueue<BaseEvent, false> tsQueue;
|
||||||
// event pools
|
// event pools
|
||||||
static Event *eventPool = nullptr;
|
static Event *eventPool = nullptr;
|
||||||
|
|
||||||
float lastOCFactor;
|
float g_lastOCFactor;
|
||||||
int slicelength;
|
int g_slicelength;
|
||||||
static int maxSliceLength = MAX_SLICE_LENGTH;
|
static int maxslicelength = MAX_SLICE_LENGTH;
|
||||||
|
|
||||||
static s64 idledCycles;
|
static s64 idledCycles;
|
||||||
static u32 fakeDecStartValue;
|
static u32 fakeDecStartValue;
|
||||||
static u64 fakeDecStartTicks;
|
static u64 fakeDecStartTicks;
|
||||||
|
|
||||||
// Are we in a function that has been called from Advance()
|
// Are we in a function that has been called from Advance()
|
||||||
static bool GlobalTimerIsSane;
|
static bool globalTimerIsSane;
|
||||||
|
|
||||||
s64 globalTimer;
|
s64 g_globalTimer;
|
||||||
u64 fakeTBStartValue;
|
u64 g_fakeTBStartValue;
|
||||||
u64 fakeTBStartTicks;
|
u64 g_fakeTBStartTicks;
|
||||||
|
|
||||||
static int ev_lost;
|
static int ev_lost;
|
||||||
|
|
||||||
|
@ -94,12 +94,12 @@ static void EmptyTimedCallback(u64 userdata, int cyclesLate) {}
|
||||||
// but the effect is largely the same.
|
// but the effect is largely the same.
|
||||||
static int DowncountToCycles(int downcount)
|
static int DowncountToCycles(int downcount)
|
||||||
{
|
{
|
||||||
return (int)(downcount / lastOCFactor);
|
return (int)(downcount / g_lastOCFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CyclesToDowncount(int cycles)
|
static int CyclesToDowncount(int cycles)
|
||||||
{
|
{
|
||||||
return (int)(cycles * lastOCFactor);
|
return (int)(cycles * g_lastOCFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RegisterEvent(const std::string& name, TimedCallback callback)
|
int RegisterEvent(const std::string& name, TimedCallback callback)
|
||||||
|
@ -135,12 +135,12 @@ void UnregisterAllEvents()
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
|
g_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(maxSliceLength);
|
PowerPC::ppcState.downcount = CyclesToDowncount(maxslicelength);
|
||||||
slicelength = maxSliceLength;
|
g_slicelength = maxslicelength;
|
||||||
globalTimer = 0;
|
g_globalTimer = 0;
|
||||||
idledCycles = 0;
|
idledCycles = 0;
|
||||||
GlobalTimerIsSane = true;
|
globalTimerIsSane = true;
|
||||||
|
|
||||||
ev_lost = RegisterEvent("_lost_event", &EmptyTimedCallback);
|
ev_lost = RegisterEvent("_lost_event", &EmptyTimedCallback);
|
||||||
}
|
}
|
||||||
|
@ -197,14 +197,14 @@ static void EventDoState(PointerWrap &p, BaseEvent* ev)
|
||||||
void DoState(PointerWrap &p)
|
void DoState(PointerWrap &p)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(tsWriteLock);
|
std::lock_guard<std::mutex> lk(tsWriteLock);
|
||||||
p.Do(slicelength);
|
p.Do(g_slicelength);
|
||||||
p.Do(globalTimer);
|
p.Do(g_globalTimer);
|
||||||
p.Do(idledCycles);
|
p.Do(idledCycles);
|
||||||
p.Do(fakeDecStartValue);
|
p.Do(fakeDecStartValue);
|
||||||
p.Do(fakeDecStartTicks);
|
p.Do(fakeDecStartTicks);
|
||||||
p.Do(fakeTBStartValue);
|
p.Do(g_fakeTBStartValue);
|
||||||
p.Do(fakeTBStartTicks);
|
p.Do(g_fakeTBStartTicks);
|
||||||
p.Do(lastOCFactor);
|
p.Do(g_lastOCFactor);
|
||||||
p.DoMarker("CoreTimingData");
|
p.DoMarker("CoreTimingData");
|
||||||
|
|
||||||
MoveEvents();
|
MoveEvents();
|
||||||
|
@ -216,11 +216,11 @@ void DoState(PointerWrap &p)
|
||||||
// This should only be called from the CPU thread, if you are calling it any other thread, you are doing something evil
|
// This should only be called from the CPU thread, if you are calling it any other thread, you are doing something evil
|
||||||
u64 GetTicks()
|
u64 GetTicks()
|
||||||
{
|
{
|
||||||
u64 ticks = (u64)globalTimer;
|
u64 ticks = (u64)g_globalTimer;
|
||||||
if (!GlobalTimerIsSane)
|
if (!globalTimerIsSane)
|
||||||
{
|
{
|
||||||
int downcount = DowncountToCycles(PowerPC::ppcState.downcount);
|
int downcount = DowncountToCycles(PowerPC::ppcState.downcount);
|
||||||
ticks += slicelength - downcount;
|
ticks += g_slicelength - downcount;
|
||||||
}
|
}
|
||||||
return ticks;
|
return ticks;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata
|
||||||
}
|
}
|
||||||
std::lock_guard<std::mutex> lk(tsWriteLock);
|
std::lock_guard<std::mutex> lk(tsWriteLock);
|
||||||
Event ne;
|
Event ne;
|
||||||
ne.time = globalTimer + cyclesIntoFuture;
|
ne.time = g_globalTimer + cyclesIntoFuture;
|
||||||
ne.type = event_type;
|
ne.type = event_type;
|
||||||
ne.userdata = userdata;
|
ne.userdata = userdata;
|
||||||
tsQueue.Push(ne);
|
tsQueue.Push(ne);
|
||||||
|
@ -321,9 +321,10 @@ void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
||||||
ne->time = GetTicks() + cyclesIntoFuture;
|
ne->time = GetTicks() + cyclesIntoFuture;
|
||||||
|
|
||||||
// If this event needs to be scheduled before the next advance(), force one early
|
// If this event needs to be scheduled before the next advance(), force one early
|
||||||
if (!GlobalTimerIsSane)
|
if (!globalTimerIsSane)
|
||||||
ForceExceptionCheck(cyclesIntoFuture);
|
ForceExceptionCheck(cyclesIntoFuture);
|
||||||
|
|
||||||
|
|
||||||
AddEventToQueue(ne);
|
AddEventToQueue(ne);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +369,7 @@ void ForceExceptionCheck(s64 cycles)
|
||||||
if (s64(DowncountToCycles(PowerPC::ppcState.downcount)) > cycles)
|
if (s64(DowncountToCycles(PowerPC::ppcState.downcount)) > cycles)
|
||||||
{
|
{
|
||||||
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int here.
|
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int here.
|
||||||
slicelength -= (DowncountToCycles(PowerPC::ppcState.downcount) - (int)cycles); // Account for cycles already executed by adjusting the g_slicelength
|
g_slicelength -= (DowncountToCycles(PowerPC::ppcState.downcount) - (int)cycles); // Account for cycles already executed by adjusting the g_slicelength
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount((int)cycles);
|
PowerPC::ppcState.downcount = CyclesToDowncount((int)cycles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,11 +385,11 @@ void ProcessFifoWaitEvents()
|
||||||
|
|
||||||
while (first)
|
while (first)
|
||||||
{
|
{
|
||||||
if (first->time <= globalTimer)
|
if (first->time <= g_globalTimer)
|
||||||
{
|
{
|
||||||
Event* evt = first;
|
Event* evt = first;
|
||||||
first = first->next;
|
first = first->next;
|
||||||
event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
|
event_types[evt->type].callback(evt->userdata, (int)(g_globalTimer - evt->time));
|
||||||
FreeEvent(evt);
|
FreeEvent(evt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -415,24 +416,24 @@ void Advance()
|
||||||
{
|
{
|
||||||
MoveEvents();
|
MoveEvents();
|
||||||
|
|
||||||
int cyclesExecuted = slicelength - DowncountToCycles(PowerPC::ppcState.downcount);
|
int cyclesExecuted = g_slicelength - DowncountToCycles(PowerPC::ppcState.downcount);
|
||||||
globalTimer += cyclesExecuted;
|
g_globalTimer += cyclesExecuted;
|
||||||
lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
|
g_lastOCFactor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(slicelength);
|
PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);
|
||||||
|
|
||||||
GlobalTimerIsSane = true;
|
globalTimerIsSane = true;
|
||||||
|
|
||||||
while (first && first->time <= globalTimer)
|
while (first && first->time <= g_globalTimer)
|
||||||
{
|
{
|
||||||
//LOG(POWERPC, "[Scheduler] %s (%lld, %lld) ",
|
//LOG(POWERPC, "[Scheduler] %s (%lld, %lld) ",
|
||||||
// event_types[first->type].name ? event_types[first->type].name : "?", (u64)globalTimer, (u64)first->time);
|
// event_types[first->type].name ? event_types[first->type].name : "?", (u64)g_globalTimer, (u64)first->time);
|
||||||
Event* evt = first;
|
Event* evt = first;
|
||||||
first = first->next;
|
first = first->next;
|
||||||
event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
|
event_types[evt->type].callback(evt->userdata, (int)(g_globalTimer - evt->time));
|
||||||
FreeEvent(evt);
|
FreeEvent(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalTimerIsSane = false;
|
globalTimerIsSane = false;
|
||||||
|
|
||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
|
@ -441,10 +442,10 @@ void Advance()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slicelength = (int)(first->time - globalTimer);
|
g_slicelength = (int)(first->time - g_globalTimer);
|
||||||
if (slicelength > maxSliceLength)
|
if (g_slicelength > maxslicelength)
|
||||||
slicelength = maxSliceLength;
|
g_slicelength = maxslicelength;
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(slicelength);
|
PowerPC::ppcState.downcount = CyclesToDowncount(g_slicelength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +454,7 @@ void LogPendingEvents()
|
||||||
Event *ptr = first;
|
Event *ptr = first;
|
||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
INFO_LOG(POWERPC, "PENDING: Now: %" PRId64 " Pending: %" PRId64 " Type: %d", globalTimer, ptr->time, ptr->type);
|
INFO_LOG(POWERPC, "PENDING: Now: %" PRId64 " Pending: %" PRId64 " Type: %d", g_globalTimer, ptr->time, ptr->type);
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,22 +517,22 @@ void SetFakeDecStartTicks(u64 val)
|
||||||
|
|
||||||
u64 GetFakeTBStartValue()
|
u64 GetFakeTBStartValue()
|
||||||
{
|
{
|
||||||
return fakeTBStartValue;
|
return g_fakeTBStartValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFakeTBStartValue(u64 val)
|
void SetFakeTBStartValue(u64 val)
|
||||||
{
|
{
|
||||||
fakeTBStartValue = val;
|
g_fakeTBStartValue = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 GetFakeTBStartTicks()
|
u64 GetFakeTBStartTicks()
|
||||||
{
|
{
|
||||||
return fakeTBStartTicks;
|
return g_fakeTBStartTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFakeTBStartTicks(u64 val)
|
void SetFakeTBStartTicks(u64 val)
|
||||||
{
|
{
|
||||||
fakeTBStartTicks = val;
|
g_fakeTBStartTicks = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -25,9 +25,12 @@ class PointerWrap;
|
||||||
namespace CoreTiming
|
namespace CoreTiming
|
||||||
{
|
{
|
||||||
|
|
||||||
extern s64 globalTimer;
|
// These really shouldn't be global, but jit64 accesses them directly
|
||||||
extern u64 fakeTBStartValue;
|
extern s64 g_globalTimer;
|
||||||
extern u64 fakeTBStartTicks;
|
extern u64 g_fakeTBStartValue;
|
||||||
|
extern u64 g_fakeTBStartTicks;
|
||||||
|
extern int g_slicelength;
|
||||||
|
extern float g_lastOCFactor;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
@ -79,7 +82,6 @@ void SetFakeTBStartTicks(u64 val);
|
||||||
|
|
||||||
void ForceExceptionCheck(s64 cycles);
|
void ForceExceptionCheck(s64 cycles);
|
||||||
|
|
||||||
extern int slicelength;
|
|
||||||
extern float lastOCFactor;
|
|
||||||
|
|
||||||
} // end of namespace
|
} // end of namespace
|
||||||
|
|
|
@ -178,7 +178,7 @@ void Interpreter::SingleStep()
|
||||||
{
|
{
|
||||||
SingleStepInner();
|
SingleStepInner();
|
||||||
|
|
||||||
CoreTiming::slicelength = 1;
|
CoreTiming::g_slicelength = 1;
|
||||||
PowerPC::ppcState.downcount = 0;
|
PowerPC::ppcState.downcount = 0;
|
||||||
CoreTiming::Advance();
|
CoreTiming::Advance();
|
||||||
|
|
||||||
|
|
|
@ -285,12 +285,12 @@ void Jit64::mfspr(UGeckoInstruction inst)
|
||||||
// cost of calling out to C for this is actually significant.
|
// cost of calling out to C for this is actually significant.
|
||||||
// Scale downcount by the CPU overclocking factor.
|
// Scale downcount by the CPU overclocking factor.
|
||||||
CVTSI2SS(XMM0, PPCSTATE(downcount));
|
CVTSI2SS(XMM0, PPCSTATE(downcount));
|
||||||
DIVSS(XMM0, M(&CoreTiming::lastOCFactor));
|
DIVSS(XMM0, M(&CoreTiming::g_lastOCFactor));
|
||||||
CVTSS2SI(RDX, R(XMM0)); // RDX is downcount scaled by the overclocking factor
|
CVTSS2SI(RDX, R(XMM0)); // RDX is downcount scaled by the overclocking factor
|
||||||
MOV(32, R(RAX), M(&CoreTiming::slicelength));
|
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)
|
SUB(64, R(RAX), R(RDX)); // cycles since the last CoreTiming::Advance() event is (slicelength - Scaled_downcount)
|
||||||
ADD(64, R(RAX), M(&CoreTiming::globalTimer));
|
ADD(64, R(RAX), M(&CoreTiming::g_globalTimer));
|
||||||
SUB(64, R(RAX), M(&CoreTiming::fakeTBStartTicks));
|
SUB(64, R(RAX), M(&CoreTiming::g_fakeTBStartTicks));
|
||||||
// It might seem convenient to correct the timer for the block position here for even more accurate
|
// It might seem convenient to correct the timer for the block position here for even more accurate
|
||||||
// timing, but as of currently, this can break games. If we end up reading a time *after* the time
|
// timing, but as of currently, this can break games. If we end up reading a time *after* the time
|
||||||
// at which an interrupt was supposed to occur, e.g. because we're 100 cycles into a block with only
|
// at which an interrupt was supposed to occur, e.g. because we're 100 cycles into a block with only
|
||||||
|
@ -298,10 +298,11 @@ void Jit64::mfspr(UGeckoInstruction inst)
|
||||||
// which won't get past the loading screen.
|
// which won't get past the loading screen.
|
||||||
//if (js.downcountAmount)
|
//if (js.downcountAmount)
|
||||||
// ADD(64, R(RAX), Imm32(js.downcountAmount));
|
// ADD(64, R(RAX), Imm32(js.downcountAmount));
|
||||||
|
|
||||||
// a / 12 = (a * 0xAAAAAAAAAAAAAAAB) >> 67
|
// a / 12 = (a * 0xAAAAAAAAAAAAAAAB) >> 67
|
||||||
MOV(64, R(RDX), Imm64(0xAAAAAAAAAAAAAAABULL));
|
MOV(64, R(RDX), Imm64(0xAAAAAAAAAAAAAAABULL));
|
||||||
MUL(64, R(RDX));
|
MUL(64, R(RDX));
|
||||||
MOV(64, R(RAX), M(&CoreTiming::fakeTBStartValue));
|
MOV(64, R(RAX), M(&CoreTiming::g_fakeTBStartValue));
|
||||||
SHR(64, R(RDX), Imm8(3));
|
SHR(64, R(RDX), Imm8(3));
|
||||||
ADD(64, R(RAX), R(RDX));
|
ADD(64, R(RAX), R(RDX));
|
||||||
MOV(64, PPCSTATE(spr[SPR_TL]), R(RAX));
|
MOV(64, PPCSTATE(spr[SPR_TL]), R(RAX));
|
||||||
|
|
Loading…
Reference in New Issue