pcsx2:gsdx: support of cross-platform (C11) aligned_malloc

This commit is contained in:
Gregory Hainaut 2014-06-13 20:56:21 +02:00
parent 9e22135f35
commit eb947dc325
3 changed files with 24 additions and 3 deletions

View File

@ -30,6 +30,9 @@ void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
{
pxAssert( align < 0x10000 );
#ifdef __USE_ISOC11
return aligned_alloc(align, size);
#else
u8* p = (u8*)malloc(size+align+headsize);
// start alignment calculations from past the header.
@ -43,6 +46,7 @@ void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
header->size = size;
return (void*)aligned;
#endif
}
void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align)
@ -53,18 +57,27 @@ void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align)
if( handle != NULL )
{
#ifdef __USE_ISOC11
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)
{
#ifdef __USE_ISOC11
free(pmem);
#else
if( pmem == NULL ) return;
AlignedMallocHeader* header = (AlignedMallocHeader*)((uptr)pmem - headsize);
free( header->baseptr );
#endif
}
// ----------------------------------------------------------------------------

View File

@ -107,6 +107,8 @@ void vmfree(void* ptr, size_t size)
// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15)
#if !defined(__USE_ISOC11)
void* _aligned_malloc(size_t size, size_t alignment)
{
ASSERT(alignment <= 0x8000);
@ -124,3 +126,5 @@ void _aligned_free(void* p)
}
#endif
#endif

View File

@ -71,6 +71,7 @@ typedef uint32 uptr;
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <time.h>
@ -185,8 +186,6 @@ using namespace std;
#else
#define _BACKWARD_BACKWARD_WARNING_H
#define hash_map map
#define hash_set set
@ -359,7 +358,12 @@ struct aligned_free_second {template<class T> void operator()(T& p) {_aligned_fr
#if !defined(_MSC_VER)
#if !defined(HAVE_ALIGNED_MALLOC)
#if defined(__USE_ISOC11)
#define _aligned_malloc(size, a) aligned_alloc(a, size)
static 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);