Mesa (master): util: Utility function to check if a number is a power of two.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Mon Sep 7 14:09:41 UTC 2009


Module: Mesa
Branch: master
Commit: 6b129a82223c674d3e11472aa8abe07fd741764a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6b129a82223c674d3e11472aa8abe07fd741764a

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Sep  7 14:21:51 2009 +0100

util: Utility function to check if a number is a power of two.

---

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

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 4c6c2bc..b12c97d 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -341,6 +341,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.
  */




More information about the mesa-commit mailing list