summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2017-11-13 13:00:53 -0800
committerIan Romanick <[email protected]>2018-03-29 14:09:28 -0700
commit22fbb5c5949b1590ef04b6432dd7f3a93a37c2ed (patch)
treec43dcd5e0d83802f39221369da90d1eed745b808 /src/util
parentd76c204d0564701b4b8b6a2bdda50e2939683e66 (diff)
util: Add and use util_is_power_of_two_nonzero
Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Eduardo Lima Mitev <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bitscan.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/bitscan.h b/src/util/bitscan.h
index 2d4e46ec0f1..a3f2d414bd6 100644
--- a/src/util/bitscan.h
+++ b/src/util/bitscan.h
@@ -119,6 +119,17 @@ util_is_power_of_two_or_zero(unsigned v)
return (v & (v - 1)) == 0;
}
+/* Determine if an unsigned value is a power of two.
+ *
+ * \note
+ * Zero is \b not treated as a power of two.
+ */
+static inline bool
+util_is_power_of_two_nonzero(unsigned v)
+{
+ return v != 0 && (v & (v - 1)) == 0;
+}
+
/* For looping over a bitmask when you want to loop over consecutive bits
* manually, for example:
*