Mesa (master): gallium/u_math: add util_logbase2_ceil

Nicolai Hähnle nh at kemper.freedesktop.org
Tue Sep 27 14:46:22 UTC 2016


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

Author: Nicolai Hähnle <nicolai.haehnle at amd.com>
Date:   Tue Sep  6 14:41:51 2016 +0200

gallium/u_math: add util_logbase2_ceil

For finding the exponent of the next power of two.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

---

 src/gallium/auxiliary/util/u_math.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index a923271..2ab5f03 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -429,6 +429,18 @@ util_logbase2(unsigned n)
 #endif
 }
 
+/**
+ * Returns the ceiling of log n base 2, and 0 when n == 0. Equivalently,
+ * returns the smallest x such that n <= 2**x.
+ */
+static inline unsigned
+util_logbase2_ceil(unsigned n)
+{
+   if (n <= 1)
+      return 0;
+
+   return 1 + util_logbase2(n - 1);
+}
 
 /**
  * Returns the smallest power of two >= x




More information about the mesa-commit mailing list