Skip to contentSkip to conversation

fpu/softfloat: Don't set Invalid for float-to-int(MAXINT)

PATCH In review Peter Maydell 2 participants 2 messages May 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpu/softfloat: Don't set Invalid for float-to-int(MAXINT)

In float-to-integer conversion, if the floating point input converts exactly to the largest or smallest integer that fits in to the result type, this is not an overflow. In this situation we were producing the correct result value, but were incorrectly setting the Invalid flag.
For example for Arm A64, "FCVTAS w0, d0" on an input of 0x41dfffffffc00000 should produce 0x7fffffff and set no flags.

Fix the boundary case to take the right half of the if() statements.

This fixes a regression from 2.11 introduced by the softfloat refactoring.

---
 fpu/softfloat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fpu/softfloat.c +2 -2
index 8401b37bd4..9bcaaebe4f 100644
@@ -1368,14 +1368,14 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode,
             r = UINT64_MAX;
         }
         if (p.sign) {
-            if (r < -(uint64_t) min) {
+            if (r <= -(uint64_t) min) {
                 return -r;
             } else {
                 s->float_exception_flags = orig_flags | float_flag_invalid;
                 return min;
             }
         } else {
-            if (r < max) {
+            if (r <= max) {
                 return r;
             } else {
                 s->float_exception_flags = orig_flags | float_flag_invalid;
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Peter Maydell

In float-to-integer conversion, if the floating point input converts exactly to the largest or smallest integer that fits in to the result type, this is not an overflow. In this situation we were producing the correct result value, but were incorrectly setting the Invalid flag.
For example for Arm A64, "FCVTAS w0, d0" on an input of 0x41dfffffffc00000 should produce 0x7fffffff and set no flags.

Fix the boundary case to take the right half of the if() statements.

This fixes a regression from 2.11 introduced by the softfloat refactoring.

Quoted 6 lines
---
 fpu/softfloat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

r~