From afc5760e6c69a75c9eab814a73cfc2011de05bdf Mon Sep 17 00:00:00 2001 From: cottonvibes Date: Fri, 8 May 2009 04:16:25 +0000 Subject: [PATCH] microVU: Cleanup and added microVU_Flags.inl to the project. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1152 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/windows/VCprojects/pcsx2_2008.vcproj | 4 + pcsx2/x86/microVU.cpp | 32 ++-- pcsx2/x86/microVU.h | 3 +- pcsx2/x86/microVU_Alloc.h | 33 ++-- pcsx2/x86/microVU_Alloc.inl | 34 ++-- pcsx2/x86/microVU_Analyze.inl | 40 ++--- pcsx2/x86/microVU_Compile.inl | 183 +++------------------ pcsx2/x86/microVU_Execute.inl | 32 ++-- pcsx2/x86/microVU_Flags.inl | 175 ++++++++++++++++++++ pcsx2/x86/microVU_Log.inl | 32 ++-- pcsx2/x86/microVU_Lower.inl | 32 ++-- pcsx2/x86/microVU_Misc.h | 34 +++- pcsx2/x86/microVU_Misc.inl | 2 +- pcsx2/x86/microVU_Tables.inl | 32 ++-- pcsx2/x86/microVU_Upper.inl | 12 +- 15 files changed, 359 insertions(+), 321 deletions(-) create mode 100644 pcsx2/x86/microVU_Flags.inl diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index 8f3bee102f..589cc0a396 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -2050,6 +2050,10 @@ RelativePath="..\..\x86\microVU_Execute.inl" > + + diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index bc01d468a4..eda6882dd4 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ // Micro VU recompiler! - author: cottonvibes(@gmail.com) diff --git a/pcsx2/x86/microVU.h b/pcsx2/x86/microVU.h index 9e1c483b62..1a3610136d 100644 --- a/pcsx2/x86/microVU.h +++ b/pcsx2/x86/microVU.h @@ -1,5 +1,5 @@ /* Pcsx2 - Pc Ps2 Emulator - * Copyright (C) 2009 Pcsx2-Playground Team + * Copyright (C) 2009 Pcsx2 Team * * 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 @@ -151,5 +151,6 @@ typedef void (*mVUrecCall)(u32, u32) __attribute__((__fastcall)); // Not sure if #include "microVU_Upper.inl" #include "microVU_Lower.inl" #include "microVU_Tables.inl" +#include "microVU_Flags.inl" #include "microVU_Compile.inl" #include "microVU_Execute.inl" diff --git a/pcsx2/x86/microVU_Alloc.h b/pcsx2/x86/microVU_Alloc.h index 0cd2f4b48e..9dbb5521d1 100644 --- a/pcsx2/x86/microVU_Alloc.h +++ b/pcsx2/x86/microVU_Alloc.h @@ -1,24 +1,23 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once - union regInfo { u32 reg; struct { diff --git a/pcsx2/x86/microVU_Alloc.inl b/pcsx2/x86/microVU_Alloc.inl index 6c9c610f19..cc177f8c4b 100644 --- a/pcsx2/x86/microVU_Alloc.inl +++ b/pcsx2/x86/microVU_Alloc.inl @@ -1,26 +1,26 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU //------------------------------------------------------------------ -// Micro VU - recPass 1 Functions +// Micro VU - Pass 2 Functions //------------------------------------------------------------------ //------------------------------------------------------------------ diff --git a/pcsx2/x86/microVU_Analyze.inl b/pcsx2/x86/microVU_Analyze.inl index ec91ca1fd1..96943fb0e6 100644 --- a/pcsx2/x86/microVU_Analyze.inl +++ b/pcsx2/x86/microVU_Analyze.inl @@ -1,26 +1,26 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU //------------------------------------------------------------------ -// Micro VU - recPass 0 Functions +// Micro VU - Pass 1 Functions //------------------------------------------------------------------ //------------------------------------------------------------------ @@ -51,7 +51,6 @@ microVUt(void) mVUanalyzeFMAC1(int Fd, int Fs, int Ft) { microVU* mVU = mVUx; - //mVUprint("microVU: FMAC1 Opcode"); mVUinfo |= _doStatus; analyzeReg1(Fs); analyzeReg1(Ft); @@ -64,7 +63,6 @@ microVUt(void) mVUanalyzeFMAC1(int Fd, int Fs, int Ft) { microVUt(void) mVUanalyzeFMAC2(int Fs, int Ft) { microVU* mVU = mVUx; - //mVUprint("microVU: FMAC2 Opcode"); analyzeReg1(Fs); analyzeReg2(Ft); } @@ -84,7 +82,6 @@ microVUt(void) mVUanalyzeFMAC2(int Fs, int Ft) { microVUt(void) mVUanalyzeFMAC3(int Fd, int Fs, int Ft) { microVU* mVU = mVUx; - //mVUprint("microVU: FMAC3 Opcode"); mVUinfo |= _doStatus; analyzeReg1(Fs); analyzeReg3(Ft); @@ -115,7 +112,6 @@ microVUt(void) mVUanalyzeFMAC4(int Fs, int Ft) { microVUt(void) mVUanalyzeIALU1(int Id, int Is, int It) { microVU* mVU = mVUx; - //mVUprint("microVU: IALU1 Opcode"); if (!Id) { mVUinfo |= _isNOP; } analyzeVIreg1(Is); analyzeVIreg1(It); @@ -124,7 +120,6 @@ microVUt(void) mVUanalyzeIALU1(int Id, int Is, int It) { microVUt(void) mVUanalyzeIALU2(int Is, int It) { microVU* mVU = mVUx; - //mVUprint("microVU: IALU2 Opcode"); if (!It) { mVUinfo |= _isNOP; } analyzeVIreg1(Is); analyzeVIreg2(It, 1); @@ -211,7 +206,6 @@ microVUt(void) mVUanalyzeMFP(int Ft) { microVUt(void) mVUanalyzeLQ(int Ft, int Is, bool writeIs) { microVU* mVU = mVUx; - //mVUprint("microVU: LQ Opcode"); analyzeVIreg1(Is); analyzeReg2(Ft); if (!Ft) { mVUinfo |= (writeIs && Is) ? _noWriteVF : _isNOP; } diff --git a/pcsx2/x86/microVU_Compile.inl b/pcsx2/x86/microVU_Compile.inl index aeb6660033..0cdfd8e36d 100644 --- a/pcsx2/x86/microVU_Compile.inl +++ b/pcsx2/x86/microVU_Compile.inl @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU @@ -34,20 +34,6 @@ else { ajmp = JMPcc((uptr)0); } \ break -// ToDo: Fix this properly. -#define flagSetMacro(xFlag, pFlag, xF, yF, zF) { \ - yF += (mVUstall > 3) ? 3 : mVUstall; \ - if (yF > zF) { \ - pFlag += (yF-zF); \ - if (pFlag >= xFlag) pFlag = (xFlag-1); \ - zF++; \ - xF = (yF-zF); \ - zF = yF; \ - yF -= xF; \ - } \ - yF++; \ -} - #define startLoop() { mVUdebug1(); mVUstall = 0; memset(&mVUregsTemp, 0, sizeof(mVUregsTemp)); } #define calcCycles(reg, x) { reg = ((reg > x) ? (reg - x) : 0); } #define tCycles(dest, src) { dest = aMax(dest, src); } @@ -59,132 +45,13 @@ // Helper Functions //------------------------------------------------------------------ -// Optimizes out unneeded status flag updates -microVUt(void) mVUstatusFlagOp() { - microVU* mVU = mVUx; - int curPC = iPC; - int i = mVUcount; - bool runLoop = 1; - if (doStatus) { mVUinfo |= _isSflag; } - else { - for (; i > 0; i--) { - incPC2(-2); - if (isSflag) { runLoop = 0; break; } - if (doStatus) { mVUinfo |= _isSflag; break; } - } - } - if (runLoop) { - for (; i > 0; i--) { - incPC2(-2); - if (isSflag) break; - mVUinfo &= ~_doStatus; - } - } - iPC = curPC; -} - -// Note: Flag handling is 'very' complex, it requires full knowledge of how microVU recs work, so don't touch! -microVUt(void) mVUsetFlags(int* bStatus, int* bMac) { - microVU* mVU = mVUx; - - // Ensure last ~4+ instructions update mac flags - int endPC = iPC; - u32 aCount = 1; // Amount of instructions needed to get 4 valid status/mac flag instances - for (int i = mVUcount, iX = 0; i > 0; i--, aCount++) { - if (doStatus) { mVUinfo |= _doMac; iX++; if ((iX >= 4) || (aCount > 4)) { break; } } - incPC2(-2); - } - - // Status/Mac Flags Setup Code - int xStatus = 8, xMac = 8; // Flag Instances start at #0 on every block ((8&3) == 0) - int pStatus = 3, pMac = 3; - int xClip = mVUregs.clip + 8, pClip = mVUregs.clip + 7; // Clip Instance starts from where it left off - int xS = 0, yS = 1, zS = 0; - int xM = 0, yM = 1, zM = 0; - int xC = 0, yC = 1, zC = 0; - u32 xCount = mVUcount; // Backup count - iPC = mVUstartPC; - for (mVUcount = 0; mVUcount < xCount; mVUcount++) { - if (((xCount - mVUcount) > aCount) && isFSSET) mVUstatusFlagOp(); // Don't Optimize out on the last ~4+ instructions - - flagSetMacro(xStatus, pStatus, xS, yS, zS); // Handles _fvsinstances - flagSetMacro(xMac, pMac, xM, yM, zM); // Handles _fvminstances - flagSetMacro(xClip, pClip, xC, yC, zC); // Handles _fvcinstances - - mVUinfo |= (xStatus&3) << 12; // _fsInstance - mVUinfo |= (xMac&3) << 10; // _fmInstance - mVUinfo |= (xClip&3) << 14; // _fcInstance - - mVUinfo |= (pStatus&3) << 18; // _fvsInstance - mVUinfo |= (pMac&3) << 16; // _fvmInstance - mVUinfo |= (pClip&3) << 20; // _fvcInstance - - if (doStatus||isFSSET||doDivFlag) { xStatus = (xStatus+1); } - if (doMac) { xMac = (xMac+1); } - if (doClip) { xClip = (xClip+1); } - incPC2(2); - } - mVUcount = xCount; // Restore count - mVUregs.clip = xClip&3; // Note: Clip timing isn't cycle-accurate between block linking; but hopefully doesn't matter - - // Temp Hack-fix until flag-algorithm rewrite - for (int i = 0; i < 4; i++) { - bStatus[i] = 0; - bMac[i] = 0; - } - - // Setup Last 4 instances of Status/Mac flags (needed for accurate block linking) - iPC = endPC; - for (int i = 3, j = 3, ii = 1, jj = 1; aCount > 0; ii++, jj++, aCount--) { - if ((doStatus||isFSSET||doDivFlag) && (i >= 0)) { - for (; (ii > 0 && i >= 0); i--, ii--) { xStatus = (xStatus-1) & 3; bStatus[i] = xStatus; } - } - if (doMac && (j >= 0)) { - for (; (jj > 0 && j >= 0); j--, jj--) { xMac = (xMac-1) & 3; bMac[j] = xMac; } - } - incPC2(-2); - } - iPC = endPC; -} - -#define getFlagReg1(x) ((x == 3) ? gprF3 : ((x == 2) ? gprF2 : ((x == 1) ? gprF1 : gprF0))) -#define getFlagReg2(x) ((x == bStatus[3]) ? gprESP : ((x == bStatus[2]) ? gprR : ((x == bStatus[1]) ? gprT2 : gprT1))) - // Recompiles Code for Proper Flags and Q/P regs on Block Linkings microVUt(void) mVUsetupBranch(int* bStatus, int* bMac) { microVU* mVU = mVUx; mVUprint("mVUsetupBranch"); - PUSH32R(gprR); // Backup gprR - MOV32RtoM((uptr)&mVU->espBackup, gprESP); - - MOV32RtoR(gprT1, getFlagReg1(bStatus[0])); - MOV32RtoR(gprT2, getFlagReg1(bStatus[1])); - MOV32RtoR(gprR, getFlagReg1(bStatus[2])); - MOV32RtoR(gprESP, getFlagReg1(bStatus[3])); - - MOV32RtoR(gprF0, gprT1); - MOV32RtoR(gprF1, gprT2); - MOV32RtoR(gprF2, gprR); - MOV32RtoR(gprF3, gprESP); - - AND32ItoR(gprT1, 0xffff0000); - AND32ItoR(gprT2, 0xffff0000); - AND32ItoR(gprR, 0xffff0000); - AND32ItoR(gprESP, 0xffff0000); - - AND32ItoR(gprF0, 0x0000ffff); - AND32ItoR(gprF1, 0x0000ffff); - AND32ItoR(gprF2, 0x0000ffff); - AND32ItoR(gprF3, 0x0000ffff); - - OR32RtoR(gprF0, getFlagReg2(bMac[0])); - OR32RtoR(gprF1, getFlagReg2(bMac[1])); - OR32RtoR(gprF2, getFlagReg2(bMac[2])); - OR32RtoR(gprF3, getFlagReg2(bMac[3])); - - MOV32MtoR(gprESP, (uptr)&mVU->espBackup); - POP32R(gprR); // Restore gprR + // Shuffle Flag Instances + mVUsetupFlags(bStatus, bMac); // Shuffle P/Q regs since every block starts at instance #0 if (mVU->p || mVU->q) { SSE2_PSHUFD_XMM_to_XMM(xmmPQ, xmmPQ, shufflePQ); } @@ -238,17 +105,6 @@ microVUt(void) mVUsetCycles() { tCycles(mVUregs.xgkick, mVUregsTemp.xgkick); } -microVUt(void) mVUdivSet() { - microVU* mVU = mVUx; - int flagReg1, flagReg2; - if (doDivFlag) { - getFlagReg(flagReg1, fsInstance); - if (!doStatus) { getFlagReg(flagReg2, fpsInstance); MOV16RtoR(flagReg1, flagReg2); } - AND16ItoR(flagReg1, 0x0fcf); - OR32MtoR (flagReg1, (uptr)&mVU->divFlag); - } -} - microVUt(void) mVUendProgram(int fStatus, int fMac) { microVU* mVU = mVUx; incCycles(100); // Ensures Valid P/Q instances (And sets all cycle data to 0) @@ -289,6 +145,7 @@ microVUt(void) mVUtestCycles() { x86SetJ8(jmp8); SUB32ItoM((uptr)&mVU->cycles, mVUcycles); } + //------------------------------------------------------------------ // Recompiler //------------------------------------------------------------------ @@ -427,7 +284,7 @@ microVUt(void*) __fastcall mVUcompile(u32 startPC, uptr pState) { } } mVUprint("mVUcompile ebit"); - if (x == (vuIndex?(0x3fff/8):(0xfff/8))) { mVUprint("microVU: Possible infinite compiling loop!"); } + if (x == (vuIndex?(0x3fff/8):(0xfff/8))) { Console::Error("microVU%d: Possible infinite compiling loop!", params vuIndex); } // Do E-bit end stuff here mVUendProgram(bStatus[3], bMac[3]); diff --git a/pcsx2/x86/microVU_Execute.inl b/pcsx2/x86/microVU_Execute.inl index b89cf2a29b..aebc97e94a 100644 --- a/pcsx2/x86/microVU_Execute.inl +++ b/pcsx2/x86/microVU_Execute.inl @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU diff --git a/pcsx2/x86/microVU_Flags.inl b/pcsx2/x86/microVU_Flags.inl new file mode 100644 index 0000000000..b42f9cb2c3 --- /dev/null +++ b/pcsx2/x86/microVU_Flags.inl @@ -0,0 +1,175 @@ +/* Pcsx2 - Pc Ps2 Emulator + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#pragma once +#ifdef PCSX2_MICROVU + +// ToDo: Fix this properly. +#define flagSetMacro(xFlag, pFlag, xF, yF, zF) { \ + yF += (mVUstall > 3) ? 3 : mVUstall; \ + if (yF > zF) { \ + pFlag += (yF-zF); \ + if (pFlag >= xFlag) pFlag = (xFlag-1); \ + zF++; \ + xF = (yF-zF); \ + zF = yF; \ + yF -= xF; \ + } \ + yF++; \ +} + +// Sets FDIV Flags at the proper time +microVUt(void) mVUdivSet() { + microVU* mVU = mVUx; + int flagReg1, flagReg2; + if (doDivFlag) { + getFlagReg(flagReg1, fsInstance); + if (!doStatus) { getFlagReg(flagReg2, fpsInstance); MOV16RtoR(flagReg1, flagReg2); } + AND16ItoR(flagReg1, 0x0fcf); + OR32MtoR (flagReg1, (uptr)&mVU->divFlag); + } +} + +// Optimizes out unneeded status flag updates +microVUt(void) mVUstatusFlagOp() { + microVU* mVU = mVUx; + int curPC = iPC; + int i = mVUcount; + bool runLoop = 1; + if (doStatus) { mVUinfo |= _isSflag; } + else { + for (; i > 0; i--) { + incPC2(-2); + if (isSflag) { runLoop = 0; break; } + if (doStatus) { mVUinfo |= _isSflag; break; } + } + } + if (runLoop) { + for (; i > 0; i--) { + incPC2(-2); + if (isSflag) break; + mVUinfo &= ~_doStatus; + } + } + iPC = curPC; +} + +// Note: Flag handling is 'very' complex, it requires full knowledge of how microVU recs work, so don't touch! +microVUt(void) mVUsetFlags(int* bStatus, int* bMac) { + microVU* mVU = mVUx; + + // Ensure last ~4+ instructions update mac flags + int endPC = iPC; + u32 aCount = 1; // Amount of instructions needed to get 4 valid status/mac flag instances + for (int i = mVUcount, iX = 0; i > 0; i--, aCount++) { + if (doStatus) { mVUinfo |= _doMac; iX++; if ((iX >= 4) || (aCount > 4)) { break; } } + incPC2(-2); + } + + // Status/Mac Flags Setup Code + int xStatus = 8, xMac = 8; // Flag Instances start at #0 on every block ((8&3) == 0) + int pStatus = 3, pMac = 3; + int xClip = mVUregs.clip + 8, pClip = mVUregs.clip + 7; // Clip Instance starts from where it left off + int xS = 0, yS = 1, zS = 0; + int xM = 0, yM = 1, zM = 0; + int xC = 0, yC = 1, zC = 0; + u32 xCount = mVUcount; // Backup count + iPC = mVUstartPC; + for (mVUcount = 0; mVUcount < xCount; mVUcount++) { + if (((xCount - mVUcount) > aCount) && isFSSET) mVUstatusFlagOp(); // Don't Optimize out on the last ~4+ instructions + + flagSetMacro(xStatus, pStatus, xS, yS, zS); // Handles _fvsinstances + flagSetMacro(xMac, pMac, xM, yM, zM); // Handles _fvminstances + flagSetMacro(xClip, pClip, xC, yC, zC); // Handles _fvcinstances + + mVUinfo |= (xStatus&3) << 12; // _fsInstance + mVUinfo |= (xMac&3) << 10; // _fmInstance + mVUinfo |= (xClip&3) << 14; // _fcInstance + + mVUinfo |= (pStatus&3) << 18; // _fvsInstance + mVUinfo |= (pMac&3) << 16; // _fvmInstance + mVUinfo |= (pClip&3) << 20; // _fvcInstance + + if (doStatus||isFSSET||doDivFlag) { xStatus = (xStatus+1); } + if (doMac) { xMac = (xMac+1); } + if (doClip) { xClip = (xClip+1); } + incPC2(2); + } + mVUcount = xCount; // Restore count + mVUregs.clip = xClip&3; // Note: Clip timing isn't cycle-accurate between block linking; but hopefully doesn't matter + + // Temp Hack-fix until flag-algorithm rewrite + for (int i = 0; i < 4; i++) { + bStatus[i] = 0; + bMac[i] = 0; + } + + // Setup Last 4 instances of Status/Mac flags (needed for accurate block linking) + iPC = endPC; + for (int i = 3, j = 3, ii = 1, jj = 1; aCount > 0; ii++, jj++, aCount--) { + if ((doStatus||isFSSET||doDivFlag) && (i >= 0)) { + for (; (ii > 0 && i >= 0); i--, ii--) { xStatus = (xStatus-1) & 3; bStatus[i] = xStatus; } + } + if (doMac && (j >= 0)) { + for (; (jj > 0 && j >= 0); j--, jj--) { xMac = (xMac-1) & 3; bMac[j] = xMac; } + } + incPC2(-2); + } + iPC = endPC; +} + +#define getFlagReg1(x) ((x == 3) ? gprF3 : ((x == 2) ? gprF2 : ((x == 1) ? gprF1 : gprF0))) +#define getFlagReg2(x) ((x == bStatus[3]) ? gprESP : ((x == bStatus[2]) ? gprR : ((x == bStatus[1]) ? gprT2 : gprT1))) + +// Recompiles Code for Proper Flags on Block Linkings +microVUt(void) mVUsetupFlags(int* bStatus, int* bMac) { + microVU* mVU = mVUx; + + PUSH32R(gprR); // Backup gprR + MOV32RtoM((uptr)&mVU->espBackup, gprESP); + + MOV32RtoR(gprT1, getFlagReg1(bStatus[0])); + MOV32RtoR(gprT2, getFlagReg1(bStatus[1])); + MOV32RtoR(gprR, getFlagReg1(bStatus[2])); + MOV32RtoR(gprESP, getFlagReg1(bStatus[3])); + + MOV32RtoR(gprF0, gprT1); + MOV32RtoR(gprF1, gprT2); + MOV32RtoR(gprF2, gprR); + MOV32RtoR(gprF3, gprESP); + + AND32ItoR(gprT1, 0xffff0000); + AND32ItoR(gprT2, 0xffff0000); + AND32ItoR(gprR, 0xffff0000); + AND32ItoR(gprESP, 0xffff0000); + + AND32ItoR(gprF0, 0x0000ffff); + AND32ItoR(gprF1, 0x0000ffff); + AND32ItoR(gprF2, 0x0000ffff); + AND32ItoR(gprF3, 0x0000ffff); + + OR32RtoR(gprF0, getFlagReg2(bMac[0])); + OR32RtoR(gprF1, getFlagReg2(bMac[1])); + OR32RtoR(gprF2, getFlagReg2(bMac[2])); + OR32RtoR(gprF3, getFlagReg2(bMac[3])); + + MOV32MtoR(gprESP, (uptr)&mVU->espBackup); + POP32R(gprR); // Restore gprR +} + +#endif //PCSX2_MICROVU \ No newline at end of file diff --git a/pcsx2/x86/microVU_Log.inl b/pcsx2/x86/microVU_Log.inl index 9c05a82317..925001fb48 100644 --- a/pcsx2/x86/microVU_Log.inl +++ b/pcsx2/x86/microVU_Log.inl @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU diff --git a/pcsx2/x86/microVU_Lower.inl b/pcsx2/x86/microVU_Lower.inl index 59cb754961..a995bb9ddd 100644 --- a/pcsx2/x86/microVU_Lower.inl +++ b/pcsx2/x86/microVU_Lower.inl @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU diff --git a/pcsx2/x86/microVU_Misc.h b/pcsx2/x86/microVU_Misc.h index ac79714c6e..e28852b638 100644 --- a/pcsx2/x86/microVU_Misc.h +++ b/pcsx2/x86/microVU_Misc.h @@ -1,5 +1,5 @@ /* Pcsx2 - Pc Ps2 Emulator - * Copyright (C) 2009 Pcsx2-Playground Team + * Copyright (C) 2009 Pcsx2 Team * * 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 @@ -142,10 +142,12 @@ declareAllVariables #define microVUf(aType) template aType #define microVUq(aType) template __forceinline aType +// Define Passes #define pass1 if (recPass == 0) #define pass2 if (recPass == 1) #define pass3 if (recPass == 2) +// Misc Macros... #define mVUcurProg mVU->prog.prog[mVU->prog.cur] #define mVUblocks mVU->prog.prog[mVU->prog.cur].block #define mVUallocInfo mVU->prog.prog[mVU->prog.cur].allocInfo @@ -169,13 +171,8 @@ declareAllVariables #define bSaveAddr (((xPC + (2 * 8)) & ((vuIndex) ? 0x3ff8:0xff8)) / 8) #define branchAddr ((xPC + 8 + (_Imm11_ * 8)) & ((vuIndex) ? 0x3ff8:0xff8)) #define shufflePQ (((mVU->p) ? 0xb0 : 0xe0) | ((mVU->q) ? 0x01 : 0x04)) -#define _Fsf_String ((_Fsf_ == 3) ? "w" : ((_Fsf_ == 2) ? "z" : ((_Fsf_ == 1) ? "y" : "x"))) -#define _Ftf_String ((_Ftf_ == 3) ? "w" : ((_Ftf_ == 2) ? "z" : ((_Ftf_ == 1) ? "y" : "x"))) -#define xyzwStr(x,s) (_X_Y_Z_W == x) ? s : -#define _XYZW_String (xyzwStr(1, "w") (xyzwStr(2, "z") (xyzwStr(3, "zw") (xyzwStr(4, "y") (xyzwStr(5, "yw") (xyzwStr(6, "yz") (xyzwStr(7, "yzw") (xyzwStr(8, "x") (xyzwStr(9, "xw") (xyzwStr(10, "xz") (xyzwStr(11, "xzw") (xyzwStr(12, "xy") (xyzwStr(13, "xyw") (xyzwStr(14, "xyz") "xyzw")))))))))))))) -#define _BC_String (_bc_x ? "x" : (_bc_y ? "y" : (_bc_z ? "z" : "w"))) - +// Pass 1 uses these to set mVUinfo #define _isNOP (1<<0) // Skip Lower Instruction #define _isBranch (1<<1) // Cur Instruction is a Branch #define _isEOB (1<<2) // End of Block @@ -206,7 +203,7 @@ declareAllVariables #define _doClip (1<<29) #define _noWriteVF (1<<30) // Don't write back the result of a lower op to VF reg if upper op writes to same reg (or if VF = 0) - +// Pass 2 uses these to read mVUinfo #define isNOP (mVUinfo & (1<<0)) #define isBranch (mVUinfo & (1<<1)) #define isEOB (mVUinfo & (1<<2)) @@ -237,9 +234,26 @@ declareAllVariables #define doClip (mVUinfo & (1<<29)) #define noWriteVF (mVUinfo & (1<<30)) -#define isMMX(_VIreg_) 0//(_VIreg_ >= 1 && _VIreg_ <=8) +// Pass 3 Helper Macros +#define _Fsf_String ((_Fsf_ == 3) ? "w" : ((_Fsf_ == 2) ? "z" : ((_Fsf_ == 1) ? "y" : "x"))) +#define _Ftf_String ((_Ftf_ == 3) ? "w" : ((_Ftf_ == 2) ? "z" : ((_Ftf_ == 1) ? "y" : "x"))) +#define xyzwStr(x,s) (_X_Y_Z_W == x) ? s : +#define _XYZW_String (xyzwStr(1, "w") (xyzwStr(2, "z") (xyzwStr(3, "zw") (xyzwStr(4, "y") (xyzwStr(5, "yw") (xyzwStr(6, "yz") (xyzwStr(7, "yzw") (xyzwStr(8, "x") (xyzwStr(9, "xw") (xyzwStr(10, "xz") (xyzwStr(11, "xzw") (xyzwStr(12, "xy") (xyzwStr(13, "xyw") (xyzwStr(14, "xyz") "xyzw")))))))))))))) +#define _BC_String (_bc_x ? "x" : (_bc_y ? "y" : (_bc_z ? "z" : "w"))) +#define mVUlogFtFs() { mVUlog(".%s vf%02d, vf%02d", _XYZW_String, _Ft_, _Fs_); } +#define mVUlogFd() { mVUlog(".%s vf%02d, vf%02d", _XYZW_String, _Fd_, _Fs_); } +#define mVUlogACC() { mVUlog(".%s ACC, vf%02d", _XYZW_String, _Fs_); } +#define mVUlogFt() { mVUlog(", vf%02d", _Ft_); } +#define mVUlogBC() { mVUlog(", vf%02d%s", _Ft_, _BC_String); } +#define mVUlogI() { mVUlog(", I"); } +#define mVUlogQ() { mVUlog(", Q"); } +#define mVUlogCLIP() { mVUlog("w.xyz vf%02d, vf%02dw", _Fs_, _Ft_); } + +// Store VI regs in mmx regs? +#define isMMX(_VIreg_) 0 //(_VIreg_ >= 1 && _VIreg_ <=8) #define mmVI(_VIreg_) (_VIreg_ - 1) +// Debug Stuff... #ifdef mVUdebug #define mVUprint Console::Status #define mVUdebug1() { \ @@ -254,6 +268,7 @@ declareAllVariables #define mVUdebug1() {} #endif +// Program Logging... #ifdef mVUlogProg #define mVUlog __mVULog #define mVUdumpProg __mVUdumpProgram @@ -262,6 +277,7 @@ declareAllVariables #define mVUdumpProg 0&& #endif +// Cache Limit Check #define mVUcacheCheck(ptr, start, limit) { \ uptr diff = ptr - start; \ if (diff >= limit) { Console::Error("microVU Error: Program went over its cache limit. Size = 0x%x", params diff); } \ diff --git a/pcsx2/x86/microVU_Misc.inl b/pcsx2/x86/microVU_Misc.inl index 48c91520e7..cdd08254e9 100644 --- a/pcsx2/x86/microVU_Misc.inl +++ b/pcsx2/x86/microVU_Misc.inl @@ -1,5 +1,5 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team +* Copyright (C) 2009 Pcsx2 Team * * 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 diff --git a/pcsx2/x86/microVU_Tables.inl b/pcsx2/x86/microVU_Tables.inl index 26dc6ea8cd..fc4b0b8852 100644 --- a/pcsx2/x86/microVU_Tables.inl +++ b/pcsx2/x86/microVU_Tables.inl @@ -1,20 +1,20 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team -* -* 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; either version 2 of the License, or -* (at your option) any later version. -* -* 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 for more details. -* -* You should have meived a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Copyright (C) 2009 Pcsx2 Team + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ #pragma once #ifdef PCSX2_MICROVU diff --git a/pcsx2/x86/microVU_Upper.inl b/pcsx2/x86/microVU_Upper.inl index f265db53a9..f22a08cf8f 100644 --- a/pcsx2/x86/microVU_Upper.inl +++ b/pcsx2/x86/microVU_Upper.inl @@ -1,5 +1,5 @@ /* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2009 Pcsx2-Playground Team +* Copyright (C) 2009 Pcsx2 Team * * 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 @@ -15,6 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ + #pragma once #ifdef PCSX2_MICROVU @@ -78,15 +79,6 @@ microVUt(void) mVUupdateFlags(int reg, int regT1, int regT2, int xyzw, bool modX // Helper Macros //------------------------------------------------------------------ -#define mVUlogFtFs() { mVUlog(".%s vf%02d, vf%02d", _XYZW_String, _Ft_, _Fs_); } -#define mVUlogFd() { mVUlog(".%s vf%02d, vf%02d", _XYZW_String, _Fd_, _Fs_); } -#define mVUlogACC() { mVUlog(".%s ACC, vf%02d", _XYZW_String, _Fs_); } -#define mVUlogFt() { mVUlog(", vf%02d", _Ft_); } -#define mVUlogBC() { mVUlog(", vf%02d%s", _Ft_, _BC_String); } -#define mVUlogI() { mVUlog(", I"); } -#define mVUlogQ() { mVUlog(", Q"); } -#define mVUlogCLIP() { mVUlog("w.xyz vf%02d, vf%02dw", _Fs_, _Ft_); } - // FMAC1 - Normal FMAC Opcodes #define mVU_FMAC1(operation, OPname) { \ microVU* mVU = mVUx; \