aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-18 01:30:45 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-27 22:18:00 +0100
commitd722c87f10a965c082055d11adecf312fce367c3 (patch)
tree7fae6432d9acc4fb75f6e72ec75028b98fab186c
parent2eb69efa7f912e604092b46d7b12a9bce3ea9995 (diff)
downloadsparse-d722c87f10a965c082055d11adecf312fce367c3.tar.gz
add helper is_power_of_2()
Add is_power_of_2() to test if a value is a power of 2. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--bits.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/bits.h b/bits.h
index c0dc952e..63a663c2 100644
--- a/bits.h
+++ b/bits.h
@@ -58,4 +58,9 @@ static inline long long bits_extend(long long val, unsigned size, int is_signed)
return val;
}
+static inline int is_power_of_2(long long val)
+{
+ return val && !(val & (val - 1));
+}
+
#endif