From 6b129a82223c674d3e11472aa8abe07fd741764a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 7 Sep 2009 14:21:51 +0100 Subject: [PATCH] util: Utility function to check if a number is a power of two. --- src/gallium/auxiliary/util/u_math.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 4c6c2bc00e1..b12c97dfb4d 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -340,6 +340,16 @@ util_is_inf_or_nan(float x) } +/** + * Test whether x is a power of two. + */ +static INLINE boolean +util_is_pot(unsigned x) +{ + return (x & (x - 1)) == 0; +} + + /** * Find first bit set in word. Least significant bit is 1. * Return 0 if no bits set. -- 2.30.2