util: Keep quiet NaNs quiet when converting to half float.
We don't want to be throwing exceptions and changing float values later by emitting a signaling binary16 nan. If we don't do this, then when we convert back to f32 in NIR constant expression evaluation, the signaling NaN can end up giving NaN for fmax(NaN, 0.0), instead of 0.0. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5933 Cc: mesa-stable Reviewed-by: Emma Anholt <emma@anholt.net> Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16233>
This commit is contained in:
parent
acf6bf88c0
commit
27e33d5c96
|
@ -83,7 +83,11 @@ _mesa_float_to_half_slow(float val)
|
|||
e = 31;
|
||||
}
|
||||
else if ((flt_e == 0xff) && (flt_m != 0)) {
|
||||
/* NaN */
|
||||
/* Retain the top bits of a NaN to make sure that the quiet/signaling
|
||||
* status stays the same.
|
||||
*/
|
||||
m = flt_m >> 13;
|
||||
if (!m)
|
||||
m = 1;
|
||||
e = 31;
|
||||
}
|
||||
|
|
|
@ -1452,7 +1452,12 @@ _mesa_float_to_half_rtz_slow(float val)
|
|||
if (flt_m != 0) {
|
||||
/* 'val' is a NaN, return NaN */
|
||||
e = 0x1f;
|
||||
m = 0x1;
|
||||
/* Retain the top bits of a NaN to make sure that the quiet/signaling
|
||||
* status stays the same.
|
||||
*/
|
||||
m = flt_m >> 13;
|
||||
if (!m)
|
||||
m = 1;
|
||||
return (s << 15) + (e << 10) + m;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue