On 17/11/26 20:37, Richard Henderson wrote:
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
The final negation of NMADD.fmt and NMSUB.fmt is arithmetic. With the
legacy NaN encoding (FCSR.NAN2008 = 0) QEMU returns the default NaN
(0x7ff7ffffffffffff for double precision, positive) for a NaN result,
then flipped its sign with float{32,64}_chs().
Observed on a Cavium Octeon III V0.2 (FPU V0.0, Linux 4.9.79) running
risu: "nmsub.d $f7,$f27,$f23,$f15" with $f27 = 0x7fffffffffffffff (a
signaling NaN in the legacy encoding), $f23 = 0 and
$f15 = 0x472fa6f57f408dcc gives 0x7ff7ffffffffffff on the hardware,
where QEMU gave 0xfff7ffffffffffff. The same was seen for the single
precision "nmsub.s $f1,$f18,$f22,$f21".
Do not change the sign of a NaN result when NAN2008 is 0. Non-NaN
results and the NAN2008 = 1 behavior are unchanged. NMADD.fmt, which
shares the code, was not exercised on the hardware.
The hardware (or its kernel FPU emulator) also returns a different NaN
than QEMU for "mul.d" with a signaling NaN operand and a denormal
operand: this is not addressed here.
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
target/mips/tcg/fpu_helper.c | 39 ++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
Isn't the larger problem that this should be using a fused multiply-add
via float64_muladd, and thus the negation via float_muladd_negate_result
(which will not affect NaN results).
Certainly MD00087 says the product uses infinite precision.
MD00087 says the opposite for NMADD/NMSUB... Vol II-A rev 6.06,
NMADD.fmt (p.376) and NMSUB.fmt (p.378):
"The intermediate product is rounded according to the current
rounding mode in FCSR [...] The results and flags are as if
separate floating-point multiply and add and negate instructions
were executed"
The infinite-precision-product wording is from the Release 6
MADDF.fmt/MSUBF.fmt (p.324), which the same manual describes as
replacing the pre-R6 instructions that were "unfused multiply-add,
with an intermediate rounding".
Those are already implemented with float_muladd (float_maddf_*/
float_msubf_*); using it for NMADD/NMSUB would remove the required
intermediate rounding and change Inexact in double-rounding cases.