From 6b129a82223c674d3e11472aa8abe07fd741764a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 7 Sep 2009 14:21:51 +0100 Subject: 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(+) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 4c6c2bc00e..b12c97dfb4 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. -- cgit v1.2.3