diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-11-03 07:50:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-03 07:50:49 +0100 |
commit | 873d4617852cddfd368e3046f718f410eade6a3e (patch) | |
tree | f750f32dbb74a92756039e28bc7eb85da2dc3fea /core | |
parent | be14d9d6448a9017c982fd7e30631525aed8f339 (diff) | |
parent | e5d7c7d5fcd40c1516ef3276ce2ff3d2c10ecc8a (diff) |
Merge pull request #40364 from marstaik/alpha2coverage_up
Alpha Hash and Alpha2Coverage Implementation
Diffstat (limited to 'core')
-rw-r--r-- | core/typedefs.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/typedefs.h b/core/typedefs.h index 2472e5fcd9..f0c32f2c95 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -193,6 +193,20 @@ static inline unsigned int nearest_shift(unsigned int p_number) { return 0; } +// constexpr function to find the floored log2 of a number +template <typename T> +constexpr T floor_log2(T x) { + return x < 2 ? x : 1 + floor_log2(x >> 1); +} + +// Get the number of bits needed to represent the number. +// IE, if you pass in 8, you will get 4. +// If you want to know how many bits are needed to store 8 values however, pass in (8 - 1). +template <typename T> +constexpr T get_num_bits(T x) { + return floor_log2(x); +} + // Swap 16, 32 and 64 bits value for endianness. #if defined(__GNUC__) #define BSWAP16(x) __builtin_bswap16(x) |