All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before
@ 2018-05-04 10:05 Peter Maydell
  2018-05-07 17:03 ` Richard Henderson
  2018-05-08 11:30 ` Alex Bennée
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Maydell @ 2018-05-04 10:05 UTC (permalink / raw)
  To: qemu-arm, qemu-devel; +Cc: patches, qemu-stable, Alex Bennée

It is implementation defined whether a multiply-add of
(0,inf,qnan) or (inf,0,qnan) raises InvalidaOperation or
not, so we let the target-specific pickNaNMulAdd function
handle this. This means that we must do the "return the
default NaN in default NaN mode" check after the call,
not before. Correct the ordering, and restore the comment
from the old propagateFloat64MulAddNaN() that warned about
this corner case.

This fixes a regression from 2.11 for Arm guests where we would
incorrectly fail to set the Invalid flag for these cases.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 fpu/softfloat.c | 52 ++++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 70e0c40a1c..8401b37bd4 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -602,34 +602,42 @@ static FloatParts pick_nan(FloatParts a, FloatParts b, float_status *s)
 static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c,
                                   bool inf_zero, float_status *s)
 {
+    int which;
+
     if (is_snan(a.cls) || is_snan(b.cls) || is_snan(c.cls)) {
         s->float_exception_flags |= float_flag_invalid;
     }
 
-    if (s->default_nan_mode) {
-        a.cls = float_class_dnan;
-    } else {
-        switch (pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls),
-                              is_qnan(b.cls), is_snan(b.cls),
-                              is_qnan(c.cls), is_snan(c.cls),
-                              inf_zero, s)) {
-        case 0:
-            break;
-        case 1:
-            a = b;
-            break;
-        case 2:
-            a = c;
-            break;
-        case 3:
-            a.cls = float_class_dnan;
-            return a;
-        default:
-            g_assert_not_reached();
-        }
+    which = pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls),
+                          is_qnan(b.cls), is_snan(b.cls),
+                          is_qnan(c.cls), is_snan(c.cls),
+                          inf_zero, s);
 
-        a.cls = float_class_msnan;
+    if (s->default_nan_mode) {
+        /* Note that this check is after pickNaNMulAdd so that function
+         * has an opportunity to set the Invalid flag.
+         */
+        a.cls = float_class_dnan;
+        return a;
     }
+
+    switch (which) {
+    case 0:
+        break;
+    case 1:
+        a = b;
+        break;
+    case 2:
+        a = c;
+        break;
+    case 3:
+        a.cls = float_class_dnan;
+        return a;
+    default:
+        g_assert_not_reached();
+    }
+    a.cls = float_class_msnan;
+
     return a;
 }
 
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before
  2018-05-04 10:05 [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before Peter Maydell
@ 2018-05-07 17:03 ` Richard Henderson
  2018-05-08 11:30 ` Alex Bennée
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-05-07 17:03 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel
  Cc: Alex Bennée, qemu-stable, patches

On 05/04/2018 03:05 AM, Peter Maydell wrote:
> It is implementation defined whether a multiply-add of
> (0,inf,qnan) or (inf,0,qnan) raises InvalidaOperation or
> not, so we let the target-specific pickNaNMulAdd function
> handle this. This means that we must do the "return the
> default NaN in default NaN mode" check after the call,
> not before. Correct the ordering, and restore the comment
> from the old propagateFloat64MulAddNaN() that warned about
> this corner case.
> 
> This fixes a regression from 2.11 for Arm guests where we would
> incorrectly fail to set the Invalid flag for these cases.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  fpu/softfloat.c | 52 ++++++++++++++++++++++++++++---------------------
>  1 file changed, 30 insertions(+), 22 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before
  2018-05-04 10:05 [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before Peter Maydell
  2018-05-07 17:03 ` Richard Henderson
@ 2018-05-08 11:30 ` Alex Bennée
  2018-05-08 13:59   ` Peter Maydell
  1 sibling, 1 reply; 4+ messages in thread
From: Alex Bennée @ 2018-05-08 11:30 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-arm, qemu-devel, patches, qemu-stable


Peter Maydell <peter.maydell@linaro.org> writes:

> It is implementation defined whether a multiply-add of
> (0,inf,qnan) or (inf,0,qnan) raises InvalidaOperation or
> not, so we let the target-specific pickNaNMulAdd function
> handle this. This means that we must do the "return the
> default NaN in default NaN mode" check after the call,
> not before. Correct the ordering, and restore the comment
> from the old propagateFloat64MulAddNaN() that warned about
> this corner case.
>
> This fixes a regression from 2.11 for Arm guests where we would
> incorrectly fail to set the Invalid flag for these cases.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>


> ---
>  fpu/softfloat.c | 52 ++++++++++++++++++++++++++++---------------------
>  1 file changed, 30 insertions(+), 22 deletions(-)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index 70e0c40a1c..8401b37bd4 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -602,34 +602,42 @@ static FloatParts pick_nan(FloatParts a, FloatParts b, float_status *s)
>  static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c,
>                                    bool inf_zero, float_status *s)
>  {
> +    int which;
> +
>      if (is_snan(a.cls) || is_snan(b.cls) || is_snan(c.cls)) {
>          s->float_exception_flags |= float_flag_invalid;
>      }
>
> -    if (s->default_nan_mode) {
> -        a.cls = float_class_dnan;
> -    } else {
> -        switch (pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls),
> -                              is_qnan(b.cls), is_snan(b.cls),
> -                              is_qnan(c.cls), is_snan(c.cls),
> -                              inf_zero, s)) {
> -        case 0:
> -            break;
> -        case 1:
> -            a = b;
> -            break;
> -        case 2:
> -            a = c;
> -            break;
> -        case 3:
> -            a.cls = float_class_dnan;
> -            return a;
> -        default:
> -            g_assert_not_reached();
> -        }
> +    which = pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls),
> +                          is_qnan(b.cls), is_snan(b.cls),
> +                          is_qnan(c.cls), is_snan(c.cls),
> +                          inf_zero, s);
>
> -        a.cls = float_class_msnan;
> +    if (s->default_nan_mode) {
> +        /* Note that this check is after pickNaNMulAdd so that function
> +         * has an opportunity to set the Invalid flag.
> +         */
> +        a.cls = float_class_dnan;
> +        return a;
>      }
> +
> +    switch (which) {
> +    case 0:
> +        break;
> +    case 1:
> +        a = b;
> +        break;
> +    case 2:
> +        a = c;
> +        break;
> +    case 3:
> +        a.cls = float_class_dnan;
> +        return a;
> +    default:
> +        g_assert_not_reached();
> +    }
> +    a.cls = float_class_msnan;
> +
>      return a;
>  }


--
Alex Bennée

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before
  2018-05-08 11:30 ` Alex Bennée
@ 2018-05-08 13:59   ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2018-05-08 13:59 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-arm, QEMU Developers, patches, qemu-stable

On 8 May 2018 at 12:30, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> It is implementation defined whether a multiply-add of
>> (0,inf,qnan) or (inf,0,qnan) raises InvalidaOperation or
>> not, so we let the target-specific pickNaNMulAdd function
>> handle this. This means that we must do the "return the
>> default NaN in default NaN mode" check after the call,
>> not before. Correct the ordering, and restore the comment
>> from the old propagateFloat64MulAddNaN() that warned about
>> this corner case.
>>
>> This fixes a regression from 2.11 for Arm guests where we would
>> incorrectly fail to set the Invalid flag for these cases.
>>
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Tested-by: Alex Bennée <alex.bennee@linaro.org>

Thanks; applied to target-arm.next.

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-08 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04 10:05 [Qemu-devel] [PATCH] softfloat: Handle default NaN mode after pickNaNMulAdd, not before Peter Maydell
2018-05-07 17:03 ` Richard Henderson
2018-05-08 11:30 ` Alex Bennée
2018-05-08 13:59   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.