qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
@ 2021-04-19  5:56 frank.chang
  2021-04-19 15:28 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: frank.chang @ 2021-04-19  5:56 UTC (permalink / raw)
  To: qemu-devel, qemu-riscv
  Cc: Frank Chang, Peter Maydell, Alex Bennée, Aurelien Jarno

From: Frank Chang <frank.chang@sifive.com>

In IEEE 754-2008 spec:
  Invalid operation exception is signaled when doing:
  fusedMultiplyAdd(0, Inf, c) or fusedMultiplyAdd(Inf, 0, c)
  unless c is a quiet NaN; if c is a quiet NaN then it is
  implementation defined whether the invalid operation exception
  is signaled.

In RISC-V Unprivileged ISA spec:
  The fused multiply-add instructions must set the invalid
  operation exception flag when the multiplicands are Inf and
  zero, even when the addend is a quiet NaN.

This commit set invalid operation execption flag for RISC-V when
multiplicands of muladd instructions are Inf and zero.

Signed-off-by: Frank Chang <frank.chang@sifive.com>
---
 fpu/softfloat-specialize.c.inc | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc
index c2f87addb25..9c37265e20b 100644
--- a/fpu/softfloat-specialize.c.inc
+++ b/fpu/softfloat-specialize.c.inc
@@ -624,6 +624,23 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
     } else {
         return 1;
     }
+#elif defined(TARGET_RISCV)
+    /*
+     * For RISC-V, InvalidOp is set when multiplicands are Inf and zero
+     * and returns default NaN.
+     */
+    if (infzero) {
+        float_raise(float_flag_invalid, status);
+        return 3;
+    }
+
+    if (is_nan(a_cls)) {
+        return 0;
+    } else if (is_nan(b_cls)) {
+        return 1;
+    } else {
+        return 2;
+    }
 #elif defined(TARGET_XTENSA)
     /*
      * For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns
-- 
2.17.1



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

* Re: [PATCH] fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
  2021-04-19  5:56 [PATCH] fpu/softfloat: set invalid excp flag for RISC-V muladd instructions frank.chang
@ 2021-04-19 15:28 ` Richard Henderson
  2021-04-20  1:18   ` Frank Chang
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2021-04-19 15:28 UTC (permalink / raw)
  To: frank.chang, qemu-devel, qemu-riscv
  Cc: Peter Maydell, Alex Bennée, Aurelien Jarno

On 4/18/21 10:56 PM, frank.chang@sifive.com wrote:
> +#elif defined(TARGET_RISCV)
> +    /*
> +     * For RISC-V, InvalidOp is set when multiplicands are Inf and zero
> +     * and returns default NaN.
> +     */
> +    if (infzero) {
> +        float_raise(float_flag_invalid, status);
> +        return 3;
> +    }
> +
> +    if (is_nan(a_cls)) {
> +        return 0;
> +    } else if (is_nan(b_cls)) {
> +        return 1;
> +    } else {
> +        return 2;
> +    }

This second half of the function made me go look into the spec to make sure you 
had got that selection right.  But RISCV is always in default_nan mode, so all 
this is unused (and overridden in pick_nan_muladd).

I think for avoidance of confusion, you should use

     if (infzero) {
         float_raise(float_flag_invalid, status);
     }
     return 3; /* default nan */


r~


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

* Re: [PATCH] fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
  2021-04-19 15:28 ` Richard Henderson
@ 2021-04-20  1:18   ` Frank Chang
  0 siblings, 0 replies; 3+ messages in thread
From: Frank Chang @ 2021-04-20  1:18 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Alex Bennée, Peter Maydell, open list:RISC-V,
	qemu-devel@nongnu.org Developers, Aurelien Jarno

[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]

On Mon, Apr 19, 2021 at 11:28 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 4/18/21 10:56 PM, frank.chang@sifive.com wrote:
> > +#elif defined(TARGET_RISCV)
> > +    /*
> > +     * For RISC-V, InvalidOp is set when multiplicands are Inf and zero
> > +     * and returns default NaN.
> > +     */
> > +    if (infzero) {
> > +        float_raise(float_flag_invalid, status);
> > +        return 3;
> > +    }
> > +
> > +    if (is_nan(a_cls)) {
> > +        return 0;
> > +    } else if (is_nan(b_cls)) {
> > +        return 1;
> > +    } else {
> > +        return 2;
> > +    }
>
> This second half of the function made me go look into the spec to make
> sure you
> had got that selection right.  But RISCV is always in default_nan mode, so
> all
> this is unused (and overridden in pick_nan_muladd).
>
> I think for avoidance of confusion, you should use
>
>      if (infzero) {
>          float_raise(float_flag_invalid, status);
>      }
>      return 3; /* default nan */
>
>
> r~
>

Sure, I'll update my patch and resend again.

Thanks
Frank Chang

[-- Attachment #2: Type: text/html, Size: 1666 bytes --]

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

end of thread, other threads:[~2021-04-20  1:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19  5:56 [PATCH] fpu/softfloat: set invalid excp flag for RISC-V muladd instructions frank.chang
2021-04-19 15:28 ` Richard Henderson
2021-04-20  1:18   ` Frank Chang

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).