diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index 06b5392d9d..47a8b2d2ad 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -1109,7 +1109,7 @@ static int Hook_omertachinmokunookitethelegacy_download_frame() { return 0; } -#define JITFUNC(f) (&MIPSComp::JitInterface::f) +#define JITFUNC(f) (&MIPSComp::MIPSFrontendInterface::f) // Can either replace with C functions or functions emitted in Asm/ArmAsm. static const ReplacementTableEntry entries[] = { diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index efdde624bf..7ec62e04c8 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -33,7 +33,7 @@ namespace MIPSComp { -class ArmJit : public ArmGen::ARMXCodeBlock, public JitInterface { +class ArmJit : public ArmGen::ARMXCodeBlock, public JitInterface, public MIPSFrontendInterface { public: ArmJit(MIPSState *mips); virtual ~ArmJit(); diff --git a/Core/MIPS/ARM64/Arm64Jit.h b/Core/MIPS/ARM64/Arm64Jit.h index e341df3e79..4aec5fecca 100644 --- a/Core/MIPS/ARM64/Arm64Jit.h +++ b/Core/MIPS/ARM64/Arm64Jit.h @@ -33,7 +33,7 @@ namespace MIPSComp { -class Arm64Jit : public Arm64Gen::ARM64CodeBlock, public JitInterface { +class Arm64Jit : public Arm64Gen::ARM64CodeBlock, public JitInterface, public MIPSFrontendInterface { public: Arm64Jit(MIPSState *mips); virtual ~Arm64Jit(); diff --git a/Core/MIPS/IR/IRJit.cpp b/Core/MIPS/IR/IRJit.cpp index e5bddd6c89..ee5f5c8206 100644 --- a/Core/MIPS/IR/IRJit.cpp +++ b/Core/MIPS/IR/IRJit.cpp @@ -254,6 +254,8 @@ void IRJit::DoJit(u32 em_address, IRBlock *b) { if (IRApplyPasses(passes, ARRAY_SIZE(passes), ir, simplified)) logBlocks = 1; code = &simplified; + if (ir.GetInstructions().size() >= 24) + logBlocks = 1; } b->SetInstructions(code->GetInstructions(), code->GetConstants()); @@ -408,4 +410,4 @@ MIPSOpcode IRJit::GetOriginalOp(MIPSOpcode op) { return b->GetOriginalFirstOp(); } -} // namespace MIPSComp \ No newline at end of file +} // namespace MIPSComp diff --git a/Core/MIPS/IR/IRJit.h b/Core/MIPS/IR/IRJit.h index e9881f6a6e..76a27d1a4b 100644 --- a/Core/MIPS/IR/IRJit.h +++ b/Core/MIPS/IR/IRJit.h @@ -101,7 +101,7 @@ private: std::vector blocks_; }; -class IRJit : public JitInterface { +class IRJit : public JitInterface, public MIPSFrontendInterface{ public: IRJit(MIPSState *mips); virtual ~IRJit(); diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index 929eeed975..0e5353ff57 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -121,6 +121,10 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) { case IROp::And: case IROp::Or: case IROp::Xor: + // Regularize, for the add/or check below. + if (symmetric && inst.src2 == inst.dest && inst.src1 != inst.src2) { + std::swap(inst.src1, inst.src2); + } if (gpr.IsImm(inst.src1) && gpr.IsImm(inst.src2)) { gpr.SetImm(inst.dest, Evaluate(gpr.GetImm(inst.src1), gpr.GetImm(inst.src2), inst.op)); } else if (gpr.IsImm(inst.src2)) { diff --git a/Core/MIPS/JitCommon/JitCommon.h b/Core/MIPS/JitCommon/JitCommon.h index e27707ea35..62a91a30c2 100644 --- a/Core/MIPS/JitCommon/JitCommon.h +++ b/Core/MIPS/JitCommon/JitCommon.h @@ -42,27 +42,11 @@ class MIPSState; namespace MIPSComp { void JitAt(); - class JitInterface { + class MIPSFrontendInterface { public: - virtual ~JitInterface() {} + virtual ~MIPSFrontendInterface() {} - virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0; - virtual const u8 *GetDispatcher() const = 0; - virtual JitBlockCache *GetBlockCache() = 0; - virtual void InvalidateCache() = 0; - virtual void InvalidateCacheAt(u32 em_address, int length = 4) = 0; - virtual void DoState(PointerWrap &p) = 0; - virtual void DoDummyState(PointerWrap &p) = 0; - virtual void RunLoopUntil(u64 globalticks) = 0; - virtual void Compile(u32 em_address) = 0; - virtual void ClearCache() = 0; virtual void EatPrefix() = 0; - virtual MIPSOpcode GetOriginalOp(MIPSOpcode op) = 0; - - // Block linking. This may need to work differently for whole-function JITs and stuff - // like that. - virtual void LinkBlock(u8 *exitPoint, const u8 *entryPoint) = 0; - virtual void UnlinkBlock(u8 *checkedEntry, u32 originalAddress) = 0; virtual void Comp_Generic(MIPSOpcode op) = 0; virtual void Comp_RunBlock(MIPSOpcode op) = 0; @@ -132,8 +116,30 @@ namespace MIPSComp { virtual int Replace_fabsf() = 0; }; - typedef void (JitInterface::*MIPSCompileFunc)(MIPSOpcode opcode); - typedef int (JitInterface::*MIPSReplaceFunc)(); + class JitInterface { + public: + virtual ~JitInterface() {} + + virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0; + virtual const u8 *GetDispatcher() const = 0; + virtual JitBlockCache *GetBlockCache() = 0; + virtual void InvalidateCache() = 0; + virtual void InvalidateCacheAt(u32 em_address, int length = 4) = 0; + virtual void DoState(PointerWrap &p) = 0; + virtual void DoDummyState(PointerWrap &p) = 0; + virtual void RunLoopUntil(u64 globalticks) = 0; + virtual void Compile(u32 em_address) = 0; + virtual void ClearCache() = 0; + virtual MIPSOpcode GetOriginalOp(MIPSOpcode op) = 0; + + // Block linking. This may need to work differently for whole-function JITs and stuff + // like that. + virtual void LinkBlock(u8 *exitPoint, const u8 *entryPoint) = 0; + virtual void UnlinkBlock(u8 *checkedEntry, u32 originalAddress) = 0; + }; + + typedef void (MIPSFrontendInterface::*MIPSCompileFunc)(MIPSOpcode opcode); + typedef int (MIPSFrontendInterface::*MIPSReplaceFunc)(); extern JitInterface *jit; diff --git a/Core/MIPS/MIPS/MipsJit.h b/Core/MIPS/MIPS/MipsJit.h index 1fcb6faea6..8c5dbf9bd3 100644 --- a/Core/MIPS/MIPS/MipsJit.h +++ b/Core/MIPS/MIPS/MipsJit.h @@ -20,6 +20,7 @@ #include "Common/MipsEmitter.h" using namespace MIPSGen; +#include "Core/MIPS/JitCommon/JitCommon.h" #include "Core/MIPS/JitCommon/JitState.h" #include "Core/MIPS/JitCommon/JitBlockCache.h" #include "../MIPSVFPUUtils.h" @@ -31,7 +32,7 @@ using namespace MIPSGen; namespace MIPSComp { -class MipsJit : public MIPSGen::MIPSCodeBlock, public JitInterface +class MipsJit : public MIPSGen::MIPSCodeBlock, public JitInterface, public MIPSFrontendInterface { public: MipsJit(MIPSState *mips); diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index f0b51db0c0..76e260b377 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -82,7 +82,7 @@ struct MIPSInstruction { #define ENCODING(a) {a} #define INSTR(name, comp, dis, inter, flags) {Instruc, name, comp, dis, inter, MIPSInfo(flags)} -#define JITFUNC(f) (&JitInterface::f) +#define JITFUNC(f) (&MIPSFrontendInterface::f) using namespace MIPSDis; using namespace MIPSInt; @@ -912,7 +912,7 @@ const MIPSInstruction *MIPSGetInstruction(MIPSOpcode op) { return instr; } -void MIPSCompileOp(MIPSOpcode op, MIPSComp::JitInterface *jit) { +void MIPSCompileOp(MIPSOpcode op, MIPSComp::MIPSFrontendInterface *jit) { if (op == 0) return; const MIPSInstruction *instr = MIPSGetInstruction(op); @@ -923,7 +923,6 @@ void MIPSCompileOp(MIPSOpcode op, MIPSComp::JitInterface *jit) { } else { ERROR_LOG_REPORT(CPU,"MIPSCompileOp %08x failed",op.encoding); } - if (info & OUT_EAT_PREFIX) jit->EatPrefix(); } else { diff --git a/Core/MIPS/MIPSTables.h b/Core/MIPS/MIPSTables.h index 39c8c06753..3987aa3e87 100644 --- a/Core/MIPS/MIPSTables.h +++ b/Core/MIPS/MIPSTables.h @@ -112,10 +112,10 @@ typedef void (CDECL *MIPSDisFunc)(MIPSOpcode opcode, char *out); typedef void (CDECL *MIPSInterpretFunc)(MIPSOpcode opcode); namespace MIPSComp { - class JitInterface; + class MIPSFrontendInterface; } -void MIPSCompileOp(MIPSOpcode op, MIPSComp::JitInterface *jit); +void MIPSCompileOp(MIPSOpcode op, MIPSComp::MIPSFrontendInterface *jit); void MIPSDisAsm(MIPSOpcode op, u32 pc, char *out, bool tabsToSpaces = false); MIPSInfo MIPSGetInfo(MIPSOpcode op); void MIPSInterpret(MIPSOpcode op); //only for those rare ones diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index a6f4444331..4206f4d307 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -46,7 +46,7 @@ struct RegCacheState { FPURegCacheState fpr; }; -class Jit : public Gen::XCodeBlock, public JitInterface { +class Jit : public Gen::XCodeBlock, public JitInterface, public MIPSFrontendInterface { public: Jit(MIPSState *mips); virtual ~Jit();