From 8f283fdb39897310c2303d466cb34bf3d85030ed Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 19 Jan 2015 23:12:04 +0100 Subject: [PATCH 1/4] If BX_ALIGNED_DELETE calls bx::aligned*(), BX_ALIGNED_NEW should as well. --- include/bx/allocator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index d9f740b..206ac55 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -25,7 +25,7 @@ # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align, __FILE__, __LINE__) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, __FILE__, __LINE__) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(bx::alignedAlloc(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align, __FILE__, __LINE__) #else # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size, 0) @@ -36,7 +36,7 @@ # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(bx::alignedAlloc(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align) #endif // BX_CONFIG_DEBUG_ALLOC From 8107e8f50041d930506af2da934d2f38adaa285c Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 19 Jan 2015 23:50:55 +0100 Subject: [PATCH 2/4] Do not force alignedAlloc calls, let allocator decide. --- include/bx/allocator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index 206ac55..8aa9f9e 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -25,7 +25,7 @@ # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align, __FILE__, __LINE__) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, __FILE__, __LINE__) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(bx::alignedAlloc(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align, __FILE__, __LINE__) #else # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size, 0) @@ -36,7 +36,7 @@ # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(bx::alignedAlloc(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align) #endif // BX_CONFIG_DEBUG_ALLOC @@ -157,7 +157,7 @@ namespace bx if (NULL != _object) { _object->~ObjectT(); - alignedFree(_allocator, _object, _align, _file, _line); + free(_allocator, _object, _align, _file, _line); } } From 524143452a7d786a72554ce9b36053f31ebd81f7 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 19 Jan 2015 23:58:14 +0100 Subject: [PATCH 3/4] Cleanup. --- include/bx/allocator.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index 8aa9f9e..3892c38 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -24,9 +24,9 @@ # define BX_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) bx::realloc(_allocator, _ptr, _size, _align, __FILE__, __LINE__) # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align, __FILE__, __LINE__) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type -# define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, __FILE__, __LINE__) +# define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, 0, __FILE__, __LINE__) # define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type -# define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align, __FILE__, __LINE__) +# define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::deleteObject(_allocator, _ptr, _align, __FILE__, __LINE__) #else # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size, 0) # define BX_REALLOC(_allocator, _ptr, _size) bx::realloc(_allocator, _ptr, _size, 0) @@ -35,9 +35,9 @@ # define BX_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) bx::realloc(_allocator, _ptr, _size, _align) # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type -# define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr) +# define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, 0) # define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type -# define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::alignedDeleteObject(_allocator, _ptr, _align) +# define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::deleteObject(_allocator, _ptr, _align) #endif // BX_CONFIG_DEBUG_ALLOC #ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT @@ -142,17 +142,7 @@ namespace bx } template - inline void deleteObject(AllocatorI* _allocator, ObjectT* _object, const char* _file = NULL, uint32_t _line = 0) - { - if (NULL != _object) - { - _object->~ObjectT(); - free(_allocator, _object, 0, _file, _line); - } - } - - template - inline void alignedDeleteObject(AllocatorI* _allocator, ObjectT* _object, size_t _align, const char* _file = NULL, uint32_t _line = 0) + inline void deleteObject(AllocatorI* _allocator, ObjectT* _object, size_t _align = 0, const char* _file = NULL, uint32_t _line = 0) { if (NULL != _object) { From 030e426247c3fb7861dd110f8f1ec937177848f9 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Thu, 22 Jan 2015 19:30:43 +0100 Subject: [PATCH 4/4] Added uint64_cntbits(). --- include/bx/uint32_t.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/include/bx/uint32_t.h b/include/bx/uint32_t.h index 57af36a..c02aa66 100644 --- a/include/bx/uint32_t.h +++ b/include/bx/uint32_t.h @@ -583,7 +583,7 @@ namespace bx union { uint32_t ui; float flt; } utof; utof.ui = f_result; return utof.flt; - } + } inline uint16_t uint16_min(uint16_t _a, uint16_t _b) { @@ -613,6 +613,29 @@ namespace bx return result; } + inline uint64_t uint64_cntbits_ref(uint64_t _val) + { + const uint32_t lo = uint32_t(_val&UINT32_MAX); + const uint32_t hi = uint32_t(_val>>32); + + const uint32_t total = bx::uint32_cntbits(lo) + + bx::uint32_cntbits(hi); + + return total; + } + + /// Count number of bits set. + inline uint64_t uint64_cntbits(uint64_t _val) + { +#if BX_COMPILER_GCC || BX_COMPILER_CLANG + return __builtin_popcountll(_val); +#elif BX_COMPILER_MSVC && BX_PLATFORM_WINDOWS + return __popcnt64(_val); +#else + return uint64_cntbits_ref(_val); +#endif // BX_COMPILER_ + } + inline uint64_t uint64_cntlz_ref(uint64_t _val) { return _val & UINT64_C(0xffffffff00000000)