From eca06c60c71afcfaf41a1797986d5a3c4739f257 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 1 Mar 2014 21:15:17 -0800 Subject: [PATCH] Spend a bit less time in Read_Instruction on load. --- Core/MIPS/MIPSAnalyst.cpp | 6 +++--- Core/MIPS/MIPSCodeUtils.cpp | 5 +++++ Core/MIPS/MIPSCodeUtils.h | 1 + Core/MemMap.cpp | 19 +++++++++++++++++-- Core/MemMap.h | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 28bc9135c4..7f013d5768 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -337,7 +337,7 @@ skip: for (u32 ahead = fromAddr; ahead < fromAddr + MAX_AHEAD_SCAN; ahead += 4) { MIPSOpcode aheadOp = Memory::Read_Instruction(ahead); - u32 target = GetBranchTargetNoRA(ahead); + u32 target = GetBranchTargetNoRA(ahead, aheadOp); if (target == INVALIDTARGET && ((aheadOp & 0xFC000000) == 0x08000000)) { target = GetJumpTarget(ahead); } @@ -358,7 +358,7 @@ skip: if (closestJumpbackAddr != INVALIDTARGET && furthestJumpbackAddr == INVALIDTARGET) { for (u32 behind = closestJumpbackTarget; behind < fromAddr; behind += 4) { MIPSOpcode behindOp = Memory::Read_Instruction(behind); - u32 target = GetBranchTargetNoRA(behind); + u32 target = GetBranchTargetNoRA(behind, behindOp); if (target == INVALIDTARGET && ((behindOp & 0xFC000000) == 0x08000000)) { target = GetJumpTarget(behind); } @@ -409,7 +409,7 @@ skip: } MIPSOpcode op = Memory::Read_Instruction(addr); - u32 target = GetBranchTargetNoRA(addr); + u32 target = GetBranchTargetNoRA(addr, op); if (target != INVALIDTARGET) { isStraightLeaf = false; if (target > furthestBranch) { diff --git a/Core/MIPS/MIPSCodeUtils.cpp b/Core/MIPS/MIPSCodeUtils.cpp index 727469fccb..7d52278f66 100644 --- a/Core/MIPS/MIPSCodeUtils.cpp +++ b/Core/MIPS/MIPSCodeUtils.cpp @@ -67,6 +67,11 @@ namespace MIPSCodeUtils u32 GetBranchTargetNoRA(u32 addr) { MIPSOpcode op = Memory::Read_Instruction(addr); + return GetBranchTargetNoRA(addr, op); + } + + u32 GetBranchTargetNoRA(u32 addr, MIPSOpcode op) + { if (op != 0) { MIPSInfo info = MIPSGetInfo(op); diff --git a/Core/MIPS/MIPSCodeUtils.h b/Core/MIPS/MIPSCodeUtils.h index 502c42f637..4e2d20d437 100644 --- a/Core/MIPS/MIPSCodeUtils.h +++ b/Core/MIPS/MIPSCodeUtils.h @@ -53,6 +53,7 @@ namespace MIPSCodeUtils u32 GetBranchTarget(u32 addr); // Ignores bltzal/etc. instructions that change RA. u32 GetBranchTargetNoRA(u32 addr); + u32 GetBranchTargetNoRA(u32 addr, MIPSOpcode op); u32 GetJumpTarget(u32 addr); u32 GetSureBranchTarget(u32 addr); bool IsVFPUBranch(MIPSOpcode op); diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 039203b497..298aedc5ce 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -176,9 +176,12 @@ void Clear() memset(m_pVRAM, 0, VRAM_SIZE); } -Opcode Read_Instruction(u32 address, bool resolveReplacements) +static Opcode Read_Instruction(u32 address, bool resolveReplacements, Opcode inst) { - Opcode inst = Opcode(Read_U32(address)); + if (!MIPS_IS_EMUHACK(inst.encoding)) { + return inst; + } + if (MIPS_IS_RUNBLOCK(inst.encoding) && MIPSComp::jit) { JitBlockCache *bc = MIPSComp::jit->GetBlockCache(); int block_num = bc->GetBlockNumberFromEmuHackOp(inst, true); @@ -218,6 +221,18 @@ Opcode Read_Instruction(u32 address, bool resolveReplacements) } } +Opcode Read_Instruction(u32 address, bool resolveReplacements) +{ + Opcode inst = Opcode(Read_U32(address)); + return Read_Instruction(address, resolveReplacements, inst); +} + +Opcode ReadUnchecked_Instruction(u32 address, bool resolveReplacements) +{ + Opcode inst = Opcode(ReadUnchecked_U32(address)); + return Read_Instruction(address, resolveReplacements, inst); +} + Opcode Read_Opcode_JIT(u32 address) { Opcode inst = Opcode(Read_U32(address)); diff --git a/Core/MemMap.h b/Core/MemMap.h index c312ac95f8..81f56df1ee 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -140,6 +140,7 @@ void Write_Opcode_JIT(const u32 _Address, const Opcode _Value); // Should be used by analyzers, disassemblers etc. Does resolve replacements. Opcode Read_Instruction(const u32 _Address, bool resolveReplacements = false); +Opcode ReadUnchecked_Instruction(const u32 _Address, bool resolveReplacements = false); u8 Read_U8(const u32 _Address); u16 Read_U16(const u32 _Address);