fpu/softfloat: set invalid excp flag for RISC-V muladd instructions
PATCH 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fpu/softfloat-specialize.c.inc +17 -0
@@ -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
Signature · 1 line
2.17.1
Quoted 7 lines · On 4/18/21 10:56 PM, [email protected] wrote:
fpu/softfloat-specialize.c.inc +7
-0+#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);
fpu/softfloat-specialize.c.inc static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, · line 643
Quoted 10 lines
fpu/softfloat-specialize.c.inc +10
-0+ 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~
Quoted 27 lines · Richard Henderson
Quoted 7 lines · On 4/18/21 10:56 PM, [email protected] wrote:
fpu/softfloat-specialize.c.inc +7
-0+#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);fpu/softfloat-specialize.c.inc static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, · line 643
Quoted 10 lines
fpu/softfloat-specialize.c.inc +10
-0+ 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 indefault_nanmode, so all
this is unused (and overridden inpick_nan_muladd).I think for avoidance of confusion, you should use
Quoted 8 lines
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