Bug report: fdiv.s taking two NaN may return a valid number and is not always the consequence of a wrong rounding
Hi there!
Overview
While this issue showed that fdiv can return a result off by one and therefore return NaN instead of infinity,
I found that fdiv.s may return wrong results for NaN inputs, where the output is not just off by one.
Hence, this is another bug than the reported off-by-one. I do not know at the moment whether the root cause is shared.
Snippet
  .section ".text.init","ax",@progbits
  .globl _start
  .align 2
_start:
  # Enable the FPU
  li t0, 0x2000
  csrs mstatus, t0
  csrw	fcsr,x0
  la t0, .fdata0
  la t1, .fdata1
  fld ft0, (t0)
  fld ft1, (t1)
  fdiv.s ft2, ft0, ft1, rup
infinite_loop:
  j infinite_loop
.section ".fdata0","ax",@progbits
  .8byte 0xeed295ee2a0a6df4 # nan
.section ".fdata1","ax",@progbits
  .8byte 0x0707b7830687b703 # nanWe get ft2=0xffffffff63028f6f = 2.40841e+21, while the expected result is 0xffffffff7fc00000=nan, validated with spike.
Note
Interestingly, the result is also wrong with cva6 version 17743bc7120f1eb24974e5d7eb7f519ef53c4bdc, but with a different value: 0x83028f70 = -3.83682e-37.
Thanks! Flavien