[FFmpeg-devel] [PATCH][RFC] lavu/libm: add exp10 support

Ganesh Ajjanagadde gajjanag at mit.edu
Tue Dec 22 17:04:59 CET 2015


On Tue, Dec 22, 2015 at 3:35 AM, Michael Niedermayer
<michael at niedermayer.cc> wrote:
> On Mon, Dec 21, 2015 at 07:19:50PM -0800, Ganesh Ajjanagadde wrote:
>> exp10 is a function available in GNU libm. Looks like no other common
>> libm has it. As such, I am mostly neutral about its inclusion, with a
>> very slight bias in favor since I am actually posting this.
>>
>> pros:
>> 1. It is faster than pow, and has less of a chance of going into one of
>> the terribly slow paths:
>> https://github.com/andikleen/glibc/blob/rtm-devel9/sysdeps/ieee754/dbl-64/e_exp10.c
>> vs
>> https://github.com/andikleen/glibc/blob/rtm-devel9/sysdeps/ieee754/dbl-64/e_pow.c.
>> Speedup is roughly 30% of the original execution time for an "average"
>> benchmark over 1e8 arguments uniformly spaced from -1 to 1
>> (similar results for other intervals):
>> ./test  4.07s user 0.00s system 100% cpu 4.068 total (exp10)
>> ./test  5.71s user 0.00s system 100% cpu 5.711 total (pow)
>>
>> cons:
>> 1. It is GNU libm only, and requires -D_GNU_SOURCE.
>> 2. Speedup is not that impressive.
>
>> 3. pow(10, x) is not terribly common in the code, and still cheaper
>> approximation (not as accurate, but often reasonable) exp(ln(10)*x) is
>> much faster:
>> ./test  2.55s user 0.00s system 99% cpu 2.548 total (exp(ln(10)*x))
>
> IMHO a exp10 fallback should be implemented using exp2() if that is faster
> and available.

I don't know whether the fallback should use exp or exp2, need to
check which is faster. And if we fallback to exp or exp2, it will turn
out that the fallback is significantly faster than the actual libm
function (as demonstrated above, like erf), nothing wrong with that,
just is somewhat strange.

>
> Code requiring absolute accuracy must be written using integers as C
> does not gurantee accuracy for float and double.
> A single libc or fallback providing more accuracy does not really help
> as our code must function correctly in the absence of such accuracy
> also the accuracy difference between exp2() and pow() should be
> negligible

A lot of our floating point code assumes IEEE-754, which has
reasonably well defined semantics. Anyway, as a general statement, I
agree.

For a proper libm, exp2(x) and pow(2, x) should be identical. I guess
what you are referring to is exp2(log2(10)*x) vs pow(10, x). In this
case, I don't know how bad the difference is; I suspect it to be more
than 1 ulp in some cases.

However, I am quite sure many implementations of pow are broken wrt
precise rounding anyway: it is a very difficult function to get right.
Nevertheless, we should ensure that the fallbacks are reasonably
correct, and are not completely off.

For me, the RFC was really whether it is all worth the trouble of
extra checks in configure. Seems like at least you have some interest,
so will post v2 soon, thanks.

>
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> In fact, the RIAA has been known to suggest that students drop out
> of college or go to community college in order to be able to afford
> settlements. -- The RIAA
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list