mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-18 04:53:06 +01:00
Cleanup.
This commit is contained in:
@@ -55,6 +55,9 @@ namespace bx
|
||||
virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) = 0;
|
||||
};
|
||||
|
||||
/// Check if pointer is aligned. _align must be power of two.
|
||||
bool isAligned(const void* _ptr, size_t _align);
|
||||
|
||||
/// Aligns pointer to nearest next aligned address. _align must be power of two.
|
||||
void* alignPtr(
|
||||
void* _ptr
|
||||
|
||||
@@ -13,13 +13,20 @@ namespace bx
|
||||
{
|
||||
}
|
||||
|
||||
inline bool isAligned(const void* _ptr, size_t _align)
|
||||
{
|
||||
union { const void* ptr; uintptr_t addr; } un;
|
||||
un.ptr = _ptr;
|
||||
return 0 == (un.addr & (_align-1) );
|
||||
}
|
||||
|
||||
inline void* alignPtr(void* _ptr, size_t _extra, size_t _align)
|
||||
{
|
||||
union { void* ptr; size_t addr; } un;
|
||||
union { void* ptr; uintptr_t addr; } un;
|
||||
un.ptr = _ptr;
|
||||
size_t unaligned = un.addr + _extra; // space for header
|
||||
size_t mask = _align-1;
|
||||
size_t aligned = BX_ALIGN_MASK(unaligned, mask);
|
||||
uintptr_t unaligned = un.addr + _extra; // space for header
|
||||
uintptr_t mask = _align-1;
|
||||
uintptr_t aligned = BX_ALIGN_MASK(unaligned, mask);
|
||||
un.addr = aligned;
|
||||
return un.ptr;
|
||||
}
|
||||
|
||||
@@ -46,14 +46,6 @@ namespace bx
|
||||
Ty tmp = _a; _a = _b; _b = tmp;
|
||||
}
|
||||
|
||||
/// Check if pointer is aligned. _align must be power of two.
|
||||
inline bool isPtrAligned(const void* _ptr, size_t _align)
|
||||
{
|
||||
union { const void* ptr; size_t addr; } un;
|
||||
un.ptr = _ptr;
|
||||
return 0 == (un.addr & (_align-1) );
|
||||
}
|
||||
|
||||
/// Scatter/gather memcpy.
|
||||
inline void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef BX_HASH_H_HEADER_GUARD
|
||||
#define BX_HASH_H_HEADER_GUARD
|
||||
|
||||
#include "bx.h"
|
||||
#include "allocator.h" // isAligned
|
||||
|
||||
namespace bx
|
||||
{
|
||||
@@ -30,7 +30,7 @@ namespace bx
|
||||
|
||||
void add(const void* _data, int _len)
|
||||
{
|
||||
if (BX_UNLIKELY(!isPtrAligned(_data, 4) ) )
|
||||
if (BX_UNLIKELY(!isAligned(_data, 4) ) )
|
||||
{
|
||||
addUnaligned(_data, _len);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user