From: WANG Rui <wangrui@loongson.cn>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: "Song Gao" <gaosong@loongson.cn>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-devel@nongnu.org, qemu@hev.cc,
mengqinggang <mengqinggang@loongson.cn>
Subject: Re: [RFC PATCH v2] target/loongarch: Fix incorrect rounding in fnm{add,sub} under certain modes
Date: Wed, 7 May 2025 23:25:12 +0800 [thread overview]
Message-ID: <CAHirt9jd4LGkGyp0xKFQYKM3CnPYUs4xJmSyg4je6iMKR_0b5A@mail.gmail.com> (raw)
In-Reply-To: <f92c8c65-8fb4-4cfe-b793-a5aa17f11c1d@linaro.org>
Hi Richard,
On Wed, May 7, 2025 at 11:04 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 5/7/25 02:14, WANG Rui wrote:
> > This patch fixes incorrect results for `[xv]fnm{add,sub}.{s,d}`
> > instructions when rounding toward {zero, positive, negative}.
> >
> > According to the LoongArch ISA specification, the result of an
> > instruction like `FNMSUB.D` is computed as:
> >
> > FR[fd] = -FP64_fusedMultiplyAdd(FR[fj], FR[fk], -FR[fa])
> >
> > Here, `FP64_fusedMultiplyAdd()` performs a fused multiply-add operation
> > compliant with IEEE 754-2008. The negation is applied to the fully
> > rounded result of the fused operation - not to any intermediate value.
> > This behavior is specifiec to LoongArch and differs from other arches,
> > which is why the existing `float_muladd_negate_result` flag does not
> > model it correctly.
>
> Loongarch does not differ from other arches; we got it wrong for everyone.
> There's no need for a new flag.
I'm not familiar with PowerPC and s390x. The official PowerPC docs[^1]
doesn't clearly specify the order of negation and rounding operations.
I also don't have access to the hardware to run experiments. However,
I did find the Linux kernel's emulation code[^2][^3] for the PowerPC
`fnmsub` instruction, which seems to suggest that negation occurs
before rounding - though it's possible that interpretation is
incorrect.
[^1]: https://www.ibm.com/docs/en/aix/7.2?topic=set-fnmsub-fnms-floating-negative-multiply-subtract-instruction
[^2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/math-emu/fnmsub.c?h=v6.15-rc5#n49
[^3}: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/math-emu/fnmsub.c?h=v6.15-rc5#n55
Regards,
-hev
>
>
> r~
next prev parent reply other threads:[~2025-05-07 15:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 9:14 [RFC PATCH v2] target/loongarch: Fix incorrect rounding in fnm{add, sub} under certain modes WANG Rui
2025-05-07 15:04 ` [RFC PATCH v2] target/loongarch: Fix incorrect rounding in fnm{add,sub} " Richard Henderson
2025-05-07 15:25 ` WANG Rui [this message]
2025-05-07 16:16 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHirt9jd4LGkGyp0xKFQYKM3CnPYUs4xJmSyg4je6iMKR_0b5A@mail.gmail.com \
--to=wangrui@loongson.cn \
--cc=gaosong@loongson.cn \
--cc=mengqinggang@loongson.cn \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu@hev.cc \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).