diff --git a/pcsx2/x86/microVU_Flags.inl b/pcsx2/x86/microVU_Flags.inl index 0b1cf476ba..22973983f8 100644 --- a/pcsx2/x86/microVU_Flags.inl +++ b/pcsx2/x86/microVU_Flags.inl @@ -224,13 +224,14 @@ _f void mVUsetupFlags(mV, microFlagCycles& mFC) { } } +#define _found ((mVUregs.needExactMatch&8)>>3) #define shortBranch() { \ if ((branch == 3) || (branch == 4)) { /*Branches*/ \ - mVUflagPass(mVU, aBranchAddr, sCount+1, found); \ + _mVUflagPass(mVU, aBranchAddr, sCount+_found, v); \ if (branch == 3) break; /*Non-conditional Branch*/ \ } \ else if (branch == 5) { /*JR/JARL*/ \ - if(!CHECK_VU_BLOCKHACK && (!found||(sCount+1<4))) { \ + if(!CHECK_VU_BLOCKHACK && (sCount+_found<4)) { \ mVUregs.needExactMatch |= 7; \ } \ break; \ @@ -239,17 +240,21 @@ _f void mVUsetupFlags(mV, microFlagCycles& mFC) { } // Scan through instructions and check if flags are read (FSxxx, FMxxx, FCxxx opcodes) -void mVUflagPass(mV, u32 startPC, u32 sCount = 0, bool found = 0) { +void _mVUflagPass(mV, u32 startPC, u32 sCount, vector& v) { + + for (u32 i = 0; i < v.size(); i++) { + if (v[i] == startPC) return; // Prevent infinite recursion + } + v.push_back(startPC); int oldPC = iPC; int oldBranch = mVUbranch; int aBranchAddr = 0; iPC = startPC / 4; mVUbranch = 0; - for (int branch = 0; (sCount < 4) || !found; sCount++) { + for (int branch = 0; sCount < 4; sCount += _found) { incPC(1); mVUopU(mVU, 3); - if (mVUregs.needExactMatch&8) found = 1; if ( curI & _Ebit_ ) { branch = 1; } if ( curI & _DTbit_ ) { branch = 6; } if (!(curI & _Ibit_) ) { incPC(-1); mVUopL(mVU, 3); incPC(1); } @@ -264,6 +269,11 @@ void mVUflagPass(mV, u32 startPC, u32 sCount = 0, bool found = 0) { setCode(); } +void mVUflagPass(mV, u32 startPC, u32 sCount = 0) { + vector v; + _mVUflagPass(mVU, startPC, sCount, v); +} + #define branchType1 if (mVUbranch <= 2) // B/BAL #define branchType2 else if (mVUbranch >= 9) // JR/JALR #define branchType3 else // Conditional Branch diff --git a/pcsx2/x86/microVU_Lower.inl b/pcsx2/x86/microVU_Lower.inl index 5b8852616c..50cf1be9dd 100644 --- a/pcsx2/x86/microVU_Lower.inl +++ b/pcsx2/x86/microVU_Lower.inl @@ -1192,7 +1192,11 @@ mVUop(mVU_XGKICK) { void setBranchA(mP, int x, int _x_) { pass1 { - if (_Imm11_ == 1 && !_x_) { mVUlow.isNOP = 1; return; } + if (_Imm11_ == 1 && !_x_) { + DevCon.WriteLn(Color_Green, "microVU%d: Branch Optimization", mVU->index); + mVUlow.isNOP = 1; + return; + } mVUbranch = x; mVUlow.branch = x; }