Mesa (softpipe-opt): util: add util_is_power_of_two function

Keith Whitwell keithw at kemper.freedesktop.org
Fri Aug 21 17:14:58 UTC 2009


Module: Mesa
Branch: softpipe-opt
Commit: b1cc196e6d18494348c2974aad5d85d1b8281ce0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b1cc196e6d18494348c2974aad5d85d1b8281ce0

Author: Keith Whitwell <keithw at vmware.com>
Date:   Fri Aug 21 18:07:35 2009 +0100

util: add util_is_power_of_two function

---

 src/gallium/auxiliary/util/u_math.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index d30fa3c..163522d 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;
+}
+
 
 
 /**




More information about the mesa-commit mailing list