2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-10-05 11:05:11 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LNX_MEMZERO_H_
|
|
|
|
#define _LNX_MEMZERO_H_
|
|
|
|
|
2014-08-17 11:03:43 +00:00
|
|
|
// This header contains non-optimized implementation of memzero_ptr and memset8, etc
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template <u32 data, typename T>
|
|
|
|
static __fi void memset32(T &obj)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
// 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. ;)
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
pxAssume((sizeof(T) & 0x3) == 0);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
u32 *dest = (u32 *)&obj;
|
|
|
|
for (int i = sizeof(T) >> 2; i; --i, ++dest)
|
|
|
|
*dest = data;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template <typename T>
|
|
|
|
static __fi void memzero(T &obj)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
memset(&obj, 0, sizeof(T));
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
template <u8 data, typename T>
|
|
|
|
static __fi void memset8(T &obj)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 15:36:59 +00:00
|
|
|
// Code is only called in the init so no need to bother with ASM
|
2016-11-12 15:28:37 +00:00
|
|
|
template <u8 data, size_t bytes>
|
|
|
|
static __fi void memset_8(void *dest)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2016-11-12 15:28:37 +00:00
|
|
|
memset(dest, data, bytes);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|