aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYounes Manton <[email protected]>2009-09-27 14:40:14 -0400
committerYounes Manton <[email protected]>2009-09-27 19:25:57 -0400
commitda793b743462e84e3bca7a0ed7f24b4c942e0834 (patch)
tree0ec0b8d0107297368b642dc540cd6e31b0082706
parent540039887ac19b5fdd099ccaad6b44b5db973c25 (diff)
util: Add util_next_power_of_two() for rounding a uint up to a POT.
-rw-r--r--src/gallium/auxiliary/util/u_math.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index cd6a9fcc091..75b075f160d 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -471,6 +471,26 @@ util_logbase2(unsigned n)
/**
+ * Returns the smallest power of two >= x
+ */
+static INLINE unsigned
+util_next_power_of_two(unsigned x)
+{
+ unsigned i;
+
+ if (x == 0)
+ return 1;
+
+ --x;
+
+ for (i = 1; i < sizeof(unsigned) * 8; i <<= 1)
+ x |= x >> i;
+
+ return x + 1;
+}
+
+
+/**
* Clamp X to [MIN, MAX].
* This is a macro to allow float, int, uint, etc. types.
*/