[libre-riscv-dev] FP unit testing (was Re: [isa-dev] FP reciprocal sqrt extension proposal)
lkcl
luke.leighton at gmail.com
Sun Jul 14 09:27:36 BST 2019
On Sunday, July 14, 2019 at 8:39:48 AM UTC+1, Jacob Lifshay wrote:
>
> On Sun, Jul 14, 2019 at 12:26 AM lkcl <luke.l... at gmail.com <javascript:>>
> wrote:
> > using bigfloat to perform the reciprocal-square-root in a much higher
> precision will cover the requirement to provide accurate FPSQRT. however
> the corner-cases (at the extreme limits of the exponent, and when the
> mantissa's MSB is zero) are going to be a bundle of fun.
> >
> Note that mpfr has code to emulate fixed-size floating point numbers,
> including handling denormal numbers. It also has mostly (see caveats)
> the same special-case semantics (+-0, +-Inf, NaN) as IEEE 754, so that
> should make it a lot easier to use.
>
https://pythonhosted.org/bigfloat/reference/index.html#bigfloat.Context
that's interesting. some IEEE754-like contexts are provided.
>
> MPFR is used in gcc to evaluate floating-point expressions at compile
> time, so it is well-tested and likely to be correct.
>
excellent
>
> mpfr does, however, have some notable caveats: see
> https://www.mpfr.org/mpfr-current/mpfr.html#MPFR-and-the-IEEE-754-Standard
>
under-normalisation not supported, because, obviously, with an
arbitrary-sized exponent you don't need to lose accuracy in the mantissa.
>>> from bigfloat import BigFloat
>>> b = BigFloat(1.0)
>>> b
BigFloat.exact('1.0000000000000000', precision=53)
>>> b.hex()
'0x0.80000000000000p+1'
>>> b._exponent()
1
>>> b._format_to_fixed_precision(1)
(False, '10', -1)
>>> b = BigFloat(52.39)
>>> b._format_to_fixed_precision(24)
(False, '52390000000000000568434189', -24)
>>> b.hex()
'0x0.d18f5c28f5c290p+6'
ah ha! perfect! that's exactly what we need. and there's a
"BigFloat.fromhex()" function as well, so it will be possible to transfer
numbers in and out of bigfloat, in order to perform conversions to (full)
IEEE754 FP16/32/64 format.
i am still puzzled as to how a *soft* FP rsqrt implementation may be
verified and found to be a correct implementation of the IEEE754 standard.
l.
More information about the libre-riscv-dev
mailing list