[+] AuRoundUpPow2

[+] AuRoundDownPow2
This commit is contained in:
Reece Wilson 2023-11-18 02:02:34 +00:00
parent 34ebfb1f2e
commit 6bf70a4bcb
2 changed files with 34 additions and 1 deletions

View File

@ -176,7 +176,7 @@ static auline bool AuBitScanReverse(AuUInt8 &index, T value)
ret = 63 - ret;
}
}
else if constexpr (sizeof(T) == sizeof(unsigned int))
else// if constexpr (sizeof(T) == sizeof(unsigned int))
{
ret = __builtin_clz(static_cast<unsigned int>(value));
if constexpr (sizeof(unsigned int) == 4)

View File

@ -37,4 +37,37 @@ template <class T>
constexpr const T AuPageRound(const T value, const T pageSize)
{
return value & ~(pageSize - 1);
}
// TODO: out of order
#include "auBitsUtils.hpp"
template <class T>
const T AuRoundUpPow2(const T value)
{
if constexpr (AuIsSame_v<T, AuUInt16>)
{
return AuRoundUpPow2<AuUInt32>(value);
}
else
{
AuUInt8 ret;
AuBitScanReverse(ret, value);
return T(1) << (ret + T(1));
}
}
template <class T>
const T AuRoundDownPow2(const T value)
{
if constexpr (AuIsSame_v<T, AuUInt16>)
{
return AuRoundDownPow2<AuUInt32>(value);
}
else
{
AuUInt8 ret;
AuBitScanReverse(ret, value);
return T(1) << ret;
}
}