From 03242a29532986390799adca71ff5b3881961bc5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 15 Jun 2023 01:36:54 +1000 Subject: [PATCH] Common: Move MemcpyFast routines to General.h And add a trivially-copyable check, so nobody accidentially uses them with non-POD types. --- common/CMakeLists.txt | 1 - common/General.h | 24 +++++++++++++++++++++-- common/MemcpyFast.h | 36 ----------------------------------- common/common.vcxproj | 1 - common/common.vcxproj.filters | 3 --- common/emitter/cpudetect.cpp | 1 - pcsx2/PrecompiledHeader.h | 1 - 7 files changed, 22 insertions(+), 45 deletions(-) delete mode 100644 common/MemcpyFast.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 6866582d54..a5b37aeb9c 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -80,7 +80,6 @@ target_sources(common PRIVATE LRUCache.h HeapArray.h HTTPDownloader.h - MemcpyFast.h MemorySettingsInterface.h MemsetFast.inl MD5Digest.h diff --git a/common/General.h b/common/General.h index 7fe634b665..6318683791 100644 --- a/common/General.h +++ b/common/General.h @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team + * Copyright (C) 2002-2023 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- @@ -15,11 +15,13 @@ #pragma once +#include "common/Pcsx2Defs.h" + #include #include #include #include -#include "common/Pcsx2Defs.h" +#include // This macro is actually useful for about any and every possible application of C++ // equality operators. @@ -196,6 +198,24 @@ 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/MemcpyFast.h b/common/MemcpyFast.h deleted file mode 100644 index 29b733cd31..0000000000 --- a/common/MemcpyFast.h +++ /dev/null @@ -1,36 +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 // memset -#include "common/Pcsx2Types.h" -#include "common/Pcsx2Defs.h" - -// 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) -{ - memset(&object, 0, sizeof(T)); -} - -// This method clears an object with the given 8 bit value. -template -static __fi void memset8(T& object) -{ - memset(&object, data, sizeof(T)); -} diff --git a/common/common.vcxproj b/common/common.vcxproj index bb54b2e1e5..5431f94f42 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -134,7 +134,6 @@ - diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index 50720e3f5f..09ab4632a4 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -201,9 +201,6 @@ Header Files - - Header Files - Header Files diff --git a/common/emitter/cpudetect.cpp b/common/emitter/cpudetect.cpp index f4655064aa..7262237f4f 100644 --- a/common/emitter/cpudetect.cpp +++ b/common/emitter/cpudetect.cpp @@ -13,7 +13,6 @@ * If not, see . */ -#include "common/MemcpyFast.h" #include "common/General.h" #include "common/emitter/tools.h" #include "common/emitter/internal.h" diff --git a/pcsx2/PrecompiledHeader.h b/pcsx2/PrecompiledHeader.h index 3d0dea8adb..2108ab3506 100644 --- a/pcsx2/PrecompiledHeader.h +++ b/pcsx2/PrecompiledHeader.h @@ -66,7 +66,6 @@ #include "PCSX2Base.h" #include "common/Console.h" -#include "common/MemcpyFast.h" #include "common/General.h" #include "common/emitter/tools.h"