diff --git a/pcsx2/VU.h b/pcsx2/VU.h index 39b1abaec7..fb9602afe7 100644 --- a/pcsx2/VU.h +++ b/pcsx2/VU.h @@ -16,9 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __VU_H__ -#define __VU_H__ - +#pragma once #include "Vif.h" #define REG_STATUS_FLAG 16 @@ -205,5 +203,3 @@ static __forceinline u32* GET_VU_MEM(VURegs* VU, u32 addr) #define VUFIX_EXTRAFLAGS 2 #define VUFIX_XGKICKDELAY2 4 extern int g_VUGameFixes; - -#endif /* __VU_H__ */ diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index 1fe93931fb..aac657e3e9 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -2421,10 +2421,30 @@ RelativePath="..\..\x86\microVU.h" > + + + + + + + + + + diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index e89e5a05eb..c4fdcd3268 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -65,7 +65,7 @@ microVUt(void) mVUreset() { if ( mVU->cache == NULL ) throw Exception::OutOfMemory(fmt_string( "microVU Error: failed to allocate recompiler memory! (addr: 0x%x)", params (u32)mVU->cache)); // Other Variables - ZeroMemory(&mVU->prog, sizeof(mVU->prog)); + memset(&mVU->prog, 0, sizeof(mVU->prog)); mVU->prog.finished = 1; mVU->prog.cleared = 1; mVU->prog.cur = -1; @@ -221,7 +221,7 @@ __declspec(naked) void __fastcall startVU0(u32 startPC, u32 cycles) { push edi; ldmxcsr g_sseVUMXCSR - + /* Should set xmmZ? */ jmp eax } } diff --git a/pcsx2/x86/microVU.h b/pcsx2/x86/microVU.h index 541581018a..e70a6d0048 100644 --- a/pcsx2/x86/microVU.h +++ b/pcsx2/x86/microVU.h @@ -19,6 +19,8 @@ #pragma once #include "Common.h" #include "VU.h" +#include "microVU_Misc.h" +#include "microVU_Alloc.h" #include "microVU_Tables.h" //#include @@ -82,8 +84,8 @@ template struct microProgram { u8 data[progSize]; u32 used; // Number of times its been used - //int cached; // Has been Cached? (can be omitted because every new program will be cached?) microBlockManager* block[progSize]; + microAllocInfo allocInfo; }; #define mMaxProg 16 // The amount of Micro Programs Recs will 'remember' (For n = 1, 2, 4, 8, 16, etc...) @@ -121,22 +123,10 @@ struct microVU { microProgManager<0x800> prog; // Micro Program Data }; -// Template Stuff -#define mVUx (vuIndex ? µVU1 : µVU0) -#define microVUt(aType) template __forceinline aType - // Opcode Tables extern void (*mVU_UPPER_OPCODE[64])( VURegs* VU, s32 info ); extern void (*mVU_LOWER_OPCODE[128])( VURegs* VU, s32 info ); -//void invalidateBlocks(u32 addr, u32 size); // Invalidates Blocks in the range [addr, addr+size) -//__forceinline void mVUinit(microVU* mVU, VURegs* vuRegsPtr, const int vuIndex); -//__forceinline void mVUreset(microVU* mVU); -//__forceinline void mVUclose(microVU* mVU); -//__forceinline void mVUclear(microVU* mVU, u32 addr, u32 size); // Clears part of a Micro Program (must use before modifying micro program!) -//void* mVUexecute(microVU* mVU, u32 startPC, u32 cycles); // Recompiles/Executes code for the number of cycles indicated (will always run for >= 'cycles' amount unless 'finished') -//void* mVUexecuteF(microVU* mVU, u32 startPC); // Recompiles/Executes code till finished - __forceinline void mVUclearProg(microVU* mVU, int progIndex); __forceinline int mVUfindLeastUsedProg(microVU* mVU); __forceinline int mVUsearchProg(microVU* mVU); diff --git a/pcsx2/x86/microVU_Alloc.cpp b/pcsx2/x86/microVU_Alloc.cpp new file mode 100644 index 0000000000..1d256e1bb2 --- /dev/null +++ b/pcsx2/x86/microVU_Alloc.cpp @@ -0,0 +1,61 @@ +/* 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 +*/ + +#include "PrecompiledHeader.h" +#include "microVU.h" +#ifdef PCSX2_MICROVU + +extern PCSX2_ALIGNED16(microVU microVU0); +extern PCSX2_ALIGNED16(microVU microVU1); + +//------------------------------------------------------------------ +// Micro VU - recPass 0 Functions +//------------------------------------------------------------------ + +//------------------------------------------------------------------ +// Micro VU - recPass 1 Functions +//------------------------------------------------------------------ +/* +#define setFd (mVU->prog.prog[mVU->prog.cur].allocInfo.info[pc] & (1<<7)) +#define getFd (mVU->prog.prog[mVU->prog.cur].allocInfo.info[pc] & (1<<1)) +#define getFs (mVU->prog.prog[mVU->prog.cur].allocInfo.info[pc] & (1<<2)) +#define getFt (mVU->prog.prog[mVU->prog.cur].allocInfo.info[pc] & (1<<3)) +*/ +#define makeFdFd (makeFd == 0) +#define makeFdFs (makeFd == 1) +#define makeFdFt (makeFd == 2) + +microVUt(void) mVUallocFMAC1a(u32 code, int& Fd, int& Fs, int& Ft, const int makeFd) { + microVU* mVU = mVUx; + if (_Fs_ == 0) { Fs = xmmZ; } else { Fs = xmmFs; } + if (_Ft_ == 0) { Ft = xmmZ; } else { Ft = xmmFt; } + if (makeFdFd) {Fd = xmmFd} + else if (makeFdFs) {Fd = Fs} + else if (makeFdFt) {Fd = Ft} + + if (_Fs_) SSE_MOVAPS_M128_to_XMM(Fs, (uptr)&mVU->regs->VF[_Fs_].UL[0]); + if (_Ft_ == _Ft_) SSE_MOVAPS_M128_to_XMM(Ft, (uptr)&mVU->regs->VF[_Ft_].UL[0]); +} + +microVUt(void) mVUallocFMAC1b(u32 code, u32 pc, int& Fd) { + microVU* mVU = mVUx; + if (_Fd_ == 0) return; + else mVUsaveReg(code, Fd, (uptr)&mVU->regs->VF[_Fd_].UL[0]); +} + +#endif //PCSX2_MICROVU diff --git a/pcsx2/x86/microVU_Alloc.h b/pcsx2/x86/microVU_Alloc.h new file mode 100644 index 0000000000..c79c2e9ec2 --- /dev/null +++ b/pcsx2/x86/microVU_Alloc.h @@ -0,0 +1,49 @@ +/* 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 +*/ + +#pragma once + +union regInfo { + u32 reg; + struct { + u8 x; + u8 y; + u8 z; + u8 w; + }; +}; + +template +struct microAllocInfo { + regInfo VF[32]; + regInfo Acc; + u8 VI[32]; + u8 i; + u8 q; + u8 p; + u8 r; + u16 info[pSize];// bit 0 = NOP? + // bit 1 = Read Fd from backup memory? + // bit 2 = Read Fs from backup memory? + // bit 3 = Read Ft from backup memory? + // bit 4 = ACC1 or ACC2? + // bit 5 = Read Q1/P1 or backup? + // bit 6 = Write to Q2/P2? + // bit 7 = Write Fd/Acc to backup memory? + u32 curPC; +}; diff --git a/pcsx2/x86/microVU_Compile.cpp b/pcsx2/x86/microVU_Compile.cpp new file mode 100644 index 0000000000..388f4c01d4 --- /dev/null +++ b/pcsx2/x86/microVU_Compile.cpp @@ -0,0 +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 +*/ + +#include "PrecompiledHeader.h" +#include "microVU.h" +#ifdef PCSX2_MICROVU + +extern PCSX2_ALIGNED16(microVU microVU0); +extern PCSX2_ALIGNED16(microVU microVU1); + +#endif //PCSX2_MICROVU \ No newline at end of file diff --git a/pcsx2/x86/microVU_Misc.cpp b/pcsx2/x86/microVU_Misc.cpp new file mode 100644 index 0000000000..85833f09ef --- /dev/null +++ b/pcsx2/x86/microVU_Misc.cpp @@ -0,0 +1,105 @@ +/* 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 +*/ + +#include "PrecompiledHeader.h" +#include "microVU.h" +#ifdef PCSX2_MICROVU + +extern PCSX2_ALIGNED16(microVU microVU0); +extern PCSX2_ALIGNED16(microVU microVU1); + +//------------------------------------------------------------------ +// Micro VU - Misc Functions +//------------------------------------------------------------------ + +microVUx(void) mVUsaveReg(u32 code, int reg, u32 offset) { + switch ( _X_Y_Z_W ) { + case 1: // W + //SSE2_PSHUFD_XMM_to_XMM(xmmT1, reg, 0x27); + //SSE_MOVSS_XMM_to_M32(offset+12, xmmT1); + SSE_MOVSS_XMM_to_M32(offset+12, reg); + break; + case 2: // Z + //SSE_MOVHLPS_XMM_to_XMM(xmmT1, reg); + //SSE_MOVSS_XMM_to_M32(offset+8, xmmT1); + SSE_MOVSS_XMM_to_M32(offset+8, reg); + break; + case 3: // ZW + SSE_MOVHPS_XMM_to_M64(offset+8, reg); + break; + case 4: // Y + //SSE2_PSHUFLW_XMM_to_XMM(xmmT1, reg, 0x4e); + //SSE_MOVSS_XMM_to_M32(offset+4, xmmT1); + SSE_MOVSS_XMM_to_M32(offset+4, reg); + break; + case 5: // YW + SSE_SHUFPS_XMM_to_XMM(reg, reg, 0xB1); + SSE_MOVHLPS_XMM_to_XMM(xmmT1, reg); + SSE_MOVSS_XMM_to_M32(offset+4, reg); + SSE_MOVSS_XMM_to_M32(offset+12, xmmT1); + SSE_SHUFPS_XMM_to_XMM(reg, reg, 0xB1); + break; + case 6: // YZ + SSE2_PSHUFD_XMM_to_XMM(xmmT1, reg, 0xc9); + SSE_MOVLPS_XMM_to_M64(offset+4, xmmT1); + break; + case 7: // YZW + SSE2_PSHUFD_XMM_to_XMM(xmmT1, reg, 0x93); //ZYXW + SSE_MOVHPS_XMM_to_M64(offset+4, xmmT1); + SSE_MOVSS_XMM_to_M32(offset+12, xmmT1); + break; + case 8: // X + SSE_MOVSS_XMM_to_M32(offset, reg); + break; + case 9: // XW + SSE_MOVHLPS_XMM_to_XMM(xmmT1, reg); + SSE_MOVSS_XMM_to_M32(offset, reg); + if ( cpucaps.hasStreamingSIMD3Extensions ) SSE3_MOVSLDUP_XMM_to_XMM(xmmT1, xmmT1); + else SSE_SHUFPS_XMM_to_XMM(xmmT1, xmmT1, 0x55); + SSE_MOVSS_XMM_to_M32(offset+12, xmmT1); + break; + case 10: //XZ + SSE_MOVHLPS_XMM_to_XMM(xmmT1, reg); + SSE_MOVSS_XMM_to_M32(offset, reg); + SSE_MOVSS_XMM_to_M32(offset+8, xmmT1); + break; + case 11: //XZW + SSE_MOVSS_XMM_to_M32(offset, reg); + SSE_MOVHPS_XMM_to_M64(offset+8, reg); + break; + case 12: // XY + SSE_MOVLPS_XMM_to_M64(offset, reg); + break; + case 13: // XYW + SSE2_PSHUFD_XMM_to_XMM(xmmT1, reg, 0x4b); //YXZW + SSE_MOVHPS_XMM_to_M64(offset, xmmT1); + SSE_MOVSS_XMM_to_M32(offset+12, xmmT1); + break; + case 14: // XYZ + SSE_MOVHLPS_XMM_to_XMM(xmmT1, reg); + SSE_MOVLPS_XMM_to_M64(offset, reg); + SSE_MOVSS_XMM_to_M32(offset+8, xmmT1); + break; + case 15: // XYZW + if( offset & 15 ) SSE_MOVUPS_XMM_to_M128(offset, reg); + else SSE_MOVAPS_XMM_to_M128(offset, reg); + break; + } +} + +#endif //PCSX2_MICROVU \ No newline at end of file diff --git a/pcsx2/x86/microVU_Misc.h b/pcsx2/x86/microVU_Misc.h new file mode 100644 index 0000000000..111c654a48 --- /dev/null +++ b/pcsx2/x86/microVU_Misc.h @@ -0,0 +1,75 @@ +/* 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 +*/ + +#pragma once + +//------------------------------------------------------------------ +// Helper Macros +//------------------------------------------------------------------ +#define _Ft_ ((code >> 16) & 0x1F) // The rt part of the instruction register +#define _Fs_ ((code >> 11) & 0x1F) // The rd part of the instruction register +#define _Fd_ ((code >> 6) & 0x1F) // The sa part of the instruction register + +#define _X ((code>>24) & 0x1) +#define _Y ((code>>23) & 0x1) +#define _Z ((code>>22) & 0x1) +#define _W ((code>>21) & 0x1) + +#define _XYZW_SS (_X+_Y+_Z+_W==1) + +#define _X_Y_Z_W (((code >> 21 ) & 0xF ) ) + +#define _Fsf_ ((code >> 21) & 0x03) +#define _Ftf_ ((code >> 23) & 0x03) + +#define _Imm11_ (s32)(code & 0x400 ? 0xfffffc00 | (code & 0x3ff) : code & 0x3ff) +#define _UImm11_ (s32)(code & 0x7ff) +/* +#define VU_VFx_ADDR(x) (uptr)&VU->VF[x].UL[0] +#define VU_VFy_ADDR(x) (uptr)&VU->VF[x].UL[1] +#define VU_VFz_ADDR(x) (uptr)&VU->VF[x].UL[2] +#define VU_VFw_ADDR(x) (uptr)&VU->VF[x].UL[3] + +#define VU_REGR_ADDR (uptr)&VU->VI[REG_R] +#define VU_REGQ_ADDR (uptr)&VU->VI[REG_Q] +#define VU_REGMAC_ADDR (uptr)&VU->VI[REG_MAC_FLAG] + +#define VU_VI_ADDR(x, read) GetVIAddr(VU, x, read, info) + +#define VU_ACCx_ADDR (uptr)&VU->ACC.UL[0] +#define VU_ACCy_ADDR (uptr)&VU->ACC.UL[1] +#define VU_ACCz_ADDR (uptr)&VU->ACC.UL[2] +#define VU_ACCw_ADDR (uptr)&VU->ACC.UL[3] +*/ + +#define xmmT1 0 // XMM0 +#define xmmFd 1 // XMM1 +#define xmmFs 2 // XMM2 +#define xmmFt 3 // XMM3 +#define xmmACC1 4 // XMM4 +#define xmmACC2 5 // XMM5 +#define xmmPQ 6 // XMM6 +#define xmmZ 7 // XMM7 + +// Template Stuff +#define mVUx (vuIndex ? µVU1 : µVU0) +#define microVUt(aType) template __forceinline aType +#define microVUx(aType) template aType +#define microVUf(aType) template aType + +microVUx(void) mVUsaveReg(u32 code, int reg, u32 offset); diff --git a/pcsx2/x86/microVU_Tables.h b/pcsx2/x86/microVU_Tables.h index 8071a30768..e0de1455e6 100644 --- a/pcsx2/x86/microVU_Tables.h +++ b/pcsx2/x86/microVU_Tables.h @@ -18,8 +18,6 @@ #pragma once -#define microVUf(aType) template aType - //------------------------------------------------------------------ // Micro VU Micromode Upper instructions //------------------------------------------------------------------ diff --git a/pcsx2/x86/microVU_Upper.cpp b/pcsx2/x86/microVU_Upper.cpp index 1c71a6374a..6a2ae14706 100644 --- a/pcsx2/x86/microVU_Upper.cpp +++ b/pcsx2/x86/microVU_Upper.cpp @@ -40,9 +40,9 @@ xmmT1 = xmm0 xmmFd = xmm1 xmmFs = xmm2 xmmFt = xmm3 -xmmAcc = xmm4 -xmmT2 = xmm5 -xmmT3 = xmm6 +xmmACC1 = xmm4 +xmmACC2 = xmm5 +xmmPQ = xmm6 xmmZ = xmm7 Most of the time the above mapping will be true, unless I find a reason not to do it this way :) @@ -77,7 +77,10 @@ have an idea of how things work. Right now its all theoretical and I'll change t //------------------------------------------------------------------ microVUf(void) mVU_ABS(){} -microVUf(void) mVU_ADD(){} +microVUf(void) mVU_ADD(){ + if (recPass == 0) {} + else {} +} microVUf(void) mVU_ADDi(){} microVUf(void) mVU_ADDq(){} microVUf(void) mVU_ADDx(){}