Skip to content

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

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