summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-09-07 14:21:51 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-09-07 15:02:06 +0100
commit6b129a82223c674d3e11472aa8abe07fd741764a (patch)
tree3a977315162055d02478faaf3f7adcd0d67332a8 /src/gallium/auxiliary/util
parent8be72bb7646d430e66cb36e09c13c13bee030d53 (diff)
util: Utility function to check if a number is a power of two.
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_math.h10
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 4c6c2bc00e..b12c97dfb4 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.
*/