From 7c9c8e197c75dae3c53c92fab1ad4a93ae64344d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 16 Jun 2023 21:25:52 +1000 Subject: [PATCH] Common: Replace MemsetFast routines with C memset And associated cleanup. On most compilers these days, it'll either inline the memset with vector fills or rep stosq, or outline with a call to memset. I trust the compiler is probably going to make a better decision here, than manual SSE intrinsics. Ends up a couple of percent faster in FMV decoding. --- common/CMakeLists.txt | 1 - common/General.h | 18 ------- common/MemsetFast.inl | 95 --------------------------------- common/common.vcxproj | 2 +- common/emitter/cpudetect.cpp | 4 -- common/emitter/tools.h | 12 ++--- pcsx2/CDVD/CDVD.cpp | 6 +-- pcsx2/CDVD/Ps1CD.cpp | 4 +- pcsx2/Cache.cpp | 2 +- pcsx2/Counters.cpp | 2 +- pcsx2/GS.cpp | 4 +- pcsx2/Gif.cpp | 2 +- pcsx2/Gif_Unit.h | 8 +-- pcsx2/Hw.cpp | 2 +- pcsx2/IPU/IPU.cpp | 18 +++---- pcsx2/IPU/IPU_Fifo.cpp | 8 +-- pcsx2/IPU/IPU_MultiISA.cpp | 13 ++--- pcsx2/IopCounters.cpp | 2 +- pcsx2/MTVU.cpp | 4 +- pcsx2/MemoryCardFile.cpp | 53 +++++++++--------- pcsx2/R3000A.cpp | 2 +- pcsx2/R5900.cpp | 6 +-- pcsx2/R5900OpcodeImpl.cpp | 2 +- pcsx2/SaveState.cpp | 24 ++++----- pcsx2/SaveState.h | 1 - pcsx2/Sif.cpp | 4 +- pcsx2/Sif.h | 2 +- pcsx2/System.cpp | 1 - pcsx2/VUmicroMem.cpp | 12 ++--- pcsx2/Vif.cpp | 12 ++--- pcsx2/vtlb.cpp | 7 ++- pcsx2/x86/R5900_Profiler.h | 6 +-- pcsx2/x86/iCore.cpp | 12 ++--- pcsx2/x86/ix86-32/iCore-32.cpp | 2 +- pcsx2/x86/ix86-32/iR5900-32.cpp | 1 - pcsx2/x86/microVU.cpp | 4 +- pcsx2/x86/microVU_Branch.inl | 8 +-- pcsx2/x86/microVU_Compile.inl | 4 +- pcsx2/x86/microVU_Profiler.h | 2 +- pcsx2/x86/newVif_Unpack.cpp | 2 +- 40 files changed, 128 insertions(+), 246 deletions(-) delete mode 100644 common/MemsetFast.inl diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a5b37aeb9c..4629c8e8db 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -81,7 +81,6 @@ target_sources(common PRIVATE HeapArray.h HTTPDownloader.h MemorySettingsInterface.h - MemsetFast.inl MD5Digest.h MRCHelpers.h Path.h diff --git a/common/General.h b/common/General.h index 6318683791..11b81be6cb 100644 --- a/common/General.h +++ b/common/General.h @@ -198,24 +198,6 @@ private: #define SafeSysMunmap(ptr, size) \ ((void)(HostSys::Munmap(ptr, size), (ptr) = 0)) -// This method can clear any object-like entity -- which is anything that is not a pointer. -// Structures, static arrays, etc. No need to include sizeof() crap, this does it automatically -// for you! -template -static __fi void memzero(T& object) -{ - static_assert(std::is_trivially_copyable_v); - std::memset(&object, 0, sizeof(T)); -} - -// This method clears an object with the given 8 bit value. -template -static __fi void memset8(T& object) -{ - static_assert(std::is_trivially_copyable_v); - std::memset(&object, data, sizeof(T)); -} - extern u64 GetTickFrequency(); extern u64 GetCPUTicks(); extern u64 GetPhysicalMemory(); diff --git a/common/MemsetFast.inl b/common/MemsetFast.inl deleted file mode 100644 index 731b8da49a..0000000000 --- a/common/MemsetFast.inl +++ /dev/null @@ -1,95 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 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 PCSX2. - * If not, see . - */ - -#pragma once - -#include - -template -__noinline void memset_sse_a(void* dest, const size_t size) -{ - const uint MZFqwc = size / 16; - - pxAssert((size & 0xf) == 0); - - __m128 srcreg; - - if (data != 0) - { - alignas(16) static const u8 loadval[8] = {data, data, data, data, data, data, data, data}; - srcreg = _mm_loadh_pi(_mm_load_ps((float*)loadval), (__m64*)loadval); - } - else - srcreg = _mm_setzero_ps(); - - float(*destxmm)[4] = (float(*)[4])dest; - - switch (MZFqwc & 0x07) - { - case 0x07: - _mm_store_ps(&destxmm[0x07 - 1][0], srcreg); - // Fall through - case 0x06: - _mm_store_ps(&destxmm[0x06 - 1][0], srcreg); - // Fall through - case 0x05: - _mm_store_ps(&destxmm[0x05 - 1][0], srcreg); - // Fall through - case 0x04: - _mm_store_ps(&destxmm[0x04 - 1][0], srcreg); - // Fall through - case 0x03: - _mm_store_ps(&destxmm[0x03 - 1][0], srcreg); - // Fall through - case 0x02: - _mm_store_ps(&destxmm[0x02 - 1][0], srcreg); - // Fall through - case 0x01: - _mm_store_ps(&destxmm[0x01 - 1][0], srcreg); - // Fall through - } - - destxmm += (MZFqwc & 0x07); - for (uint i = 0; i < MZFqwc / 8; ++i, destxmm += 8) - { - _mm_store_ps(&destxmm[0][0], srcreg); - _mm_store_ps(&destxmm[1][0], srcreg); - _mm_store_ps(&destxmm[2][0], srcreg); - _mm_store_ps(&destxmm[3][0], srcreg); - _mm_store_ps(&destxmm[4][0], srcreg); - _mm_store_ps(&destxmm[5][0], srcreg); - _mm_store_ps(&destxmm[6][0], srcreg); - _mm_store_ps(&destxmm[7][0], srcreg); - } -}; - -static __fi void memzero_sse_a(void* dest, const size_t size) -{ - memset_sse_a<0>(dest, size); -} - -template -__noinline void memset_sse_a(T& dest) -{ - static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset"); - memset_sse_a(&dest, sizeof(dest)); -} - -template -void memzero_sse_a(T& dest) -{ - static_assert((sizeof(dest) & 0xf) == 0, "Bad size for SSE memset"); - memset_sse_a<0>(&dest, sizeof(dest)); -} diff --git a/common/common.vcxproj b/common/common.vcxproj index 5431f94f42..ca7263cc56 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -180,4 +180,4 @@ - + \ No newline at end of file diff --git a/common/emitter/cpudetect.cpp b/common/emitter/cpudetect.cpp index 7262237f4f..ca7da0ba00 100644 --- a/common/emitter/cpudetect.cpp +++ b/common/emitter/cpudetect.cpp @@ -66,8 +66,6 @@ x86capabilities::x86capabilities() , PhysicalCores(0) , LogicalCores(0) { - memzero(VendorName); - memzero(FamilyName); } #if defined(_MSC_VER) #pragma optimize("", on) @@ -148,7 +146,6 @@ void x86capabilities::Identify() s32 regs[4]; u32 cmds; - memzero(VendorName); cpuid(regs, 0); cmds = regs[0]; @@ -201,7 +198,6 @@ void x86capabilities::Identify() EFlags = regs[3]; } - memzero(FamilyName); cpuid((int*)FamilyName, 0x80000002); cpuid((int*)(FamilyName + 16), 0x80000003); cpuid((int*)(FamilyName + 32), 0x80000004); diff --git a/common/emitter/tools.h b/common/emitter/tools.h index ad46bd55ad..83857a6555 100644 --- a/common/emitter/tools.h +++ b/common/emitter/tools.h @@ -46,8 +46,8 @@ public: u32 EFlags2; // Extended Feature Flags pg2 u32 SEFlag; // Structured Extended Feature Flags Enumeration - char VendorName[16]; // Vendor/Creator ID - char FamilyName[50]; // the original cpu name + char VendorName[16] = {}; // Vendor/Creator ID + char FamilyName[50] = {}; // the original cpu name // ---------------------------------------------------------------------------- // x86 CPU Capabilities Section (all boolean flags!) @@ -55,6 +55,8 @@ public: union { + u64 AllCapabilities = 0; + struct { u32 hasFloatingPointUnit : 1; @@ -101,13 +103,11 @@ public: u32 hasAMD64BitArchitecture : 1; u32 hasStreamingSIMD4ExtensionsA : 1; }; - - u64 AllCapabilities; }; // Core Counts! - u32 PhysicalCores; - u32 LogicalCores; + u32 PhysicalCores = 0; + u32 LogicalCores = 0; public: x86capabilities(); diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index d432c2faca..30b3c09aaa 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -913,7 +913,7 @@ static uint cdvdBlockReadTime(CDVD_MODE_TYPE mode) void cdvdReset() { - memzero(cdvd); + std::memset(&cdvd, 0, sizeof(cdvd)); cdvd.Type = CDVD_TYPE_NODISC; cdvd.Spinning = false; @@ -1824,7 +1824,7 @@ static void cdvdWrite04(u8 rt) cdvd.SCMDParamC = 0; cdvdUpdateStatus(CDVD_STATUS_STOP); cdvd.Spinning = false; - memzero(cdvd.SCMDResult); + std::memset(cdvd.SCMDResult, 0, sizeof(cdvd.SCMDResult)); cdvdSetIrq(); break; @@ -2337,7 +2337,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND CDVD_LOG("cdvdWrite16: SCMD %s (%x) (ParamP = %x)", sCmdName[rt], rt, cdvd.SCMDParamP); cdvd.sCommand = rt; - memzero(cdvd.SCMDResult); + std::memset(cdvd.SCMDResult, 0, sizeof(cdvd.SCMDResult)); switch (rt) { diff --git a/pcsx2/CDVD/Ps1CD.cpp b/pcsx2/CDVD/Ps1CD.cpp index 687b4bf1af..8f2a9973e9 100644 --- a/pcsx2/CDVD/Ps1CD.cpp +++ b/pcsx2/CDVD/Ps1CD.cpp @@ -591,7 +591,7 @@ void cdrReadInterrupt() if (cdr.RErr == -1) { DevCon.Warning("CD err"); - memzero(cdr.Transfer); + std::memset(cdr.Transfer, 0, sizeof(cdr.Transfer)); cdr.Stat = DiskError; cdr.StatP |= STATUS_ERROR; cdr.Result[0] = cdr.StatP; @@ -1107,7 +1107,7 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) void cdrReset() { - memzero(cdr); + std::memset(&cdr, 0, sizeof(cdr)); cdr.CurTrack = 1; cdr.File = 1; cdr.Channel = 1; diff --git a/pcsx2/Cache.cpp b/pcsx2/Cache.cpp index cc2ed32ce2..79f0e2d961 100644 --- a/pcsx2/Cache.cpp +++ b/pcsx2/Cache.cpp @@ -165,7 +165,7 @@ namespace void resetCache() { - memzero(cache); + std::memset(&cache, 0, sizeof(cache)); } static bool findInCache(const CacheSet& set, uptr ppf, int* way) diff --git a/pcsx2/Counters.cpp b/pcsx2/Counters.cpp index ec407e031a..51bc1b6a44 100644 --- a/pcsx2/Counters.cpp +++ b/pcsx2/Counters.cpp @@ -164,7 +164,7 @@ void rcntInit() g_FrameCount = 0; - memzero(counters); + std::memset(counters, 0, sizeof(counters)); for (i=0; i<4; i++) { counters[i].rate = 2; diff --git a/pcsx2/GS.cpp b/pcsx2/GS.cpp index 52a44d157b..6d350551d6 100644 --- a/pcsx2/GS.cpp +++ b/pcsx2/GS.cpp @@ -40,7 +40,7 @@ void gsReset() { GetMTGS().ResetGS(true); gsVideoMode = GS_VideoMode::Uninitialized; - memzero(g_RealGSMem); + std::memset(g_RealGSMem, 0, sizeof(g_RealGSMem)); UpdateVSyncRate(true); } @@ -85,7 +85,7 @@ static __fi void gsCSRwrite( const tGS_CSR& csr ) gifUnit.gsSIGNAL.queued = false; gifUnit.gsFINISH.gsFINISHFired = true; // Privilage registers also reset. - memzero(g_RealGSMem); + std::memset(g_RealGSMem, 0, sizeof(g_RealGSMem)); GSIMR.reset(); CSRreg.Reset(); GetMTGS().SendSimplePacket(GS_RINGTYPE_RESET, 0, 0, 0); diff --git a/pcsx2/Gif.cpp b/pcsx2/Gif.cpp index 6c017c37a1..b6e631c8f7 100644 --- a/pcsx2/Gif.cpp +++ b/pcsx2/Gif.cpp @@ -82,7 +82,7 @@ bool CheckPaths() void GIF_Fifo::init() { - memzero(data); + std::memset(data, 0, sizeof(data)); fifoSize = 0; gifRegs.stat.FQC = 0; diff --git a/pcsx2/Gif_Unit.h b/pcsx2/Gif_Unit.h index 3a37f2cd50..1f80618d6e 100644 --- a/pcsx2/Gif_Unit.h +++ b/pcsx2/Gif_Unit.h @@ -65,7 +65,7 @@ struct Gif_Tag setTag(pMem, analyze); } - __ri void Reset() { memzero(*this); } + __ri void Reset() { std::memset(this, 0, sizeof(*this)); } __ri u8 curReg() { return regs[nRegIdx & 0xf]; } __ri void packedStep() @@ -163,21 +163,21 @@ struct GS_Packet s32 cycles; // EE Cycles taken to process this GS packet s32 readAmount; // Dummy read-amount data needed for proper buffer calculations GS_Packet() { Reset(); } - void Reset() { memzero(*this); } + void Reset() { std::memset(this, 0, sizeof(*this)); } }; struct GS_SIGNAL { u32 data[2]; bool queued; - void Reset() { memzero(*this); } + void Reset() { std::memset(this, 0, sizeof(*this)); } }; struct GS_FINISH { bool gsFINISHFired; - void Reset() { memzero(*this); } + void Reset() { std::memset(this, 0, sizeof(*this)); } }; static __fi void incTag(u32& offset, u32& size, u32 incAmount) diff --git a/pcsx2/Hw.cpp b/pcsx2/Hw.cpp index aeb1460eab..928877369c 100644 --- a/pcsx2/Hw.cpp +++ b/pcsx2/Hw.cpp @@ -58,7 +58,7 @@ void hwReset() { hwInit(); - memzero( eeHw ); + std::memset(eeHw, 0, sizeof(eeHw)); psHu32(SBUS_F260) = 0x1D000060; diff --git a/pcsx2/IPU/IPU.cpp b/pcsx2/IPU/IPU.cpp index ffdd43832e..2b5d084b36 100644 --- a/pcsx2/IPU/IPU.cpp +++ b/pcsx2/IPU/IPU.cpp @@ -23,8 +23,6 @@ #include #include "Config.h" -#include "common/MemsetFast.inl" - // the BP doesn't advance and returns -1 if there is no data to be read alignas(16) tIPU_cmd ipu_cmd; alignas(16) tIPU_BP g_BP; @@ -88,7 +86,7 @@ __ri static u8 getBits32(u8* address, bool advance) void tIPU_cmd::clear() { - memzero_sse_a(*this); + std::memset(this, 0, sizeof(*this)); current = 0xffffffff; } @@ -104,9 +102,9 @@ __fi void IPUProcessInterrupt() void ipuReset() { IPUWorker = MULTI_ISA_SELECT(IPUWorker); - memzero(ipuRegs); - memzero(g_BP); - memzero(decoder); + std::memset(&ipuRegs, 0, sizeof(ipuRegs)); + std::memset(&g_BP, 0, sizeof(g_BP)); + std::memset(&decoder, 0, sizeof(decoder)); decoder.picture_structure = FRAME_PICTURE; //default: progressive...my guess:P @@ -314,7 +312,7 @@ __fi u64 ipuRead64(u32 mem) void ipuSoftReset() { ipu_fifo.clear(); - memzero(g_BP); + std::memset(&g_BP, 0, sizeof(g_BP)); coded_block_pattern = 0; g_ipu_thresh[0] = 0; @@ -389,7 +387,7 @@ __fi bool ipuWrite64(u32 mem, u64 value) static void ipuBCLR(u32 val) { ipu_fifo.in.clear(); - memzero(g_BP); + std::memset(&g_BP, 0, sizeof(g_BP)); g_BP.BP = val & 0x7F; ipuRegs.cmd.BUSY = 0; @@ -441,8 +439,8 @@ static __ri void ipuBDEC(tIPU_CMD_BDEC bdec) decoder.dcr = bdec.DCR; decoder.macroblock_modes |= bdec.MBI ? MACROBLOCK_INTRA : MACROBLOCK_PATTERN; - memzero_sse_a(decoder.mb8); - memzero_sse_a(decoder.mb16); + std::memset(&decoder.mb8, 0, sizeof(decoder.mb8)); + std::memset(&decoder.mb16, 0, sizeof(decoder.mb16)); } static void ipuSETTH(u32 val) diff --git a/pcsx2/IPU/IPU_Fifo.cpp b/pcsx2/IPU/IPU_Fifo.cpp index 3df82a3a27..7d2666da79 100644 --- a/pcsx2/IPU/IPU_Fifo.cpp +++ b/pcsx2/IPU/IPU_Fifo.cpp @@ -27,13 +27,13 @@ void IPU_Fifo::init() out.writepos = 0; in.readpos = 0; in.writepos = 0; - memzero(in.data); - memzero(out.data); + std::memset(in.data, 0, sizeof(in.data)); + std::memset(out.data, 0, sizeof(out.data)); } void IPU_Fifo_Input::clear() { - memzero(data); + std::memset(data, 0, sizeof(data)); g_BP.IFC = 0; ipuRegs.ctrl.IFC = 0; readpos = 0; @@ -50,7 +50,7 @@ void IPU_Fifo_Input::clear() void IPU_Fifo_Output::clear() { - memzero(data); + std::memset(data, 0, sizeof(data)); ipuRegs.ctrl.OFC = 0; readpos = 0; writepos = 0; diff --git a/pcsx2/IPU/IPU_MultiISA.cpp b/pcsx2/IPU/IPU_MultiISA.cpp index 1c8d323649..70856befc7 100644 --- a/pcsx2/IPU/IPU_MultiISA.cpp +++ b/pcsx2/IPU/IPU_MultiISA.cpp @@ -26,7 +26,8 @@ #include "IPU/IPUdma.h" #include "IPU/yuv2rgb.h" #include "IPU/IPU_MultiISA.h" -#include "common/MemsetFast.inl" + +#include "common/General.h" // the IPU is fixed to 16 byte strides (128-bit / QWC resolution): static const uint decoder_stride = 16; @@ -960,7 +961,7 @@ __ri static bool slice_non_intra_DCT(s16 * const dest, const int stride, const b if (!skip) { - memzero_sse_a(decoder.DCTblock); + std::memset(decoder.DCTblock, 0, sizeof(decoder.DCTblock)); } if (!get_non_intra_block(&last)) @@ -1033,8 +1034,8 @@ __ri static bool mpeg2sliceIDEC() } decoder.coded_block_pattern = 0x3F;//all 6 blocks - memzero_sse_a(mb8); - memzero_sse_a(rgb32); + std::memset(&mb8, 0, sizeof(mb8)); + std::memset(&rgb32, 0, sizeof(rgb32)); [[fallthrough]]; case 1: @@ -1282,8 +1283,8 @@ __fi static bool mpeg2_slice() ipuRegs.ctrl.ECD = 0; ipuRegs.top = 0; - memzero_sse_a(mb8); - memzero_sse_a(mb16); + std::memset(&mb8, 0, sizeof(mb8)); + std::memset(&mb16, 0, sizeof(mb16)); [[fallthrough]]; case 1: diff --git a/pcsx2/IopCounters.cpp b/pcsx2/IopCounters.cpp index 3871200010..55ce15b98f 100644 --- a/pcsx2/IopCounters.cpp +++ b/pcsx2/IopCounters.cpp @@ -136,7 +136,7 @@ void psxRcntInit() { int i; - memzero(psxCounters); + std::memset(psxCounters, 0, sizeof(psxCounters)); for (i = 0; i < 3; i++) { diff --git a/pcsx2/MTVU.cpp b/pcsx2/MTVU.cpp index 31f92ef681..f5721e7fd7 100644 --- a/pcsx2/MTVU.cpp +++ b/pcsx2/MTVU.cpp @@ -129,8 +129,8 @@ void VU_Thread::Reset() m_write_pos = 0; m_ato_read_pos = 0; m_read_pos = 0; - memzero(vif); - memzero(vifRegs); + std::memset(&vif, 0, sizeof(vif)); + std::memset(&vifRegs, 0, sizeof(vifRegs)); for (size_t i = 0; i < 4; ++i) vu1Thread.vuCycles[i] = 0; vu1Thread.mtvuInterrupts = 0; diff --git a/pcsx2/MemoryCardFile.cpp b/pcsx2/MemoryCardFile.cpp index 2d3df915a3..532cb74e2e 100644 --- a/pcsx2/MemoryCardFile.cpp +++ b/pcsx2/MemoryCardFile.cpp @@ -36,9 +36,11 @@ #include -static const int MCD_SIZE = 1024 * 8 * 16; // Legacy PSX card default size +static constexpr int MCD_SIZE = 1024 * 8 * 16; // Legacy PSX card default size -static const int MC2_MBSIZE = 1024 * 528 * 2; // Size of a single megabyte of card data +static constexpr int MC2_MBSIZE = 1024 * 528 * 2; // Size of a single megabyte of card data + +static constexpr int MC2_ERASE_SIZE = 528 * 16; static const char* s_folder_mem_card_id_file = "_pcsx2_superblock"; @@ -166,17 +168,16 @@ static bool ConvertRAWtoNoECC(const char* file_in, const char* file_out) class FileMemoryCard { protected: - std::FILE* m_file[8]; - std::string m_filenames[8]; - u8 m_effeffs[528 * 16]; + std::FILE* m_file[8] = {}; + std::string m_filenames[8] = {}; SafeArray m_currentdata; - u64 m_chksum[8]; - bool m_ispsx[8]; - u32 m_chkaddr; + u64 m_chksum[8] = {}; + bool m_ispsx[8] = {}; + u32 m_chkaddr = 0; public: FileMemoryCard(); - virtual ~FileMemoryCard() = default; + ~FileMemoryCard(); void Lock(); void Unlock(); @@ -257,11 +258,9 @@ std::string FileMcd_GetDefaultName(uint slot) return StringUtil::StdStringFromFormat("Mcd%03u.ps2", slot + 1); } -FileMemoryCard::FileMemoryCard() - : m_chkaddr(0) -{ - memset8<0xff>(m_effeffs); -} +FileMemoryCard::FileMemoryCard() = default; + +FileMemoryCard::~FileMemoryCard() = default; void FileMemoryCard::Open() { @@ -431,9 +430,12 @@ bool FileMemoryCard::Create(const char* mcdFile, uint sizeInMB) if (!fp) return false; - for (uint i = 0; i < (MC2_MBSIZE * sizeInMB) / sizeof(m_effeffs); i++) + u8 buf[MC2_ERASE_SIZE]; + std::memset(buf, 0xff, sizeof(buf)); + + for (uint i = 0; i < (MC2_MBSIZE * sizeInMB) / sizeof(buf); i++) { - if (std::fwrite(m_effeffs, sizeof(m_effeffs), 1, fp.get()) != 1) + if (std::fwrite(buf, sizeof(buf), 1, fp.get()) != 1) return false; } return true; @@ -557,7 +559,10 @@ s32 FileMemoryCard::EraseBlock(uint slot, u32 adr) if (!Seek(mcfp, adr)) return 0; - return std::fwrite(m_effeffs, sizeof(m_effeffs), 1, mcfp) == 1; + + u8 buf[MC2_ERASE_SIZE]; + std::memset(buf, 0xff, sizeof(buf)); + return std::fwrite(buf, sizeof(buf), 1, mcfp) == 1; } u64 FileMemoryCard::GetCRC(uint slot) @@ -963,13 +968,13 @@ bool FileMcd_CreateNewCard(const std::string_view& name, MemoryCardType type, Me Console.WriteLn("(FileMcd) Creating new PS2 %uMB memory card: '%s'", size / MC2_MBSIZE, full_path.c_str()); // PS2 Memory Card - u8 m_effeffs[528 * 16]; - memset8<0xff>(m_effeffs); + u8 buf[MC2_ERASE_SIZE]; + std::memset(buf, 0xff, sizeof(buf)); - const u32 count = size / sizeof(m_effeffs); + const u32 count = size / sizeof(buf); for (uint i = 0; i < count; i++) { - if (std::fwrite(m_effeffs, sizeof(m_effeffs), 1, fp.get()) != 1) + if (std::fwrite(buf, sizeof(buf), 1, fp.get()) != 1) { Host::ReportFormattedErrorAsync("Memory Card Creation Failed", "Failed to write file '%s'.", full_path.c_str()); return false; @@ -983,13 +988,13 @@ bool FileMcd_CreateNewCard(const std::string_view& name, MemoryCardType type, Me Console.WriteLn("(FileMcd) Creating new PSX 128 KiB memory card: '%s'", full_path.c_str()); // PSX Memory Card; 8192 is the size in bytes of a single block of a PSX memory card (8 KiB). - u8 m_effeffs_psx[8192]; - memset8<0xff>(m_effeffs_psx); + u8 buf[8192]; + std::memset(buf, 0xff, sizeof(buf)); // PSX cards consist of 16 blocks, each 8 KiB in size. for (uint i = 0; i < 16; i++) { - if (std::fwrite(m_effeffs_psx, sizeof(m_effeffs_psx), 1, fp.get()) != 1) + if (std::fwrite(buf, sizeof(buf), 1, fp.get()) != 1) { Host::ReportFormattedErrorAsync("Memory Card Creation Failed", "Failed to write file '%s'.", full_path.c_str()); return false; diff --git a/pcsx2/R3000A.cpp b/pcsx2/R3000A.cpp index f3fde73e1f..832b0e26e6 100644 --- a/pcsx2/R3000A.cpp +++ b/pcsx2/R3000A.cpp @@ -48,7 +48,7 @@ alignas(16) psxRegisters psxRegs; void psxReset() { - memzero(psxRegs); + std::memset(&psxRegs, 0, sizeof(psxRegs)); psxRegs.pc = 0xbfc00000; // Start in bootstrap psxRegs.CP0.n.Status = 0x10900000; // COP0 enabled | BEV = 1 | TS = 1 diff --git a/pcsx2/R5900.cpp b/pcsx2/R5900.cpp index b08efda887..d13da7d076 100644 --- a/pcsx2/R5900.cpp +++ b/pcsx2/R5900.cpp @@ -77,9 +77,9 @@ void cpuReset() GetVmMemory().Reset(); - memzero(cpuRegs); - memzero(fpuRegs); - memzero(tlb); + std::memset(&cpuRegs, 0, sizeof(cpuRegs)); + std::memset(&fpuRegs, 0, sizeof(fpuRegs)); + std::memset(&tlb, 0, sizeof(tlb)); cpuRegs.pc = 0xbfc00000; //set pc reg to stack cpuRegs.CP0.n.Config = 0x440; diff --git a/pcsx2/R5900OpcodeImpl.cpp b/pcsx2/R5900OpcodeImpl.cpp index eb06a21ae0..ae17ff77f2 100644 --- a/pcsx2/R5900OpcodeImpl.cpp +++ b/pcsx2/R5900OpcodeImpl.cpp @@ -154,7 +154,7 @@ void Deci2Reset() { deci2handler = 0; deci2addr = 0; - memzero( deci2buffer ); + std::memset(deci2buffer, 0, sizeof(deci2buffer)); } void SaveStateBase::deci2Freeze() diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index c227dde923..bab4a2be6e 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -124,19 +124,19 @@ void SaveStateBase::PrepBlock( int size ) } } -void SaveStateBase::FreezeTag( const char* src ) +void SaveStateBase::FreezeTag(const char* src) { - const uint allowedlen = sizeof( m_tagspace )-1; - pxAssertDev(strlen(src) < allowedlen, "Tag name exceeds the allowed length"); + char tagspace[32]; + pxAssertDev(std::strlen(src) < (sizeof(tagspace) - 1), "Tag name exceeds the allowed length"); - memzero( m_tagspace ); - strcpy( m_tagspace, src ); - Freeze( m_tagspace ); + std::memset(tagspace, 0, sizeof(tagspace)); + StringUtil::Strlcpy(tagspace, src, sizeof(tagspace)); + Freeze(tagspace); - if( strcmp( m_tagspace, src ) != 0 ) + if (std::strcmp(tagspace, src) != 0) { std::string msg(fmt::format("Savestate data corruption detected while reading tag: {}", src)); - pxFail( msg.c_str() ); + pxFail(msg.c_str()); throw Exception::SaveStateLoadError().SetDiagMsg(std::move(msg)); } } @@ -151,11 +151,11 @@ SaveStateBase& SaveStateBase::FreezeBios() u32 bioscheck = BiosChecksum; char biosdesc[256]; - memzero( biosdesc ); - memcpy( biosdesc, BiosDescription.c_str(), std::min( sizeof(biosdesc), BiosDescription.length() ) ); + std::memset(biosdesc, 0, sizeof(biosdesc)); + StringUtil::Strlcpy(biosdesc, BiosDescription, sizeof(biosdesc)); - Freeze( bioscheck ); - Freeze( biosdesc ); + Freeze(bioscheck); + Freeze(biosdesc); if (bioscheck != BiosChecksum) { diff --git a/pcsx2/SaveState.h b/pcsx2/SaveState.h index 4f77b93742..39dc63f175 100644 --- a/pcsx2/SaveState.h +++ b/pcsx2/SaveState.h @@ -78,7 +78,6 @@ class SaveStateBase { protected: VmStateBuffer* m_memory; - char m_tagspace[32]; u32 m_version; // version of the savestate being loaded. diff --git a/pcsx2/Sif.cpp b/pcsx2/Sif.cpp index 05efd2fd9f..68ce5fef5e 100644 --- a/pcsx2/Sif.cpp +++ b/pcsx2/Sif.cpp @@ -23,8 +23,8 @@ void sifReset() { - memzero(sif0); - memzero(sif1); + std::memset(&sif0, 0, sizeof(sif0)); + std::memset(&sif1, 0, sizeof(sif1)); } void SaveStateBase::sifFreeze() diff --git a/pcsx2/Sif.h b/pcsx2/Sif.h index 77ea5cf281..9ca83c695e 100644 --- a/pcsx2/Sif.h +++ b/pcsx2/Sif.h @@ -141,7 +141,7 @@ struct sifFifo } void clear() { - memzero(data); + std::memset(data, 0, sizeof(data)); readPos = 0; writePos = 0; size = 0; diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index 6c386104e7..ac7b2946af 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -28,7 +28,6 @@ #include "x86/newVif.h" #include "common/Align.h" -#include "common/MemsetFast.inl" #include "common/Perf.h" #include "common/StringUtil.h" diff --git a/pcsx2/VUmicroMem.cpp b/pcsx2/VUmicroMem.cpp index 43f1545260..89f7d421d7 100644 --- a/pcsx2/VUmicroMem.cpp +++ b/pcsx2/VUmicroMem.cpp @@ -64,9 +64,9 @@ void vuMemoryReserve::Reset() //memMapVUmicro(); // === VU0 Initialization === - memzero(VU0.ACC); - memzero(VU0.VF); - memzero(VU0.VI); + std::memset(&VU0.ACC, 0, sizeof(VU0.ACC)); + std::memset(VU0.VF, 0, sizeof(VU0.VF)); + std::memset(VU0.VI, 0, sizeof(VU0.VI)); VU0.VF[0].f.x = 0.0f; VU0.VF[0].f.y = 0.0f; VU0.VF[0].f.z = 0.0f; @@ -74,9 +74,9 @@ void vuMemoryReserve::Reset() VU0.VI[0].UL = 0; // === VU1 Initialization === - memzero(VU1.ACC); - memzero(VU1.VF); - memzero(VU1.VI); + std::memset(&VU1.ACC, 0, sizeof(VU1.ACC)); + std::memset(VU1.VF, 0, sizeof(VU1.VF)); + std::memset(VU1.VI, 0, sizeof(VU1.VI)); VU1.VF[0].f.x = 0.0f; VU1.VF[0].f.y = 0.0f; VU1.VF[0].f.z = 0.0f; diff --git a/pcsx2/Vif.cpp b/pcsx2/Vif.cpp index 06ba897849..f80f2b46e6 100644 --- a/pcsx2/Vif.cpp +++ b/pcsx2/Vif.cpp @@ -29,8 +29,8 @@ alignas(16) vifStruct vif0, vif1; void vif0Reset() { /* Reset the whole VIF, meaning the internal pcsx2 vars and all the registers */ - memzero(vif0); - memzero(vif0Regs); + std::memset(&vif0, 0, sizeof(vif0)); + std::memset(&vif0Regs, 0, sizeof(vif0Regs)); resetNewVif(0); } @@ -38,8 +38,8 @@ void vif0Reset() void vif1Reset() { /* Reset the whole VIF, meaning the internal pcsx2 vars, and all the registers */ - memzero(vif1); - memzero(vif1Regs); + std::memset(&vif1, 0, sizeof(vif1)); + std::memset(&vif1Regs, 0, sizeof(vif1Regs)); resetNewVif(1); } @@ -127,7 +127,7 @@ __fi void vif0FBRST(u32 value) SaveCol._u64[1] = vif0.MaskCol._u64[1]; SaveRow._u64[0] = vif0.MaskRow._u64[0]; SaveRow._u64[1] = vif0.MaskRow._u64[1]; - memzero(vif0); + std::memset(&vif0, 0, sizeof(vif0)); vif0.MaskCol._u64[0] = SaveCol._u64[0]; vif0.MaskCol._u64[1] = SaveCol._u64[1]; vif0.MaskRow._u64[0] = SaveRow._u64[0]; @@ -225,7 +225,7 @@ __fi void vif1FBRST(u32 value) SaveRow._u64[0] = vif1.MaskRow._u64[0]; SaveRow._u64[1] = vif1.MaskRow._u64[1]; u8 mfifo_empty = vif1.inprogress & 0x10; - memzero(vif1); + std::memset(&vif1, 0, sizeof(vif1)); vif1.MaskCol._u64[0] = SaveCol._u64[0]; vif1.MaskCol._u64[1] = SaveCol._u64[1]; vif1.MaskRow._u64[0] = SaveRow._u64[0]; diff --git a/pcsx2/vtlb.cpp b/pcsx2/vtlb.cpp index 32fe35cd00..7dceebdbbc 100644 --- a/pcsx2/vtlb.cpp +++ b/pcsx2/vtlb.cpp @@ -39,7 +39,6 @@ #include "VMManager.h" #include "common/Align.h" -#include "common/MemsetFast.inl" #include "fmt/core.h" @@ -1215,7 +1214,7 @@ void vtlb_VMapUnmap(u32 vaddr, u32 size) void vtlb_Init() { vtlbHandlerCount = 0; - memzero(vtlbdata.RWFT); + std::memset(vtlbdata.RWFT, 0, sizeof(vtlbdata.RWFT)); #define VTLB_BuildUnmappedHandler(baseName) \ baseName##ReadSm, baseName##ReadSm, baseName##ReadSm, \ @@ -1420,7 +1419,7 @@ void VtlbMemoryReserve::Assign(VirtualMemoryManagerPtr allocator, size_t offset, void VtlbMemoryReserve::Reset() { - memzero_sse_a(GetPtr(), GetSize()); + std::memset(GetPtr(), 0, GetSize()); } @@ -1577,7 +1576,7 @@ bool vtlb_private::PageFaultHandler(const PageFaultInfo& info) void mmap_ResetBlockTracking() { //DbgCon.WriteLn( "vtlb/mmap: Block Tracking reset..." ); - memzero(m_PageProtectInfo); + std::memset(m_PageProtectInfo, 0, sizeof(m_PageProtectInfo)); if (eeMem) HostSys::MemProtect(eeMem->Main, Ps2MemSize::MainRam, PageAccess_ReadWrite()); vtlb_UpdateFastmemProtection(0, Ps2MemSize::MainRam, PageAccess_ReadWrite()); diff --git a/pcsx2/x86/R5900_Profiler.h b/pcsx2/x86/R5900_Profiler.h index 37310cc746..8350547699 100644 --- a/pcsx2/x86/R5900_Profiler.h +++ b/pcsx2/x86/R5900_Profiler.h @@ -243,9 +243,9 @@ struct eeProfiler void Reset() { - memzero(opStats); - memzero(memStats); - memzero(memStatsConst); + std::memset(opStats, 0, sizeof(opStats)); + std::memset(memStats, 0, sizeof(memStats)); + std::memset(memStatsConst, 0, sizeof(memStatsConst)); memStatsSlow = 0; memStatsFast = 0; memMask = 0xF700FFF0; diff --git a/pcsx2/x86/iCore.cpp b/pcsx2/x86/iCore.cpp index 9569c55c52..d0757c6217 100644 --- a/pcsx2/x86/iCore.cpp +++ b/pcsx2/x86/iCore.cpp @@ -41,7 +41,7 @@ _x86regs x86regs[iREGCNT_GPR], s_saveX86regs[iREGCNT_GPR]; // Clear allocation counter void _initXMMregs() { - memzero(xmmregs); + std::memset(xmmregs, 0, sizeof(xmmregs)); g_xmmAllocCounter = 0; } @@ -906,11 +906,11 @@ int _allocIfUsedFPUtoXMM(int fpureg, int mode) void _recClearInst(EEINST* pinst) { // we set everything as being live to begin with, since it needs to be written at the end of the block - memzero(*pinst); - memset8(pinst->regs); - memset8(pinst->fpuregs); - memset8(pinst->vfregs); - memset8(pinst->viregs); + std::memset(pinst, 0, sizeof(EEINST)); + std::memset(pinst->regs, EEINST_LIVE, sizeof(pinst->regs)); + std::memset(pinst->fpuregs, EEINST_LIVE, sizeof(pinst->fpuregs)); + std::memset(pinst->vfregs, EEINST_LIVE, sizeof(pinst->vfregs)); + std::memset(pinst->viregs, EEINST_LIVE, sizeof(pinst->viregs)); } // returns nonzero value if reg has been written between [startpc, endpc-4] diff --git a/pcsx2/x86/ix86-32/iCore-32.cpp b/pcsx2/x86/ix86-32/iCore-32.cpp index 0f267eeeba..d35c73d574 100644 --- a/pcsx2/x86/ix86-32/iCore-32.cpp +++ b/pcsx2/x86/ix86-32/iCore-32.cpp @@ -37,7 +37,7 @@ static uint g_x86checknext; void _initX86regs() { - memzero(x86regs); + std::memset(x86regs, 0, sizeof(x86regs)); g_x86AllocCounter = 0; g_x86checknext = 0; } diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index d59cf3c023..b8952934ae 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -33,7 +33,6 @@ #include "common/AlignedMalloc.h" #include "common/FastJmp.h" -#include "common/MemsetFast.inl" #include "common/Perf.h" // Only for MOVQ workaround. diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index 38da4d7310..1d57d5a984 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -40,7 +40,7 @@ void mVUreserveCache(microVU& mVU) // Only run this once per VU! ;) void mVUinit(microVU& mVU, uint vuIndex) { - memzero(mVU.prog); + std::memset(&mVU.prog, 0, sizeof(mVU.prog)); mVU.index = vuIndex; mVU.cop2 = 0; @@ -155,7 +155,7 @@ __fi void mVUclear(mV, u32 addr, u32 size) if (!mVU.prog.cleared) { mVU.prog.cleared = 1; // Next execution searches/creates a new microprogram - memzero(mVU.prog.lpState); // Clear pipeline state + std::memset(&mVU.prog.lpState, 0, sizeof(mVU.prog.lpState)); // Clear pipeline state for (u32 i = 0; i < (mVU.progSize / 2); i++) { mVU.prog.quick[i].block = NULL; // Clear current quick-reference block diff --git a/pcsx2/x86/microVU_Branch.inl b/pcsx2/x86/microVU_Branch.inl index c580f6e122..d265960b7b 100644 --- a/pcsx2/x86/microVU_Branch.inl +++ b/pcsx2/x86/microVU_Branch.inl @@ -26,8 +26,8 @@ __fi int getLastFlagInst(microRegInfo& pState, int* xFlag, int flagType, int isE return (((pState.flagInfo >> (2 * flagType + 2)) & 3) - 1) & 3; } -void mVU0clearlpStateJIT() { if (!microVU0.prog.cleared) memzero(microVU0.prog.lpState); } -void mVU1clearlpStateJIT() { if (!microVU1.prog.cleared) memzero(microVU1.prog.lpState); } +void mVU0clearlpStateJIT() { if (!microVU0.prog.cleared) std::memset(µVU0.prog.lpState, 0, sizeof(microVU1.prog.lpState)); } +void mVU1clearlpStateJIT() { if (!microVU1.prog.cleared) std::memset(µVU1.prog.lpState, 0, sizeof(microVU1.prog.lpState)); } void mVUDTendProgram(mV, microFlagCycles* mFC, int isEbit) { @@ -166,8 +166,8 @@ void mVUendProgram(mV, microFlagCycles* mFC, int isEbit) if (isEbit && isEbit != 3) { - memzero(mVUinfo); - memzero(mVUregsTemp); + std::memset(&mVUinfo, 0, sizeof(mVUinfo)); + std::memset(&mVUregsTemp, 0, sizeof(mVUregsTemp)); mVUincCycles(mVU, 100); // Ensures Valid P/Q instances (And sets all cycle data to 0) mVUcycles -= 100; qInst = mVU.q; diff --git a/pcsx2/x86/microVU_Compile.inl b/pcsx2/x86/microVU_Compile.inl index 21c29b7932..1f8bba3432 100644 --- a/pcsx2/x86/microVU_Compile.inl +++ b/pcsx2/x86/microVU_Compile.inl @@ -497,8 +497,8 @@ __fi void startLoop(mV) DevCon.WriteLn(Color_Green, "microVU%d: D-bit set! PC = %x", getIndex, xPC); if (curI & _Tbit_) DevCon.WriteLn(Color_Green, "microVU%d: T-bit set! PC = %x", getIndex, xPC); - memzero(mVUinfo); - memzero(mVUregsTemp); + std::memset(&mVUinfo, 0, sizeof(mVUinfo)); + std::memset(&mVUregsTemp, 0, sizeof(mVUregsTemp)); } // Initialize VI Constants (vi15 propagates through blocks) diff --git a/pcsx2/x86/microVU_Profiler.h b/pcsx2/x86/microVU_Profiler.h index 9e9de013b2..1190cdbb24 100644 --- a/pcsx2/x86/microVU_Profiler.h +++ b/pcsx2/x86/microVU_Profiler.h @@ -108,7 +108,7 @@ struct microProfiler int index; void Reset(int _index) { - memzero(*this); + std::memset(this, 0, sizeof(*this)); index = _index; } void EmitOp(microOpcode op) diff --git a/pcsx2/x86/newVif_Unpack.cpp b/pcsx2/x86/newVif_Unpack.cpp index b3f975fbfb..9a9cca5081 100644 --- a/pcsx2/x86/newVif_Unpack.cpp +++ b/pcsx2/x86/newVif_Unpack.cpp @@ -82,7 +82,7 @@ void resetNewVif(int idx) nVif[idx].idx = idx; nVif[idx].bSize = 0; - memzero(nVif[idx].buffer); + std::memset(nVif[idx].buffer, 0, sizeof(nVif[idx].buffer)); if (newVifDynaRec) dVifReset(idx);