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/dsputil.h"
29 #include "libavcodec/simple_idct.h"
30 #include "libavcodec/version.h"
31 #include "dsputil_x86.h"
32 #include "idct_xvid.h"
34 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
35 int dstStride, int src1Stride, int h);
36 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
37 uint8_t *src2, int dstStride,
38 int src1Stride, int h);
39 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
40 int dstStride, int src1Stride, int h);
41 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
42 int dstStride, int src1Stride, int h);
43 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
44 int dstStride, int src1Stride, int h);
45 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
46 int dstStride, int src1Stride, int h);
47 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
48 int dstStride, int srcStride, int h);
49 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
50 int dstStride, int srcStride, int h);
51 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
52 int dstStride, int srcStride,
54 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
55 int dstStride, int srcStride, int h);
56 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
57 int dstStride, int srcStride, int h);
58 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
59 int dstStride, int srcStride,
61 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
62 int dstStride, int srcStride);
63 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
64 int dstStride, int srcStride);
65 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
66 int dstStride, int srcStride);
67 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
68 int dstStride, int srcStride);
69 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
70 int dstStride, int srcStride);
71 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
72 int dstStride, int srcStride);
73 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
74 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
76 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
78 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
80 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
83 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
86 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
90 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
91 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
93 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
94 const uint8_t *diff, int w,
95 int *left, int *left_top);
96 int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
98 int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
101 void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
102 int32_t min, int32_t max, unsigned int len);
103 void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
104 int32_t min, int32_t max, unsigned int len);
105 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
106 int32_t min, int32_t max, unsigned int len);
107 void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
108 int32_t min, int32_t max, unsigned int len);
112 PIXELS16(static, ff_avg, , , _mmxext)
113 PIXELS16(static, ff_put, , , _mmxext)
115 #define QPEL_OP(OPNAME, RND, MMX) \
116 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
119 ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
122 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
126 uint8_t * const half = (uint8_t*)temp; \
127 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
129 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
130 stride, stride, 8); \
133 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
136 ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
140 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
144 uint8_t * const half = (uint8_t*)temp; \
145 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
147 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
151 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
155 uint8_t * const half = (uint8_t*)temp; \
156 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
158 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
159 stride, stride, 8); \
162 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
165 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
169 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
173 uint8_t * const half = (uint8_t*)temp; \
174 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
176 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
180 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
183 uint64_t half[8 + 9]; \
184 uint8_t * const halfH = ((uint8_t*)half) + 64; \
185 uint8_t * const halfHV = ((uint8_t*)half); \
186 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
188 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
190 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
191 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
195 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
198 uint64_t half[8 + 9]; \
199 uint8_t * const halfH = ((uint8_t*)half) + 64; \
200 uint8_t * const halfHV = ((uint8_t*)half); \
201 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
203 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
205 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
206 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
210 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
213 uint64_t half[8 + 9]; \
214 uint8_t * const halfH = ((uint8_t*)half) + 64; \
215 uint8_t * const halfHV = ((uint8_t*)half); \
216 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
218 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
220 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
221 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
225 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
228 uint64_t half[8 + 9]; \
229 uint8_t * const halfH = ((uint8_t*)half) + 64; \
230 uint8_t * const halfHV = ((uint8_t*)half); \
231 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
233 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
235 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
236 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
240 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
243 uint64_t half[8 + 9]; \
244 uint8_t * const halfH = ((uint8_t*)half) + 64; \
245 uint8_t * const halfHV = ((uint8_t*)half); \
246 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
248 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
249 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
253 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
256 uint64_t half[8 + 9]; \
257 uint8_t * const halfH = ((uint8_t*)half) + 64; \
258 uint8_t * const halfHV = ((uint8_t*)half); \
259 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
261 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
262 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
266 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
269 uint64_t half[8 + 9]; \
270 uint8_t * const halfH = ((uint8_t*)half); \
271 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
273 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
275 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
279 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
282 uint64_t half[8 + 9]; \
283 uint8_t * const halfH = ((uint8_t*)half); \
284 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
286 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
288 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
292 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
296 uint8_t * const halfH = ((uint8_t*)half); \
297 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
299 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
303 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
306 ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
309 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
313 uint8_t * const half = (uint8_t*)temp; \
314 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
316 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
320 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
323 ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
324 stride, stride, 16);\
327 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
331 uint8_t * const half = (uint8_t*)temp; \
332 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
334 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
335 stride, stride, 16); \
338 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
342 uint8_t * const half = (uint8_t*)temp; \
343 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
345 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
349 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
352 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
356 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
360 uint8_t * const half = (uint8_t*)temp; \
361 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
363 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
364 stride, stride, 16); \
367 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
370 uint64_t half[16 * 2 + 17 * 2]; \
371 uint8_t * const halfH = ((uint8_t*)half) + 256; \
372 uint8_t * const halfHV = ((uint8_t*)half); \
373 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
375 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
377 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
379 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
383 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
386 uint64_t half[16 * 2 + 17 * 2]; \
387 uint8_t * const halfH = ((uint8_t*)half) + 256; \
388 uint8_t * const halfHV = ((uint8_t*)half); \
389 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
391 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
393 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
395 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
399 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
402 uint64_t half[16 * 2 + 17 * 2]; \
403 uint8_t * const halfH = ((uint8_t*)half) + 256; \
404 uint8_t * const halfHV = ((uint8_t*)half); \
405 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
407 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
409 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
411 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
415 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
418 uint64_t half[16 * 2 + 17 * 2]; \
419 uint8_t * const halfH = ((uint8_t*)half) + 256; \
420 uint8_t * const halfHV = ((uint8_t*)half); \
421 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
423 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
425 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
427 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
431 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
434 uint64_t half[16 * 2 + 17 * 2]; \
435 uint8_t * const halfH = ((uint8_t*)half) + 256; \
436 uint8_t * const halfHV = ((uint8_t*)half); \
437 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
439 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
441 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
445 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
448 uint64_t half[16 * 2 + 17 * 2]; \
449 uint8_t * const halfH = ((uint8_t*)half) + 256; \
450 uint8_t * const halfHV = ((uint8_t*)half); \
451 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
453 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
455 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
459 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
462 uint64_t half[17 * 2]; \
463 uint8_t * const halfH = ((uint8_t*)half); \
464 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
466 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
468 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
472 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
475 uint64_t half[17 * 2]; \
476 uint8_t * const halfH = ((uint8_t*)half); \
477 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
479 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
481 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
485 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
488 uint64_t half[17 * 2]; \
489 uint8_t * const halfH = ((uint8_t*)half); \
490 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
492 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
496 QPEL_OP(put_, _, mmxext)
497 QPEL_OP(avg_, _, mmxext)
498 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
499 #endif /* HAVE_YASM */
501 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
503 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
504 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
505 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
506 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
507 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
508 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
509 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
510 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
511 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
512 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
513 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
514 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
515 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
516 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
517 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
518 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
521 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
525 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
527 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
528 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
529 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
531 if (!high_bit_depth) {
532 c->clear_block = ff_clear_block_mmx;
533 c->clear_blocks = ff_clear_blocks_mmx;
534 c->draw_edges = ff_draw_edges_mmx;
537 #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
541 c->add_bytes = ff_add_bytes_mmx;
542 #endif /* HAVE_MMX_INLINE */
544 #if HAVE_MMX_EXTERNAL
545 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
546 #endif /* HAVE_MMX_EXTERNAL */
549 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
552 #if HAVE_MMXEXT_INLINE
553 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
555 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
556 c->idct_put = ff_idct_xvid_mmxext_put;
557 c->idct_add = ff_idct_xvid_mmxext_add;
558 c->idct = ff_idct_xvid_mmxext;
560 #endif /* HAVE_MMXEXT_INLINE */
562 #if HAVE_MMXEXT_EXTERNAL
563 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
564 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
566 SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
567 SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
568 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
569 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
571 /* slower than cmov version on AMD */
572 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
573 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
575 c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
576 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
577 #endif /* HAVE_MMXEXT_EXTERNAL */
580 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
584 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
586 c->vector_clipf = ff_vector_clipf_sse;
588 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
589 if (CONFIG_XVMC && avctx->hwaccel && avctx->hwaccel->decode_mb)
592 if (!high_bit_depth) {
593 c->clear_block = ff_clear_block_sse;
594 c->clear_blocks = ff_clear_blocks_sse;
596 #endif /* HAVE_SSE_INLINE */
599 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
602 #endif /* HAVE_YASM */
605 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
609 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
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 #endif /* HAVE_SSE2_EXTERNAL */
631 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
634 #if HAVE_SSSE3_EXTERNAL
635 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
636 if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
637 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
639 if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
640 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
641 c->bswap_buf = ff_bswap32_buf_ssse3;
642 #endif /* HAVE_SSSE3_EXTERNAL */
645 static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
648 #if HAVE_SSE4_EXTERNAL
649 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
650 #endif /* HAVE_SSE4_EXTERNAL */
653 av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
655 int cpu_flags = av_get_cpu_flags();
657 #if HAVE_7REGS && HAVE_INLINE_ASM
658 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
659 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
662 if (X86_MMX(cpu_flags)) {
664 const int idct_algo = avctx->idct_algo;
666 if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
667 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
668 c->idct_put = ff_simple_idct_put_mmx;
669 c->idct_add = ff_simple_idct_add_mmx;
670 c->idct = ff_simple_idct_mmx;
671 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
672 } else if (idct_algo == FF_IDCT_XVIDMMX) {
673 c->idct_put = ff_idct_xvid_mmx_put;
674 c->idct_add = ff_idct_xvid_mmx_add;
675 c->idct = ff_idct_xvid_mmx;
678 #endif /* HAVE_INLINE_ASM */
680 dsputil_init_mmx(c, avctx, cpu_flags);
683 if (X86_MMXEXT(cpu_flags))
684 dsputil_init_mmxext(c, avctx, cpu_flags);
686 if (X86_SSE(cpu_flags))
687 dsputil_init_sse(c, avctx, cpu_flags);
689 if (X86_SSE2(cpu_flags))
690 dsputil_init_sse2(c, avctx, cpu_flags);
692 if (EXTERNAL_SSSE3(cpu_flags))
693 dsputil_init_ssse3(c, avctx, cpu_flags);
695 if (EXTERNAL_SSE4(cpu_flags))
696 dsputil_init_sse4(c, avctx, cpu_flags);
699 ff_dsputilenc_init_mmx(c, avctx);