softfloat: Handle default NaN mode after pickNaNMulAdd, not before
PATCH 1/1 softfloat: Handle default NaN mode after pickNaNMulAdd, not before
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.
--- fpu/softfloat.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-)
fpu/softfloat.c +30 -22
@@ -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; }
Signature · 1 line
2.17.0
Quoted 9 lines · Peter Maydell
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.
Quoted 8 lines
This fixes a regression from 2.11 for Arm guests where we would incorrectly fail to set the Invalid flag for these cases.
Signed-off-by Peter Maydell <[email protected]>--- fpu/softfloat.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-)
r~
Quoted 9 lines · Peter Maydell
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.
Quoted 5 lines
This fixes a regression from 2.11 for Arm guests where we would incorrectly fail to set the Invalid flag for these cases.
Signed-off-by Peter Maydell <[email protected]>
Quoted 62 lines
--- fpu/softfloat.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-)fpu/softfloat.c +22
-22@@ -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 ;
fpu/softfloat.c static FloatParts pick_nan(FloatParts a, FloatParts b, float_status *s) · line 642
Quoted 10 lines
fpu/softfloat.c +8
-0+case 3 : + a.cls = float_class_dnan; +return a; +default : +g_assert_not_reached (); + } + a.cls = float_class_msnan; +return a; }
--
Alex Bennée
Quoted 12 lines · Alex Bennée
Quoted 9 lines · Peter Maydell
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.
Quoted 8 lines
Quoted 5 lines
This fixes a regression from 2.11 for Arm guests where we would incorrectly fail to set the Invalid flag for these cases.
Signed-off-by Peter Maydell <[email protected]>Reviewed-by Alex Bennée <[email protected]>Tested-by Alex Bennée <[email protected]>
Thanks; applied to target-arm.next.
-- PMM