[libre-riscv-dev] FP unit testing (was Re: [isa-dev] FP reciprocal sqrt extension proposal)

Jacob Lifshay programmerjake at gmail.com
Thu Jul 25 09:44:55 BST 2019


On Thu, Jul 25, 2019 at 1:27 AM lkcl <luke.leighton at gmail.com> wrote:
>
> so, with thanks to andrew for pointing out the difference between fsqrt and fRsqrt in the special cases handling, that saved some time in wriiing the RTL:
>
>         with m.If(self.i.ctx.op == 2): # RSQRT
>             # if a is +/- zero return NaN
>             with m.If(a1.is_zero):
>                 m.d.comb += self.o.z.nan(0)
>             # -ve number is NaN
>             with m.Elif(a1.s):
>                 m.d.comb += self.o.z.nan(0)
>             # if a is inf return zero (-ve already excluded, above)
>             with m.Elif(a1.is_inf):
>                 m.d.comb += self.o.z.zero(0)
>             # if a is NaN return NaN
>             with m.Elif(a1.is_nan):
>                 m.d.comb += self.o.z.nan(0)
>             # Denormalised Number checks next, so pass a/b data through
>             with m.Else():
>                 ....
>
> however one key difference: where fpsqrt(-ve 0) returns -ve inf, fpRsqrt(-ve 0) still returns canonical NaN.  i.e. i don't believe it's quite exactly the same (swapping 0-test and Inf-test).
>
> does that look reasonable?
The special case values should be (for reciprocal sqrt):
NaN -> NaN (ignoring signaling/quiet)
-Inf -> NaN
-finite -> NaN
-0 -> -Inf (div-by-zero; weird, but this is how ieee 754 defines it)
+0 -> +Inf (div-by-zero)
+finite -> rsqrt
+Inf -> +0

Jacob Lifshay



More information about the libre-riscv-dev mailing list