On Wed, Dec 23, 2015 at 12:29 AM, Ganesh Ajjanagadde <gajjanaga...@gmail.com> wrote: > exp10 is a function available in GNU libm. Looks like no other common > libm has it. This adds support for it to FFmpeg. > > There are essentially 2 ways of handling the fallback: > 1. Using pow(10, x) > 2. Using exp2(M_LOG2_10 * x). > > First one represents a Pareto improvement, with no speed or accuracy > regression anywhere, but speed improvement limited to GNU libm. > > Second one represents a slight accuracy loss (relative error ~ 1e-13) > for non GNU libm. Speedup of > 2x is obtained on non GNU libm platforms, > ~30% on GNU libm. These are "average case numbers", another benefit is > the lack of triggering of the well-known terrible worst case paths > through pow. > > Based on reviews, second one chosen. Comment added accordingly. > > Reviewed-by: Michael Niedermayer <mich...@niedermayer.cc> > Reviewed-by: Ronald S. Bultje <rsbul...@gmail.com> > Signed-off-by: Ganesh Ajjanagadde <gajjanaga...@gmail.com> > --- > configure | 2 ++ > libavutil/libm.h | 24 ++++++++++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/configure b/configure > index 54c9789..ea717a5 100755 > --- a/configure > +++ b/configure > @@ -1815,6 +1815,8 @@ MATH_FUNCS=" > copysign > cosf > erf > + exp10 > + exp10f > exp2 > exp2f > expf > diff --git a/libavutil/libm.h b/libavutil/libm.h > index 146768a..9705755 100644 > --- a/libavutil/libm.h > +++ b/libavutil/libm.h > @@ -292,6 +292,30 @@ static inline double erf(double z) > #define exp2f(x) ((float)exp2(x)) > #endif /* HAVE_EXP2F */ > > +/* Somewhat inaccurate fallbacks, relative error ~ 1e-13 concentrated on very > +small and very large values. For perfection accuracy-wise, should use pow. > +Speed benefits (>2x average, with no super slow paths) deemed to be worth the > +accuracy tradeoff */ > +#if !HAVE_EXP10 > +static av_always_inline double exp10(double x) > +{ > +#ifndef M_LOG2_10 > +#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */ > +#endif
Should include mathematic.h for this constant, it already defines common constants if not present. > + return exp2(M_LOG2_10 * x); > +} > +#endif /* HAVE_EXP10 */ > + > +#if !HAVE_EXP10F > +static av_always_inline float exp10f(float x) > +{ > +#ifndef M_LOG2_10 > +#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */ > +#endif > + return exp2f(M_LOG2_10 * x); > +} > +#endif /* HAVE_EXP10F */ > + > #if !HAVE_ISINF > #undef isinf > /* Note: these do not follow the BSD/Apple/GNU convention of returning -1 for > -- > 2.6.4 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel