From: Keith Whitwell Date: Fri, 21 Aug 2009 17:07:35 +0000 (+0100) Subject: util: add util_is_power_of_two function X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b1cc196e6d18494348c2974aad5d85d1b8281ce0;p=mesa.git util: add util_is_power_of_two function --- diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index d30fa3c2d59..163522d3ef8 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -273,6 +273,14 @@ util_fast_pow(float x, float y) return util_fast_exp2(util_fast_log2(x) * y); } +/* Note that this counts zero as a power of two. + */ +static INLINE boolean +util_is_power_of_two( unsigned v ) +{ + return (v & (v-1)) == 0; +} + /**