Skip to contentSkip to conversation

Softfloat Fixes for 2.12

PATCH Superseded Alex Bennée 3 participants 6 messages Apr 12, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Softfloat Fixes for 2.12

Hi,

I'd hope to include fixes for our longstanding fcvt bugs but I ran out of time. The fixes in this series are purely regression fixes from the softfloat re-factor. On the plus side I have a very good test case of fcvt now ;-)

Only my patch is not reviewed.

Alex Bennée (1):
fpu/softfloat: raise float_invalid for NaN in float_to_int

Emilio G. Cota (1):
softfloat: fix {min,max}nummag for same-abs-value inputs

 fpu/softfloat.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/2 softfloat: fix {min, max}nummag for same-abs-value inputs

From: "Emilio G. Cota" <[email protected]>

Before 8936006 ("fpu/softfloat: re-factor minmax", 2018-02-21), we used to return +Zero for maxnummag(-Zero,+Zero); after that commit, we return -Zero.

Fix it by making {min,max}nummag consistent with {min,max}num, deferring to the latter when the absolute value of the operands is the same.

With this fix we now pass fp-test.

---
 fpu/softfloat.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
fpu/softfloat.c +9 -8
index b46dccc63e..9b99aa6ec8 100644
@@ -1704,7 +1704,6 @@ static FloatParts minmax_floats(FloatParts a, FloatParts b, bool ismin,
         return pick_nan(a, b, s);
     } else {
         int a_exp, b_exp;
-        bool a_sign, b_sign;
 
         switch (a.cls) {
         case float_class_normal:
@@ -1735,20 +1734,22 @@ static FloatParts minmax_floats(FloatParts a, FloatParts b, bool ismin,
             break;
         }
 
-        a_sign = a.sign;
-        b_sign = b.sign;
-        if (ismag) {
-            a_sign = b_sign = 0;
+        if (ismag && (a_exp != b_exp || a.frac != b.frac)) {
+            bool a_less = a_exp < b_exp;
+            if (a_exp == b_exp) {
+                a_less = a.frac < b.frac;
+            }
+            return a_less ^ ismin ? b : a;
         }
 
-        if (a_sign == b_sign) {
+        if (a.sign == b.sign) {
             bool a_less = a_exp < b_exp;
             if (a_exp == b_exp) {
                 a_less = a.frac < b.frac;
             }
-            return a_sign ^ a_less ^ ismin ? b : a;
+            return a.sign ^ a_less ^ ismin ? b : a;
         } else {
-            return a_sign ^ ismin ? b : a;
+            return a.sign ^ ismin ? b : a;
         }
     }
 }
Signature · 1 line
2.17.0
#2 lore raw

PATCH 2/2 fpu/softfloat: raise float_invalid for NaN in float_to_int

In reply to Alex Bennée

Fixes https://bugs.launchpad.net/qemu/+bug/1759264

Cc Bastian Koppelmann <[email protected]>
---
 fpu/softfloat.c | 1 +
 1 file changed, 1 insertion(+)
fpu/softfloat.c +1 -0
index 9b99aa6ec8..ddc77c273c 100644
@@ -1344,6 +1344,7 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode,
     case float_class_qnan:
     case float_class_dnan:
     case float_class_msnan:
+        s->float_exception_flags = orig_flags | float_flag_invalid;
         return max;
     case float_class_inf:
         return p.sign ? min : max;
Signature · 1 line
2.17.0
#3 lore raw

Re: [Qemu-devel] [PATCH v1 2/2] fpu/softfloat: raise float_invalid for NaN in float_to_int

Quoted 13 lines · Alex Bennée

Fixes https://bugs.launchpad.net/qemu/+bug/1759264

Cc Bastian Koppelmann <[email protected]>
---
 fpu/softfloat.c | 1 +
 1 file changed, 1 insertion(+)
fpu/softfloat.c +0 -0
index 9b99aa6ec8..ddc77c273c 100644

fpu/softfloat.c static int64_t round_to_int_and_pack(FloatParts in, int rmode, · line 1350

Quoted 7 lines
fpu/softfloat.c +1 -0
@@ -1344,6 +1344,7 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode,
     case float_class_qnan:
     case float_class_dnan:
     case float_class_msnan:
+        s->float_exception_flags = orig_flags | float_flag_invalid;
         return max;
     case float_class_inf:
         return p.sign ? min : max;

Don't we also need to raise the Invalid flag for float_class_inf ?

In both cases, this is fixing a regression introduced in commit ab52f973a50, I think.

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v1 2/2] fpu/softfloat: raise float_invalid for NaN in float_to_int

Quoted 9 lines · Peter Maydell
Quoted 8 lines · Alex Bennée

Fixes https://bugs.launchpad.net/qemu/+bug/1759264

Cc Bastian Koppelmann <[email protected]>
---
 fpu/softfloat.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

fpu/softfloat.c static int64_t round_to_int_and_pack(FloatParts in, int rmode, · line 1350

Quoted 12 lines
fpu/softfloat.c +1 -0
index 9b99aa6ec8..ddc77c273c 100644
@@ -1344,6 +1344,7 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode,
     case float_class_qnan:
     case float_class_dnan:
     case float_class_msnan:
+        s->float_exception_flags = orig_flags | float_flag_invalid;
         return max;
     case float_class_inf:
         return p.sign ? min : max;

Don't we also need to raise the Invalid flag for float_class_inf ?

Yup, as mentioned in the bug report.

Cheers,
Bastian

#5 lore raw

Re: [Qemu-devel] [PATCH v1 2/2] fpu/softfloat: raise float_invalid for NaN in float_to_int

In reply to Peter Maydell
Quoted 24 lines · Peter Maydell
Quoted 13 lines · Alex Bennée

Fixes https://bugs.launchpad.net/qemu/+bug/1759264

Cc Bastian Koppelmann <[email protected]>
---
 fpu/softfloat.c | 1 +
 1 file changed, 1 insertion(+)
fpu/softfloat.c +0 -0
index 9b99aa6ec8..ddc77c273c 100644

fpu/softfloat.c static int64_t round_to_int_and_pack(FloatParts in, int rmode, · line 1350

Quoted 7 lines
fpu/softfloat.c +1 -0
@@ -1344,6 +1344,7 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode,
     case float_class_qnan:
     case float_class_dnan:
     case float_class_msnan:
+        s->float_exception_flags = orig_flags | float_flag_invalid;
         return max;
     case float_class_inf:
         return p.sign ? min : max;

Don't we also need to raise the Invalid flag for float_class_inf ?

Quoted 2 lines

In both cases, this is fixing a regression introduced in commit ab52f973a50, I think.

And I guess the round_to_uint_and_pack as well which doesn't handle the input inf case.

Quoted 3 lines

thanks
-- PMM

--
Alex Bennée