TheThirdOne/rars

fmadd / fmsub error when adding with zero

helderdaniel opened this issue · 1 comments

Hi,

when trying to use fmadd/fmsub (fnmadd/fnmsub) to add the product with a register that holds floating point zero, the result is always zero:

.data
A: .float 1.0, 2.0, 0.0

.text
la t0, A
flw fa1, 0(t0)
flw fa2, 4(t0)
flw fa3, 8(t0)
fmadd.s fa0, fa1, fa2, fa3 #fa0 = should hold 2.0 but holds 0.0

if fa3 has a value different than zero, it performs the operation correctly:

.data
A: .float 1.0, 2.0, 3.0
(...)
fmadd.s fa0, fa1, fa2, fa3 #fa0 = holds 5.0 as it should

It is not a problem of flw.
Loading zero to fa3 with:

fcvt.s.w fa0,x0
or
fmsub fa0,fa0,fa0

and then executing:

fmadd.s fa0, fa1, fa2, fa3

gives also zero result.

Not initializing fa3 register, letting all the bits have zero value (this is the value RARS init the FP registers), the same operation gives NAN.
But a FP register with all bits zero should hold FP +0.0.

The same happens with double precision functions: fmadd.d, ...

This was tested with latest version:

rars_533d3c0,jar

Thanks for this issue. This should be fixed by b4943e8. Honestly, I don't know why I made this bug.