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:
cottonvibes 2011-01-12 23:05:46 +00:00
parent 7fe180015e
commit 3b88defb36
1 changed files with 12 additions and 17 deletions

View File

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