BitUtils: Add CountLeadingZeros

This commit is contained in:
MerryMage
2020-12-27 22:37:37 +00:00
parent 4705af59c6
commit d695fcb126
4 changed files with 52 additions and 45 deletions

View File

@ -9,12 +9,9 @@
#include <type_traits>
#include <vector>
#include "Common/BitUtils.h"
#include "Common/CommonTypes.h"
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace MathUtil
{
constexpr double TAU = 6.2831853071795865;
@ -154,21 +151,5 @@ float MathFloatVectorSum(const std::vector<float>&);
// Rounds down. 0 -> undefined
inline int IntLog2(u64 val)
{
#if defined(__GNUC__)
return 63 - __builtin_clzll(val);
#elif defined(_MSC_VER)
unsigned long result = ULONG_MAX;
_BitScanReverse64(&result, val);
return result;
#else
int result = -1;
while (val != 0)
{
val >>= 1;
++result;
}
return result;
#endif
return 63 - Common::CountLeadingZeros(val);
}