x86: dsputil: Suppress deprecation warnings for XvMC bits
[ffmpeg.git] / libavcodec / x86 / dsputil_init.c
1 /*
2  * This file is part of Libav.
3  *
4  * Libav is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * Libav is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "config.h"
20 #include "libavutil/attributes.h"
21 #include "libavutil/cpu.h"
22 #include "libavutil/internal.h"
23 #include "libavutil/x86/asm.h"
24 #include "libavutil/x86/cpu.h"
25 #include "libavcodec/dsputil.h"
26 #include "libavcodec/simple_idct.h"
27 #include "dsputil_x86.h"
28 #include "idct_xvid.h"
29
30 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
31                               int dstStride, int src1Stride, int h);
32 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
33                                      uint8_t *src2, int dstStride,
34                                      int src1Stride, int h);
35 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
36                               int dstStride, int src1Stride, int h);
37 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
38                                int dstStride, int src1Stride, int h);
39 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
40                                int dstStride, int src1Stride, int h);
41 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
42                                       int dstStride, int src1Stride, int h);
43 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
44                                          int dstStride, int srcStride, int h);
45 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
46                                          int dstStride, int srcStride, int h);
47 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
48                                                  int dstStride, int srcStride,
49                                                  int h);
50 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
51                                         int dstStride, int srcStride, int h);
52 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
53                                         int dstStride, int srcStride, int h);
54 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
55                                                 int dstStride, int srcStride,
56                                                 int h);
57 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
58                                          int dstStride, int srcStride);
59 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
60                                          int dstStride, int srcStride);
61 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
62                                                  int dstStride, int srcStride);
63 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
64                                         int dstStride, int srcStride);
65 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
66                                         int dstStride, int srcStride);
67 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
68                                                 int dstStride, int srcStride);
69 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
70 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
71
72 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
73                                       int order);
74 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
75                                     int order);
76 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
77                                                const int16_t *v3,
78                                                int order, int mul);
79 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
80                                              const int16_t *v3,
81                                              int order, int mul);
82 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
83                                               const int16_t *v3,
84                                               int order, int mul);
85
86 void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
87                                         const int16_t *window, unsigned int len);
88 void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
89                                       const int16_t *window, unsigned int len);
90 void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
91                                   const int16_t *window, unsigned int len);
92 void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
93                                 const int16_t *window, unsigned int len);
94 void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
95                                  const int16_t *window, unsigned int len);
96 void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
97                                       const int16_t *window, unsigned int len);
98
99 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
100 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
101
102 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
103                                           const uint8_t *diff, int w,
104                                           int *left, int *left_top);
105 int  ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
106                                        int w, int left);
107 int  ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
108                                       int w, int left);
109
110 void ff_vector_clip_int32_mmx     (int32_t *dst, const int32_t *src,
111                                    int32_t min, int32_t max, unsigned int len);
112 void ff_vector_clip_int32_sse2    (int32_t *dst, const int32_t *src,
113                                    int32_t min, int32_t max, unsigned int len);
114 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
115                                    int32_t min, int32_t max, unsigned int len);
116 void ff_vector_clip_int32_sse4    (int32_t *dst, const int32_t *src,
117                                    int32_t min, int32_t max, unsigned int len);
118
119 #if HAVE_YASM
120
121 PIXELS16(static, ff_avg, , , _mmxext)
122 PIXELS16(static, ff_put, , , _mmxext)
123
124 #define QPEL_OP(OPNAME, RND, MMX)                                       \
125 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src,   \
126                                           ptrdiff_t stride)             \
127 {                                                                       \
128     ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);              \
129 }                                                                       \
130                                                                         \
131 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src,    \
132                                          ptrdiff_t stride)              \
133 {                                                                       \
134     uint64_t temp[8];                                                   \
135     uint8_t * const half = (uint8_t*)temp;                              \
136     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
137                                                    stride, 8);          \
138     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
139                                         stride, stride, 8);             \
140 }                                                                       \
141                                                                         \
142 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src,    \
143                                          ptrdiff_t stride)              \
144 {                                                                       \
145     ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride,    \
146                                                    stride, 8);          \
147 }                                                                       \
148                                                                         \
149 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src,    \
150                                          ptrdiff_t stride)              \
151 {                                                                       \
152     uint64_t temp[8];                                                   \
153     uint8_t * const half = (uint8_t*)temp;                              \
154     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
155                                                    stride, 8);          \
156     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride,     \
157                                         stride, 8);                     \
158 }                                                                       \
159                                                                         \
160 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src,    \
161                                          ptrdiff_t stride)              \
162 {                                                                       \
163     uint64_t temp[8];                                                   \
164     uint8_t * const half = (uint8_t*)temp;                              \
165     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
166                                                    8, stride);          \
167     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
168                                         stride, stride, 8);             \
169 }                                                                       \
170                                                                         \
171 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src,    \
172                                          ptrdiff_t stride)              \
173 {                                                                       \
174     ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src,            \
175                                                    stride, stride);     \
176 }                                                                       \
177                                                                         \
178 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src,    \
179                                          ptrdiff_t stride)              \
180 {                                                                       \
181     uint64_t temp[8];                                                   \
182     uint8_t * const half = (uint8_t*)temp;                              \
183     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
184                                                    8, stride);          \
185     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
186                                         stride, 8);                     \
187 }                                                                       \
188                                                                         \
189 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src,    \
190                                          ptrdiff_t stride)              \
191 {                                                                       \
192     uint64_t half[8 + 9];                                               \
193     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
194     uint8_t * const halfHV = ((uint8_t*)half);                          \
195     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
196                                                    stride, 9);          \
197     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
198                                         stride, 9);                     \
199     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
200     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
201                                         stride, 8, 8);                  \
202 }                                                                       \
203                                                                         \
204 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src,    \
205                                          ptrdiff_t stride)              \
206 {                                                                       \
207     uint64_t half[8 + 9];                                               \
208     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
209     uint8_t * const halfHV = ((uint8_t*)half);                          \
210     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
211                                                    stride, 9);          \
212     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
213                                         stride, 9);                     \
214     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
215     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
216                                         stride, 8, 8);                  \
217 }                                                                       \
218                                                                         \
219 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src,    \
220                                          ptrdiff_t stride)              \
221 {                                                                       \
222     uint64_t half[8 + 9];                                               \
223     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
224     uint8_t * const halfHV = ((uint8_t*)half);                          \
225     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
226                                                    stride, 9);          \
227     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
228                                         stride, 9);                     \
229     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
230     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
231                                         stride, 8, 8);                  \
232 }                                                                       \
233                                                                         \
234 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src,    \
235                                          ptrdiff_t stride)              \
236 {                                                                       \
237     uint64_t half[8 + 9];                                               \
238     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
239     uint8_t * const halfHV = ((uint8_t*)half);                          \
240     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
241                                                    stride, 9);          \
242     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
243                                         stride, 9);                     \
244     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
245     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
246                                         stride, 8, 8);                  \
247 }                                                                       \
248                                                                         \
249 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src,    \
250                                          ptrdiff_t stride)              \
251 {                                                                       \
252     uint64_t half[8 + 9];                                               \
253     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
254     uint8_t * const halfHV = ((uint8_t*)half);                          \
255     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
256                                                    stride, 9);          \
257     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
258     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
259                                         stride, 8, 8);                  \
260 }                                                                       \
261                                                                         \
262 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src,    \
263                                          ptrdiff_t stride)              \
264 {                                                                       \
265     uint64_t half[8 + 9];                                               \
266     uint8_t * const halfH  = ((uint8_t*)half) + 64;                     \
267     uint8_t * const halfHV = ((uint8_t*)half);                          \
268     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
269                                                    stride, 9);          \
270     ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
271     ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
272                                         stride, 8, 8);                  \
273 }                                                                       \
274                                                                         \
275 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src,    \
276                                          ptrdiff_t stride)              \
277 {                                                                       \
278     uint64_t half[8 + 9];                                               \
279     uint8_t * const halfH = ((uint8_t*)half);                           \
280     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
281                                                    stride, 9);          \
282     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH,              \
283                                         8, stride, 9);                  \
284     ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
285                                                    stride, 8);          \
286 }                                                                       \
287                                                                         \
288 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src,    \
289                                          ptrdiff_t stride)              \
290 {                                                                       \
291     uint64_t half[8 + 9];                                               \
292     uint8_t * const halfH = ((uint8_t*)half);                           \
293     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
294                                                    stride, 9);          \
295     ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
296                                         stride, 9);                     \
297     ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
298                                                    stride, 8);          \
299 }                                                                       \
300                                                                         \
301 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src,    \
302                                          ptrdiff_t stride)              \
303 {                                                                       \
304     uint64_t half[9];                                                   \
305     uint8_t * const halfH = ((uint8_t*)half);                           \
306     ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
307                                                    stride, 9);          \
308     ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
309                                                    stride, 8);          \
310 }                                                                       \
311                                                                         \
312 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src,  \
313                                            ptrdiff_t stride)            \
314 {                                                                       \
315     ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);            \
316 }                                                                       \
317                                                                         \
318 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src,   \
319                                           ptrdiff_t stride)             \
320 {                                                                       \
321     uint64_t temp[32];                                                  \
322     uint8_t * const half = (uint8_t*)temp;                              \
323     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
324                                                     stride, 16);        \
325     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
326                                          stride, 16);                   \
327 }                                                                       \
328                                                                         \
329 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src,   \
330                                           ptrdiff_t stride)             \
331 {                                                                       \
332     ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src,           \
333                                                     stride, stride, 16);\
334 }                                                                       \
335                                                                         \
336 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src,   \
337                                           ptrdiff_t stride)             \
338 {                                                                       \
339     uint64_t temp[32];                                                  \
340     uint8_t * const half = (uint8_t*)temp;                              \
341     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
342                                                     stride, 16);        \
343     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half,            \
344                                          stride, stride, 16);           \
345 }                                                                       \
346                                                                         \
347 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src,   \
348                                           ptrdiff_t stride)             \
349 {                                                                       \
350     uint64_t temp[32];                                                  \
351     uint8_t * const half = (uint8_t*)temp;                              \
352     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
353                                                     stride);            \
354     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
355                                          stride, 16);                   \
356 }                                                                       \
357                                                                         \
358 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src,   \
359                                           ptrdiff_t stride)             \
360 {                                                                       \
361     ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src,           \
362                                                     stride, stride);    \
363 }                                                                       \
364                                                                         \
365 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src,   \
366                                           ptrdiff_t stride)             \
367 {                                                                       \
368     uint64_t temp[32];                                                  \
369     uint8_t * const half = (uint8_t*)temp;                              \
370     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
371                                                     stride);            \
372     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half,         \
373                                          stride, stride, 16);           \
374 }                                                                       \
375                                                                         \
376 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src,   \
377                                           ptrdiff_t stride)             \
378 {                                                                       \
379     uint64_t half[16 * 2 + 17 * 2];                                     \
380     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
381     uint8_t * const halfHV = ((uint8_t*)half);                          \
382     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
383                                                     stride, 17);        \
384     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
385                                          stride, 17);                   \
386     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
387                                                     16, 16);            \
388     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
389                                          stride, 16, 16);               \
390 }                                                                       \
391                                                                         \
392 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src,   \
393                                           ptrdiff_t stride)             \
394 {                                                                       \
395     uint64_t half[16 * 2 + 17 * 2];                                     \
396     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
397     uint8_t * const halfHV = ((uint8_t*)half);                          \
398     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
399                                                     stride, 17);        \
400     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
401                                          stride, 17);                   \
402     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
403                                                     16, 16);            \
404     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
405                                          stride, 16, 16);               \
406 }                                                                       \
407                                                                         \
408 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src,   \
409                                           ptrdiff_t stride)             \
410 {                                                                       \
411     uint64_t half[16 * 2 + 17 * 2];                                     \
412     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
413     uint8_t * const halfHV = ((uint8_t*)half);                          \
414     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
415                                                     stride, 17);        \
416     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
417                                          stride, 17);                   \
418     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
419                                                     16, 16);            \
420     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
421                                          stride, 16, 16);               \
422 }                                                                       \
423                                                                         \
424 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src,   \
425                                           ptrdiff_t stride)             \
426 {                                                                       \
427     uint64_t half[16 * 2 + 17 * 2];                                     \
428     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
429     uint8_t * const halfHV = ((uint8_t*)half);                          \
430     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
431                                                     stride, 17);        \
432     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
433                                          stride, 17);                   \
434     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
435                                                     16, 16);            \
436     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
437                                          stride, 16, 16);               \
438 }                                                                       \
439                                                                         \
440 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src,   \
441                                           ptrdiff_t stride)             \
442 {                                                                       \
443     uint64_t half[16 * 2 + 17 * 2];                                     \
444     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
445     uint8_t * const halfHV = ((uint8_t*)half);                          \
446     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
447                                                     stride, 17);        \
448     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
449                                                     16, 16);            \
450     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
451                                          stride, 16, 16);               \
452 }                                                                       \
453                                                                         \
454 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src,   \
455                                           ptrdiff_t stride)             \
456 {                                                                       \
457     uint64_t half[16 * 2 + 17 * 2];                                     \
458     uint8_t * const halfH  = ((uint8_t*)half) + 256;                    \
459     uint8_t * const halfHV = ((uint8_t*)half);                          \
460     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
461                                                     stride, 17);        \
462     ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
463                                                     16, 16);            \
464     ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
465                                          stride, 16, 16);               \
466 }                                                                       \
467                                                                         \
468 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src,   \
469                                           ptrdiff_t stride)             \
470 {                                                                       \
471     uint64_t half[17 * 2];                                              \
472     uint8_t * const halfH = ((uint8_t*)half);                           \
473     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
474                                                     stride, 17);        \
475     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
476                                          stride, 17);                   \
477     ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
478                                                     stride, 16);        \
479 }                                                                       \
480                                                                         \
481 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src,   \
482                                           ptrdiff_t stride)             \
483 {                                                                       \
484     uint64_t half[17 * 2];                                              \
485     uint8_t * const halfH = ((uint8_t*)half);                           \
486     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
487                                                     stride, 17);        \
488     ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
489                                          stride, 17);                   \
490     ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
491                                                     stride, 16);        \
492 }                                                                       \
493                                                                         \
494 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src,   \
495                                           ptrdiff_t stride)             \
496 {                                                                       \
497     uint64_t half[17 * 2];                                              \
498     uint8_t * const halfH = ((uint8_t*)half);                           \
499     ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
500                                                     stride, 17);        \
501     ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
502                                                     stride, 16);        \
503 }
504
505 QPEL_OP(put_,        _,        mmxext)
506 QPEL_OP(avg_,        _,        mmxext)
507 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
508 #endif /* HAVE_YASM */
509
510 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX)                          \
511     do {                                                                     \
512     c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
513     c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
514     c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
515     c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
516     c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
517     c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
518     c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
519     c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
520     c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
521     c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
522     c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
523     c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
524     c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
525     c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
526     c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
527     c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
528     } while (0)
529
530 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
531                                      int cpu_flags)
532 {
533 #if HAVE_MMX_INLINE
534     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
535
536     c->put_pixels_clamped        = ff_put_pixels_clamped_mmx;
537     c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
538     c->add_pixels_clamped        = ff_add_pixels_clamped_mmx;
539
540     if (!high_bit_depth) {
541         c->clear_block  = ff_clear_block_mmx;
542         c->clear_blocks = ff_clear_blocks_mmx;
543         c->draw_edges   = ff_draw_edges_mmx;
544
545         switch (avctx->idct_algo) {
546         case FF_IDCT_AUTO:
547         case FF_IDCT_SIMPLEMMX:
548             c->idct_put              = ff_simple_idct_put_mmx;
549             c->idct_add              = ff_simple_idct_add_mmx;
550             c->idct                  = ff_simple_idct_mmx;
551             c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
552             break;
553         case FF_IDCT_XVIDMMX:
554             c->idct_put              = ff_idct_xvid_mmx_put;
555             c->idct_add              = ff_idct_xvid_mmx_add;
556             c->idct                  = ff_idct_xvid_mmx;
557             break;
558         }
559     }
560
561     c->gmc = ff_gmc_mmx;
562
563     c->add_bytes = ff_add_bytes_mmx;
564 #endif /* HAVE_MMX_INLINE */
565
566 #if HAVE_MMX_EXTERNAL
567     c->vector_clip_int32 = ff_vector_clip_int32_mmx;
568 #endif /* HAVE_MMX_EXTERNAL */
569 }
570
571 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
572                                         int cpu_flags)
573 {
574 #if HAVE_MMXEXT_INLINE
575     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
576
577     if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
578         c->idct_put = ff_idct_xvid_mmxext_put;
579         c->idct_add = ff_idct_xvid_mmxext_add;
580         c->idct     = ff_idct_xvid_mmxext;
581     }
582 #endif /* HAVE_MMXEXT_INLINE */
583
584 #if HAVE_MMXEXT_EXTERNAL
585     SET_QPEL_FUNCS(avg_qpel,        0, 16, mmxext, );
586     SET_QPEL_FUNCS(avg_qpel,        1,  8, mmxext, );
587
588     SET_QPEL_FUNCS(put_qpel,        0, 16, mmxext, );
589     SET_QPEL_FUNCS(put_qpel,        1,  8, mmxext, );
590     SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
591     SET_QPEL_FUNCS(put_no_rnd_qpel, 1,  8, mmxext, );
592
593     /* slower than cmov version on AMD */
594     if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
595         c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
596
597     c->scalarproduct_int16          = ff_scalarproduct_int16_mmxext;
598     c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
599
600     if (avctx->flags & CODEC_FLAG_BITEXACT) {
601         c->apply_window_int16 = ff_apply_window_int16_mmxext;
602     } else {
603         c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
604     }
605 #endif /* HAVE_MMXEXT_EXTERNAL */
606 }
607
608 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
609                                      int cpu_flags)
610 {
611 #if HAVE_SSE_INLINE
612     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
613
614     if (!high_bit_depth) {
615 #if FF_API_XVMC
616 FF_DISABLE_DEPRECATION_WARNINGS
617         if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
618             /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
619 FF_ENABLE_DEPRECATION_WARNINGS
620 #endif /* FF_API_XVMC */
621         c->clear_block  = ff_clear_block_sse;
622         c->clear_blocks = ff_clear_blocks_sse;
623 #if FF_API_XVMC
624         }
625 #endif /* FF_API_XVMC */
626     }
627
628     c->vector_clipf = ff_vector_clipf_sse;
629 #endif /* HAVE_SSE_INLINE */
630 }
631
632 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
633                                       int cpu_flags)
634 {
635 #if HAVE_SSE2_INLINE
636     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
637
638     if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX) {
639         c->idct_put              = ff_idct_xvid_sse2_put;
640         c->idct_add              = ff_idct_xvid_sse2_add;
641         c->idct                  = ff_idct_xvid_sse2;
642         c->idct_permutation_type = FF_SSE2_IDCT_PERM;
643     }
644 #endif /* HAVE_SSE2_INLINE */
645
646 #if HAVE_SSE2_EXTERNAL
647     c->scalarproduct_int16          = ff_scalarproduct_int16_sse2;
648     c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
649     if (cpu_flags & AV_CPU_FLAG_ATOM) {
650         c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
651     } else {
652         c->vector_clip_int32 = ff_vector_clip_int32_sse2;
653     }
654     if (avctx->flags & CODEC_FLAG_BITEXACT) {
655         c->apply_window_int16 = ff_apply_window_int16_sse2;
656     } else if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
657         c->apply_window_int16 = ff_apply_window_int16_round_sse2;
658     }
659     c->bswap_buf = ff_bswap32_buf_sse2;
660 #endif /* HAVE_SSE2_EXTERNAL */
661 }
662
663 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
664                                        int cpu_flags)
665 {
666 #if HAVE_SSSE3_EXTERNAL
667     c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
668     if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
669         c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
670
671     if (cpu_flags & AV_CPU_FLAG_ATOM)
672         c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
673     else
674         c->apply_window_int16 = ff_apply_window_int16_ssse3;
675     if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
676         c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
677     c->bswap_buf = ff_bswap32_buf_ssse3;
678 #endif /* HAVE_SSSE3_EXTERNAL */
679 }
680
681 static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
682                                       int cpu_flags)
683 {
684 #if HAVE_SSE4_EXTERNAL
685     c->vector_clip_int32 = ff_vector_clip_int32_sse4;
686 #endif /* HAVE_SSE4_EXTERNAL */
687 }
688
689 av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
690 {
691     int cpu_flags = av_get_cpu_flags();
692
693 #if HAVE_7REGS && HAVE_INLINE_ASM
694     if (cpu_flags & AV_CPU_FLAG_CMOV)
695         c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
696 #endif
697
698     if (X86_MMX(cpu_flags))
699         dsputil_init_mmx(c, avctx, cpu_flags);
700
701     if (X86_MMXEXT(cpu_flags))
702         dsputil_init_mmxext(c, avctx, cpu_flags);
703
704     if (X86_SSE(cpu_flags))
705         dsputil_init_sse(c, avctx, cpu_flags);
706
707     if (X86_SSE2(cpu_flags))
708         dsputil_init_sse2(c, avctx, cpu_flags);
709
710     if (EXTERNAL_SSSE3(cpu_flags))
711         dsputil_init_ssse3(c, avctx, cpu_flags);
712
713     if (EXTERNAL_SSE4(cpu_flags))
714         dsputil_init_sse4(c, avctx, cpu_flags);
715
716     if (CONFIG_ENCODERS)
717         ff_dsputilenc_init_mmx(c, avctx);
718 }