2 * Copyright (c) 2000, 2001 Fabrice Bellard
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/x86/asm.h"
27 #include "libavutil/x86/cpu.h"
28 #include "libavcodec/avcodec.h"
29 #include "libavcodec/dsputil.h"
30 #include "libavcodec/pixels.h"
31 #include "libavcodec/simple_idct.h"
32 #include "libavcodec/version.h"
33 #include "dsputil_x86.h"
35 #include "idct_xvid.h"
37 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
38 int dstStride, int src1Stride, int h);
39 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
40 uint8_t *src2, int dstStride,
41 int src1Stride, int h);
42 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
43 int dstStride, int src1Stride, int h);
44 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
45 int dstStride, int src1Stride, int h);
46 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
47 int dstStride, int src1Stride, int h);
48 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
49 int dstStride, int src1Stride, int h);
50 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
51 int dstStride, int srcStride, int h);
52 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
53 int dstStride, int srcStride, int h);
54 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
55 int dstStride, int srcStride,
57 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
58 int dstStride, int srcStride, int h);
59 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
60 int dstStride, int srcStride, int h);
61 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
62 int dstStride, int srcStride,
64 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
65 int dstStride, int srcStride);
66 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
67 int dstStride, int srcStride);
68 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
69 int dstStride, int srcStride);
70 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
71 int dstStride, int srcStride);
72 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
73 int dstStride, int srcStride);
74 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
75 int dstStride, int srcStride);
76 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmx
77 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmx
79 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
81 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
83 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
86 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
89 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
93 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
94 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
96 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
97 const uint8_t *diff, int w,
98 int *left, int *left_top);
99 int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
101 int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
104 void ff_vector_clip_int32_mmx(int32_t *dst, const int32_t *src,
105 int32_t min, int32_t max, unsigned int len);
106 void ff_vector_clip_int32_sse2(int32_t *dst, const int32_t *src,
107 int32_t min, int32_t max, unsigned int len);
108 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
109 int32_t min, int32_t max, unsigned int len);
110 void ff_vector_clip_int32_sse4(int32_t *dst, const int32_t *src,
111 int32_t min, int32_t max, unsigned int len);
115 #define ff_put_pixels16_mmxext ff_put_pixels16_mmx
116 #define ff_put_pixels8_mmxext ff_put_pixels8_mmx
118 void ff_avg_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
119 ptrdiff_t line_size, int h);
121 #define QPEL_OP(OPNAME, RND, MMX) \
122 static void OPNAME ## qpel8_mc00_ ## MMX(uint8_t *dst, uint8_t *src, \
125 ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
128 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
132 uint8_t *const half = (uint8_t *) temp; \
133 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
135 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
136 stride, stride, 8); \
139 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
142 ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
146 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
150 uint8_t *const half = (uint8_t *) temp; \
151 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
153 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
157 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
161 uint8_t *const half = (uint8_t *) temp; \
162 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
164 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
165 stride, stride, 8); \
168 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
171 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
175 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
179 uint8_t *const half = (uint8_t *) temp; \
180 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
182 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
186 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
189 uint64_t half[8 + 9]; \
190 uint8_t *const halfH = (uint8_t *) half + 64; \
191 uint8_t *const halfHV = (uint8_t *) half; \
192 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
194 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
196 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
197 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
201 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
204 uint64_t half[8 + 9]; \
205 uint8_t *const halfH = (uint8_t *) half + 64; \
206 uint8_t *const halfHV = (uint8_t *) half; \
207 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
209 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
211 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
212 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
216 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
219 uint64_t half[8 + 9]; \
220 uint8_t *const halfH = (uint8_t *) half + 64; \
221 uint8_t *const halfHV = (uint8_t *) half; \
222 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
224 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
226 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
227 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
231 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
234 uint64_t half[8 + 9]; \
235 uint8_t *const halfH = (uint8_t *) half + 64; \
236 uint8_t *const halfHV = (uint8_t *) half; \
237 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
239 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
241 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
242 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
246 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
249 uint64_t half[8 + 9]; \
250 uint8_t *const halfH = (uint8_t *) half + 64; \
251 uint8_t *const halfHV = (uint8_t *) half; \
252 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
254 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
255 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
259 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
262 uint64_t half[8 + 9]; \
263 uint8_t *const halfH = (uint8_t *) half + 64; \
264 uint8_t *const halfHV = (uint8_t *) half; \
265 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
267 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
268 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
272 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
275 uint64_t half[8 + 9]; \
276 uint8_t *const halfH = (uint8_t *) half; \
277 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
279 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
281 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
285 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
288 uint64_t half[8 + 9]; \
289 uint8_t *const halfH = (uint8_t *) half; \
290 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
292 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
294 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
298 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
302 uint8_t *const halfH = (uint8_t *) half; \
303 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
305 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
309 static void OPNAME ## qpel16_mc00_ ## MMX(uint8_t *dst, uint8_t *src, \
312 ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
315 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
319 uint8_t *const half = (uint8_t *) temp; \
320 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
322 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
326 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
329 ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
330 stride, stride, 16);\
333 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
337 uint8_t *const half = (uint8_t*) temp; \
338 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
340 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
341 stride, stride, 16); \
344 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
348 uint8_t *const half = (uint8_t *) temp; \
349 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
351 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
355 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
358 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
362 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
366 uint8_t *const half = (uint8_t *) temp; \
367 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
369 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
370 stride, stride, 16); \
373 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
376 uint64_t half[16 * 2 + 17 * 2]; \
377 uint8_t *const halfH = (uint8_t *) half + 256; \
378 uint8_t *const halfHV = (uint8_t *) half; \
379 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
381 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
383 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
385 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
389 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
392 uint64_t half[16 * 2 + 17 * 2]; \
393 uint8_t *const halfH = (uint8_t *) half + 256; \
394 uint8_t *const halfHV = (uint8_t *) half; \
395 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
397 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
399 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
401 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
405 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
408 uint64_t half[16 * 2 + 17 * 2]; \
409 uint8_t *const halfH = (uint8_t *) half + 256; \
410 uint8_t *const halfHV = (uint8_t *) half; \
411 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
413 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
415 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
417 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
421 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
424 uint64_t half[16 * 2 + 17 * 2]; \
425 uint8_t *const halfH = (uint8_t *) half + 256; \
426 uint8_t *const halfHV = (uint8_t *) half; \
427 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
429 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
431 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
433 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
437 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
440 uint64_t half[16 * 2 + 17 * 2]; \
441 uint8_t *const halfH = (uint8_t *) half + 256; \
442 uint8_t *const halfHV = (uint8_t *) half; \
443 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
445 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
447 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
451 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
454 uint64_t half[16 * 2 + 17 * 2]; \
455 uint8_t *const halfH = (uint8_t *) half + 256; \
456 uint8_t *const halfHV = (uint8_t *) half; \
457 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
459 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
461 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
465 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
468 uint64_t half[17 * 2]; \
469 uint8_t *const halfH = (uint8_t *) half; \
470 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
472 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
474 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
478 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
481 uint64_t half[17 * 2]; \
482 uint8_t *const halfH = (uint8_t *) half; \
483 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
485 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
487 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
491 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
494 uint64_t half[17 * 2]; \
495 uint8_t *const halfH = (uint8_t *) half; \
496 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
498 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
502 QPEL_OP(put_, _, mmxext)
503 QPEL_OP(avg_, _, mmxext)
504 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
506 #endif /* HAVE_YASM */
508 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
510 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
511 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
512 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
513 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
514 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
515 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
516 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
517 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
518 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
519 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
520 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
521 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
522 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
523 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
524 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
525 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
528 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
529 int cpu_flags, unsigned high_bit_depth)
532 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
533 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
535 if (!high_bit_depth) {
536 c->draw_edges = ff_draw_edges_mmx;
539 #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
543 c->add_bytes = ff_add_bytes_mmx;
544 #endif /* HAVE_MMX_INLINE */
546 #if HAVE_MMX_EXTERNAL
547 if (!high_bit_depth) {
548 c->clear_block = ff_clear_block_mmx;
549 c->clear_blocks = ff_clear_blocks_mmx;
551 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
552 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
553 #endif /* HAVE_MMX_EXTERNAL */
556 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
557 int cpu_flags, unsigned high_bit_depth)
559 #if HAVE_MMXEXT_INLINE
560 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
561 c->idct_put = ff_idct_xvid_mmxext_put;
562 c->idct_add = ff_idct_xvid_mmxext_add;
563 c->idct = ff_idct_xvid_mmxext;
565 #endif /* HAVE_MMXEXT_INLINE */
567 #if HAVE_MMXEXT_EXTERNAL
568 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
569 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
571 SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
572 SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
573 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
574 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
576 /* slower than cmov version on AMD */
577 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
578 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
580 c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
581 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
582 #endif /* HAVE_MMXEXT_EXTERNAL */
585 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
586 int cpu_flags, unsigned high_bit_depth)
589 #if HAVE_SSE_EXTERNAL
590 c->vector_clipf = ff_vector_clipf_sse;
592 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
593 if (CONFIG_XVMC && avctx->hwaccel && avctx->hwaccel->decode_mb)
596 if (!high_bit_depth) {
597 c->clear_block = ff_clear_block_sse;
598 c->clear_blocks = ff_clear_blocks_sse;
601 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
604 #endif /* HAVE_YASM */
607 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
608 int cpu_flags, unsigned high_bit_depth)
611 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
612 c->idct_put = ff_idct_xvid_sse2_put;
613 c->idct_add = ff_idct_xvid_sse2_add;
614 c->idct = ff_idct_xvid_sse2;
615 c->idct_permutation_type = FF_SSE2_IDCT_PERM;
617 #endif /* HAVE_SSE2_INLINE */
619 #if HAVE_SSE2_EXTERNAL
620 c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
621 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
622 if (cpu_flags & AV_CPU_FLAG_ATOM) {
623 c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
625 c->vector_clip_int32 = ff_vector_clip_int32_sse2;
627 c->bswap_buf = ff_bswap32_buf_sse2;
628 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_sse2;
629 #endif /* HAVE_SSE2_EXTERNAL */
632 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
633 int cpu_flags, unsigned high_bit_depth)
635 #if HAVE_SSSE3_EXTERNAL
636 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
637 if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
638 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
640 if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
641 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
642 c->bswap_buf = ff_bswap32_buf_ssse3;
643 #endif /* HAVE_SSSE3_EXTERNAL */
646 static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
647 int cpu_flags, unsigned high_bit_depth)
649 #if HAVE_SSE4_EXTERNAL
650 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
651 #endif /* HAVE_SSE4_EXTERNAL */
654 av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
655 unsigned high_bit_depth)
657 int cpu_flags = av_get_cpu_flags();
659 #if HAVE_7REGS && HAVE_INLINE_ASM
660 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
661 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
664 if (X86_MMX(cpu_flags)) {
666 const int idct_algo = avctx->idct_algo;
668 if (avctx->lowres == 0 && !high_bit_depth) {
669 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
670 c->idct_put = ff_simple_idct_put_mmx;
671 c->idct_add = ff_simple_idct_add_mmx;
672 c->idct = ff_simple_idct_mmx;
673 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
674 } else if (idct_algo == FF_IDCT_XVIDMMX) {
675 c->idct_put = ff_idct_xvid_mmx_put;
676 c->idct_add = ff_idct_xvid_mmx_add;
677 c->idct = ff_idct_xvid_mmx;
680 #endif /* HAVE_INLINE_ASM */
682 dsputil_init_mmx(c, avctx, cpu_flags, high_bit_depth);
685 if (X86_MMXEXT(cpu_flags))
686 dsputil_init_mmxext(c, avctx, cpu_flags, high_bit_depth);
688 if (X86_SSE(cpu_flags))
689 dsputil_init_sse(c, avctx, cpu_flags, high_bit_depth);
691 if (X86_SSE2(cpu_flags))
692 dsputil_init_sse2(c, avctx, cpu_flags, high_bit_depth);
694 if (EXTERNAL_SSSE3(cpu_flags))
695 dsputil_init_ssse3(c, avctx, cpu_flags, high_bit_depth);
697 if (EXTERNAL_SSE4(cpu_flags))
698 dsputil_init_sse4(c, avctx, cpu_flags, high_bit_depth);
701 ff_dsputilenc_init_mmx(c, avctx, high_bit_depth);