diff mbox series

[3/6] add helper is_power_of_2()

Message ID 20201127222516.44915-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series 'bits translation' simplification | expand

Commit Message

Luc Van Oostenryck Nov. 27, 2020, 10:25 p.m. UTC
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>
---
 bits.h | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/bits.h b/bits.h
index c0dc952eaed9..63a663c248e4 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