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 { diff --git a/src/util/softfloat.c b/src/util/softfloat.c index cc386aa46fb..2ff835f7452 100644 --- a/src/util/softfloat.c +++ b/src/util/softfloat.c @@ -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; }