mirror of https://github.com/PCSX2/pcsx2.git
common: remove memset duplicates
Use standard memset instead of memset_8 Move memzero/memset8 in a common OS file.
This commit is contained in:
parent
b3474b5a71
commit
632b4971de
|
@ -124,7 +124,6 @@
|
||||||
<ClInclude Include="..\..\include\Utilities\FixedPointTypes.h" />
|
<ClInclude Include="..\..\include\Utilities\FixedPointTypes.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\General.h" />
|
<ClInclude Include="..\..\include\Utilities\General.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\HashMap.h" />
|
<ClInclude Include="..\..\include\Utilities\HashMap.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\lnx_memzero.h" />
|
|
||||||
<ClInclude Include="..\..\include\Utilities\MathUtils.h" />
|
<ClInclude Include="..\..\include\Utilities\MathUtils.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\MemcpyFast.h" />
|
<ClInclude Include="..\..\include\Utilities\MemcpyFast.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\Path.h" />
|
<ClInclude Include="..\..\include\Utilities\Path.h" />
|
||||||
|
@ -136,7 +135,6 @@
|
||||||
<ClInclude Include="..\..\include\Utilities\RedtapeWindows.h" />
|
<ClInclude Include="..\..\include\Utilities\RedtapeWindows.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\SafeArray.h" />
|
<ClInclude Include="..\..\include\Utilities\SafeArray.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\StringHelpers.h" />
|
<ClInclude Include="..\..\include\Utilities\StringHelpers.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\win_memzero.h" />
|
|
||||||
<ClInclude Include="..\..\include\Utilities\wxAppWithHelpers.h" />
|
<ClInclude Include="..\..\include\Utilities\wxAppWithHelpers.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\wxBaseTools.h" />
|
<ClInclude Include="..\..\include\Utilities\wxBaseTools.h" />
|
||||||
<ClInclude Include="..\..\include\Utilities\wxGuiTools.h" />
|
<ClInclude Include="..\..\include\Utilities\wxGuiTools.h" />
|
||||||
|
|
|
@ -165,9 +165,6 @@
|
||||||
<ClInclude Include="..\..\include\Utilities\HashMap.h">
|
<ClInclude Include="..\..\include\Utilities\HashMap.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\Utilities\lnx_memzero.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\include\Utilities\MathUtils.h">
|
<ClInclude Include="..\..\include\Utilities\MathUtils.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -201,9 +198,6 @@
|
||||||
<ClInclude Include="..\..\include\Utilities\StringHelpers.h">
|
<ClInclude Include="..\..\include\Utilities\StringHelpers.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\include\Utilities\win_memzero.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\include\Utilities\wxAppWithHelpers.h">
|
<ClInclude Include="..\..\include\Utilities\wxAppWithHelpers.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -15,12 +15,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(__POSIX__)
|
|
||||||
#include "lnx_memzero.h"
|
|
||||||
#else
|
|
||||||
#include "win_memzero.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// For 32-bit MSVC compiles, memcmp performs much worse than memcmp_mmx and
|
// For 32-bit MSVC compiles, memcmp performs much worse than memcmp_mmx and
|
||||||
// other implementations. So for this combination only, prefer memcmp_mmx
|
// other implementations. So for this combination only, prefer memcmp_mmx
|
||||||
#if defined(_MSC_VER) && !defined(_M_X86_64)
|
#if defined(_MSC_VER) && !defined(_M_X86_64)
|
||||||
|
@ -28,3 +22,19 @@ extern u8 memcmp_mmx(const void *src1, const void *src2, int cmpsize);
|
||||||
#else
|
#else
|
||||||
#define memcmp_mmx memcmp
|
#define memcmp_mmx memcmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
|
@ -1,60 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LNX_MEMZERO_H_
|
|
||||||
#define _LNX_MEMZERO_H_
|
|
||||||
|
|
||||||
// This header contains non-optimized implementation of memzero_ptr and memset8, etc
|
|
||||||
|
|
||||||
template <u32 data, typename T>
|
|
||||||
static __fi void memset32(T &obj)
|
|
||||||
{
|
|
||||||
// this function works on 32-bit aligned lengths of data only.
|
|
||||||
// If the data length is not a factor of 32 bits, the C++ optimizing compiler will
|
|
||||||
// probably just generate mysteriously broken code in Release builds. ;)
|
|
||||||
|
|
||||||
pxAssume((sizeof(T) & 0x3) == 0);
|
|
||||||
|
|
||||||
u32 *dest = (u32 *)&obj;
|
|
||||||
for (int i = sizeof(T) >> 2; i; --i, ++dest)
|
|
||||||
*dest = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static __fi void memzero(T &obj)
|
|
||||||
{
|
|
||||||
memset(&obj, 0, sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <u8 data, typename T>
|
|
||||||
static __fi void memset8(T &obj)
|
|
||||||
{
|
|
||||||
// Aligned sizes use the optimized 32 bit inline memset. Unaligned sizes use memset.
|
|
||||||
if ((sizeof(T) & 0x3) != 0)
|
|
||||||
memset(&obj, data, sizeof(T));
|
|
||||||
else {
|
|
||||||
const u32 data32 = data + (data << 8) + (data << 16) + (data << 24);
|
|
||||||
memset32<data32>(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Code is only called in the init so no need to bother with ASM
|
|
||||||
template <u8 data, size_t bytes>
|
|
||||||
static __fi void memset_8(void *dest)
|
|
||||||
{
|
|
||||||
memset(dest, data, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,45 +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
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(disable : 4063) // case '1' is not a valid value for switch()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// These functions are meant for memset operations of constant length only.
|
|
||||||
// For dynamic length clears, use the C-compiler provided memset instead.
|
|
||||||
|
|
||||||
template <u8 data, size_t bytes>
|
|
||||||
static __fi void memset_8(void *dest)
|
|
||||||
{
|
|
||||||
memset(dest, data, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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_8<data, sizeof(T)>(&object);
|
|
||||||
}
|
|
|
@ -59,7 +59,6 @@ set(UtilitiesHeaders
|
||||||
../../include/Utilities/FixedPointTypes.h
|
../../include/Utilities/FixedPointTypes.h
|
||||||
../../include/Utilities/General.h
|
../../include/Utilities/General.h
|
||||||
../../include/Utilities/HashMap.h
|
../../include/Utilities/HashMap.h
|
||||||
../../include/Utilities/lnx_memzero.h
|
|
||||||
../../include/Utilities/MemcpyFast.h
|
../../include/Utilities/MemcpyFast.h
|
||||||
../../include/Utilities/MemsetFast.inl
|
../../include/Utilities/MemsetFast.inl
|
||||||
../../include/Utilities/Path.h
|
../../include/Utilities/Path.h
|
||||||
|
|
|
@ -193,7 +193,7 @@ static void _DynGen_Dispatchers()
|
||||||
HostSys::MemProtectStatic( iopRecDispatchers, PageAccess_ReadWrite() );
|
HostSys::MemProtectStatic( iopRecDispatchers, PageAccess_ReadWrite() );
|
||||||
|
|
||||||
// clear the buffer to 0xcc (easier debugging).
|
// clear the buffer to 0xcc (easier debugging).
|
||||||
memset_8<0xcc,__pagesize>( iopRecDispatchers );
|
memset( iopRecDispatchers, 0xcc, __pagesize);
|
||||||
|
|
||||||
xSetPtr( iopRecDispatchers );
|
xSetPtr( iopRecDispatchers );
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@ static void _DynGen_Dispatchers()
|
||||||
HostSys::MemProtectStatic( eeRecDispatchers, PageAccess_ReadWrite() );
|
HostSys::MemProtectStatic( eeRecDispatchers, PageAccess_ReadWrite() );
|
||||||
|
|
||||||
// clear the buffer to 0xcc (easier debugging).
|
// clear the buffer to 0xcc (easier debugging).
|
||||||
memset_8<0xcc,__pagesize>( eeRecDispatchers );
|
memset( eeRecDispatchers, 0xcc, __pagesize);
|
||||||
|
|
||||||
xSetPtr( eeRecDispatchers );
|
xSetPtr( eeRecDispatchers );
|
||||||
|
|
||||||
|
|
|
@ -318,7 +318,7 @@ void vtlb_dynarec_init()
|
||||||
HostSys::MemProtectStatic( m_IndirectDispatchers, PageAccess_ReadWrite() );
|
HostSys::MemProtectStatic( m_IndirectDispatchers, PageAccess_ReadWrite() );
|
||||||
|
|
||||||
// clear the buffer to 0xcc (easier debugging).
|
// clear the buffer to 0xcc (easier debugging).
|
||||||
memset_8<0xcc,0x1000>( m_IndirectDispatchers );
|
memset( m_IndirectDispatchers, 0xcc, __pagesize);
|
||||||
|
|
||||||
for( int mode=0; mode<2; ++mode )
|
for( int mode=0; mode<2; ++mode )
|
||||||
{
|
{
|
||||||
|
|
|
@ -565,7 +565,7 @@ __pagealigned u8 mVUsearchXMM[__pagesize];
|
||||||
// Note: Structs must be 16-byte aligned! (GCC doesn't guarantee this)
|
// Note: Structs must be 16-byte aligned! (GCC doesn't guarantee this)
|
||||||
void mVUcustomSearch() {
|
void mVUcustomSearch() {
|
||||||
HostSys::MemProtectStatic(mVUsearchXMM, PageAccess_ReadWrite());
|
HostSys::MemProtectStatic(mVUsearchXMM, PageAccess_ReadWrite());
|
||||||
memset_8<0xcc,__pagesize>(mVUsearchXMM);
|
memset(mVUsearchXMM, 0xcc, __pagesize);
|
||||||
xSetPtr(mVUsearchXMM);
|
xSetPtr(mVUsearchXMM);
|
||||||
|
|
||||||
xMOVAPS (xmm0, ptr32[ecx]);
|
xMOVAPS (xmm0, ptr32[ecx]);
|
||||||
|
|
Loading…
Reference in New Issue