diff --git a/src/core/bitmath_func.cpp b/src/core/bitmath_func.cpp index 65188c9fd8..04c2e35b10 100644 --- a/src/core/bitmath_func.cpp +++ b/src/core/bitmath_func.cpp @@ -55,6 +55,13 @@ uint8 FindFirstBit(uint32 x) return pos; } +uint8 FindFirstBit64(uint64 x) +{ + if (x == 0) return 0; + if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit(x); + return FindFirstBit(x >> 32) + 32; +} + #endif /** diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index 2d908130b8..5bbb4ca016 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -198,6 +198,13 @@ inline uint8 FindFirstBit(uint32 x) return __builtin_ctz(x); } +inline uint8 FindFirstBit64(uint64 x) +{ + if (x == 0) return 0; + + return __builtin_ctzll(x); +} + #else /** Lookup table to check which bit is set in a 6 bit variable */