qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-id: 20180504100547.14621-1-peter.maydell@linaro.org
(cherry picked from commit 1839189bbf89889076aadf0c793c1b57977b28d7)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>

authored by

Peter Maydell and committed by
Michael Roth
51d5decb 0e4b4b4f

+28 -20
+28 -20
fpu/softfloat.c
··· 602 602 static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c, 603 603 bool inf_zero, float_status *s) 604 604 { 605 + int which; 606 + 605 607 if (is_snan(a.cls) || is_snan(b.cls) || is_snan(c.cls)) { 606 608 s->float_exception_flags |= float_flag_invalid; 607 609 } 608 610 611 + which = pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls), 612 + is_qnan(b.cls), is_snan(b.cls), 613 + is_qnan(c.cls), is_snan(c.cls), 614 + inf_zero, s); 615 + 609 616 if (s->default_nan_mode) { 617 + /* Note that this check is after pickNaNMulAdd so that function 618 + * has an opportunity to set the Invalid flag. 619 + */ 610 620 a.cls = float_class_dnan; 611 - } else { 612 - switch (pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls), 613 - is_qnan(b.cls), is_snan(b.cls), 614 - is_qnan(c.cls), is_snan(c.cls), 615 - inf_zero, s)) { 616 - case 0: 617 - break; 618 - case 1: 619 - a = b; 620 - break; 621 - case 2: 622 - a = c; 623 - break; 624 - case 3: 625 - a.cls = float_class_dnan; 626 - return a; 627 - default: 628 - g_assert_not_reached(); 629 - } 621 + return a; 622 + } 630 623 631 - a.cls = float_class_msnan; 624 + switch (which) { 625 + case 0: 626 + break; 627 + case 1: 628 + a = b; 629 + break; 630 + case 2: 631 + a = c; 632 + break; 633 + case 3: 634 + a.cls = float_class_dnan; 635 + return a; 636 + default: 637 + g_assert_not_reached(); 632 638 } 639 + a.cls = float_class_msnan; 640 + 633 641 return a; 634 642 } 635 643