From 2698b3da1b881e32829a217d0db8f899df6fdf77 Mon Sep 17 00:00:00 2001 From: cottonvibes Date: Sun, 24 Jan 2010 22:04:49 +0000 Subject: [PATCH] Created the macro "memcpy_const" for memcpy's with constant sizes, and set pcsx2 to use it where applicable... currently just uses memcpy_amd internally... Also some minor mVU compiler optimizations. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2515 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Utilities/MemcpyFast.h | 6 ++++-- pcsx2/CDVD/CDVD.cpp | 2 +- pcsx2/x86/iVU1micro.cpp | 16 ++++++++-------- pcsx2/x86/ix86-32/iR5900-32.cpp | 8 ++++---- pcsx2/x86/microVU.cpp | 3 ++- pcsx2/x86/microVU.h | 6 +++--- pcsx2/x86/microVU_Branch.inl | 4 ++-- pcsx2/x86/microVU_Compile.inl | 8 +++++--- pcsx2/x86/newVif_HashBucket.h | 2 +- 9 files changed, 30 insertions(+), 25 deletions(-) diff --git a/common/include/Utilities/MemcpyFast.h b/common/include/Utilities/MemcpyFast.h index 0ae3427e18..3e03ab08e2 100644 --- a/common/include/Utilities/MemcpyFast.h +++ b/common/include/Utilities/MemcpyFast.h @@ -36,5 +36,7 @@ // Only used in the Windows version of memzero.h. But it's in Misc.cpp for some reason. void _memset16_unaligned( void* dest, u16 data, size_t size ); -#define memcpy_fast memcpy_amd_ -#define memcpy_aligned memcpy_amd_ +#define memcpy_fast memcpy_amd_ // Fast memcpy +#define memcpy_aligned memcpy_amd_ // Memcpy with 16-byte Aligned addresses +#define memcpy_const memcpy_amd_ // Memcpy with constant size +#define memcpy_constA memcpy_amd_ // Memcpy with constant size and 16-byte aligned diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index 100cb70cfb..2ef8ec0466 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -642,7 +642,7 @@ int cdvdReadSector() { mdest[11] = 0; // normal 2048 bytes of sector data - memcpy_fast( &mdest[12], cdr.Transfer, 2048); + memcpy_const(&mdest[12], cdr.Transfer, 2048); // 4 bytes of edc (not calculated at present) mdest[2060] = 0; diff --git a/pcsx2/x86/iVU1micro.cpp b/pcsx2/x86/iVU1micro.cpp index 11c6553b9d..8e4a999283 100644 --- a/pcsx2/x86/iVU1micro.cpp +++ b/pcsx2/x86/iVU1micro.cpp @@ -130,17 +130,17 @@ namespace VU1micro XMMRegisters::Freeze(); runCount++; - memcpy_fast((u8*)backVUregs, (u8*)&VU1, sizeof(VURegs)); - memcpy_fast((u8*)backVUmem, (u8*)VU1.Mem, 0x4000); + memcpy_const((u8*)backVUregs, (u8*)&VU1, sizeof(VURegs)); + memcpy_const((u8*)backVUmem, (u8*)VU1.Mem, 0x4000); do { // while loop needed since not always will return finished SuperVUExecuteProgram(VU1.VI[ REG_TPC ].UL & 0x3fff, 1); } while( VU0.VI[ REG_VPU_STAT ].UL&0x100 ); - memcpy_fast((u8*)cmpVUregs, (u8*)&VU1, sizeof(VURegs)); - memcpy_fast((u8*)cmpVUmem, (u8*)VU1.Mem, 0x4000); - memcpy_fast((u8*)&VU1, (u8*)backVUregs, sizeof(VURegs)); - memcpy_fast((u8*)VU1.Mem, (u8*)backVUmem, 0x4000); + memcpy_const((u8*)cmpVUregs, (u8*)&VU1, sizeof(VURegs)); + memcpy_const((u8*)cmpVUmem, (u8*)VU1.Mem, 0x4000); + memcpy_const((u8*)&VU1, (u8*)backVUregs, sizeof(VURegs)); + memcpy_const((u8*)VU1.Mem, (u8*)backVUmem, 0x4000); //Currently breaking mVU execution is disabled. Check mVUtestCycles() in microVU_Compile.inl runVUrec(VU1.VI[REG_TPC].UL, 300000 /*0x7fffffff*/, 1); @@ -231,8 +231,8 @@ namespace VU1micro if (mVUdebugNow) { resetVUrec(1); - memcpy_fast((u8*)&VU1, (u8*)backVUregs, sizeof(VURegs)); - memcpy_fast((u8*)VU1.Mem, (u8*)backVUmem, 0x4000); + memcpy_const((u8*)&VU1, (u8*)backVUregs, sizeof(VURegs)); + memcpy_const((u8*)VU1.Mem, (u8*)backVUmem, 0x4000); runVUrec(VU1.VI[REG_TPC].UL, 300000 /*0x7fffffff*/, 1); diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index bf4f1bdf25..79a1eebe3c 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -965,8 +965,8 @@ void SaveBranchState() s_saveRegHasSignExt = g_cpuRegHasSignExt; // save all mmx regs - memcpy_fast(s_saveMMXregs, mmxregs, sizeof(mmxregs)); - memcpy_fast(s_saveXMMregs, xmmregs, sizeof(xmmregs)); + memcpy_const(s_saveMMXregs, mmxregs, sizeof(mmxregs)); + memcpy_const(s_saveXMMregs, xmmregs, sizeof(xmmregs)); } void LoadBranchState() @@ -982,8 +982,8 @@ void LoadBranchState() g_cpuRegHasSignExt = g_cpuPrevRegHasSignExt = s_saveRegHasSignExt; // restore all mmx regs - memcpy_fast(mmxregs, s_saveMMXregs, sizeof(mmxregs)); - memcpy_fast(xmmregs, s_saveXMMregs, sizeof(xmmregs)); + memcpy_const(mmxregs, s_saveMMXregs, sizeof(mmxregs)); + memcpy_const(xmmregs, s_saveXMMregs, sizeof(xmmregs)); } void iFlushCall(int flushtype) diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index c43d5cb205..c29b2c0620 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -201,7 +201,8 @@ microVUf(void) mVUclearProg(int progIndex) { // Caches Micro Program microVUf(void) mVUcacheProg(int progIndex) { microVU* mVU = mVUx; - memcpy_fast(mVU->prog.prog[progIndex].data, mVU->regs->Micro, mVU->microMemSize); + if (!vuIndex) memcpy_const(mVU->prog.prog[progIndex].data, mVU->regs->Micro, 0x1000); + else memcpy_const(mVU->prog.prog[progIndex].data, mVU->regs->Micro, 0x4000); mVUdumpProg(progIndex); } diff --git a/pcsx2/x86/microVU.h b/pcsx2/x86/microVU.h index 7ed3aaf97c..0d68db6d7d 100644 --- a/pcsx2/x86/microVU.h +++ b/pcsx2/x86/microVU.h @@ -62,9 +62,9 @@ public: listI++; blockEnd->block = (microBlock*)_aligned_malloc(sizeof(microBlock), 16); blockEnd->next = new microBlockLink; - memcpy_fast(blockEnd->block, pBlock, sizeof(microBlock)); - thisBlock = blockEnd->block; - blockEnd = blockEnd->next; + memcpy_const(blockEnd->block, pBlock, sizeof(microBlock)); + thisBlock = blockEnd->block; + blockEnd = blockEnd->next; } return thisBlock; } diff --git a/pcsx2/x86/microVU_Branch.inl b/pcsx2/x86/microVU_Branch.inl index 6df70a9154..e3c5d0b662 100644 --- a/pcsx2/x86/microVU_Branch.inl +++ b/pcsx2/x86/microVU_Branch.inl @@ -98,7 +98,7 @@ void normBranchCompile(microVU* mVU, u32 branchPC) { } void normJumpCompile(mV, microFlagCycles& mFC, bool isEvilJump) { - memcpy_fast(&mVUpBlock->pStateEnd, &mVUregs, sizeof(microRegInfo)); + memcpy_const(&mVUpBlock->pStateEnd, &mVUregs, sizeof(microRegInfo)); mVUsetupBranch(mVU, mFC); mVUbackupRegs(mVU); @@ -155,7 +155,7 @@ void condBranch(mV, microFlagCycles& mFC, int JMPcc) { s32* ajmp = xJcc32((JccComparisonType)JMPcc); u32 bPC = iPC; // mVUcompile can modify iPC, mVUpBlock, and mVUregs so back them up microBlock* pBlock = mVUpBlock; - memcpy_fast(&pBlock->pStateEnd, &mVUregs, sizeof(microRegInfo)); + memcpy_const(&pBlock->pStateEnd, &mVUregs, sizeof(microRegInfo)); incPC2(1); // Get PC for branch not-taken mVUcompile(mVU, xPC, (uptr)&mVUregs); diff --git a/pcsx2/x86/microVU_Compile.inl b/pcsx2/x86/microVU_Compile.inl index 3b7ffb4e04..0913be1faa 100644 --- a/pcsx2/x86/microVU_Compile.inl +++ b/pcsx2/x86/microVU_Compile.inl @@ -110,8 +110,8 @@ microVUt(void) startLoop(mV) { if (curI & _Mbit_) { Console.WriteLn(Color_Green, "microVU%d: M-bit set!", getIndex); } if (curI & _Dbit_) { DevCon.WriteLn (Color_Green, "microVU%d: D-bit set!", getIndex); } if (curI & _Tbit_) { DevCon.WriteLn (Color_Green, "microVU%d: T-bit set!", getIndex); } - memset(&mVUinfo, 0, sizeof(mVUinfo)); - memset(&mVUregsTemp, 0, sizeof(mVUregsTemp)); + memzero(mVUinfo); + memzero(mVUregsTemp); } microVUt(void) doIbit(mV) { @@ -316,7 +316,9 @@ microVUt(void) mVUinitFirstPass(microVU* mVU, uptr pState, u8* thisPtr) { mVUcycles = 0; // Skips "M" phase, and starts counting cycles at "T" stage mVU->p = 0; // All blocks start at p index #0 mVU->q = 0; // All blocks start at q index #0 - memcpy_fast(&mVUregs, (microRegInfo*)pState, sizeof(microRegInfo)); // Loads up Pipeline State Info + if ((uptr)&mVUregs != pState) { // Loads up Pipeline State Info + memcpy_const(&mVUregs, (microRegInfo*)pState, sizeof(microRegInfo)); + } mVUblock.x86ptrStart = thisPtr; mVUpBlock = mVUblocks[mVUstartPC/2]->add(&mVUblock); // Add this block to block manager mVUregs.blockType = 0; diff --git a/pcsx2/x86/newVif_HashBucket.h b/pcsx2/x86/newVif_HashBucket.h index bd0daccbbb..d55a98132f 100644 --- a/pcsx2/x86/newVif_HashBucket.h +++ b/pcsx2/x86/newVif_HashBucket.h @@ -87,7 +87,7 @@ public: wxEmptyString ); } - memcpy_fast(&bucket.Chain[bucket.Size++], &dataPtr, sizeof(T)); + memcpy_const(&bucket.Chain[bucket.Size++], &dataPtr, sizeof(T)); } void clear() { for (int i = 0; i < hSize; i++) {