From e5d7c7d5fcd40c1516ef3276ce2ff3d2c10ecc8a Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Mon, 13 Jul 2020 01:27:01 -0700 Subject: Alpha Hash and Alpha2Coverage Implementation --- core/typedefs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core') 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 +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 +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) -- cgit v1.2.3