[*] Clang/GCC AuBitScanReverse fix

This commit is contained in:
Reece Wilson 2023-11-18 01:40:45 +00:00
parent c0977cbc0a
commit 34ebfb1f2e

View File

@ -152,23 +152,41 @@ static auline bool AuBitScanReverse(AuUInt8 &index, T value)
if (lower == 0) if (lower == 0)
{ {
ret = __builtin_clzl(static_cast<AuUInt32>(value & 0xffffffff))); ret = __builtin_clzl(static_cast<AuUInt32>(value & 0xffffffff)));
ret += 32; ret = 63 - ret;
} }
else else
{ {
ret = __builtin_clzl(static_cast<AuUInt32>(lower)); ret = __builtin_clzl(static_cast<AuUInt32>(lower));
ret = 31 - ret;
} }
#else #else
ret = __builtin_clzll(static_cast<AuUInt64>(value)); ret = __builtin_clzll(static_cast<AuUInt64>(value));
ret = 63 - ret;
#endif #endif
} }
else if constexpr (sizeof(T) == sizeof(unsigned long)) else if constexpr (sizeof(T) == sizeof(unsigned long))
{ {
ret = __builtin_clzl(static_cast<unsigned long>(value)); ret = __builtin_clzl(static_cast<unsigned long>(value));
if constexpr (sizeof(unsigned long) == 4)
{
ret = 31 - ret;
}
else if constexpr (sizeof(unsigned long) == 8)
{
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)); ret = __builtin_clz(static_cast<unsigned int>(value));
if constexpr (sizeof(unsigned int) == 4)
{
ret = 31 - ret;
}
else if constexpr (sizeof(unsigned int) == 8)
{
ret = 63 - ret;
}
} }
success = true; success = true;