mirror of https://github.com/PCSX2/pcsx2.git
rewrote zerospu2's pcsx2_aligned_malloc/free which linux builds might use.
the old logic was wrong for a few cases. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4206 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
7fe180015e
commit
3b88defb36
|
@ -67,27 +67,22 @@ inline u64 GetMicroTime()
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
// declare linux equivalents
|
// 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 align)
|
static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t alignment) {
|
||||||
{
|
assert(alignment <= 0x8000);
|
||||||
assert( align < 0x10000 );
|
uptr r = (uptr)malloc(size + --alignment + 2);
|
||||||
char* p = (char*)malloc(size+align);
|
uptr o = (r + 2 + alignment) & ~(uptr)alignment;
|
||||||
int off = 2+align - ((int)(uptr)(p+2) % align);
|
if (!r) return NULL;
|
||||||
|
((u16*)o)[-1] = (u16)(o-r);
|
||||||
p += off;
|
return (void*)o;
|
||||||
*(u16*)(p-2) = off;
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static __forceinline void pcsx2_aligned_free(void* pmem)
|
static __forceinline void pcsx2_aligned_free(void* p) {
|
||||||
{
|
if (!p) return;
|
||||||
if( pmem != NULL ) {
|
free((void*)((uptr)p-((u16*)p)[-1]));
|
||||||
char* p = (char*)pmem;
|
|
||||||
free(p - (int)*(u16*)(p-2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define _aligned_malloc pcsx2_aligned_malloc
|
#define _aligned_malloc pcsx2_aligned_malloc
|
||||||
#define _aligned_free pcsx2_aligned_free
|
#define _aligned_free pcsx2_aligned_free
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue