summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMarios Staikopoulos <marios@staik.net>2020-07-13 01:27:01 -0700
committerMarios Staikopoulos <marios@staik.net>2020-11-02 20:11:20 -0800
commite5d7c7d5fcd40c1516ef3276ce2ff3d2c10ecc8a (patch)
tree71c867615a841caed7b93be4d39f9b4ea7b006da /core
parent0b910cd8b7b4ef661a2b52dd8c5962363e6c5150 (diff)
Alpha Hash and Alpha2Coverage Implementation
Diffstat (limited to 'core')
-rw-r--r--core/typedefs.h14
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)