aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/bitscan.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/bitscan.h')
-rw-r--r--src/util/bitscan.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/bitscan.h b/src/util/bitscan.h
index 611e8120596..2d4e46ec0f1 100644
--- a/src/util/bitscan.h
+++ b/src/util/bitscan.h
@@ -31,6 +31,7 @@
#include <assert.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#if defined(_MSC_VER)
@@ -107,6 +108,17 @@ u_bit_scan64(uint64_t *mask)
return i;
}
+/* Determine if an unsigned value is a power of two.
+ *
+ * \note
+ * Zero is treated as a power of two.
+ */
+static inline bool
+util_is_power_of_two_or_zero(unsigned v)
+{
+ return (v & (v - 1)) == 0;
+}
+
/* For looping over a bitmask when you want to loop over consecutive bits
* manually, for example:
*