From: José Fonseca Date: Mon, 7 Sep 2009 13:21:51 +0000 (+0100) Subject: util: Utility function to check if a number is a power of two. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6b129a82223c674d3e11472aa8abe07fd741764a;p=mesa.git util: Utility function to check if a number is a power of two. --- 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.