Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: fdiv.s taking two NaN may return a valid number and is not always the consequence of a wrong rounding #85

Open
flaviens opened this issue Apr 17, 2023 · 0 comments

Comments

@flaviens
Copy link
Contributor

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 # nan

We 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant