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 "dsputil_x86.h"
31 #include "idct_xvid.h"
33 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
34 int dstStride, int src1Stride, int h);
35 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
36 uint8_t *src2, int dstStride,
37 int src1Stride, int h);
38 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
39 int dstStride, int src1Stride, int h);
40 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
41 int dstStride, int src1Stride, int h);
42 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
43 int dstStride, int src1Stride, int h);
44 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
45 int dstStride, int src1Stride, int h);
46 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
47 int dstStride, int srcStride, int h);
48 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
49 int dstStride, int srcStride, int h);
50 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
51 int dstStride, int srcStride,
53 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
54 int dstStride, int srcStride, int h);
55 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
56 int dstStride, int srcStride, int h);
57 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
58 int dstStride, int srcStride,
60 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
61 int dstStride, int srcStride);
62 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
63 int dstStride, int srcStride);
64 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
65 int dstStride, int srcStride);
66 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
67 int dstStride, int srcStride);
68 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
69 int dstStride, int srcStride);
70 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
71 int dstStride, int srcStride);
72 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
73 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
75 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
77 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
79 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
82 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
85 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
89 void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
90 const int16_t *window, unsigned int len);
91 void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
92 const int16_t *window, unsigned int len);
93 void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
94 const int16_t *window, unsigned int len);
95 void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
96 const int16_t *window, unsigned int len);
97 void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
98 const int16_t *window, unsigned int len);
99 void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
100 const int16_t *window, unsigned int len);
102 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
103 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
105 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
106 const uint8_t *diff, int w,
107 int *left, int *left_top);
108 int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
110 int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
113 void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
114 int32_t min, int32_t max, unsigned int len);
115 void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
116 int32_t min, int32_t max, unsigned int len);
117 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
118 int32_t min, int32_t max, unsigned int len);
119 void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
120 int32_t min, int32_t max, unsigned int len);
124 PIXELS16(static, ff_avg, , , _mmxext)
125 PIXELS16(static, ff_put, , , _mmxext)
127 #define QPEL_OP(OPNAME, RND, MMX) \
128 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
131 ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
134 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
138 uint8_t * const half = (uint8_t*)temp; \
139 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
141 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
142 stride, stride, 8); \
145 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
148 ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
152 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
156 uint8_t * const half = (uint8_t*)temp; \
157 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
159 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
163 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
167 uint8_t * const half = (uint8_t*)temp; \
168 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
170 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
171 stride, stride, 8); \
174 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
177 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
181 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
185 uint8_t * const half = (uint8_t*)temp; \
186 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
188 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
192 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
195 uint64_t half[8 + 9]; \
196 uint8_t * const halfH = ((uint8_t*)half) + 64; \
197 uint8_t * const halfHV = ((uint8_t*)half); \
198 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
200 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
202 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
203 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
207 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
210 uint64_t half[8 + 9]; \
211 uint8_t * const halfH = ((uint8_t*)half) + 64; \
212 uint8_t * const halfHV = ((uint8_t*)half); \
213 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
215 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
217 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
218 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
222 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
225 uint64_t half[8 + 9]; \
226 uint8_t * const halfH = ((uint8_t*)half) + 64; \
227 uint8_t * const halfHV = ((uint8_t*)half); \
228 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
230 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
232 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
233 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
237 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
240 uint64_t half[8 + 9]; \
241 uint8_t * const halfH = ((uint8_t*)half) + 64; \
242 uint8_t * const halfHV = ((uint8_t*)half); \
243 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
245 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
247 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
248 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
252 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
255 uint64_t half[8 + 9]; \
256 uint8_t * const halfH = ((uint8_t*)half) + 64; \
257 uint8_t * const halfHV = ((uint8_t*)half); \
258 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
260 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
261 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
265 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
268 uint64_t half[8 + 9]; \
269 uint8_t * const halfH = ((uint8_t*)half) + 64; \
270 uint8_t * const halfHV = ((uint8_t*)half); \
271 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
273 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
274 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
278 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
281 uint64_t half[8 + 9]; \
282 uint8_t * const halfH = ((uint8_t*)half); \
283 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
285 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
287 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
291 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
294 uint64_t half[8 + 9]; \
295 uint8_t * const halfH = ((uint8_t*)half); \
296 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
298 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
300 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
304 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
308 uint8_t * const halfH = ((uint8_t*)half); \
309 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
311 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
315 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
318 ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
321 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
325 uint8_t * const half = (uint8_t*)temp; \
326 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
328 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
332 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
335 ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
336 stride, stride, 16);\
339 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
343 uint8_t * const half = (uint8_t*)temp; \
344 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
346 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
347 stride, stride, 16); \
350 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
354 uint8_t * const half = (uint8_t*)temp; \
355 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
357 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
361 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
364 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
368 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
372 uint8_t * const half = (uint8_t*)temp; \
373 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
375 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
376 stride, stride, 16); \
379 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
382 uint64_t half[16 * 2 + 17 * 2]; \
383 uint8_t * const halfH = ((uint8_t*)half) + 256; \
384 uint8_t * const halfHV = ((uint8_t*)half); \
385 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
387 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
389 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
391 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
395 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
398 uint64_t half[16 * 2 + 17 * 2]; \
399 uint8_t * const halfH = ((uint8_t*)half) + 256; \
400 uint8_t * const halfHV = ((uint8_t*)half); \
401 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
403 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
405 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
407 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
411 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
414 uint64_t half[16 * 2 + 17 * 2]; \
415 uint8_t * const halfH = ((uint8_t*)half) + 256; \
416 uint8_t * const halfHV = ((uint8_t*)half); \
417 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
419 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
421 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
423 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
427 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
430 uint64_t half[16 * 2 + 17 * 2]; \
431 uint8_t * const halfH = ((uint8_t*)half) + 256; \
432 uint8_t * const halfHV = ((uint8_t*)half); \
433 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
435 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
437 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
439 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
443 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
446 uint64_t half[16 * 2 + 17 * 2]; \
447 uint8_t * const halfH = ((uint8_t*)half) + 256; \
448 uint8_t * const halfHV = ((uint8_t*)half); \
449 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
451 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
453 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
457 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
460 uint64_t half[16 * 2 + 17 * 2]; \
461 uint8_t * const halfH = ((uint8_t*)half) + 256; \
462 uint8_t * const halfHV = ((uint8_t*)half); \
463 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
465 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
467 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
471 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
474 uint64_t half[17 * 2]; \
475 uint8_t * const halfH = ((uint8_t*)half); \
476 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
478 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
480 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
484 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
487 uint64_t half[17 * 2]; \
488 uint8_t * const halfH = ((uint8_t*)half); \
489 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
491 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
493 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
497 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
500 uint64_t half[17 * 2]; \
501 uint8_t * const halfH = ((uint8_t*)half); \
502 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
504 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
508 QPEL_OP(put_, _, mmxext)
509 QPEL_OP(avg_, _, mmxext)
510 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
511 #endif /* HAVE_YASM */
513 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
515 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
516 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
517 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
518 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
519 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
520 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
521 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
522 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
523 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
524 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
525 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
526 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
527 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
528 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
529 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
530 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
533 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
537 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
539 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
540 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
541 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
543 if (!high_bit_depth) {
544 c->clear_block = ff_clear_block_mmx;
545 c->clear_blocks = ff_clear_blocks_mmx;
546 c->draw_edges = ff_draw_edges_mmx;
549 #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
553 c->add_bytes = ff_add_bytes_mmx;
554 #endif /* HAVE_MMX_INLINE */
556 #if HAVE_MMX_EXTERNAL
557 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
558 #endif /* HAVE_MMX_EXTERNAL */
561 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
564 #if HAVE_MMXEXT_INLINE
565 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
567 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
568 c->idct_put = ff_idct_xvid_mmxext_put;
569 c->idct_add = ff_idct_xvid_mmxext_add;
570 c->idct = ff_idct_xvid_mmxext;
572 #endif /* HAVE_MMXEXT_INLINE */
574 #if HAVE_MMXEXT_EXTERNAL
575 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
576 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
578 SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
579 SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
580 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
581 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
583 /* slower than cmov version on AMD */
584 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
585 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
587 c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
588 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
590 if (avctx->flags & CODEC_FLAG_BITEXACT) {
591 c->apply_window_int16 = ff_apply_window_int16_mmxext;
593 c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
595 #endif /* HAVE_MMXEXT_EXTERNAL */
598 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
602 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
604 if (!high_bit_depth) {
606 FF_DISABLE_DEPRECATION_WARNINGS
607 if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
608 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
609 FF_ENABLE_DEPRECATION_WARNINGS
610 #endif /* FF_API_XVMC */
611 c->clear_block = ff_clear_block_sse;
612 c->clear_blocks = ff_clear_blocks_sse;
615 #endif /* FF_API_XVMC */
618 c->vector_clipf = ff_vector_clipf_sse;
619 #endif /* HAVE_SSE_INLINE */
622 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
625 #endif /* HAVE_YASM */
628 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
632 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
634 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
635 c->idct_put = ff_idct_xvid_sse2_put;
636 c->idct_add = ff_idct_xvid_sse2_add;
637 c->idct = ff_idct_xvid_sse2;
638 c->idct_permutation_type = FF_SSE2_IDCT_PERM;
640 #endif /* HAVE_SSE2_INLINE */
642 #if HAVE_SSE2_EXTERNAL
643 c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
644 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
645 if (cpu_flags & AV_CPU_FLAG_ATOM) {
646 c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
648 c->vector_clip_int32 = ff_vector_clip_int32_sse2;
650 if (avctx->flags & CODEC_FLAG_BITEXACT) {
651 c->apply_window_int16 = ff_apply_window_int16_sse2;
652 } else if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
653 c->apply_window_int16 = ff_apply_window_int16_round_sse2;
655 c->bswap_buf = ff_bswap32_buf_sse2;
656 #endif /* HAVE_SSE2_EXTERNAL */
659 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
662 #if HAVE_SSSE3_EXTERNAL
663 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
664 if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
665 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
667 if (cpu_flags & AV_CPU_FLAG_ATOM)
668 c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
670 c->apply_window_int16 = ff_apply_window_int16_ssse3;
671 if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
672 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
673 c->bswap_buf = ff_bswap32_buf_ssse3;
674 #endif /* HAVE_SSSE3_EXTERNAL */
677 static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
680 #if HAVE_SSE4_EXTERNAL
681 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
682 #endif /* HAVE_SSE4_EXTERNAL */
685 av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
687 int cpu_flags = av_get_cpu_flags();
689 #if HAVE_7REGS && HAVE_INLINE_ASM
690 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
691 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
694 if (X86_MMX(cpu_flags)) {
696 const int idct_algo = avctx->idct_algo;
698 if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
699 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
700 c->idct_put = ff_simple_idct_put_mmx;
701 c->idct_add = ff_simple_idct_add_mmx;
702 c->idct = ff_simple_idct_mmx;
703 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
704 } else if (idct_algo == FF_IDCT_XVIDMMX) {
705 c->idct_put = ff_idct_xvid_mmx_put;
706 c->idct_add = ff_idct_xvid_mmx_add;
707 c->idct = ff_idct_xvid_mmx;
710 #endif /* HAVE_INLINE_ASM */
712 dsputil_init_mmx(c, avctx, cpu_flags);
715 if (X86_MMXEXT(cpu_flags))
716 dsputil_init_mmxext(c, avctx, cpu_flags);
718 if (X86_SSE(cpu_flags))
719 dsputil_init_sse(c, avctx, cpu_flags);
721 if (X86_SSE2(cpu_flags))
722 dsputil_init_sse2(c, avctx, cpu_flags);
724 if (EXTERNAL_SSSE3(cpu_flags))
725 dsputil_init_ssse3(c, avctx, cpu_flags);
727 if (EXTERNAL_SSE4(cpu_flags))
728 dsputil_init_sse4(c, avctx, cpu_flags);
731 ff_dsputilenc_init_mmx(c, avctx);