[FFmpeg-devel] [PATCHv3 2/2] all: move ff_exp10, ff_exp10f, ff_fast_powf to lavu/ffmath.h
Ganesh Ajjanagadde
gajjanag at gmail.com
Tue Mar 15 03:05:00 CET 2016
The idea is to use ffmath.h for internal implementations of math functions.
Currently, it is used for variants of libm functions, but is by no means
limited to such things.
Note that this is not exported; use lavu/mathematics for such purposes.
Suggested-by: Ronald S. Bultje <rsbultje at gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanag at gmail.com>
---
libavcodec/aacenc_utils.h | 2 +-
libavcodec/aacpsy.c | 3 +-
libavcodec/acelp_pitch_delay.c | 3 +-
libavcodec/cngdec.c | 2 +-
libavcodec/dcaenc.c | 2 +-
libavcodec/imc.c | 2 +-
libavcodec/on2avc.c | 2 +-
libavcodec/opus.c | 2 +-
libavcodec/wmadec.c | 3 +-
libavcodec/wmaenc.c | 2 +-
libavcodec/wmaprodec.c | 2 +-
libavfilter/af_anequalizer.c | 1 +
libavfilter/af_compand.c | 1 +
libavfilter/af_volume.c | 1 +
libavfilter/f_ebur128.c | 1 +
libavfilter/vaf_spectrumsynth.c | 1 +
libavfilter/vsrc_testsrc.c | 1 +
libavutil/eval.c | 1 +
libavutil/ffmath.h | 67 +++++++++++++++++++++++++++++++++++++++++
libavutil/internal.h | 36 ----------------------
20 files changed, 85 insertions(+), 50 deletions(-)
create mode 100644 libavutil/ffmath.h
diff --git a/libavcodec/aacenc_utils.h b/libavcodec/aacenc_utils.h
index 07f7337..bb1dcb4 100644
--- a/libavcodec/aacenc_utils.h
+++ b/libavcodec/aacenc_utils.h
@@ -28,7 +28,7 @@
#ifndef AVCODEC_AACENC_UTILS_H
#define AVCODEC_AACENC_UTILS_H
-#include "libavutil/internal.h"
+#include "libavutil/ffmath.h"
#include "aac.h"
#include "aacenctab.h"
#include "aactab.h"
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 8643fe7..0898baf 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -25,8 +25,7 @@
*/
#include "libavutil/attributes.h"
-#include "libavutil/internal.h"
-#include "libavutil/libm.h"
+#include "libavutil/ffmath.h"
#include "avcodec.h"
#include "aactab.h"
diff --git a/libavcodec/acelp_pitch_delay.c b/libavcodec/acelp_pitch_delay.c
index c2533b1..8ec1ba3 100644
--- a/libavcodec/acelp_pitch_delay.c
+++ b/libavcodec/acelp_pitch_delay.c
@@ -21,9 +21,8 @@
*/
#include "libavutil/common.h"
+#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
-#include "libavutil/internal.h"
-#include "libavutil/libm.h"
#include "libavutil/mathematics.h"
#include "avcodec.h"
#include "acelp_pitch_delay.h"
diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c
index 0251086..34f8814 100644
--- a/libavcodec/cngdec.c
+++ b/libavcodec/cngdec.c
@@ -22,7 +22,7 @@
#include <math.h>
#include "libavutil/common.h"
-#include "libavutil/internal.h"
+#include "libavutil/ffmath.h"
#include "avcodec.h"
#include "celp_filters.h"
#include "internal.h"
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 70e9230..ab40e37 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -24,7 +24,7 @@
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
-#include "libavutil/internal.h"
+#include "libavutil/ffmath.h"
#include "avcodec.h"
#include "dca.h"
#include "dcadata.h"
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 085ec09..850bc9d 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -35,9 +35,9 @@
#include <stdio.h>
#include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
#include "libavutil/internal.h"
-#include "libavutil/libm.h"
#include "avcodec.h"
#include "bswapdsp.h"
#include "get_bits.h"
diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index 62c71cc..3064c6f 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -21,8 +21,8 @@
*/
#include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
-#include "libavutil/internal.h"
#include "avcodec.h"
#include "bytestream.h"
#include "fft.h"
diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index f2b8ecc..47f2657 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -27,7 +27,7 @@
#include <stdint.h>
#include "libavutil/error.h"
-#include "libavutil/internal.h"
+#include "libavutil/ffmath.h"
#include "opus.h"
#include "vorbis.h"
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 1a84323..7130bf6 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -34,8 +34,7 @@
*/
#include "libavutil/attributes.h"
-#include "libavutil/internal.h"
-#include "libavutil/libm.h"
+#include "libavutil/ffmath.h"
#include "avcodec.h"
#include "internal.h"
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index d0727e6..418e958 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -20,7 +20,7 @@
*/
#include "libavutil/attributes.h"
-#include "libavutil/internal.h"
+#include "libavutil/ffmath.h"
#include "avcodec.h"
#include "internal.h"
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 2ea59e9..2cc1b09 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -88,8 +88,8 @@
#include <inttypes.h>
+#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
-#include "libavutil/internal.h"
#include "libavutil/intfloat.h"
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
diff --git a/libavfilter/af_anequalizer.c b/libavfilter/af_anequalizer.c
index a344c77..2403460 100644
--- a/libavfilter/af_anequalizer.c
+++ b/libavfilter/af_anequalizer.c
@@ -21,6 +21,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
+#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c
index b746364..0bb719f 100644
--- a/libavfilter/af_compand.c
+++ b/libavfilter/af_compand.c
@@ -29,6 +29,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
+#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "audio.h"
diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
index 3913e7b..4d6b916 100644
--- a/libavfilter/af_volume.c
+++ b/libavfilter/af_volume.c
@@ -27,6 +27,7 @@
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
+#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
index c4b30b4..59eaedd 100644
--- a/libavfilter/f_ebur128.c
+++ b/libavfilter/f_ebur128.c
@@ -33,6 +33,7 @@
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/dict.h"
+#include "libavutil/ffmath.h"
#include "libavutil/xga_font_data.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
diff --git a/libavfilter/vaf_spectrumsynth.c b/libavfilter/vaf_spectrumsynth.c
index 8d4014e..ee394b4 100644
--- a/libavfilter/vaf_spectrumsynth.c
+++ b/libavfilter/vaf_spectrumsynth.c
@@ -27,6 +27,7 @@
#include "libavcodec/avfft.h"
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index a75dd4c..f0c0985 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -37,6 +37,7 @@
#include "libavutil/avassert.h"
#include "libavutil/common.h"
+#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 2acbbb4..37b8511 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -31,6 +31,7 @@
#include "avutil.h"
#include "common.h"
#include "eval.h"
+#include "ffmath.h"
#include "internal.h"
#include "log.h"
#include "mathematics.h"
diff --git a/libavutil/ffmath.h b/libavutil/ffmath.h
new file mode 100644
index 0000000..aad1347
--- /dev/null
+++ b/libavutil/ffmath.h
@@ -0,0 +1,67 @@
+/*
+ * copyright (c) 2016 Ganesh Ajjanagadde <gajjanag at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * internal math functions header
+ */
+
+#ifndef AVUTIL_FFMATH_H
+#define AVUTIL_FFMATH_H
+
+#include "attributes.h"
+#include "libm.h"
+
+/**
+ * Compute 10^x for floating point values. Note: this function is by no means
+ * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
+ * For instance, maximum relative error for the double precision variant is
+ * ~ 1e-13 for very small and very large values.
+ * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
+ * some inputs.
+ * @param x exponent
+ * @return 10^x
+ */
+static av_always_inline double ff_exp10(double x)
+{
+ return exp2(M_LOG2_10 * x);
+}
+
+static av_always_inline float ff_exp10f(float x)
+{
+ return exp2f(M_LOG2_10 * x);
+}
+
+/**
+ * Compute x^y for floating point x, y. Note: this function is faster than the
+ * libm variant due to mainly 2 reasons:
+ * 1. It does not handle any edge cases. In particular, this is only guaranteed
+ * to work correctly for x > 0.
+ * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
+ * @param x base
+ * @param y exponent
+ * @return x^y
+ */
+static av_always_inline float ff_fast_powf(float x, float y)
+{
+ return expf(logf(x) * y);
+}
+
+#endif /* AVUTIL_FFMATH_H */
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 340e18b..61784b5 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -295,42 +295,6 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
}
/**
- * Compute 10^x for floating point values. Note: this function is by no means
- * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
- * For instance, maximum relative error for the double precision variant is
- * ~ 1e-13 for very small and very large values.
- * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
- * some inputs.
- * @param x exponent
- * @return 10^x
- */
-static av_always_inline double ff_exp10(double x)
-{
- return exp2(M_LOG2_10 * x);
-}
-
-static av_always_inline float ff_exp10f(float x)
-{
- return exp2f(M_LOG2_10 * x);
-}
-
-/**
- * Compute x^y for floating point x, y. Note: this function is faster than the
- * libm variant due to mainly 2 reasons:
- * 1. It does not handle any edge cases. In particular, this is only guaranteed
- * to work correctly for x > 0.
- * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
- * @param x base
- * @param y exponent
- * @return x^y
- */
-static av_always_inline float ff_fast_powf(float x, float y)
-{
- return expf(logf(x) * y);
-}
-
-
-/**
* A wrapper for open() setting O_CLOEXEC.
*/
av_warn_unused_result
--
2.7.3
More information about the ffmpeg-devel
mailing list