Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/40761 )
Change subject: src/include/lib.h: Add is_power_of_two ......................................................................
src/include/lib.h: Add is_power_of_two
Used to check if a number is a power of two at runtime.
BUG=b:147042464
Signed-off-by: Raul E Rangel rrangel@chromium.org Change-Id: Ia238773b15b600b7b6062b741a24a93081398a43 --- M src/include/lib.h 1 file changed, 6 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/61/40761/1
diff --git a/src/include/lib.h b/src/include/lib.h index 168d8ca..f353ce5 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -55,4 +55,10 @@ /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */ static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); }
+/* Return 1 if number is power of two */ +static inline unsigned int is_power_of_two(unsigned int x) +{ + return (x != 0) && ((x & (x - 1)) == 0); +} + #endif /* __LIB_H__ */