From c8a37d8292b5ae284edb662b1ef525bae6b5215f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 19 Aug 2019 20:01:49 +0100 Subject: [PATCH] Add 64 bit FindFirstBit function --- src/core/bitmath_func.cpp | 7 +++++++ src/core/bitmath_func.hpp | 7 +++++++ 2 files changed, 14 insertions(+) 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 */