This fixes the build if __builtin_clz is unsupported.
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
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