Alpha Hash and Alpha2Coverage Implementation

This commit is contained in:
Marios Staikopoulos
2020-07-13 01:27:01 -07:00
parent 0b910cd8b7
commit e5d7c7d5fc
8 changed files with 434 additions and 78 deletions

View File

@@ -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)