summaryrefslogtreecommitdiff
path: root/src/util/half_float.c
diff options
context:
space:
mode:
authorChia-I Wu <olvaffe@gmail.com>2022-04-28 14:25:36 -0700
committerMarge Bot <emma+marge@anholt.net>2022-05-02 23:36:50 +0000
commit27e33d5c963f13a47c4b9276378db913d8ecb189 (patch)
treefd8931ea2b59adfb35d2e78798abbfb96cf9d4bf /src/util/half_float.c
parentacf6bf88c07e0a1f0283ad1acd0e5f0d2a156535 (diff)
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>
Diffstat (limited to 'src/util/half_float.c')
-rw-r--r--src/util/half_float.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/util/half_float.c b/src/util/half_float.c
index 05aeac14abb..606e4b9522e 100644
--- a/src/util/half_float.c
+++ b/src/util/half_float.c
@@ -83,8 +83,12 @@ _mesa_float_to_half_slow(float val)
e = 31;
}
else if ((flt_e == 0xff) && (flt_m != 0)) {
- /* NaN */
- m = 1;
+ /* 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;
}
else {