Common: Move MemcpyFast routines to General.h

And add a trivially-copyable check, so nobody accidentially uses them
with non-POD types.
This commit is contained in:
Stenzek 2023-06-15 01:36:54 +10:00 committed by Connor McLaughlin
parent 9613b43d50
commit 03242a2953
7 changed files with 22 additions and 45 deletions

View File

@ -80,7 +80,6 @@ target_sources(common PRIVATE
LRUCache.h
HeapArray.h
HTTPDownloader.h
MemcpyFast.h
MemorySettingsInterface.h
MemsetFast.inl
MD5Digest.h

View File

@ -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 <atomic>
#include <map>
#include <memory>
#include <string>
#include "common/Pcsx2Defs.h"
#include <cstring>
// 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 <typename T>
static __fi void memzero(T& object)
{
static_assert(std::is_trivially_copyable_v<T>);
std::memset(&object, 0, sizeof(T));
}
// This method clears an object with the given 8 bit value.
template <u8 data, typename T>
static __fi void memset8(T& object)
{
static_assert(std::is_trivially_copyable_v<T>);
std::memset(&object, data, sizeof(T));
}
extern u64 GetTickFrequency();
extern u64 GetCPUTicks();
extern u64 GetPhysicalMemory();

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstring> // 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 <typename T>
static __fi void memzero(T& object)
{
memset(&object, 0, sizeof(T));
}
// This method clears an object with the given 8 bit value.
template <u8 data, typename T>
static __fi void memset8(T& object)
{
memset(&object, data, sizeof(T));
}

View File

@ -134,7 +134,6 @@
<ClInclude Include="Exceptions.h" />
<ClInclude Include="General.h" />
<ClInclude Include="MathUtils.h" />
<ClInclude Include="MemcpyFast.h" />
<ClInclude Include="Path.h" />
<ClInclude Include="PrecompiledHeader.h" />
<ClInclude Include="ReadbackSpinManager.h" />

View File

@ -201,9 +201,6 @@
<ClInclude Include="MathUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MemcpyFast.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Path.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@ -13,7 +13,6 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/MemcpyFast.h"
#include "common/General.h"
#include "common/emitter/tools.h"
#include "common/emitter/internal.h"

View File

@ -66,7 +66,6 @@
#include "PCSX2Base.h"
#include "common/Console.h"
#include "common/MemcpyFast.h"
#include "common/General.h"
#include "common/emitter/tools.h"