Skip to contentSkip to conversation

fpu/softfloat: set invalid excp flag for RISC-V muladd instructions

PATCH Applied [email protected] 3 participants 5 messages Apr 20, 2021 – Apr 22, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fpu/softfloat: set invalid excp flag for RISC-V muladd instructions

From: Frank Chang <[email protected]>

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.

---
 fpu/softfloat-specialize.c.inc | 6 ++++++
 1 file changed, 6 insertions(+)
fpu/softfloat-specialize.c.inc +6 -0
index c2f87addb25..12f29fbfc5e 100644
@@ -624,6 +624,12 @@ 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 */
+    if (infzero) {
+        float_raise(float_flag_invalid, status);
+    }
+    return 3; /* deafult NaN */
 #elif defined(TARGET_XTENSA)
     /*
      * For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 14 lines · On 4/19/21 6:31 PM, [email protected] wrote:

From: Frank Chang<[email protected]>

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.

Quoted 8 lines

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

---
  fpu/softfloat-specialize.c.inc | 6 ++++++
  1 file changed, 6 insertions(+)

Alistair, will you take this via your riscv queue?

r~

#2 lore raw
Quoted 25 lines · Richard Henderson
Quoted 14 lines · On 4/19/21 6:31 PM, [email protected] wrote:

From: Frank Chang<[email protected]>

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.

Quoted 8 lines

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

---
  fpu/softfloat-specialize.c.inc | 6 ++++++
  1 file changed, 6 insertions(+)
Quoted 3 lines

Alistair, will you take this via your riscv queue?

Yep, getting it now

Alistair

Quoted 4 lines

r~

#4 lore raw
Quoted 5 lines · Richard Henderson
Quoted 1 line · On 4/19/21 6:31 PM, [email protected] wrote:

+ return 3; /* deafult NaN */

Late notice of spelling error: default.

Fixed when I applied it.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 3 lines

r~