diff --git a/common/include/Utilities/PageFaultSource.h b/common/include/Utilities/PageFaultSource.h index fc4e88ce4d..fa6a8ab6b8 100644 --- a/common/include/Utilities/PageFaultSource.h +++ b/common/include/Utilities/PageFaultSource.h @@ -266,72 +266,6 @@ protected: virtual void CommitBlocks( uptr page, uint blocks ); }; -// -------------------------------------------------------------------------------------- -// SpatialArrayReserve -// -------------------------------------------------------------------------------------- -// A spatial array is one where large areas of the memory reserve will remain unused during -// process execution. Only areas put to use will be committed to virtual memory. -// -// Spatial array efficiency depends heavily on selecting the right parameters for the array's -// primary intended use. Memory in a spatial array is arranged by blocks, with each block -// containing some number of pages (pages are 4096 bytes each on most platforms). When the -// array is accessed, the entire block containing the addressed memory will be committed at -// once. Blocks can be a single page in size (4096 bytes), though this is highly discouraged -// due to overhead and fragmentation penalties. -// -// Balancing block sizes: -// Larger blocks are good for reducing memory fragmentation and block-tracking overhead, but -// can also result in a lot of otherwise unused memory being committed to memory. Smaller -// blocks are good for arrays that will tend toward more sequential behavior, as they reduce -// the amount of unused memory being committed. However, since every block requires a -// tracking entry, assigning small blocks to a very large array can result in quite a bit of -// unwanted overhead. Furthermore, if the array is accessed randomly, system physical memory -// will become very fragmented, which will also hurt performance. -// -// By default, the base block size is based on a heuristic that balances the size of the spatial -// array reserve against a best-guess performance profile for the target platform. -// -class SpatialArrayReserve : public BaseVmReserveListener -{ - typedef BaseVmReserveListener _parent; - -protected: - uint m_numblocks; - - // Array of block bits, each bit indicating if the block has been committed to memory - // or not. The array length is typically determined via ((numblocks+7) / 8), though the - // actual array size may be larger in order to accommodate 32-bit or 128-bit accelerated - // operations. - ScopedAlignedAlloc m_blockbits; - -public: - SpatialArrayReserve( const wxString& name ); - - virtual void* Reserve( size_t size = 0, uptr base = 0, uptr upper_bounds = 0 ); - virtual void Reset(); - virtual bool TryResize( uint newsize ); - - void OnCommittedBlock( void* block ); - - SpatialArrayReserve& SetBlockCount( uint blocks ); - SpatialArrayReserve& SetBlockSizeInPages( uint bytes ); - - uptr SetBlockSize( uptr bytes ); - - operator void*() { return m_baseptr; } - operator const void*() const { return m_baseptr; } - - operator u8*() { return (u8*)m_baseptr; } - operator const u8*() const { return (u8*)m_baseptr; } - - using _parent::operator[]; - -protected: - void ReprotectCommittedBlocks( const PageProtectionMode& newmode ); - void DoCommitAndProtect( uptr page ); - uint _calcBlockBitArrayLength() const; -}; - #ifdef __linux__ # define PCSX2_PAGEFAULT_PROTECT diff --git a/common/src/Utilities/VirtualMemory.cpp b/common/src/Utilities/VirtualMemory.cpp index cb7c2dbe6b..edbfbbf853 100644 --- a/common/src/Utilities/VirtualMemory.cpp +++ b/common/src/Utilities/VirtualMemory.cpp @@ -336,154 +336,6 @@ void BaseVmReserveListener::OnPageFaultEvent(const PageFaultInfo& info, bool& ha #endif } - -// -------------------------------------------------------------------------------------- -// SpatialArrayReserve (implementations) -// -------------------------------------------------------------------------------------- - -SpatialArrayReserve::SpatialArrayReserve( const wxString& name ) : - _parent( name ), m_numblocks(0) -{ - m_prot_mode = PageAccess_ReadWrite(); -} - -uint SpatialArrayReserve::_calcBlockBitArrayLength() const -{ - // divide by 8 (rounded up) to compress 8 bits into each byte. - // mask off lower bits (rounded up) to allow for 128-bit alignment and SSE operations. - return (((m_numblocks + 7) / 8) + 15) & ~15; -} - -void* SpatialArrayReserve::Reserve( size_t size, uptr base, uptr upper_bounds ) -{ - void* addr = _parent::Reserve( size, base, upper_bounds ); - if (!addr) return NULL; - - if (m_blocksize) SetBlockSizeInPages( m_blocksize ); - m_blockbits.Alloc( _calcBlockBitArrayLength() ); - - return addr; -} - -void SpatialArrayReserve::ReprotectCommittedBlocks( const PageProtectionMode& newmode ) -{ - if (!m_pages_commited) return; - - u8* curptr = GetPtr(); - const uint blockBytes = m_blocksize * __pagesize; - for (uint i=0; iSetBlockSize(_16kb); - recRAMCopy->Reserve(Ps2MemSize::MainRam); + recRAMCopy = (u8*)_aligned_malloc(Ps2MemSize::MainRam, 4096); } if (!recRAM) { - recLutReserve_RAM = new R5900LutReserve_RAM( L"R5900 RAM LUT" ); - recLutReserve_RAM->SetBlockSize(_16kb); - recLutReserve_RAM->Reserve(Ps2MemSize::MainRam + Ps2MemSize::Rom + Ps2MemSize::Rom1); + recLutReserve_RAM = (u8*)_aligned_malloc(recLutSize, 4096); } - BASEBLOCK* basepos = (BASEBLOCK*)recLutReserve_RAM->GetPtr(); + BASEBLOCK* basepos = (BASEBLOCK*)recLutReserve_RAM; recRAM = basepos; basepos += (Ps2MemSize::MainRam / 4); recROM = basepos; basepos += (Ps2MemSize::Rom / 4); recROM1 = basepos; basepos += (Ps2MemSize::Rom1 / 4); - pxAssert(recLutReserve_RAM->GetPtrEnd() == (u8*)basepos); - for (int i = 0; i < 0x10000; i++) recLUT_SetPage(recLUT, 0, 0, 0, i, 0); @@ -722,8 +695,8 @@ static void recResetRaw() Console.WriteLn( Color_StrongBlack, "EE/iR5900-32 Recompiler Reset" ); recMem->Reset(); - recRAMCopy->Reset(); - recLutReserve_RAM->Reset(); + ClearRecLUT((BASEBLOCK*)recLutReserve_RAM, recLutSize); + memset(recRAMCopy, 0, Ps2MemSize::MainRam); maxrecmem = 0; @@ -747,8 +720,8 @@ static void recResetRaw() static void recShutdown() { safe_delete( recMem ); - safe_delete( recRAMCopy ); - safe_delete( recLutReserve_RAM ); + safe_aligned_free( recRAMCopy ); + safe_aligned_free( recLutReserve_RAM ); recBlocks.Reset(); @@ -2168,7 +2141,7 @@ StartRecomp: if ((oldBlock->startpc + oldBlock->size * 4) <= HWADDR(startpc)) break; - if (memcmp(&(*recRAMCopy)[oldBlock->startpc / 4], PSM(oldBlock->startpc), + if (memcmp(&recRAMCopy[oldBlock->startpc / 4], PSM(oldBlock->startpc), oldBlock->size * 4)) { recClear(startpc, (pc - startpc) / 4); @@ -2178,7 +2151,7 @@ StartRecomp: } } - memcpy(&(*recRAMCopy)[HWADDR(startpc) / 4], PSM(startpc), pc - startpc); + memcpy(&recRAMCopy[HWADDR(startpc) / 4], PSM(startpc), pc - startpc); } s_pCurBlock->SetFnptr((uptr)recPtr);