Skip to content

nir: Update saturated float->int/uint conversion algorithm

Jesse Natalie requested to merge jenatali/mesa:conversions-fixes into master

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.

Addresses one of the points of #3824 (closed), and fixes CLOn12 conformance in the conversions suite (which was regressed during upstreaming).

Merge request reports