openhwgroup / cvfpu

Parametric floating-point unit with support for standard RISC-V formats and operations as well as transprecision formats.
Apache License 2.0
432 stars 115 forks source link

[BUG] Incorrectly set fflags: An underflow exception is triggered when the computed result is an exact subnormal number. #121

Open fly-1011 opened 5 months ago

fly-1011 commented 5 months ago

Bug Description When using the division instruction, CVA6 incorrectly triggers an underflow exception when the computed result is an exact subnormal number (e.g., 0x00000001). This contradicts the IEEE 754 standard, which specifies that an exact subnormal result should not trigger the underflow exception flag.

Steps to Reproduce:

  1. Initialize ft4 to 0x00000001 and ft6 to 0x3F800000
  2. Execute the instruction: fdiv.s ft1, ft4, ft6.
  3. Observe the value of fflags.

The log from CVA6 is as follows:

core   0: 0x000000008000201e (0x186270d3) fdiv.s  ft1, ft4, ft6
3 0x000000008000201e (0x186270d3) f 1 0xffffffff00000001
core   0: 0x0000000080002022 (0x001023f3) csrrs   t2, fflags, zero
3 0x0000000080002022 (0x001023f3) x 7 0x0000000000000002

The log from Spike is as follows:

core   0: 0x000000008000201e (0x186270d3) fdiv.s  ft1, ft4, ft6
core   0: 3 0x000000008000201e (0x186270d3) f1  0xffffffff00000001
core   0: 0x0000000080002022 (0x001023f3) csrrs   t2, fflags, zero
core   0: 3 0x0000000080002022 (0x001023f3) x7  0x0000000000000000

The computed result is 2^-149, which can be exactly represented as a subnormal number. Therefore, in this case, the underflow exception should not be triggered.

See:https://github.com/openhwgroup/cva6/issues/2129

pascalgouedo commented 1 month ago

Same answer than #110

fly-1011 commented 1 month ago

与#110答案相同

Please see the answer in https://github.com/openhwgroup/cvfpu/issues/120#issuecomment-2337965138