Browse code

all: move ff_exp10, ff_exp10f, ff_fast_powf to lavu/ffmath.h

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.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanag@gmail.com>

Ganesh Ajjanagadde authored on 2016/03/15 10:28:56
Showing 20 changed files
... ...
@@ -28,7 +28,7 @@
28 28
 #ifndef AVCODEC_AACENC_UTILS_H
29 29
 #define AVCODEC_AACENC_UTILS_H
30 30
 
31
-#include "libavutil/internal.h"
31
+#include "libavutil/ffmath.h"
32 32
 #include "aac.h"
33 33
 #include "aacenctab.h"
34 34
 #include "aactab.h"
... ...
@@ -25,8 +25,7 @@
25 25
  */
26 26
 
27 27
 #include "libavutil/attributes.h"
28
-#include "libavutil/internal.h"
29
-#include "libavutil/libm.h"
28
+#include "libavutil/ffmath.h"
30 29
 
31 30
 #include "avcodec.h"
32 31
 #include "aactab.h"
... ...
@@ -21,9 +21,8 @@
21 21
  */
22 22
 
23 23
 #include "libavutil/common.h"
24
+#include "libavutil/ffmath.h"
24 25
 #include "libavutil/float_dsp.h"
25
-#include "libavutil/internal.h"
26
-#include "libavutil/libm.h"
27 26
 #include "libavutil/mathematics.h"
28 27
 #include "avcodec.h"
29 28
 #include "acelp_pitch_delay.h"
... ...
@@ -22,7 +22,7 @@
22 22
 #include <math.h>
23 23
 
24 24
 #include "libavutil/common.h"
25
-#include "libavutil/internal.h"
25
+#include "libavutil/ffmath.h"
26 26
 #include "avcodec.h"
27 27
 #include "celp_filters.h"
28 28
 #include "internal.h"
... ...
@@ -24,7 +24,7 @@
24 24
 #include "libavutil/avassert.h"
25 25
 #include "libavutil/channel_layout.h"
26 26
 #include "libavutil/common.h"
27
-#include "libavutil/internal.h"
27
+#include "libavutil/ffmath.h"
28 28
 #include "avcodec.h"
29 29
 #include "dca.h"
30 30
 #include "dcadata.h"
... ...
@@ -35,9 +35,9 @@
35 35
 #include <stdio.h>
36 36
 
37 37
 #include "libavutil/channel_layout.h"
38
+#include "libavutil/ffmath.h"
38 39
 #include "libavutil/float_dsp.h"
39 40
 #include "libavutil/internal.h"
40
-#include "libavutil/libm.h"
41 41
 #include "avcodec.h"
42 42
 #include "bswapdsp.h"
43 43
 #include "get_bits.h"
... ...
@@ -21,8 +21,8 @@
21 21
  */
22 22
 
23 23
 #include "libavutil/channel_layout.h"
24
+#include "libavutil/ffmath.h"
24 25
 #include "libavutil/float_dsp.h"
25
-#include "libavutil/internal.h"
26 26
 #include "avcodec.h"
27 27
 #include "bytestream.h"
28 28
 #include "fft.h"
... ...
@@ -27,7 +27,7 @@
27 27
 #include <stdint.h>
28 28
 
29 29
 #include "libavutil/error.h"
30
-#include "libavutil/internal.h"
30
+#include "libavutil/ffmath.h"
31 31
 
32 32
 #include "opus.h"
33 33
 #include "vorbis.h"
... ...
@@ -34,8 +34,7 @@
34 34
  */
35 35
 
36 36
 #include "libavutil/attributes.h"
37
-#include "libavutil/internal.h"
38
-#include "libavutil/libm.h"
37
+#include "libavutil/ffmath.h"
39 38
 
40 39
 #include "avcodec.h"
41 40
 #include "internal.h"
... ...
@@ -20,7 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "libavutil/attributes.h"
23
-#include "libavutil/internal.h"
23
+#include "libavutil/ffmath.h"
24 24
 
25 25
 #include "avcodec.h"
26 26
 #include "internal.h"
... ...
@@ -88,8 +88,8 @@
88 88
 
89 89
 #include <inttypes.h>
90 90
 
91
+#include "libavutil/ffmath.h"
91 92
 #include "libavutil/float_dsp.h"
92
-#include "libavutil/internal.h"
93 93
 #include "libavutil/intfloat.h"
94 94
 #include "libavutil/intreadwrite.h"
95 95
 #include "avcodec.h"
... ...
@@ -21,6 +21,7 @@
21 21
 
22 22
 #include "libavutil/intreadwrite.h"
23 23
 #include "libavutil/avstring.h"
24
+#include "libavutil/ffmath.h"
24 25
 #include "libavutil/opt.h"
25 26
 #include "libavutil/parseutils.h"
26 27
 #include "avfilter.h"
... ...
@@ -29,6 +29,7 @@
29 29
 
30 30
 #include "libavutil/avassert.h"
31 31
 #include "libavutil/avstring.h"
32
+#include "libavutil/ffmath.h"
32 33
 #include "libavutil/opt.h"
33 34
 #include "libavutil/samplefmt.h"
34 35
 #include "audio.h"
... ...
@@ -27,6 +27,7 @@
27 27
 #include "libavutil/channel_layout.h"
28 28
 #include "libavutil/common.h"
29 29
 #include "libavutil/eval.h"
30
+#include "libavutil/ffmath.h"
30 31
 #include "libavutil/float_dsp.h"
31 32
 #include "libavutil/intreadwrite.h"
32 33
 #include "libavutil/opt.h"
... ...
@@ -33,6 +33,7 @@
33 33
 #include "libavutil/avstring.h"
34 34
 #include "libavutil/channel_layout.h"
35 35
 #include "libavutil/dict.h"
36
+#include "libavutil/ffmath.h"
36 37
 #include "libavutil/xga_font_data.h"
37 38
 #include "libavutil/opt.h"
38 39
 #include "libavutil/timestamp.h"
... ...
@@ -27,6 +27,7 @@
27 27
 #include "libavcodec/avfft.h"
28 28
 #include "libavutil/avassert.h"
29 29
 #include "libavutil/channel_layout.h"
30
+#include "libavutil/ffmath.h"
30 31
 #include "libavutil/opt.h"
31 32
 #include "libavutil/parseutils.h"
32 33
 #include "avfilter.h"
... ...
@@ -37,6 +37,7 @@
37 37
 
38 38
 #include "libavutil/avassert.h"
39 39
 #include "libavutil/common.h"
40
+#include "libavutil/ffmath.h"
40 41
 #include "libavutil/opt.h"
41 42
 #include "libavutil/imgutils.h"
42 43
 #include "libavutil/intreadwrite.h"
... ...
@@ -31,6 +31,7 @@
31 31
 #include "avutil.h"
32 32
 #include "common.h"
33 33
 #include "eval.h"
34
+#include "ffmath.h"
34 35
 #include "internal.h"
35 36
 #include "log.h"
36 37
 #include "mathematics.h"
37 38
new file mode 100644
... ...
@@ -0,0 +1,67 @@
0
+/*
1
+ * copyright (c) 2016 Ganesh Ajjanagadde <gajjanag@gmail.com>
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+/**
21
+ * @file
22
+ * internal math functions header
23
+ */
24
+
25
+#ifndef AVUTIL_FFMATH_H
26
+#define AVUTIL_FFMATH_H
27
+
28
+#include "attributes.h"
29
+#include "libm.h"
30
+
31
+/**
32
+ * Compute 10^x for floating point values. Note: this function is by no means
33
+ * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
34
+ * For instance, maximum relative error for the double precision variant is
35
+ * ~ 1e-13 for very small and very large values.
36
+ * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
37
+ * some inputs.
38
+ * @param x exponent
39
+ * @return 10^x
40
+ */
41
+static av_always_inline double ff_exp10(double x)
42
+{
43
+    return exp2(M_LOG2_10 * x);
44
+}
45
+
46
+static av_always_inline float ff_exp10f(float x)
47
+{
48
+    return exp2f(M_LOG2_10 * x);
49
+}
50
+
51
+/**
52
+ * Compute x^y for floating point x, y. Note: this function is faster than the
53
+ * libm variant due to mainly 2 reasons:
54
+ * 1. It does not handle any edge cases. In particular, this is only guaranteed
55
+ * to work correctly for x > 0.
56
+ * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
57
+ * @param x base
58
+ * @param y exponent
59
+ * @return x^y
60
+ */
61
+static av_always_inline float ff_fast_powf(float x, float y)
62
+{
63
+    return expf(logf(x) * y);
64
+}
65
+
66
+#endif /* AVUTIL_FFMATH_H */
... ...
@@ -295,42 +295,6 @@ static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin,
295 295
 }
296 296
 
297 297
 /**
298
- * Compute 10^x for floating point values. Note: this function is by no means
299
- * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
300
- * For instance, maximum relative error for the double precision variant is
301
- * ~ 1e-13 for very small and very large values.
302
- * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
303
- * some inputs.
304
- * @param x exponent
305
- * @return 10^x
306
- */
307
-static av_always_inline double ff_exp10(double x)
308
-{
309
-    return exp2(M_LOG2_10 * x);
310
-}
311
-
312
-static av_always_inline float ff_exp10f(float x)
313
-{
314
-    return exp2f(M_LOG2_10 * x);
315
-}
316
-
317
-/**
318
- * Compute x^y for floating point x, y. Note: this function is faster than the
319
- * libm variant due to mainly 2 reasons:
320
- * 1. It does not handle any edge cases. In particular, this is only guaranteed
321
- * to work correctly for x > 0.
322
- * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
323
- * @param x base
324
- * @param y exponent
325
- * @return x^y
326
- */
327
-static av_always_inline float ff_fast_powf(float x, float y)
328
-{
329
-    return expf(logf(x) * y);
330
-}
331
-
332
-
333
-/**
334 298
  * A wrapper for open() setting O_CLOEXEC.
335 299
  */
336 300
 av_warn_unused_result