mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Cleanup.
This commit is contained in:
@@ -26,7 +26,7 @@ namespace bx
|
||||
{
|
||||
const uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
const uintptr_t unaligned = addr + _extra; // space for header
|
||||
const uintptr_t aligned = alignUp(unaligned, int32_t(_align) );
|
||||
const uintptr_t aligned = alignUp(unaligned, _align);
|
||||
|
||||
return bitCast<void*>(aligned);
|
||||
}
|
||||
|
||||
@@ -640,35 +640,28 @@ namespace bx
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC bool isAligned(Ty _a, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC bool isAligned(Ty _a, size_t _align)
|
||||
{
|
||||
const Ty mask = Ty(max(1, _align) - 1);
|
||||
return 0 == (_a & mask);
|
||||
const size_t mask = max<size_t>(1, _align) - 1;
|
||||
return 0 == (size_t(_a) & mask);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC bool isAligned(Ty* _ptr, int32_t _align)
|
||||
template<>
|
||||
inline BX_CONSTEXPR_FUNC bool isAligned(const void* _ptr, size_t _align)
|
||||
{
|
||||
const uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
return isAligned(addr, _align);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC bool isAligned(const Ty* _ptr, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC Ty alignDown(Ty _a, size_t _align)
|
||||
{
|
||||
const uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
return isAligned(addr, _align);
|
||||
const size_t mask = max<size_t>(1, _align) - 1;
|
||||
return Ty(size_t(_a) & ~mask);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC Ty alignDown(Ty _a, int32_t _align)
|
||||
{
|
||||
const Ty mask = Ty(max(1, _align) - 1);
|
||||
return Ty(_a & ~mask);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC Ty* alignDown(Ty* _ptr, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC Ty* alignDown(Ty* _ptr, size_t _align)
|
||||
{
|
||||
uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
addr = alignDown(addr, _align);
|
||||
@@ -676,7 +669,7 @@ namespace bx
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC const Ty* alignDown(const Ty* _ptr, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC const Ty* alignDown(const Ty* _ptr, size_t _align)
|
||||
{
|
||||
uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
addr = alignDown(addr, _align);
|
||||
@@ -684,14 +677,14 @@ namespace bx
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC Ty alignUp(Ty _a, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC Ty alignUp(Ty _a, size_t _align)
|
||||
{
|
||||
const Ty mask = Ty(max(1, _align) - 1);
|
||||
return Ty( (_a + mask) & ~mask);
|
||||
const size_t mask = max<size_t>(1, _align) - 1;
|
||||
return Ty( (size_t(_a) + mask) & ~mask);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC Ty* alignUp(Ty* _ptr, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC Ty* alignUp(Ty* _ptr, size_t _align)
|
||||
{
|
||||
uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
addr = alignUp(addr, _align);
|
||||
@@ -699,7 +692,7 @@ namespace bx
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC const Ty* alignUp(const Ty* _ptr, int32_t _align)
|
||||
inline BX_CONSTEXPR_FUNC const Ty* alignUp(const Ty* _ptr, size_t _align)
|
||||
{
|
||||
uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
addr = alignUp(addr, _align);
|
||||
|
||||
@@ -263,39 +263,35 @@ namespace bx
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC bool isAligned(Ty _a, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC bool isAligned(Ty _a, size_t _align);
|
||||
|
||||
///
|
||||
template<>
|
||||
BX_CONSTEXPR_FUNC bool isAligned(const void* _ptr, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC bool isAligned(Ty* _ptr, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC Ty alignDown(Ty _a, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC bool isAligned(const Ty* _ptr, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC Ty* alignDown(Ty* _ptr, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC Ty alignDown(Ty _a, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC const Ty* alignDown(const Ty* _ptr, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC Ty* alignDown(Ty* _ptr, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC Ty alignUp(Ty _a, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC const Ty* alignDown(const Ty* _ptr, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC Ty* alignUp(Ty* _ptr, size_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC Ty alignUp(Ty _a, int32_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC Ty* alignUp(Ty* _ptr, int32_t _align);
|
||||
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC const Ty* alignUp(const Ty* _ptr, int32_t _align);
|
||||
BX_CONSTEXPR_FUNC const Ty* alignUp(const Ty* _ptr, size_t _align);
|
||||
|
||||
/// Convert float to half-float.
|
||||
///
|
||||
|
||||
@@ -284,7 +284,7 @@ TEST_CASE("Format %d, %i, %o, %u, %x", "[string][printf]")
|
||||
REQUIRE(test("-001", "%04i", -1) );
|
||||
REQUIRE(test("+001", "%+04i", 1) );
|
||||
|
||||
if (sizeof(intmax_t) == 4)
|
||||
if constexpr (sizeof(intmax_t) == 4)
|
||||
{
|
||||
REQUIRE(test("2147483647", "%jd", INTMAX_MAX) );
|
||||
}
|
||||
@@ -333,7 +333,7 @@ TEST_CASE("Format %td", "[string][printf]")
|
||||
|
||||
REQUIRE(test("-1", "%td", size) );
|
||||
|
||||
if (4 == sizeof(ptrdiff_t) )
|
||||
if constexpr (4 == sizeof(ptrdiff_t) )
|
||||
{
|
||||
REQUIRE(test("-1073741824", "%td", ptrdiff_t(3221225472) ) );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user