nir: Update saturated float->int/uint conversion algorithm
authorJesse Natalie <jenatali@microsoft.com>
Mon, 28 Dec 2020 23:45:58 +0000 (15:45 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 5 Jan 2021 19:46:25 +0000 (19:46 +0000)
commit4d83306a9aabb5f9ea7e6a54d0e25c0f82805965
tree756454d1df09cd42391ede8c19ecb70b4ce27dee
parentfcecc21832607e33e859ebb65377b5cac882c890
nir: Update saturated float->int/uint conversion algorithm

The mantissa for a float doesn't contain enough data to accurately represent
the min/max values for some destination types. Instead of clamping before
converting, clamp after converting when coming from floats. This improves
conformance of CL conversions, specifically for float -> long/ulong with
int64 emulation enabled.

Refactors the limit determination from the clamp, so we can determine
limits for the dest type (int/uint) in both the source (float) and dest
type. The limit as a float is used for comparison, while the limit as a
dest type is used for bcsel.

Important note is that the comparison is inverted to fge instead of flt,
so the bcsel chooses the direct int/uint over the converted float in the
case where the comparison comes up equal, but the conversion can't produce
the exact min/max value.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8256>
src/compiler/nir/nir_conversion_builder.h