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/x86/asm.h"
26 #include "libavutil/x86/cpu.h"
27 #include "libavcodec/dsputil.h"
28 #include "libavcodec/simple_idct.h"
29 #include "dsputil_x86.h"
30 #include "idct_xvid.h"
32 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
33 int dstStride, int src1Stride, int h);
34 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
35 uint8_t *src2, int dstStride,
36 int src1Stride, int h);
37 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
38 int dstStride, int src1Stride, int h);
39 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
40 int dstStride, int src1Stride, int h);
41 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
42 int dstStride, int src1Stride, int h);
43 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
44 int dstStride, int src1Stride, int h);
45 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
46 int dstStride, int srcStride, int h);
47 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
48 int dstStride, int srcStride, int h);
49 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
50 int dstStride, int srcStride,
52 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
53 int dstStride, int srcStride, int h);
54 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
55 int dstStride, int srcStride, int h);
56 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
57 int dstStride, int srcStride,
59 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
60 int dstStride, int srcStride);
61 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
62 int dstStride, int srcStride);
63 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
64 int dstStride, int srcStride);
65 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
66 int dstStride, int srcStride);
67 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
68 int dstStride, int srcStride);
69 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
70 int dstStride, int srcStride);
71 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
72 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
74 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
76 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
78 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
81 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
84 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
88 void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
89 const int16_t *window, unsigned int len);
90 void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
91 const int16_t *window, unsigned int len);
92 void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
93 const int16_t *window, unsigned int len);
94 void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
95 const int16_t *window, unsigned int len);
96 void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
97 const int16_t *window, unsigned int len);
98 void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
99 const int16_t *window, unsigned int len);
101 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
102 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
104 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
105 const uint8_t *diff, int w,
106 int *left, int *left_top);
107 int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
109 int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
112 void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
113 int32_t min, int32_t max, unsigned int len);
114 void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
115 int32_t min, int32_t max, unsigned int len);
116 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
117 int32_t min, int32_t max, unsigned int len);
118 void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
119 int32_t min, int32_t max, unsigned int len);
123 PIXELS16(static, ff_avg, , , _mmxext)
124 PIXELS16(static, ff_put, , , _mmxext)
126 #define QPEL_OP(OPNAME, RND, MMX) \
127 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
130 ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
133 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
137 uint8_t * const half = (uint8_t*)temp; \
138 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
140 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
141 stride, stride, 8); \
144 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
147 ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
151 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
155 uint8_t * const half = (uint8_t*)temp; \
156 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
158 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
162 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
166 uint8_t * const half = (uint8_t*)temp; \
167 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
169 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
170 stride, stride, 8); \
173 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
176 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
180 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
184 uint8_t * const half = (uint8_t*)temp; \
185 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
187 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
191 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
194 uint64_t half[8 + 9]; \
195 uint8_t * const halfH = ((uint8_t*)half) + 64; \
196 uint8_t * const halfHV = ((uint8_t*)half); \
197 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
199 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
201 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
202 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
206 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
209 uint64_t half[8 + 9]; \
210 uint8_t * const halfH = ((uint8_t*)half) + 64; \
211 uint8_t * const halfHV = ((uint8_t*)half); \
212 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
214 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
216 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
217 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
221 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
224 uint64_t half[8 + 9]; \
225 uint8_t * const halfH = ((uint8_t*)half) + 64; \
226 uint8_t * const halfHV = ((uint8_t*)half); \
227 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
229 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
231 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
232 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
236 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
239 uint64_t half[8 + 9]; \
240 uint8_t * const halfH = ((uint8_t*)half) + 64; \
241 uint8_t * const halfHV = ((uint8_t*)half); \
242 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
244 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
246 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
247 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
251 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
254 uint64_t half[8 + 9]; \
255 uint8_t * const halfH = ((uint8_t*)half) + 64; \
256 uint8_t * const halfHV = ((uint8_t*)half); \
257 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
259 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
260 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
264 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
267 uint64_t half[8 + 9]; \
268 uint8_t * const halfH = ((uint8_t*)half) + 64; \
269 uint8_t * const halfHV = ((uint8_t*)half); \
270 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
272 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
273 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
277 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
280 uint64_t half[8 + 9]; \
281 uint8_t * const halfH = ((uint8_t*)half); \
282 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
284 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
286 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
290 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
293 uint64_t half[8 + 9]; \
294 uint8_t * const halfH = ((uint8_t*)half); \
295 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
297 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
299 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
303 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
307 uint8_t * const halfH = ((uint8_t*)half); \
308 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
310 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
314 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
317 ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
320 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
324 uint8_t * const half = (uint8_t*)temp; \
325 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
327 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
331 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
334 ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
335 stride, stride, 16);\
338 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
342 uint8_t * const half = (uint8_t*)temp; \
343 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
345 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
346 stride, stride, 16); \
349 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
353 uint8_t * const half = (uint8_t*)temp; \
354 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
356 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
360 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
363 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
367 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
371 uint8_t * const half = (uint8_t*)temp; \
372 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
374 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
375 stride, stride, 16); \
378 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
381 uint64_t half[16 * 2 + 17 * 2]; \
382 uint8_t * const halfH = ((uint8_t*)half) + 256; \
383 uint8_t * const halfHV = ((uint8_t*)half); \
384 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
386 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
388 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
390 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
394 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
397 uint64_t half[16 * 2 + 17 * 2]; \
398 uint8_t * const halfH = ((uint8_t*)half) + 256; \
399 uint8_t * const halfHV = ((uint8_t*)half); \
400 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
402 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
404 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
406 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
410 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
413 uint64_t half[16 * 2 + 17 * 2]; \
414 uint8_t * const halfH = ((uint8_t*)half) + 256; \
415 uint8_t * const halfHV = ((uint8_t*)half); \
416 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
418 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
420 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
422 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
426 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
429 uint64_t half[16 * 2 + 17 * 2]; \
430 uint8_t * const halfH = ((uint8_t*)half) + 256; \
431 uint8_t * const halfHV = ((uint8_t*)half); \
432 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
434 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
436 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
438 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
442 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
445 uint64_t half[16 * 2 + 17 * 2]; \
446 uint8_t * const halfH = ((uint8_t*)half) + 256; \
447 uint8_t * const halfHV = ((uint8_t*)half); \
448 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
450 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
452 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
456 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
459 uint64_t half[16 * 2 + 17 * 2]; \
460 uint8_t * const halfH = ((uint8_t*)half) + 256; \
461 uint8_t * const halfHV = ((uint8_t*)half); \
462 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
464 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
466 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
470 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
473 uint64_t half[17 * 2]; \
474 uint8_t * const halfH = ((uint8_t*)half); \
475 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
477 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
479 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
483 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
486 uint64_t half[17 * 2]; \
487 uint8_t * const halfH = ((uint8_t*)half); \
488 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
490 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
492 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
496 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
499 uint64_t half[17 * 2]; \
500 uint8_t * const halfH = ((uint8_t*)half); \
501 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
503 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
507 QPEL_OP(put_, _, mmxext)
508 QPEL_OP(avg_, _, mmxext)
509 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
510 #endif /* HAVE_YASM */
512 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
514 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
515 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
516 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
517 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
518 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
519 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
520 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
521 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
522 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
523 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
524 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
525 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
526 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
527 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
528 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
529 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
532 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
536 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
538 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
539 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
540 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
542 if (!high_bit_depth) {
543 c->clear_block = ff_clear_block_mmx;
544 c->clear_blocks = ff_clear_blocks_mmx;
545 c->draw_edges = ff_draw_edges_mmx;
548 #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
552 c->add_bytes = ff_add_bytes_mmx;
553 #endif /* HAVE_MMX_INLINE */
555 #if HAVE_MMX_EXTERNAL
556 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
557 #endif /* HAVE_MMX_EXTERNAL */
560 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
563 #if HAVE_MMXEXT_INLINE
564 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
566 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
567 c->idct_put = ff_idct_xvid_mmxext_put;
568 c->idct_add = ff_idct_xvid_mmxext_add;
569 c->idct = ff_idct_xvid_mmxext;
571 #endif /* HAVE_MMXEXT_INLINE */
573 #if HAVE_MMXEXT_EXTERNAL
574 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
575 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
577 SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
578 SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
579 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
580 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
582 /* slower than cmov version on AMD */
583 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
584 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
586 c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
587 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
589 if (avctx->flags & CODEC_FLAG_BITEXACT) {
590 c->apply_window_int16 = ff_apply_window_int16_mmxext;
592 c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
594 #endif /* HAVE_MMXEXT_EXTERNAL */
597 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
601 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
603 if (!high_bit_depth) {
605 if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
606 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
607 #endif /* FF_API_XVMC */
608 c->clear_block = ff_clear_block_sse;
609 c->clear_blocks = ff_clear_blocks_sse;
612 #endif /* FF_API_XVMC */
615 c->vector_clipf = ff_vector_clipf_sse;
616 #endif /* HAVE_SSE_INLINE */
619 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
622 #endif /* HAVE_YASM */
625 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
629 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
631 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
632 c->idct_put = ff_idct_xvid_sse2_put;
633 c->idct_add = ff_idct_xvid_sse2_add;
634 c->idct = ff_idct_xvid_sse2;
635 c->idct_permutation_type = FF_SSE2_IDCT_PERM;
637 #endif /* HAVE_SSE2_INLINE */
639 #if HAVE_SSE2_EXTERNAL
640 c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
641 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
642 if (cpu_flags & AV_CPU_FLAG_ATOM) {
643 c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
645 c->vector_clip_int32 = ff_vector_clip_int32_sse2;
647 if (avctx->flags & CODEC_FLAG_BITEXACT) {
648 c->apply_window_int16 = ff_apply_window_int16_sse2;
649 } else if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
650 c->apply_window_int16 = ff_apply_window_int16_round_sse2;
652 c->bswap_buf = ff_bswap32_buf_sse2;
653 #endif /* HAVE_SSE2_EXTERNAL */
656 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
659 #if HAVE_SSSE3_EXTERNAL
660 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
661 if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
662 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
664 if (cpu_flags & AV_CPU_FLAG_ATOM)
665 c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
667 c->apply_window_int16 = ff_apply_window_int16_ssse3;
668 if (!(cpu_flags & (AV_CPU_FLAG_SSE42 | AV_CPU_FLAG_3DNOW))) // cachesplit
669 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
670 c->bswap_buf = ff_bswap32_buf_ssse3;
671 #endif /* HAVE_SSSE3_EXTERNAL */
674 static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
677 #if HAVE_SSE4_EXTERNAL
678 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
679 #endif /* HAVE_SSE4_EXTERNAL */
682 av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx)
684 int cpu_flags = av_get_cpu_flags();
686 #if HAVE_7REGS && HAVE_INLINE_ASM
687 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
688 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
691 if (X86_MMX(cpu_flags)) {
693 const int idct_algo = avctx->idct_algo;
695 if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
696 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
697 c->idct_put = ff_simple_idct_put_mmx;
698 c->idct_add = ff_simple_idct_add_mmx;
699 c->idct = ff_simple_idct_mmx;
700 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
701 } else if (idct_algo == FF_IDCT_XVIDMMX) {
702 c->idct_put = ff_idct_xvid_mmx_put;
703 c->idct_add = ff_idct_xvid_mmx_add;
704 c->idct = ff_idct_xvid_mmx;
707 #endif /* HAVE_INLINE_ASM */
709 dsputil_init_mmx(c, avctx, cpu_flags);
712 if (X86_MMXEXT(cpu_flags))
713 dsputil_init_mmxext(c, avctx, cpu_flags);
715 if (X86_SSE(cpu_flags))
716 dsputil_init_sse(c, avctx, cpu_flags);
718 if (X86_SSE2(cpu_flags))
719 dsputil_init_sse2(c, avctx, cpu_flags);
721 if (EXTERNAL_SSSE3(cpu_flags))
722 dsputil_init_ssse3(c, avctx, cpu_flags);
724 if (EXTERNAL_SSE4(cpu_flags))
725 dsputil_init_sse4(c, avctx, cpu_flags);
728 ff_dsputilenc_init_mmx(c, avctx);