Browse code

Move ff_sqrt() to libavutil/intmath.h

Originally committed as revision 22345 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2010/03/09 06:19:56
Showing 9 changed files
... ...
@@ -30,6 +30,7 @@
30 30
 #include <stdlib.h>
31 31
 #include <stdio.h>
32 32
 #include <limits.h>
33
+#include "libavutil/intmath.h"
33 34
 #include "avcodec.h"
34 35
 #include "dsputil.h"
35 36
 #include "mathops.h"
... ...
@@ -27,6 +27,7 @@
27 27
  * The simplest mpeg encoder (well, it was the simplest!).
28 28
  */
29 29
 
30
+#include "libavutil/intmath.h"
30 31
 #include "avcodec.h"
31 32
 #include "dsputil.h"
32 33
 #include "mpegvideo.h"
... ...
@@ -27,6 +27,7 @@
27 27
  * The simplest mpeg encoder (well, it was the simplest!).
28 28
  */
29 29
 
30
+#include "libavutil/intmath.h"
30 31
 #include "avcodec.h"
31 32
 #include "dsputil.h"
32 33
 #include "mpegvideo.h"
... ...
@@ -22,6 +22,7 @@
22 22
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 23
  */
24 24
 
25
+#include "libavutil/intmath.h"
25 26
 #include "avcodec.h"
26 27
 #include "get_bits.h"
27 28
 #include "ra144.h"
... ...
@@ -25,6 +25,7 @@
25 25
  * Rate control for video encoders.
26 26
  */
27 27
 
28
+#include "libavutil/intmath.h"
28 29
 #include "avcodec.h"
29 30
 #include "dsputil.h"
30 31
 #include "ratecontrol.h"
... ...
@@ -21,6 +21,7 @@
21 21
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 22
  */
23 23
 
24
+#include "libavutil/intmath.h"
24 25
 #include "avcodec.h"
25 26
 #include "bytestream.h"
26 27
 
... ...
@@ -18,6 +18,7 @@
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 19
  */
20 20
 
21
+#include "libavutil/intmath.h"
21 22
 #include "avcodec.h"
22 23
 #include "dsputil.h"
23 24
 #include "snow.h"
... ...
@@ -128,28 +128,6 @@
128 128
 
129 129
 /* math */
130 130
 
131
-extern const uint8_t ff_sqrt_tab[256];
132
-
133
-static inline av_const unsigned int ff_sqrt(unsigned int a)
134
-{
135
-    unsigned int b;
136
-
137
-    if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
138
-    else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
139
-#if !CONFIG_SMALL
140
-    else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
141
-    else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8]   ;
142
-#endif
143
-    else {
144
-        int s = av_log2_16bit(a >> 16) >> 1;
145
-        unsigned int c = a >> (s + 2);
146
-        b = ff_sqrt_tab[c >> (s + 8)];
147
-        b = FASTDIV(c,b) + (b << s);
148
-    }
149
-
150
-    return b - (a < b * b);
151
-}
152
-
153 131
 #if ARCH_X86
154 132
 #define MASK_ABS(mask, level)\
155 133
             __asm__ volatile(\
... ...
@@ -56,4 +56,26 @@ extern const uint32_t ff_inverse[257];
56 56
 
57 57
 #endif /* FASTDIV */
58 58
 
59
+extern const uint8_t ff_sqrt_tab[256];
60
+
61
+static inline av_const unsigned int ff_sqrt(unsigned int a)
62
+{
63
+    unsigned int b;
64
+
65
+    if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
66
+    else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
67
+#if !CONFIG_SMALL
68
+    else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
69
+    else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8]   ;
70
+#endif
71
+    else {
72
+        int s = av_log2_16bit(a >> 16) >> 1;
73
+        unsigned int c = a >> (s + 2);
74
+        b = ff_sqrt_tab[c >> (s + 8)];
75
+        b = FASTDIV(c,b) + (b << s);
76
+    }
77
+
78
+    return b - (a < b * b);
79
+}
80
+
59 81
 #endif /* AVUTIL_INTMATH_H */