util: don't use __builtin_clz unconditionally
authorMarek Olšák <marek.olsak@amd.com>
Wed, 1 Aug 2018 02:50:44 +0000 (22:50 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 1 Aug 2018 03:28:01 +0000 (23:28 -0400)
This fixes the build if __builtin_clz is unsupported.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/util/half_float.c

index 588f050d924984296c24d4af1e68287f265e5aa6..2eff2c84f51f1e7eeccbedaeb32e4b036dc838ec 100644 (file)
@@ -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