IRInterpreter: Cache the MIPSState pointer in a local, faster address check

This commit is contained in:
Henrik Rydgård 2024-05-10 23:21:51 +02:00
parent ad541f204b
commit c332d564db
2 changed files with 25 additions and 7 deletions

View file

@ -246,21 +246,24 @@ void IRJit::RunLoopUntil(u64 globalticks) {
if (coreState != 0) {
break;
}
while (mips_->downcount >= 0) {
u32 inst = Memory::ReadUnchecked_U32(mips_->pc);
MIPSState *mips = mips_;
while (mips->downcount >= 0) {
u32 inst = Memory::ReadUnchecked_U32(mips->pc);
u32 opcode = inst & 0xFF000000;
if (opcode == MIPS_EMUHACK_OPCODE) {
IRBlock *block = blocks_.GetBlockUnchecked(inst & 0xFFFFFF);
u32 startPC = mips_->pc;
mips_->pc = IRInterpret(mips_, block->GetInstructions(), block->GetNumInstructions());
u32 startPC = mips->pc;
mips->pc = IRInterpret(mips, block->GetInstructions(), block->GetNumInstructions());
// Note: this will "jump to zero" on a badly constructed block missing exits.
if (!Memory::IsValidAddress(mips_->pc) || (mips_->pc & 3) != 0) {
Core_ExecException(mips_->pc, startPC, ExecExceptionType::JUMP);
if (!Memory::IsValid4AlignedAddress(mips->pc)) {
Core_ExecException(mips->pc, startPC, ExecExceptionType::JUMP);
break;
}
} else {
// RestoreRoundingMode(true);
Compile(mips_->pc);
Compile(mips->pc);
// ApplyRoundingMode(true);
}
}

View file

@ -296,6 +296,21 @@ inline bool IsValidAddress(const u32 address) {
}
}
inline bool IsValid4AlignedAddress(const u32 address) {
if ((address & 0x3E000003) == 0x08000000) {
return true;
} else if ((address & 0x3F800003) == 0x04000000) {
return true;
} else if ((address & 0xBFFFC003) == 0x00010000) {
return true;
} else if ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize) {
return (address & 3) == 0;
} else {
return false;
}
}
inline u32 MaxSizeAtAddress(const u32 address){
if ((address & 0x3E000000) == 0x08000000) {
return 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF);