diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 6b04261733..66ebeb938a 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -538,6 +538,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index f336712f86..7e8ba76570 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -912,6 +912,9 @@ Dialog + + MIPS\JitCommon + @@ -919,4 +922,4 @@ - + \ No newline at end of file diff --git a/Core/MIPS/ARM/ArmAsm.cpp b/Core/MIPS/ARM/ArmAsm.cpp index 2766880246..7e58457222 100644 --- a/Core/MIPS/ARM/ArmAsm.cpp +++ b/Core/MIPS/ARM/ArmAsm.cpp @@ -23,9 +23,9 @@ #include "MemoryUtil.h" #include "ArmEmitter.h" -#include "ArmJit.h" -#include "../JitCommon/JitCommon.h" -#include "ArmAsm.h" +#include "Core/MIPS/JitCommon/JitCommon.h" +#include "Core/MIPS/ARM/ArmJit.h" +#include "Core/MIPS/ARM/ArmAsm.h" using namespace ArmGen; @@ -208,4 +208,4 @@ void Jit::GenerateFixedCode() FlushIcache(); } -} // namespace +} // namespace MIPSComp diff --git a/Core/MIPS/ARM/ArmCompALU.cpp b/Core/MIPS/ARM/ArmCompALU.cpp index 6aefbff4f3..5906b2d934 100644 --- a/Core/MIPS/ARM/ArmCompALU.cpp +++ b/Core/MIPS/ARM/ArmCompALU.cpp @@ -176,8 +176,13 @@ namespace MIPSComp u32 rsImm = gpr.GetImm(rs); gpr.MapDirtyIn(rd, rt); // TODO: Special case when rsImm can be represented as an Operand2 - MOVI2R(R0, rsImm); - (this->*arith)(gpr.R(rd), R0, gpr.R(rt)); + if (!isSub) { + MOVI2R(R0, rsImm); + (this->*arith)(gpr.R(rd), gpr.R(rt), R0); + } else { + MOVI2R(R0, rsImm); + (this->*arith)(gpr.R(rd), R0, gpr.R(rt)); + } } else { // Generic solution gpr.MapDirtyInIn(rd, rs, rt); diff --git a/Core/MIPS/ARM/ArmCompLoadStore.cpp b/Core/MIPS/ARM/ArmCompLoadStore.cpp index 0f24287165..34b38562fd 100644 --- a/Core/MIPS/ARM/ArmCompLoadStore.cpp +++ b/Core/MIPS/ARM/ArmCompLoadStore.cpp @@ -153,6 +153,8 @@ namespace MIPSComp case 41: //sh case 43: //sw if (gpr.IsImm(rs) && Memory::IsValidAddress(iaddr)) { + // TODO: Avoid mapping a register for the "zero" register, use R0 instead. + // We can compute the full address at compile time. Kickass. u32 addr = iaddr & 0x3FFFFFFF; // Must be OK even if rs == rt since we have the value from imm already. diff --git a/Core/MIPS/ARM/ArmCompVFPU.cpp b/Core/MIPS/ARM/ArmCompVFPU.cpp index 23d9c4ed27..f594048d5f 100644 --- a/Core/MIPS/ARM/ArmCompVFPU.cpp +++ b/Core/MIPS/ARM/ArmCompVFPU.cpp @@ -87,15 +87,15 @@ namespace MIPSComp switch (regnum) { case 0: // S js.prefixS = data; - js.prefixSFlag = ArmJitState::PREFIX_KNOWN_DIRTY; + js.prefixSFlag = JitState::PREFIX_KNOWN_DIRTY; break; case 1: // T js.prefixT = data; - js.prefixTFlag = ArmJitState::PREFIX_KNOWN_DIRTY; + js.prefixTFlag = JitState::PREFIX_KNOWN_DIRTY; break; case 2: // D js.prefixD = data; - js.prefixDFlag = ArmJitState::PREFIX_KNOWN_DIRTY; + js.prefixDFlag = JitState::PREFIX_KNOWN_DIRTY; break; default: ERROR_LOG(CPU, "VPFX - bad regnum %i : data=%08x", regnum, data); @@ -104,7 +104,8 @@ namespace MIPSComp } void Jit::ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz) { - if (prefix == 0xE4) return; + if (prefix == 0xE4) + return; int n = GetNumVectorElements(sz); u8 origV[4]; @@ -113,8 +114,7 @@ namespace MIPSComp for (int i = 0; i < n; i++) origV[i] = vregs[i]; - for (int i = 0; i < n; i++) - { + for (int i = 0; i < n; i++) { int regnum = (prefix >> (i*2)) & 3; int abs = (prefix >> (8+i)) & 1; int negate = (prefix >> (16+i)) & 1; @@ -156,7 +156,7 @@ namespace MIPSComp } void Jit::GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg) { - _assert_(js.prefixDFlag & ArmJitState::PREFIX_KNOWN); + _assert_(js.prefixDFlag & JitState::PREFIX_KNOWN); GetVectorRegs(regs, sz, vectorReg); if (js.prefixD == 0) @@ -171,8 +171,9 @@ namespace MIPSComp } void Jit::ApplyPrefixD(const u8 *vregs, VectorSize sz) { - _assert_(js.prefixDFlag & ArmJitState::PREFIX_KNOWN); - if (!js.prefixD) return; + _assert_(js.prefixDFlag & JitState::PREFIX_KNOWN); + if (!js.prefixD) + return; int n = GetNumVectorElements(sz); for (int i = 0; i < n; i++) { @@ -1041,11 +1042,11 @@ namespace MIPSComp // TODO: Optimization if rt is Imm? // Set these BEFORE disable! if (imm - 128 == VFPU_CTRL_SPREFIX) { - js.prefixSFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixSFlag = JitState::PREFIX_UNKNOWN; } else if (imm - 128 == VFPU_CTRL_TPREFIX) { - js.prefixTFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixTFlag = JitState::PREFIX_UNKNOWN; } else if (imm - 128 == VFPU_CTRL_DPREFIX) { - js.prefixDFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixDFlag = JitState::PREFIX_UNKNOWN; } } else { //ERROR @@ -1072,11 +1073,11 @@ namespace MIPSComp fpr.ReleaseSpillLocksAndDiscardTemps(); if (imm - 128 == VFPU_CTRL_SPREFIX) { - js.prefixSFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixSFlag = JitState::PREFIX_UNKNOWN; } else if (imm - 128 == VFPU_CTRL_TPREFIX) { - js.prefixTFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixTFlag = JitState::PREFIX_UNKNOWN; } else if (imm - 128 == VFPU_CTRL_DPREFIX) { - js.prefixDFlag = ArmJitState::PREFIX_UNKNOWN; + js.prefixDFlag = JitState::PREFIX_UNKNOWN; } } } diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp index fae1cb8a43..39a2bafe6d 100644 --- a/Core/MIPS/ARM/ArmJit.cpp +++ b/Core/MIPS/ARM/ArmJit.cpp @@ -99,22 +99,22 @@ void Jit::FlushAll() void Jit::FlushPrefixV() { - if ((js.prefixSFlag & ArmJitState::PREFIX_DIRTY) != 0) { + if ((js.prefixSFlag & JitState::PREFIX_DIRTY) != 0) { MOVI2R(R0, js.prefixS); STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_SPREFIX])); - js.prefixSFlag = (ArmJitState::PrefixState) (js.prefixSFlag & ~ArmJitState::PREFIX_DIRTY); + js.prefixSFlag = (JitState::PrefixState) (js.prefixSFlag & ~JitState::PREFIX_DIRTY); } - if ((js.prefixTFlag & ArmJitState::PREFIX_DIRTY) != 0) { + if ((js.prefixTFlag & JitState::PREFIX_DIRTY) != 0) { MOVI2R(R0, js.prefixT); STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_TPREFIX])); - js.prefixTFlag = (ArmJitState::PrefixState) (js.prefixTFlag & ~ArmJitState::PREFIX_DIRTY); + js.prefixTFlag = (JitState::PrefixState) (js.prefixTFlag & ~JitState::PREFIX_DIRTY); } - if ((js.prefixDFlag & ArmJitState::PREFIX_DIRTY) != 0) { + if ((js.prefixDFlag & JitState::PREFIX_DIRTY) != 0) { MOVI2R(R0, js.prefixD); STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_DPREFIX])); - js.prefixDFlag = (ArmJitState::PrefixState) (js.prefixDFlag & ~ArmJitState::PREFIX_DIRTY); + js.prefixDFlag = (JitState::PrefixState) (js.prefixDFlag & ~JitState::PREFIX_DIRTY); } } @@ -181,8 +181,8 @@ void Jit::Compile(u32 em_address) blocks.FinalizeBlock(block_num, jo.enableBlocklink); // Drat. The VFPU hit an uneaten prefix at the end of a block. - if (js.startDefaultPrefix && js.MayHavePrefix()) - { + if (js.startDefaultPrefix && js.MayHavePrefix()) { + WARN_LOG(JIT, "Uneaten prefix at end of block: %08x", js.compilerPC - 4); js.startDefaultPrefix = false; // Our assumptions are all wrong so it's clean-slate time. ClearCache(); @@ -212,6 +212,8 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b) // We add a check before the block, used when entering from a linked block. b->checkedEntry = GetCodePtr(); // Downcount flag check. The last block decremented downcounter, and the flag should still be available. + // Possible idea: Move the MOVI2R and B *before* checkedEntry, and just branch backwards there. + // possible drawback is that branch predictors will predict short backward branches as taken. SetCC(CC_LT); MOVI2R(R0, js.blockStart); B((const void *)outerLoopPCInR0); @@ -228,7 +230,6 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b) int cycles = 0; int partialFlushOffset = 0; - char temp[256]; while (js.compiling) { gpr.SetCompilerPC(js.compilerPC); // Let it know for log messages @@ -250,6 +251,8 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b) } } FlushLitPool(); + + char temp[256]; if (logBlocks > 0 && dontLogBlocks == 0) { for (u32 cpc = em_address; cpc != js.compilerPC + 4; cpc += 4) { MIPSDisAsm(Memory::Read_Instruction(cpc), cpc, temp, true); @@ -263,12 +266,12 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b) INFO_LOG(JIT, "=============== ARM ==============="); DisassembleArm(b->normalEntry, GetCodePtr() - b->normalEntry); } - if (logBlocks > 0) logBlocks--; - if (dontLogBlocks > 0) dontLogBlocks--; + if (logBlocks > 0) + logBlocks--; + if (dontLogBlocks > 0) + dontLogBlocks--; - AlignCode16(); - - // Don't forget to zap the instruction cache! + // Don't forget to zap the newly written instructions in the instruction cache! FlushIcache(); b->originalSize = numInstructions; @@ -327,8 +330,7 @@ void Jit::WriteDownCount(int offset) if (jo.downcountInRegister) { int theDowncount = js.downcountAmount + offset; Operand2 op2; - if (TryMakeOperand2(theDowncount, op2)) // We can enlarge this if we used rotations - { + if (TryMakeOperand2(theDowncount, op2)) { SUBS(R7, R7, op2); } else { // Should be fine to use R2 here, flushed the regcache anyway. @@ -340,8 +342,7 @@ void Jit::WriteDownCount(int offset) int theDowncount = js.downcountAmount + offset; LDR(R1, CTXREG, offsetof(MIPSState, downcount)); Operand2 op2; - if (TryMakeOperand2(theDowncount, op2)) // We can enlarge this if we used rotations - { + if (TryMakeOperand2(theDowncount, op2)) { SUBS(R1, R1, op2); STR(R1, CTXREG, offsetof(MIPSState, downcount)); } else { diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index 7948097fff..fbd76230eb 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -19,6 +19,7 @@ #include "../../../Globals.h" +#include "Core/MIPS/JitCommon/JitState.h" #include "Core/MIPS/JitCommon/JitBlockCache.h" #include "Core/MIPS/ARM/ArmRegCache.h" #include "Core/MIPS/ARM/ArmRegCacheFPU.h" @@ -43,111 +44,6 @@ struct ArmJitOptions bool downcountInRegister; }; -struct ArmJitState -{ - enum PrefixState - { - PREFIX_UNKNOWN = 0x00, - PREFIX_KNOWN = 0x01, - PREFIX_DIRTY = 0x10, - PREFIX_KNOWN_DIRTY = 0x11, - }; - - u32 compilerPC; - u32 blockStart; - int nextExit; - bool cancel; - bool inDelaySlot; - int downcountAmount; - bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block - JitBlock *curBlock; - - // VFPU prefix magic - bool startDefaultPrefix; - u32 prefixS; - u32 prefixT; - u32 prefixD; - PrefixState prefixSFlag; - PrefixState prefixTFlag; - PrefixState prefixDFlag; - - ArmJitState() - : prefixSFlag(PREFIX_UNKNOWN), - prefixTFlag(PREFIX_UNKNOWN), - prefixDFlag(PREFIX_UNKNOWN) {} - - void PrefixStart() { - if (startDefaultPrefix) { - EatPrefix(); - } else { - PrefixUnknown(); - } - } - void PrefixUnknown() { - prefixSFlag = PREFIX_UNKNOWN; - prefixTFlag = PREFIX_UNKNOWN; - prefixDFlag = PREFIX_UNKNOWN; - } - bool MayHavePrefix() const { - if (HasUnknownPrefix()) { - return true; - } else if (prefixS != 0xE4 || prefixT != 0xE4 || prefixD != 0) { - return true; - } else if (VfpuWriteMask() != 0) { - return true; - } - - return false; - } - bool HasUnknownPrefix() const { - if (!(prefixSFlag & PREFIX_KNOWN) || !(prefixTFlag & PREFIX_KNOWN) || !(prefixDFlag & PREFIX_KNOWN)) { - return true; - } - return false; - } - bool HasNoPrefix() const { - return (prefixDFlag & PREFIX_KNOWN) && (prefixSFlag & PREFIX_KNOWN) && (prefixTFlag & PREFIX_KNOWN) && (prefixS == 0xE4 && prefixT == 0xE4 && prefixD == 0); - } - - void EatPrefix() { - if ((prefixSFlag & PREFIX_KNOWN) == 0 || prefixS != 0xE4) { - prefixSFlag = PREFIX_KNOWN_DIRTY; - prefixS = 0xE4; - } - if ((prefixTFlag & PREFIX_KNOWN) == 0 || prefixT != 0xE4) { - prefixTFlag = PREFIX_KNOWN_DIRTY; - prefixT = 0xE4; - } - if ((prefixDFlag & PREFIX_KNOWN) == 0 || prefixD != 0x0 || VfpuWriteMask() != 0) { - prefixDFlag = PREFIX_KNOWN_DIRTY; - prefixD = 0x0; - } - } - - u8 VfpuWriteMask() const { - _assert_(prefixDFlag & PREFIX_KNOWN); - return (prefixD >> 8) & 0xF; - } - - bool VfpuWriteMask(int i) const { - _assert_(prefixDFlag & PREFIX_KNOWN); - return (prefixD >> (8 + i)) & 1; - } -}; - - -enum CompileDelaySlotFlags -{ - // Easy, nothing extra. - DELAYSLOT_NICE = 0, - // Flush registers after delay slot. - DELAYSLOT_FLUSH = 1, - // Preserve flags. - DELAYSLOT_SAFE = 2, - // Flush registers after and preserve flags. - DELAYSLOT_SAFE_FLUSH = DELAYSLOT_FLUSH | DELAYSLOT_SAFE, -}; - class Jit : public ArmGen::ARMXCodeBlock { public: @@ -291,7 +187,7 @@ private: JitBlockCache blocks; ArmJitOptions jo; - ArmJitState js; + JitState js; ArmRegCache gpr; ArmRegCacheFPU fpr; diff --git a/Core/MIPS/JitCommon/JitCommon.h b/Core/MIPS/JitCommon/JitCommon.h index 8569132bcb..5fdc2791e1 100644 --- a/Core/MIPS/JitCommon/JitCommon.h +++ b/Core/MIPS/JitCommon/JitCommon.h @@ -19,6 +19,9 @@ #include "Common/Common.h" +struct JitBlock; + + #if defined(PPC) #include "../PPC/PpcJit.h" #elif defined(ARM) @@ -43,5 +46,5 @@ #define EMUOP_RETKERNEL 1 // Returns to the simulated PSP kernel from a thread namespace MIPSComp { -extern Jit *jit; + extern Jit *jit; } diff --git a/Core/MIPS/JitCommon/JitState.h b/Core/MIPS/JitCommon/JitState.h new file mode 100644 index 0000000000..ad9dd7926b --- /dev/null +++ b/Core/MIPS/JitCommon/JitState.h @@ -0,0 +1,135 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + + +#pragma once + +struct JitBlock; + +namespace MIPSComp { + + enum CompileDelaySlotFlags + { + // Easy, nothing extra. + DELAYSLOT_NICE = 0, + // Flush registers after delay slot. + DELAYSLOT_FLUSH = 1, + // Preserve flags. + DELAYSLOT_SAFE = 2, + // Flush registers after and preserve flags. + DELAYSLOT_SAFE_FLUSH = DELAYSLOT_FLUSH | DELAYSLOT_SAFE, + }; + + struct JitState + { + enum PrefixState + { + PREFIX_UNKNOWN = 0x00, + PREFIX_KNOWN = 0x01, + PREFIX_DIRTY = 0x10, + PREFIX_KNOWN_DIRTY = 0x11, + }; + + enum AfterOp + { + AFTER_NONE = 0x00, + AFTER_CORE_STATE = 0x01, + AFTER_REWIND_PC_BAD_STATE = 0x02, + }; + + JitState() + : prefixSFlag(PREFIX_UNKNOWN), + prefixTFlag(PREFIX_UNKNOWN), + prefixDFlag(PREFIX_UNKNOWN), + startDefaultPrefix(true) {} + + u32 compilerPC; + u32 blockStart; + int nextExit; + bool cancel; + bool inDelaySlot; + // See JitState::AfterOp for values. + int afterOp; + int downcountAmount; + int numInstructions; + bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block + JitBlock *curBlock; + + // VFPU prefix magic + bool startDefaultPrefix; + u32 prefixS; + u32 prefixT; + u32 prefixD; + PrefixState prefixSFlag; + PrefixState prefixTFlag; + PrefixState prefixDFlag; + + void PrefixStart() { + if (startDefaultPrefix) { + EatPrefix(); + } else { + PrefixUnknown(); + } + } + void PrefixUnknown() { + prefixSFlag = PREFIX_UNKNOWN; + prefixTFlag = PREFIX_UNKNOWN; + prefixDFlag = PREFIX_UNKNOWN; + } + bool MayHavePrefix() const { + if (HasUnknownPrefix()) { + return true; + } else if (prefixS != 0xE4 || prefixT != 0xE4 || prefixD != 0) { + return true; + } else if (VfpuWriteMask() != 0) { + return true; + } + return false; + } + bool HasUnknownPrefix() const { + if (!(prefixSFlag & PREFIX_KNOWN) || !(prefixTFlag & PREFIX_KNOWN) || !(prefixDFlag & PREFIX_KNOWN)) { + return true; + } + return false; + } + bool HasNoPrefix() const { + return (prefixDFlag & PREFIX_KNOWN) && (prefixSFlag & PREFIX_KNOWN) && (prefixTFlag & PREFIX_KNOWN) && (prefixS == 0xE4 && prefixT == 0xE4 && prefixD == 0); + } + void EatPrefix() { + if ((prefixSFlag & PREFIX_KNOWN) == 0 || prefixS != 0xE4) { + prefixSFlag = PREFIX_KNOWN_DIRTY; + prefixS = 0xE4; + } + if ((prefixTFlag & PREFIX_KNOWN) == 0 || prefixT != 0xE4) { + prefixTFlag = PREFIX_KNOWN_DIRTY; + prefixT = 0xE4; + } + if ((prefixDFlag & PREFIX_KNOWN) == 0 || prefixD != 0x0 || VfpuWriteMask() != 0) { + prefixDFlag = PREFIX_KNOWN_DIRTY; + prefixD = 0x0; + } + } + u8 VfpuWriteMask() const { + _assert_(prefixDFlag & JitState::PREFIX_KNOWN); + return (prefixD >> 8) & 0xF; + } + bool VfpuWriteMask(int i) const { + _assert_(prefixDFlag & JitState::PREFIX_KNOWN); + return (prefixD >> (8 + i)) & 1; + } + }; +} diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 44aa4ca62e..dd60fb4758 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -921,7 +921,7 @@ const MIPSInstruction *MIPSGetInstruction(MIPSOpcode op) void MIPSCompileOp(MIPSOpcode op) { - if (op==0) + if (op == 0) return; const MIPSInstruction *instr = MIPSGetInstruction(op); const MIPSInfo info = MIPSGetInfo(op); diff --git a/Core/MIPS/x86/CompVFPU.cpp b/Core/MIPS/x86/CompVFPU.cpp index 331b9956d2..fa1bfbe551 100644 --- a/Core/MIPS/x86/CompVFPU.cpp +++ b/Core/MIPS/x86/CompVFPU.cpp @@ -1556,6 +1556,7 @@ void Jit::Comp_Mftv(MIPSOpcode op) { // rt = 0, imm = 255 appears to be used as a CPU interlock by some games. if (rt != MIPS_REG_ZERO) { if (imm < 128) { //R(rt) = VI(imm); + // TODO: Avoid goind through memory fpr.StoreFromRegisterV(imm); gpr.BindToRegister(rt, false, true); MOV(32, gpr.R(rt), fpr.V(imm)); diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index 1bb6974ff1..7f2fdbcfda 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -27,6 +27,7 @@ #include "Common/x64Emitter.h" #include "Core/MIPS/JitCommon/JitBlockCache.h" +#include "Core/MIPS/JitCommon/JitState.h" #include "RegCache.h" #include "RegCacheFPU.h" @@ -54,117 +55,6 @@ struct JitOptions int continueMaxInstructions; }; -struct JitState -{ - enum PrefixState - { - PREFIX_UNKNOWN = 0x00, - PREFIX_KNOWN = 0x01, - PREFIX_DIRTY = 0x10, - PREFIX_KNOWN_DIRTY = 0x11, - }; - - enum AfterOp - { - AFTER_NONE = 0x00, - AFTER_CORE_STATE = 0x01, - AFTER_REWIND_PC_BAD_STATE = 0x02, - }; - - JitState() - : prefixSFlag(PREFIX_UNKNOWN), - prefixTFlag(PREFIX_UNKNOWN), - prefixDFlag(PREFIX_UNKNOWN) {} - - u32 compilerPC; - u32 blockStart; - int nextExit; - bool cancel; - bool inDelaySlot; - // See JitState::AfterOp for values. - int afterOp; - int downcountAmount; - int numInstructions; - bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block - JitBlock *curBlock; - - // VFPU prefix magic - bool startDefaultPrefix; - u32 prefixS; - u32 prefixT; - u32 prefixD; - PrefixState prefixSFlag; - PrefixState prefixTFlag; - PrefixState prefixDFlag; - - void PrefixStart() { - if (startDefaultPrefix) { - EatPrefix(); - } else { - PrefixUnknown(); - } - } - void PrefixUnknown() { - prefixSFlag = PREFIX_UNKNOWN; - prefixTFlag = PREFIX_UNKNOWN; - prefixDFlag = PREFIX_UNKNOWN; - } - bool MayHavePrefix() const { - if (HasUnknownPrefix()) { - return true; - } else if (prefixS != 0xE4 || prefixT != 0xE4 || prefixD != 0) { - return true; - } else if (VfpuWriteMask() != 0) { - return true; - } - - return false; - } - bool HasUnknownPrefix() const { - if (!(prefixSFlag & PREFIX_KNOWN) || !(prefixTFlag & PREFIX_KNOWN) || !(prefixDFlag & PREFIX_KNOWN)) { - return true; - } - return false; - } - bool HasNoPrefix() const { - return (prefixDFlag & PREFIX_KNOWN) && (prefixSFlag & PREFIX_KNOWN) && (prefixTFlag & PREFIX_KNOWN) && (prefixS == 0xE4 && prefixT == 0xE4 && prefixD == 0); - } - void EatPrefix() { - if ((prefixSFlag & PREFIX_KNOWN) == 0 || prefixS != 0xE4) { - prefixSFlag = PREFIX_KNOWN_DIRTY; - prefixS = 0xE4; - } - if ((prefixTFlag & PREFIX_KNOWN) == 0 || prefixT != 0xE4) { - prefixTFlag = PREFIX_KNOWN_DIRTY; - prefixT = 0xE4; - } - if ((prefixDFlag & PREFIX_KNOWN) == 0 || prefixD != 0x0 || VfpuWriteMask() != 0) { - prefixDFlag = PREFIX_KNOWN_DIRTY; - prefixD = 0x0; - } - } - u8 VfpuWriteMask() const { - _assert_(prefixDFlag & JitState::PREFIX_KNOWN); - return (prefixD >> 8) & 0xF; - } - bool VfpuWriteMask(int i) const { - _assert_(prefixDFlag & JitState::PREFIX_KNOWN); - return (prefixD >> (8 + i)) & 1; - } -}; - -enum CompileDelaySlotFlags -{ - // Easy, nothing extra. - DELAYSLOT_NICE = 0, - // Flush registers after delay slot. - DELAYSLOT_FLUSH = 1, - // Preserve flags. - DELAYSLOT_SAFE = 2, - // Flush registers after and preserve flags. - DELAYSLOT_SAFE_FLUSH = DELAYSLOT_FLUSH | DELAYSLOT_SAFE, -}; - // TODO: Hmm, humongous. struct RegCacheState { GPRRegCacheState gpr;