util: add util_is_power_of_two function
authorKeith Whitwell <keithw@vmware.com>
Fri, 21 Aug 2009 17:07:35 +0000 (18:07 +0100)
committerKeith Whitwell <keithw@vmware.com>
Fri, 21 Aug 2009 17:07:35 +0000 (18:07 +0100)
src/gallium/auxiliary/util/u_math.h

index d30fa3c2d590af929a38ef0d815aae3eabf3ae9d..163522d3ef870bc41e82cc6f0eedcf492f1e61a9 100644 (file)
@@ -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;
+}
+
 
 
 /**