[libre-riscv-dev] [isa-dev] Re: FP transcendentals (trigonometry, root/exp/log) proposal
Jacob Lifshay
programmerjake at gmail.com
Sun Sep 15 22:51:05 BST 2019
On Sun, Sep 15, 2019, 14:21 Mitchalsup <mitchalsup at aol.com> wrote:
> I would argue that correctly-rounded log2 and exp2 instructions are still
> necessary, since they do round differently than the hypothetical log2p1 and
> exp2m1 (which are not currently being proposed, logp1 and expm1 are
> instead, which are base e log and exp rather than base 2; log2p1 and exp2m1
> are not in the C standard but logp1 and expm1 are).
>
>
> Consider EXP2 in the range [-1..+1]
> a) the input argument range contains 1/2 of all IEEE representable values
> b) the output range [0.5..2.0] contains 3 / 2048 of all IEEE representable
> values.
> Thus:: EXP2 has already killed the accuracy regardless of how well
> rounding is performed.
>
> A similar argument can be constructed wrt Ln2
>
> The accuracy is already gone--and in the classical region of use (small
> numbers.)
>
That's true, but I'm looking at accuracy from a slightly different
perspective: does it produce the same results (in correctly-rounded mode,
of course) as a correctly rounded exp2 or log2 operation? If not, then it
can't be used instead of libm's functions (assuming libm even tries to be
correctly-rounded, which it should by default) because it doesn't produce
the correct results. This is important because correctly-rounded results
are the most portable way to achieve identical results cross-platform
(including on x86_64, ARM, and other non-risc-v platforms. x86_32 is a mess
due to x87 instructions, so I will conveniently ignore that).
If the user asks for a correctly-rounded exp2 or log2 operation, they
should get one, even if there are other functions that have better
precision. Otherwise, there's not much point in having separate exp2 and
log2 instructions since pow, exp/exp2/exp10, and log/log2/log10 (for GPU
precision) can be implemented using expm1 and/or logp1 and a muladd in
between.
All of the above isn't really necessary for GPU applications, since they
never tried to achieve correct-rounding in the first place, however it is
definitely needed on Unix platforms, since those generally try for
correctly-rounded operations and users often assume the operations are
reproducible.
Jacob
>
More information about the libre-riscv-dev
mailing list