diff options
author | José Fonseca <[email protected]> | 2008-01-17 13:39:14 +0900 |
---|---|---|
committer | José Fonseca <[email protected]> | 2008-01-17 13:39:14 +0900 |
commit | 271f9dac79a9247de9a57f4d248e404bf1652a13 (patch) | |
tree | 70e049d11449f2d41a7e27076995d86827e46be7 /src/mesa/pipe/p_util.h | |
parent | b016f0adba8278f3744d3aaa207a1b586d51756d (diff) |
Back-port miscellaneous fixes from internal branch (mostly portability fixes).
These are changes that are in our internal branch, but somehow were skipped
so far. It was done using visual comparison of the branches --
it is likely that changes are being carried on the wrong way
Diffstat (limited to 'src/mesa/pipe/p_util.h')
-rw-r--r-- | src/mesa/pipe/p_util.h | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/src/mesa/pipe/p_util.h b/src/mesa/pipe/p_util.h index 69ec62e3079..573fef9b83a 100644 --- a/src/mesa/pipe/p_util.h +++ b/src/mesa/pipe/p_util.h @@ -111,6 +111,32 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size ) #define CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T)) +/** + * Return a pointer aligned to next multiple of N bytes. + */ +static INLINE void * +align_pointer( void *unaligned, uint alignment ) +{ + if (sizeof(void *) == 64) { + union { + void *p; + uint64 u; + } pu; + pu.p = unaligned; + pu.u = (pu.u + alignment - 1) & ~(uint64) (alignment - 1); + return pu.p; + } + else { + /* 32-bit pointers */ + union { + void *p; + uint u; + } pu; + pu.p = unaligned; + pu.u = (pu.u + alignment - 1) & ~(alignment - 1); + return pu.p; + } +} /** * Return memory on given byte alignment @@ -123,19 +149,18 @@ align_malloc(size_t bytes, uint alignment) (void) posix_memalign(& mem, alignment, bytes); return mem; #else - typedef unsigned long int uintptr_t; - uintptr_t ptr, buf; + char *ptr, *buf; assert( alignment > 0 ); - ptr = (uintptr_t) MALLOC(bytes + alignment + sizeof(void *)); + ptr = (char *) MALLOC(bytes + alignment + sizeof(void *)); if (!ptr) return NULL; - buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); - *(uintptr_t *)(buf - sizeof(void *)) = ptr; + buf = (char *) align_pointer( ptr + sizeof(void *), alignment ); + *(char **)(buf - sizeof(void *)) = ptr; - return (void *) buf; + return buf; #endif /* defined(HAVE_POSIX_MEMALIGN) */ } @@ -169,28 +194,17 @@ align_free(void *ptr) static INLINE void * align16( void *unaligned ) { - if (sizeof(void *) == 64) { - union { - void *p; - uint64 u; - } pu; - pu.p = unaligned; - pu.u = (pu.u + 15) & ~15; - return pu.p; - } - else { - /* 32-bit pointers */ - union { - void *p; - uint u; - } pu; - pu.p = unaligned; - pu.u = (pu.u + 15) & ~15; - return pu.p; - } + return align_pointer( unaligned, 16 ); } +static INLINE int align_int(int x, int align) +{ + return (x + align - 1) & ~(align - 1); +} + + + #if defined(__MSC__) && defined(__WIN32__) static INLINE unsigned ffs( unsigned u ) { |