From: Eric Anholt Date: Thu, 27 Jun 2019 23:04:42 +0000 (-0700) Subject: gallium/util: Switch util_float_to_half to _mesa_float_to_half()'s impl. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8b8af6d3;p=mesa.git gallium/util: Switch util_float_to_half to _mesa_float_to_half()'s impl. The util_float_to_half() implementation was much smaller, but when trying to switch _mesa_float_to_half to it, many testcases (dEQP-VK.spirv_assembly.instruction.graphics.opquantize.*, piglit.spec.arb_shading_language_packing.*packhalf2x16) start failing on Intel. Replace the broken impl so that people don't have to debug it later. Acked-by: Michel Dänzer Reviewed-by: Marek Olšák Tested-by: Marge Bot Part-of: --- diff --git a/src/gallium/auxiliary/util/u_half.h b/src/gallium/auxiliary/util/u_half.h index afce14f3603..a107dcb74b1 100644 --- a/src/gallium/auxiliary/util/u_half.h +++ b/src/gallium/auxiliary/util/u_half.h @@ -30,6 +30,7 @@ #include "pipe/p_compiler.h" #include "util/u_math.h" +#include "util/half_float.h" #ifdef __cplusplus extern "C" { @@ -46,58 +47,7 @@ extern "C" { static inline uint16_t util_float_to_half(float f) { - uint32_t sign_mask = 0x80000000; - uint32_t round_mask = ~0xfff; - uint32_t f32inf = 0xff << 23; - uint32_t f16inf = 0x1f << 23; - uint32_t sign; - union fi magic; - union fi f32; - uint16_t f16; - - magic.ui = 0xf << 23; - - f32.f = f; - - /* Sign */ - sign = f32.ui & sign_mask; - f32.ui ^= sign; - - if (f32.ui == f32inf) { - /* Inf */ - f16 = 0x7c00; - } else if (f32.ui > f32inf) { - /* NaN */ - f16 = 0x7e00; - } else { - /* Number */ - f32.ui &= round_mask; - f32.f *= magic.f; - f32.ui -= round_mask; - /* - * XXX: The magic mul relies on denorms being available, otherwise - * all f16 denorms get flushed to zero - hence when this is used - * for tgsi_exec in softpipe we won't get f16 denorms. - */ - /* - * Clamp to max finite value if overflowed. - * OpenGL has completely undefined rounding behavior for float to - * half-float conversions, and this matches what is mandated for float - * to fp11/fp10, which recommend round-to-nearest-finite too. - * (d3d10 is deeply unhappy about flushing such values to infinity, and - * while it also mandates round-to-zero it doesn't care nearly as much - * about that.) - */ - if (f32.ui > f16inf) - f32.ui = f16inf - 1; - - f16 = f32.ui >> 13; - } - - /* Sign */ - f16 |= sign >> 16; - - return f16; + return _mesa_float_to_half(f); } static inline float