Merge branch 'alignment' of git://github.com/xsacha/pcsx2 into xsacha-alignment

Gregory: Get all changes but keep C11 code path which will be the future
 (if someone can find info on Visual Studio support)
* Keep the old posix api to use address sanitizer on gcc 4.9

Conflicts:
	common/build/Utilities/utilities.vcxproj.filters
	common/build/Utilities/utilities_vs2012.vcxproj.filters
	common/build/Utilities/utilities_vs2013.vcxproj.filters
	common/include/Utilities/MemcpyFast.h
	common/include/Utilities/StringHelpers.h
	common/src/Utilities/AlignedMalloc.cpp
	common/src/Utilities/vssprintf.cpp
	plugins/GSdx/stdafx.cpp
This commit is contained in:
Gregory Hainaut 2015-06-05 20:31:14 +02:00
commit 4feeaac7d1
11 changed files with 33 additions and 219 deletions

View File

@ -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 )

View File

@ -15,8 +15,6 @@
#pragma once
#include <wx/string.h>
namespace HashTools {
/// <summary>

View File

@ -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

View File

@ -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 )
@ -51,18 +50,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 )

View File

@ -186,94 +186,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 )
{
@ -372,13 +284,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 )

View File

@ -33,19 +33,9 @@ void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
#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;
void *result=0;
posix_memalign(&result, alignment, size);
return result;
#endif
}
@ -57,45 +47,13 @@ void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t 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 );
}

View File

@ -54,11 +54,11 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release)
# variable with all sources of this library
set(UtilitiesSources
AlignedMalloc.cpp
../../include/Utilities/FixedPointTypes.inl
../../include/Utilities/EventSource.inl
../../include/Utilities/SafeArray.inl
../../include/Utilities/TlsVariable.inl
AlignedMalloc.cpp
CheckedStaticBox.cpp
Console.cpp
EventSource.cpp

View File

@ -103,7 +103,7 @@ void vmfree(void* ptr, size_t size)
#endif
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
#if !defined(_MSC_VER)
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
@ -111,18 +111,9 @@ void vmfree(void* ptr, size_t size)
void* _aligned_malloc(size_t size, size_t alignment)
{
ASSERT(alignment <= 0x8000);
size_t r = (size_t)malloc(size + --alignment + 2);
size_t off = (r + 2 + alignment) & ~(size_t)alignment;
if(!r) return NULL;
((uint16*)off)[-1] = (uint16)(off-r);
return (void*)off;
}
void _aligned_free(void* p)
{
if(!p) return;
free((void*)((size_t)p-((uint16*)p)[-1]));
void* ret;
posix_memalign(&return, a, size);
return ret;
}
#endif

View File

@ -359,19 +359,20 @@ struct aligned_free_second {template<class T> void operator()(T& p) {_aligned_fr
#undef abs
#if !defined(_MSC_VER)
#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)
#else
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
__forceinline unsigned char _BitScanForward(unsigned long* const Index, const unsigned long Mask)

View File

@ -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

View File

@ -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