Branimir Karadžić 9 年之前
父節點
當前提交
e98a802f09
共有 4 個文件被更改,包括 16 次插入14 次删除
  1. 3 0
      include/bx/allocator.h
  2. 11 4
      include/bx/allocator.inl
  3. 0 8
      include/bx/bx.h
  4. 2 2
      include/bx/hash.h

+ 3 - 0
include/bx/allocator.h

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

+ 11 - 4
include/bx/allocator.inl

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

+ 0 - 8
include/bx/bx.h

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

+ 2 - 2
include/bx/hash.h

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