From 4fb6ab40a1b110b097b42b9135d75257568a1e66 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Mon, 20 Oct 2014 02:33:57 +1300 Subject: [PATCH 1/3] Eliminated getPointers which are memcpyed or memset. Removes 12 getPointers. --- Source/Core/Core/HW/DVDInterface.cpp | 5 +++-- Source/Core/Core/HW/EXI_DeviceEthernet.cpp | 2 +- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp | 2 +- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp | 4 ++-- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_hid.cpp | 2 +- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 6 +++--- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.h | 2 +- Source/Core/Core/PowerPC/PPCCache.cpp | 3 +-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp index 7429f64cae..3d72e8a75a 100644 --- a/Source/Core/Core/HW/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVDInterface.cpp @@ -668,7 +668,8 @@ void ExecuteCommand() else if ((iDVDOffset == 0x1f900000) || (iDVDOffset == 0x1f900020)) { ERROR_LOG(DVDINTERFACE, "GC-AM: READ MEDIA BOARD COMM AREA (1f900020)"); - memcpy(Memory::GetPointer(m_DIMAR.Address), media_buffer + iDVDOffset - 0x1f900000, m_DILENGTH.Length); + u8* source = media_buffer + iDVDOffset - 0x1f900000; + Memory::CopyToEmu(m_DIMAR.Address, source, m_DILENGTH.Length); for (u32 i = 0; i < m_DILENGTH.Length; i += 4) ERROR_LOG(DVDINTERFACE, "GC-AM: %08x", Memory::Read_U32(m_DIMAR.Address + i)); break; @@ -827,7 +828,7 @@ void ExecuteCommand() else { u32 addr = m_DIMAR.Address; - memcpy(media_buffer + offset, Memory::GetPointer(addr), len); + Memory::CopyFromEmu(media_buffer + offset, addr, len); while (len >= 4) { ERROR_LOG(DVDINTERFACE, "GC-AM Media Board WRITE (0xAA): %08x: %08x", iDVDOffset, Memory::Read_U32(addr)); diff --git a/Source/Core/Core/HW/EXI_DeviceEthernet.cpp b/Source/Core/Core/HW/EXI_DeviceEthernet.cpp index aad43d96e5..b4effff093 100644 --- a/Source/Core/Core/HW/EXI_DeviceEthernet.cpp +++ b/Source/Core/Core/HW/EXI_DeviceEthernet.cpp @@ -192,7 +192,7 @@ void CEXIETHERNET::DMARead(u32 addr, u32 size) { DEBUG_LOG(SP1, "DMA read: %08x %x", addr, size); - memcpy(Memory::GetPointer(addr), &mBbaMem[transfer.address], size); + Memory::CopyToEmu(addr, &mBbaMem[transfer.address], size); transfer.address += size; } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp index 3154c0e3b2..9d2b13d5b4 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp @@ -118,7 +118,7 @@ bool CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress) // Read TMD to the buffer VolumeHandler::RAWReadToPtr(pTMD, TMDOffset, TMDsz); - memcpy(Memory::GetPointer(CommandBuffer.PayloadBuffer[0].m_Address), pTMD, TMDsz); + Memory::CopyToEmu(CommandBuffer.PayloadBuffer[0].m_Address, pTMD, TMDsz); WII_IPC_HLE_Interface::ES_DIVerify(pTMD, TMDsz); ReturnValue = 1; diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 18e924c839..7ce15fa178 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -666,11 +666,11 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) // shouldn't matter at all. Just fill out some fields just // to be on the safe side. u32 Address = Buffer.PayloadBuffer[0].m_Address; - memset(Memory::GetPointer(Address), 0, 0xD8); + Memory::Memset(Address, 0, 0xD8); Memory::Write_U64(TitleID, Address + 4 + (0x1dc - 0x1d0)); // title ID Memory::Write_U16(0xffff, Address + 4 + (0x1e4 - 0x1d0)); // unnnown Memory::Write_U32(0xff00, Address + 4 + (0x1ec - 0x1d0)); // access mask - memset(Memory::GetPointer(Address + 4 + (0x222 - 0x1d0)), 0xff, 0x20); // content permissions + Memory::Memset(Address + 4 + (0x222 - 0x1d0), 0xff, 0x20); // content permissions } else { diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_hid.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_hid.cpp index 18b83a312e..f8684474f3 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_hid.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_hid.cpp @@ -197,7 +197,7 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress) u8 * buffer = (u8*)malloc(wLength + LIBUSB_CONTROL_SETUP_SIZE); libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex, wLength); - memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, Memory::GetPointer(data), wLength); + Memory::CopyFromEmu(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength); libusb_fill_control_transfer(transfer, dev_handle, buffer, handleUsbUpdates, (void*)(size_t)_CommandAddress, /* no timeout */ 0); libusb_submit_transfer(transfer); diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index 1a1cb0b2ef..dde888b971 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -950,8 +950,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) Memory::Read_U8(BufferIn + 8 + 3) ); INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETNTOP %s", ip_s); - memset(Memory::GetPointer(BufferOut), 0, BufferOutSize); - memcpy(Memory::GetPointer(BufferOut), ip_s, strlen(ip_s)); + Memory::Memset(BufferOut, 0, BufferOutSize); + Memory::CopyToEmu(BufferOut, (u8*)ip_s, strlen(ip_s)); break; } @@ -1436,7 +1436,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress) s32 icmp_length = sizeof(data); if (BufferInSize2 == sizeof(data)) - memcpy(data, Memory::GetPointer(_BufferIn2), BufferInSize2); + Memory::CopyFromEmu(data, _BufferIn2, BufferInSize2); else { // TODO sequence number is incremented either statically, by diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.h index 4d42334ade..fcdfb54f5a 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -123,7 +123,7 @@ private: inline void FillBuffer(const void* src, const size_t size) const { - memcpy(Memory::GetPointer(m_buffer), src, size); + Memory::CopyToEmu(m_buffer, (u8*)src, size); } inline void SetRetVal(const u32 retval) const diff --git a/Source/Core/Core/PowerPC/PPCCache.cpp b/Source/Core/Core/PowerPC/PPCCache.cpp index 7e96e64a45..0c3a6e79aa 100644 --- a/Source/Core/Core/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/PowerPC/PPCCache.cpp @@ -129,8 +129,7 @@ namespace PowerPC else t = way_from_plru[plru[set]]; // load - u8 *p = Memory::GetPointer(addr & ~0x1f); - memcpy(data[set][t], p, 32); + Memory::CopyFromEmu((u8*)data[set][t], (addr & ~0x1f), 32); if (valid[set] & (1 << t)) { if (tags[set][t] & (ICACHE_VMEM_BIT >> 12)) From 3aa979d7d7f14c27d75b2cd3b4feb664e6f88c38 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Mon, 20 Oct 2014 02:51:01 +1300 Subject: [PATCH 2/3] Remove another 3 getPointers. Thanks neobrain for spotting these. --- Source/Core/VideoCommon/BPStructs.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 9488284978..f7778282ba 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -270,16 +270,16 @@ static void BPWritten(const BPCmd& bp) u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9; u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5; - u8 *ptr = nullptr; + u32 addr = 0; // TODO - figure out a cleaner way. if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) - ptr = Memory::GetPointer(bpmem.tmem_config.tlut_src << 5); + addr = bpmem.tmem_config.tlut_src << 5; else - ptr = Memory::GetPointer((bpmem.tmem_config.tlut_src & 0xFFFFF) << 5); + addr = (bpmem.tmem_config.tlut_src & 0xFFFFF) << 5; - if (ptr) - memcpy(texMem + tlutTMemAddr, ptr, tlutXferCount); + if (addr) + Memory::CopyFromEmu(texMem + tlutTMemAddr, addr, tlutXferCount); else PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5); @@ -453,7 +453,7 @@ static void BPWritten(const BPCmd& bp) // NOTE: libogc's implementation of GX_PreloadEntireTexture seems flawed, so it's not necessarily a good reference for RE'ing this feature. BPS_TmemConfig& tmem_cfg = bpmem.tmem_config; - u8* src_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5); // TODO: Should we add mask here on GC? + u32 src_addr = tmem_cfg.preload_addr << 5; // TODO: Should we add mask here on GC? u32 size = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE; u32 tmem_addr_even = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE; @@ -462,7 +462,7 @@ static void BPWritten(const BPCmd& bp) if (tmem_addr_even + size > TMEM_SIZE) size = TMEM_SIZE - tmem_addr_even; - memcpy(texMem + tmem_addr_even, src_ptr, size); + Memory::CopyFromEmu(texMem + tmem_addr_even, src_addr, size); } else // RGBA8 tiles (and CI14, but that might just be stupid libogc!) { @@ -475,11 +475,11 @@ static void BPWritten(const BPCmd& bp) tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE) return; - memcpy(texMem + tmem_addr_even, src_ptr, TMEM_LINE_SIZE); - memcpy(texMem + tmem_addr_odd, src_ptr + TMEM_LINE_SIZE, TMEM_LINE_SIZE); + Memory::CopyFromEmu(texMem + tmem_addr_even, src_addr, TMEM_LINE_SIZE); + Memory::CopyFromEmu(texMem + tmem_addr_odd, src_addr + TMEM_LINE_SIZE, TMEM_LINE_SIZE); tmem_addr_even += TMEM_LINE_SIZE; tmem_addr_odd += TMEM_LINE_SIZE; - src_ptr += TMEM_LINE_SIZE * 2; + src_addr += TMEM_LINE_SIZE * 2; } } } From 23832987b535b514a164cda789f1f6b4e4165a7f Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Thu, 23 Oct 2014 18:15:29 +1300 Subject: [PATCH 3/3] Revert changes preloading of RGBA8 tiles. This path should probally be optimised, but it's out of the scope of this PR. --- Source/Core/VideoCommon/BPStructs.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index f7778282ba..cd3302beb3 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -466,6 +466,8 @@ static void BPWritten(const BPCmd& bp) } else // RGBA8 tiles (and CI14, but that might just be stupid libogc!) { + u8* src_ptr = Memory::GetPointer(src_addr); + // AR and GB tiles are stored in separate TMEM banks => can't use a single memcpy for everything u32 tmem_addr_odd = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE; @@ -475,11 +477,12 @@ static void BPWritten(const BPCmd& bp) tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE) return; - Memory::CopyFromEmu(texMem + tmem_addr_even, src_addr, TMEM_LINE_SIZE); - Memory::CopyFromEmu(texMem + tmem_addr_odd, src_addr + TMEM_LINE_SIZE, TMEM_LINE_SIZE); + // TODO: This isn't very optimised, does a whole lot of small memcpys + memcpy(texMem + tmem_addr_even, src_ptr, TMEM_LINE_SIZE); + memcpy(texMem + tmem_addr_odd, src_ptr + TMEM_LINE_SIZE, TMEM_LINE_SIZE); tmem_addr_even += TMEM_LINE_SIZE; tmem_addr_odd += TMEM_LINE_SIZE; - src_addr += TMEM_LINE_SIZE * 2; + src_ptr += TMEM_LINE_SIZE * 2; } } }