mirror of https://github.com/PCSX2/pcsx2.git
Use posix_memalign and _aligned_malloc for alignment. Remove unused code.
This commit is contained in:
parent
707d32536c
commit
2ba0b1b76b
|
@ -95,7 +95,6 @@
|
|||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Console.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Exceptions.cpp" />
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -99,7 +99,6 @@
|
|||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Console.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Exceptions.cpp" />
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -99,7 +99,6 @@
|
|||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Console.cpp" />
|
||||
<ClCompile Include="..\..\src\Utilities\Exceptions.cpp" />
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace HostSys
|
|||
|
||||
extern void MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode );
|
||||
|
||||
extern void Munmap( void* base, size_t size );
|
||||
extern void Munmap( void* base, size_t size ) { Munmap( (uptr)base, size); }
|
||||
|
||||
template< uint size >
|
||||
void MemProtectStatic( u8 (&arr)[size], const PageProtectionMode& mode )
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <wx/string.h>
|
||||
|
||||
namespace HashTools {
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -35,9 +35,6 @@
|
|||
|
||||
#endif
|
||||
|
||||
// Only used in the Windows version of memzero.h. But it's in Misc.cpp for some reason.
|
||||
void _memset16_unaligned( void* dest, u16 data, size_t size );
|
||||
|
||||
// MemcpyVibes.cpp functions
|
||||
extern void memcpy_vibes(void * dest, const void * src, int size);
|
||||
extern void gen_memcpy_vibes();
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
|
||||
// Force availability of to WinNT APIs (change to 0x600 to enable XP-specific APIs)
|
||||
// Force availability of to WinNT APIs (change to 0x600 to disable XP-specific APIs)
|
||||
#ifndef WINVER
|
||||
#define WINVER 0x0501
|
||||
#define _WIN32_WINNT 0x0501
|
||||
|
|
|
@ -48,16 +48,31 @@
|
|||
#define safe_aligned_free( ptr ) \
|
||||
((void) ( _aligned_free( ptr ), (ptr) = NULL ))
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
|
||||
static __forceinline void* _aligned_malloc(size_t size, size_t alignment) {
|
||||
void *result=0;
|
||||
posix_memalign(&result, alignment, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align);
|
||||
extern void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align);
|
||||
extern void pcsx2_aligned_free(void* pmem);
|
||||
void* __fastcall _aligned_realloc(void* handle, size_t size, size_t align)
|
||||
{
|
||||
pxAssert( align < 0x10000 );
|
||||
|
||||
// aligned_malloc: Implement/declare linux equivalents here!
|
||||
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
|
||||
# define _aligned_malloc pcsx2_aligned_malloc
|
||||
# define _aligned_free pcsx2_aligned_free
|
||||
# define _aligned_realloc pcsx2_aligned_realloc
|
||||
void* newbuf = _aligned_malloc( size, align );
|
||||
|
||||
if( handle != NULL )
|
||||
{
|
||||
memcpy_fast( newbuf, handle, size );
|
||||
free( handle );
|
||||
}
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
static __forceinline void _aligned_free(void* p) {
|
||||
free(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
|
|
@ -250,6 +250,3 @@ extern void ssprintf(std::string& dest, const char* fmt, ...);
|
|||
extern void ssappendf(std::string& dest, const char* format, ...);
|
||||
extern void vssprintf(std::string& dest, const char* format, va_list args);
|
||||
extern void vssappendf(std::string& dest, const char* format, va_list args);
|
||||
|
||||
extern std::string fmt_string( const char* fmt, ... );
|
||||
extern std::string vfmt_string( const char* fmt, va_list args );
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#ifndef _LNX_MEMZERO_H_
|
||||
#define _LNX_MEMZERO_H_
|
||||
|
||||
// This header contains non-optimized implementation of memzero_ptr and memset8,
|
||||
// memset16, etc.
|
||||
// This header contains non-optimized implementation of memzero_ptr and memset8, etc
|
||||
|
||||
template< u32 data, typename T >
|
||||
static __fi void memset32( T& obj )
|
||||
|
@ -57,18 +56,6 @@ static __fi void memset8( T& obj )
|
|||
}
|
||||
}
|
||||
|
||||
template< u16 data, typename T >
|
||||
static __fi void memset16( T& obj )
|
||||
{
|
||||
if( (sizeof(T) & 0x3) != 0 )
|
||||
_memset16_unaligned( &obj, data, sizeof( T ) );
|
||||
else {
|
||||
const u32 data32 = data + (data<<16);
|
||||
memset32<data32>( obj );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// An optimized memset for 8 bit destination data.
|
||||
template< u8 data, size_t bytes >
|
||||
static __fi void memset_8( void *dest )
|
||||
|
|
|
@ -373,94 +373,6 @@ static __fi void memset_8( void *dest )
|
|||
}
|
||||
}
|
||||
|
||||
template< u16 data, size_t _bytes >
|
||||
static __fi void memset_16( void *dest )
|
||||
{
|
||||
if( MZFbytes == 0 ) return;
|
||||
|
||||
// Assertion: data length must be a multiple of 16 or 32 bits
|
||||
pxAssume( (MZFbytes & 0x1) == 0 );
|
||||
|
||||
if( (MZFbytes & 0x3) != 0 )
|
||||
{
|
||||
// Unaligned data length. No point in doing an optimized inline version (too complicated with
|
||||
// remainders and such).
|
||||
|
||||
_memset16_unaligned( dest, data, MZFbytes );
|
||||
return;
|
||||
}
|
||||
|
||||
//u64 _xmm_backup[2];
|
||||
|
||||
// This function only works on 32-bit alignments of data copied.
|
||||
pxAssume( (MZFbytes & 0x3) == 0 );
|
||||
|
||||
enum
|
||||
{
|
||||
remdat = MZFbytes >> 2,
|
||||
data32 = data + (data<<16)
|
||||
};
|
||||
|
||||
// macro to execute the x86/32 "stosd" copies.
|
||||
switch( remdat )
|
||||
{
|
||||
case 1:
|
||||
*(u32*)dest = data32;
|
||||
return;
|
||||
|
||||
case 2:
|
||||
((u32*)dest)[0] = data32;
|
||||
((u32*)dest)[1] = data32;
|
||||
return;
|
||||
|
||||
case 3:
|
||||
__asm
|
||||
{
|
||||
mov edi, dest;
|
||||
mov eax, data32;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
}
|
||||
return;
|
||||
|
||||
case 4:
|
||||
__asm
|
||||
{
|
||||
mov edi, dest;
|
||||
mov eax, data32;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
}
|
||||
return;
|
||||
|
||||
case 5:
|
||||
__asm
|
||||
{
|
||||
mov edi, dest;
|
||||
mov eax, data32;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
stosd;
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
__asm
|
||||
{
|
||||
mov ecx, remdat;
|
||||
mov edi, dest;
|
||||
mov eax, data32;
|
||||
rep stosd;
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
template< u32 data, size_t MZFbytes >
|
||||
static __fi void memset_32( void *dest )
|
||||
{
|
||||
|
@ -559,13 +471,6 @@ static __fi void memset8( T& object )
|
|||
memset_8<data, sizeof(T)>( &object );
|
||||
}
|
||||
|
||||
// This method clears an object with the given 16 bit value.
|
||||
template< u16 data, typename T >
|
||||
static __fi void memset16( T& object )
|
||||
{
|
||||
memset_16<data, sizeof(T)>( &object );
|
||||
}
|
||||
|
||||
// This method clears an object with the given 32 bit value.
|
||||
template< u32 data, typename T >
|
||||
static __fi void memset32( T& object )
|
||||
|
|
|
@ -1,101 +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/>.
|
||||
*/
|
||||
|
||||
// This module contains implementations of _aligned_malloc for platforms that don't have
|
||||
// it built into their CRT/libc.
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
struct AlignedMallocHeader
|
||||
{
|
||||
u32 size; // size of the allocated buffer (minus alignment and header)
|
||||
void* baseptr; // offset of the original allocated pointer
|
||||
};
|
||||
|
||||
static const uint headsize = sizeof(AlignedMallocHeader);
|
||||
|
||||
void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
|
||||
{
|
||||
pxAssert( align < 0x10000 );
|
||||
|
||||
#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
|
||||
return aligned_alloc(align, size);
|
||||
#else
|
||||
u8* p = (u8*)malloc(size+align+headsize);
|
||||
|
||||
// start alignment calculations from past the header.
|
||||
uptr pasthead = (uptr)(p+headsize);
|
||||
uptr aligned = (pasthead + align-1) & ~(align-1);
|
||||
|
||||
AlignedMallocHeader* header = (AlignedMallocHeader*)(aligned-headsize);
|
||||
pxAssert( (uptr)header >= (uptr)p );
|
||||
|
||||
header->baseptr = p;
|
||||
header->size = size;
|
||||
|
||||
return (void*)aligned;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align)
|
||||
{
|
||||
pxAssert( align < 0x10000 );
|
||||
|
||||
void* newbuf = pcsx2_aligned_malloc( size, align );
|
||||
|
||||
if( handle != NULL )
|
||||
{
|
||||
#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
|
||||
memcpy_fast( newbuf, handle, size );
|
||||
free( handle );
|
||||
#else
|
||||
AlignedMallocHeader* header = (AlignedMallocHeader*)((uptr)handle - headsize);
|
||||
memcpy_fast( newbuf, handle, std::min( size, header->size ) );
|
||||
free( header->baseptr );
|
||||
#endif
|
||||
}
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
__fi void pcsx2_aligned_free(void* pmem)
|
||||
{
|
||||
#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
|
||||
free(pmem);
|
||||
#else
|
||||
if( pmem == NULL ) return;
|
||||
AlignedMallocHeader* header = (AlignedMallocHeader*)((uptr)pmem - headsize);
|
||||
free( header->baseptr );
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// And for lack of a better home ...
|
||||
|
||||
|
||||
// Special unaligned memset used when all other optimized memsets fail (it's called from
|
||||
// memzero_obj and stuff).
|
||||
__fi void _memset16_unaligned( void* dest, u16 data, size_t size )
|
||||
{
|
||||
pxAssume( (size & 0x1) == 0 );
|
||||
|
||||
u16* dst = (u16*)dest;
|
||||
for(int i=size; i; --i, ++dst )
|
||||
*dst = data;
|
||||
}
|
||||
|
||||
__fi void HostSys::Munmap( void* base, size_t size )
|
||||
{
|
||||
Munmap( (uptr)base, size );
|
||||
}
|
|
@ -87,7 +87,6 @@ set(UtilitiesSources
|
|||
../../include/Utilities/EventSource.inl
|
||||
../../include/Utilities/SafeArray.inl
|
||||
../../include/Utilities/TlsVariable.inl
|
||||
AlignedMalloc.cpp
|
||||
CheckedStaticBox.cpp
|
||||
Console.cpp
|
||||
EventSource.cpp
|
||||
|
|
|
@ -815,22 +815,3 @@ void ssprintf(std::string& str, const char* fmt, ...)
|
|||
vssprintf(str, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
// See ssprintf for usage details and differences from sprintf formatting.
|
||||
std::string fmt_string( const char* fmt, ... )
|
||||
{
|
||||
std::string retval;
|
||||
va_list args;
|
||||
va_start( args, fmt );
|
||||
vssprintf( retval, fmt, args );
|
||||
va_end( args );
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::string vfmt_string( const char* fmt, va_list args )
|
||||
{
|
||||
std::string retval;
|
||||
vssprintf( retval, fmt, args );
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -103,28 +103,3 @@ void vmfree(void* ptr, size_t size)
|
|||
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
|
||||
|
||||
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
|
||||
|
||||
#if !defined(__USE_ISOC11) || defined(ASAN_WORKAROUND)
|
||||
|
||||
void* _aligned_malloc(size_t size, size_t alignment)
|
||||
{
|
||||
ASSERT(alignment <= 0x8000);
|
||||
size_t r = (size_t)malloc(size + --alignment + 2);
|
||||
size_t o = (r + 2 + alignment) & ~(size_t)alignment;
|
||||
if(!r) return NULL;
|
||||
((uint16*)o)[-1] = (uint16)(o-r);
|
||||
return (void*)o;
|
||||
}
|
||||
|
||||
void _aligned_free(void* p)
|
||||
{
|
||||
if(!p) return;
|
||||
free((void*)((size_t)p-((uint16*)p)[-1]));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -357,18 +357,15 @@ struct aligned_free_second {template<class T> void operator()(T& p) {_aligned_fr
|
|||
#undef abs
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
static inline void _aligned_malloc(size, a) {
|
||||
void* ret;
|
||||
posix_memalign(&return, a, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
|
||||
|
||||
#define _aligned_malloc(size, a) aligned_alloc(a, size)
|
||||
static inline void _aligned_free(void* p) { free(p); }
|
||||
|
||||
#elif !defined(HAVE_ALIGNED_MALLOC)
|
||||
|
||||
extern void* _aligned_malloc(size_t size, size_t alignment);
|
||||
extern void _aligned_free(void* p);
|
||||
|
||||
#endif
|
||||
static inline void _aligned_free(void* p) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
// http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/mingw32/intrin_x86.h?view=markup
|
||||
|
||||
|
|
|
@ -69,32 +69,17 @@ extern std::string s_strIniPath;
|
|||
extern u32 THR_KeyEvent; // value for passing out key events beetwen threads
|
||||
extern bool THR_bShift;
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
|
||||
|
||||
// declare linux equivalents
|
||||
static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t align)
|
||||
{
|
||||
assert( align < 0x10000 );
|
||||
char* p = (char*)malloc(size+align);
|
||||
int off = 2+align - ((int)(uptr)(p+2) % align);
|
||||
|
||||
p += off;
|
||||
*(u16*)(p-2) = off;
|
||||
|
||||
return p;
|
||||
#if !defined(_MSC_VER)
|
||||
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
|
||||
static __forceinline void* _aligned_malloc(size_t size, size_t alignment) {
|
||||
void *result=0;
|
||||
posix_memalign(&result, alignment, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
static __forceinline void pcsx2_aligned_free(void* pmem)
|
||||
{
|
||||
if( pmem != NULL ) {
|
||||
char* p = (char*)pmem;
|
||||
free(p - (int)*(u16*)(p-2));
|
||||
}
|
||||
static __forceinline void _aligned_free(void* p) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
#define _aligned_malloc pcsx2_aligned_malloc
|
||||
#define _aligned_free pcsx2_aligned_free
|
||||
|
||||
#endif
|
||||
|
||||
#include <sys/timeb.h> // ftime(), struct timeb
|
||||
|
|
|
@ -63,26 +63,15 @@ inline u64 GetMicroTime()
|
|||
#endif
|
||||
}
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
|
||||
static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t alignment) {
|
||||
assert(alignment <= 0x8000);
|
||||
uptr r = (uptr)malloc(size + --alignment + 2);
|
||||
uptr o = (r + 2 + alignment) & ~(uptr)alignment;
|
||||
if (!r) return NULL;
|
||||
((u16*)o)[-1] = (u16)(o-r);
|
||||
return (void*)o;
|
||||
static __forceinline void* _aligned_malloc(size_t size, size_t alignment) {
|
||||
void *result=0;
|
||||
posix_memalign(&result, alignment, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
static __forceinline void pcsx2_aligned_free(void* p) {
|
||||
if (!p) return;
|
||||
free((void*)((uptr)p-((u16*)p)[-1]));
|
||||
static __forceinline void _aligned_free(void* p) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
#define _aligned_malloc pcsx2_aligned_malloc
|
||||
#define _aligned_free pcsx2_aligned_free
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue