Mesa (master): util: don't use __builtin_clz unconditionally

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 1 03:29:05 UTC 2018


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Tue Jul 31 22:50:44 2018 -0400

util: don't use __builtin_clz unconditionally

This fixes the build if __builtin_clz is unsupported.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/util/half_float.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/util/half_float.c b/src/util/half_float.c
index 588f050d92..2eff2c84f5 100644
--- a/src/util/half_float.c
+++ b/src/util/half_float.c
@@ -215,7 +215,17 @@ uint16_t _mesa_uint16_div_64k_to_half(uint16_t v)
       return v << 8;
 
    /* Count the leading 0s in the uint16_t */
-   int n = __builtin_clz(v) - (sizeof(unsigned int) - sizeof(uint16_t)) * 8;
+#ifdef HAVE___BUILTIN_CLZ
+   int n = __builtin_clz(v) - 16;
+#else
+   int n = 16;
+   for (int i = 15; i >= 0; i--) {
+      if (v & (1 << i)) {
+         n = 15 - i;
+         break;
+      }
+   }
+#endif
 
    /* Shift the mantissa up so bit 16 is the hidden 1 bit,
     * mask it off, then shift back down to 10 bits




More information about the mesa-commit mailing list