Skip to content

Commit

Permalink
CPU/Recompiler: Don't use far code for mtc0 cache check
Browse files Browse the repository at this point in the history
Redundant for a few instructions.
  • Loading branch information
stenzek committed Dec 19, 2024
1 parent fe1fa76 commit 10e2079
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/core/cpu_recompiler_arm32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,15 +2265,19 @@ void CPU::ARM32Recompiler::Compile_mtc0(CompileFlags cf)
// We could just inline the whole thing..
Flush(FLUSH_FOR_C_CALL);

SwitchToFarCodeIfBitSet(changed_bits, 16);
Label caches_unchanged;
armAsm->tst(changed_bits, 1u << 16);
armAsm->b(eq, &caches_unchanged);
EmitCall(reinterpret_cast<const void*>(&CPU::UpdateMemoryPointers));
armAsm->ldr(RARG1, PTR(ptr)); // reload value for interrupt test below
armAsm->bind(&caches_unchanged);

// might need to reload fastmem base too
if (CodeCache::IsUsingFastmem() && m_block->HasFlag(CodeCache::BlockFlags::ContainsLoadStoreInstructions) &&
IsHostRegAllocated(RMEMBASE.GetCode()))
{
FreeHostReg(RMEMBASE.GetCode());
}
SwitchToNearCode(true);

TestInterrupts(RARG1);
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/cpu_recompiler_arm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,11 +2428,13 @@ void CPU::ARM64Recompiler::Compile_mtc0(CompileFlags cf)
// We could just inline the whole thing..
Flush(FLUSH_FOR_C_CALL);

SwitchToFarCodeIfBitSet(changed_bits, 16);
Label caches_unchanged;
armAsm->tbz(changed_bits, 16, &caches_unchanged);
EmitCall(reinterpret_cast<const void*>(&CPU::UpdateMemoryPointers));
armAsm->ldr(RWARG1, PTR(ptr)); // reload value for interrupt test below
armAsm->ldr(RMEMBASE, PTR(&g_state.fastmem_base));
SwitchToNearCode(true);
if (CodeCache::IsUsingFastmem())
armAsm->ldr(RMEMBASE, PTR(&g_state.fastmem_base));
armAsm->bind(&caches_unchanged);

TestInterrupts(RWARG1);
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/cpu_recompiler_riscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2283,13 +2283,15 @@ void CPU::RISCV64Recompiler::Compile_mtc0(CompileFlags cf)
// We could just inline the whole thing..
Flush(FLUSH_FOR_C_CALL);

Label caches_unchanged;
rvAsm->SRLIW(RSCRATCH, changed_bits, 16);
rvAsm->ANDI(RSCRATCH, RSCRATCH, 1);
SwitchToFarCode(true, &Assembler::BEQ, RSCRATCH, zero);
rvAsm->BEQ(RSCRATCH, zero, &caches_unchanged);
EmitCall(reinterpret_cast<const void*>(&CPU::UpdateMemoryPointers));
rvAsm->LW(new_value, PTR(ptr));
rvAsm->LD(RMEMBASE, PTR(&g_state.fastmem_base));
SwitchToNearCode(true);
if (CodeCache::IsUsingFastmem())
rvAsm->LD(RMEMBASE, PTR(&g_state.fastmem_base));
rvAsm->Bind(&caches_unchanged);

TestInterrupts(RARG1);
}
Expand Down
9 changes: 6 additions & 3 deletions src/core/cpu_recompiler_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,12 +2241,15 @@ void CPU::X64Recompiler::Compile_mtc0(CompileFlags cf)
// We could just inline the whole thing..
Flush(FLUSH_FOR_C_CALL);

Label caches_unchanged;
cg->test(changed_bits, 1u << 16);
SwitchToFarCode(true, &CodeGenerator::jnz);
cg->jz(caches_unchanged);
cg->call(&CPU::UpdateMemoryPointers);
cg->mov(RWARG2, cg->dword[PTR(ptr)]); // reload value for interrupt test below
cg->mov(RMEMBASE, cg->qword[PTR(&g_state.fastmem_base)]);
SwitchToNearCode(true);
if (CodeCache::IsUsingFastmem())
cg->mov(RMEMBASE, cg->qword[PTR(&g_state.fastmem_base)]);

cg->L(caches_unchanged);

TestInterrupts(RWARG2);
}
Expand Down

0 comments on commit 10e2079

Please sign in to comment.