CPU: Use pending ticks as downcount comparison

Saves a few cycles decrementing the downcount.
This commit is contained in:
Connor McLaughlin 2019-12-05 16:28:44 +10:00
parent 0171dc4241
commit eeea5125f7
5 changed files with 14 additions and 28 deletions

View File

@ -39,16 +39,14 @@ void CodeCache::Initialize(System* system, Core* core, Bus* bus, bool use_recomp
void CodeCache::Execute() void CodeCache::Execute()
{ {
if (m_core->m_downcount < 0)
return;
CodeBlockKey next_block_key = GetNextBlockKey(); CodeBlockKey next_block_key = GetNextBlockKey();
for (;;) while (m_core->m_pending_ticks < m_core->m_downcount)
{ {
if (m_core->HasPendingInterrupt()) if (m_core->HasPendingInterrupt())
{ {
// TODO: Fill in m_next_instruction... // TODO: Fill in m_next_instruction...
//m_core->SafeReadMemoryWord(m_core->m_regs.pc, &m_core->m_next_instruction.bits);
m_core->DispatchInterrupt(); m_core->DispatchInterrupt();
next_block_key = GetNextBlockKey(); next_block_key = GetNextBlockKey();
} }
@ -58,8 +56,7 @@ void CodeCache::Execute()
{ {
Log_WarningPrintf("Falling back to uncached interpreter at 0x%08X", m_core->GetRegs().pc); Log_WarningPrintf("Falling back to uncached interpreter at 0x%08X", m_core->GetRegs().pc);
InterpretUncachedBlock(); InterpretUncachedBlock();
if (m_core->m_downcount < 0) continue;
break;
} }
reexecute_block: reexecute_block:
@ -79,7 +76,7 @@ void CodeCache::Execute()
else else
InterpretCachedBlock(*block); InterpretCachedBlock(*block);
if (m_core->m_downcount < 0) if (m_core->m_pending_ticks >= m_core->m_downcount)
break; break;
else if (m_core->HasPendingInterrupt() || !USE_BLOCK_LINKING) else if (m_core->HasPendingInterrupt() || !USE_BLOCK_LINKING)
continue; continue;
@ -426,8 +423,7 @@ void CodeCache::InterpretCachedBlock(const CodeBlock& block)
for (const CodeBlockInstruction& cbi : block.instructions) for (const CodeBlockInstruction& cbi : block.instructions)
{ {
m_core->m_pending_ticks += 1; m_core->m_pending_ticks++;
m_core->m_downcount -= 1;
// now executing the instruction we previously fetched // now executing the instruction we previously fetched
m_core->m_current_instruction.bits = cbi.instruction.bits; m_core->m_current_instruction.bits = cbi.instruction.bits;
@ -463,8 +459,7 @@ void CodeCache::InterpretUncachedBlock()
bool in_branch_delay_slot = false; bool in_branch_delay_slot = false;
for (;;) for (;;)
{ {
m_core->m_pending_ticks += 1; m_core->m_pending_ticks++;
m_core->m_downcount -= 1;
// now executing the instruction we previously fetched // now executing the instruction we previously fetched
m_core->m_current_instruction.bits = m_core->m_next_instruction.bits; m_core->m_current_instruction.bits = m_core->m_next_instruction.bits;

View File

@ -123,7 +123,7 @@ bool Core::ReadMemoryByte(VirtualMemoryAddress addr, u8* value)
return false; return false;
} }
AddTicks(cycles); m_pending_ticks += cycles;
return true; return true;
} }
@ -141,7 +141,7 @@ bool Core::ReadMemoryHalfWord(VirtualMemoryAddress addr, u16* value)
return false; return false;
} }
AddTicks(cycles); m_pending_ticks += cycles;
return true; return true;
} }
@ -157,7 +157,7 @@ bool Core::ReadMemoryWord(VirtualMemoryAddress addr, u32* value)
return false; return false;
} }
AddTicks(cycles); m_pending_ticks += cycles;
return true; return true;
} }
@ -579,13 +579,12 @@ void Core::DisassembleAndPrint(u32 addr, u32 instructions_before /* = 0 */, u32
void Core::Execute() void Core::Execute()
{ {
while (m_downcount >= 0) while (m_pending_ticks <= m_downcount)
{ {
if (HasPendingInterrupt()) if (HasPendingInterrupt())
DispatchInterrupt(); DispatchInterrupt();
m_pending_ticks += 1; m_pending_ticks++;
m_downcount -= 1;
// now executing the instruction we previously fetched // now executing the instruction we previously fetched
m_current_instruction.bits = m_next_instruction.bits; m_current_instruction.bits = m_next_instruction.bits;

View File

@ -91,13 +91,6 @@ private:
bool InUserMode() const { return m_cop0_regs.sr.KUc; } bool InUserMode() const { return m_cop0_regs.sr.KUc; }
bool InKernelMode() const { return !m_cop0_regs.sr.KUc; } bool InKernelMode() const { return !m_cop0_regs.sr.KUc; }
// timing
ALWAYS_INLINE void AddTicks(TickCount ticks)
{
m_pending_ticks += ticks;
m_downcount -= ticks;
}
void DisassembleAndPrint(u32 addr); void DisassembleAndPrint(u32 addr);
void DisassembleAndLog(u32 addr); void DisassembleAndLog(u32 addr);
void DisassembleAndPrint(u32 addr, u32 instructions_before, u32 instructions_after); void DisassembleAndPrint(u32 addr, u32 instructions_before, u32 instructions_after);

View File

@ -847,7 +847,6 @@ void CodeGenerator::AddPendingCycles()
return; return;
EmitAddCPUStructField(offsetof(Core, m_pending_ticks), Value::FromConstantU32(m_delayed_cycles_add)); EmitAddCPUStructField(offsetof(Core, m_pending_ticks), Value::FromConstantU32(m_delayed_cycles_add));
EmitAddCPUStructField(offsetof(Core, m_downcount), Value::FromConstantU32(~u32(m_delayed_cycles_add - 1)));
m_delayed_cycles_add = 0; m_delayed_cycles_add = 0;
} }

View File

@ -14,7 +14,7 @@ u64 Thunks::ReadMemoryByte(Core* cpu, u32 address)
return UINT64_C(0xFFFFFFFFFFFFFFFF); return UINT64_C(0xFFFFFFFFFFFFFFFF);
} }
cpu->AddTicks(cycles); cpu->m_pending_ticks += cycles;
return ZeroExtend64(temp); return ZeroExtend64(temp);
} }
@ -31,7 +31,7 @@ u64 Thunks::ReadMemoryHalfWord(Core* cpu, u32 address)
return UINT64_C(0xFFFFFFFFFFFFFFFF); return UINT64_C(0xFFFFFFFFFFFFFFFF);
} }
cpu->AddTicks(cycles); cpu->m_pending_ticks += cycles;
return ZeroExtend64(temp); return ZeroExtend64(temp);
} }
@ -48,7 +48,7 @@ u64 Thunks::ReadMemoryWord(Core* cpu, u32 address)
return UINT64_C(0xFFFFFFFFFFFFFFFF); return UINT64_C(0xFFFFFFFFFFFFFFFF);
} }
cpu->AddTicks(cycles); cpu->m_pending_ticks += cycles;
return ZeroExtend64(temp); return ZeroExtend64(temp);
} }