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/simple_idct.h"
31 #include "libavcodec/version.h"
32 #include "dsputil_x86.h"
33 #include "idct_xvid.h"
35 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
36 int dstStride, int src1Stride, int h);
37 void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1,
38 uint8_t *src2, int dstStride,
39 int src1Stride, int h);
40 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
41 int dstStride, int src1Stride, int h);
42 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
43 int dstStride, int src1Stride, int h);
44 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
45 int dstStride, int src1Stride, int h);
46 void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
47 int dstStride, int src1Stride, int h);
48 void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
49 int dstStride, int srcStride, int h);
50 void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
51 int dstStride, int srcStride, int h);
52 void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
53 int dstStride, int srcStride,
55 void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
56 int dstStride, int srcStride, int h);
57 void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
58 int dstStride, int srcStride, int h);
59 void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src,
60 int dstStride, int srcStride,
62 void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
63 int dstStride, int srcStride);
64 void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
65 int dstStride, int srcStride);
66 void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
67 int dstStride, int srcStride);
68 void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
69 int dstStride, int srcStride);
70 void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
71 int dstStride, int srcStride);
72 void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
73 int dstStride, int srcStride);
74 #define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
75 #define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
77 int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
79 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
81 int32_t ff_scalarproduct_and_madd_int16_mmxext(int16_t *v1, const int16_t *v2,
84 int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
87 int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
91 void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
92 void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
94 void ff_add_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *top,
95 const uint8_t *diff, int w,
96 int *left, int *left_top);
97 int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
99 int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
102 void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
103 int32_t min, int32_t max, unsigned int len);
104 void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
105 int32_t min, int32_t max, unsigned int len);
106 void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
107 int32_t min, int32_t max, unsigned int len);
108 void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
109 int32_t min, int32_t max, unsigned int len);
113 PIXELS16(static, ff_avg, , , _mmxext)
114 PIXELS16(static, ff_put, , , _mmxext)
116 #define QPEL_OP(OPNAME, RND, MMX) \
117 static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
120 ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
123 static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
127 uint8_t * const half = (uint8_t*)temp; \
128 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
130 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
131 stride, stride, 8); \
134 static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
137 ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
141 static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
145 uint8_t * const half = (uint8_t*)temp; \
146 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
148 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
152 static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
156 uint8_t * const half = (uint8_t*)temp; \
157 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
159 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half, \
160 stride, stride, 8); \
163 static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
166 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, \
170 static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
174 uint8_t * const half = (uint8_t*)temp; \
175 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, \
177 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
181 static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
184 uint64_t half[8 + 9]; \
185 uint8_t * const halfH = ((uint8_t*)half) + 64; \
186 uint8_t * const halfHV = ((uint8_t*)half); \
187 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
189 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
191 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
192 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
196 static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
199 uint64_t half[8 + 9]; \
200 uint8_t * const halfH = ((uint8_t*)half) + 64; \
201 uint8_t * const halfHV = ((uint8_t*)half); \
202 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
204 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
206 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
207 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
211 static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
214 uint64_t half[8 + 9]; \
215 uint8_t * const halfH = ((uint8_t*)half) + 64; \
216 uint8_t * const halfHV = ((uint8_t*)half); \
217 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
219 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, \
221 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
222 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
226 static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
229 uint64_t half[8 + 9]; \
230 uint8_t * const halfH = ((uint8_t*)half) + 64; \
231 uint8_t * const halfHV = ((uint8_t*)half); \
232 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
234 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
236 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
237 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
241 static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
244 uint64_t half[8 + 9]; \
245 uint8_t * const halfH = ((uint8_t*)half) + 64; \
246 uint8_t * const halfHV = ((uint8_t*)half); \
247 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
249 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
250 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, \
254 static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
257 uint64_t half[8 + 9]; \
258 uint8_t * const halfH = ((uint8_t*)half) + 64; \
259 uint8_t * const halfHV = ((uint8_t*)half); \
260 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
262 ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
263 ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, \
267 static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
270 uint64_t half[8 + 9]; \
271 uint8_t * const halfH = ((uint8_t*)half); \
272 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
274 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, \
276 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
280 static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
283 uint64_t half[8 + 9]; \
284 uint8_t * const halfH = ((uint8_t*)half); \
285 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
287 ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
289 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
293 static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
297 uint8_t * const halfH = ((uint8_t*)half); \
298 ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
300 ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, \
304 static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
307 ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
310 static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
314 uint8_t * const half = (uint8_t*)temp; \
315 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
317 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
321 static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
324 ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
325 stride, stride, 16);\
328 static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
332 uint8_t * const half = (uint8_t*)temp; \
333 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
335 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
336 stride, stride, 16); \
339 static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
343 uint8_t * const half = (uint8_t*)temp; \
344 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
346 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, \
350 static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
353 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, \
357 static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
361 uint8_t * const half = (uint8_t*)temp; \
362 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
364 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
365 stride, stride, 16); \
368 static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
371 uint64_t half[16 * 2 + 17 * 2]; \
372 uint8_t * const halfH = ((uint8_t*)half) + 256; \
373 uint8_t * const halfHV = ((uint8_t*)half); \
374 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
376 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
378 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
380 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
384 static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
387 uint64_t half[16 * 2 + 17 * 2]; \
388 uint8_t * const halfH = ((uint8_t*)half) + 256; \
389 uint8_t * const halfHV = ((uint8_t*)half); \
390 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
392 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
394 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
396 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
400 static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
403 uint64_t half[16 * 2 + 17 * 2]; \
404 uint8_t * const halfH = ((uint8_t*)half) + 256; \
405 uint8_t * const halfHV = ((uint8_t*)half); \
406 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
408 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
410 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
412 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
416 static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
419 uint64_t half[16 * 2 + 17 * 2]; \
420 uint8_t * const halfH = ((uint8_t*)half) + 256; \
421 uint8_t * const halfHV = ((uint8_t*)half); \
422 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
424 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
426 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
428 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
432 static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
435 uint64_t half[16 * 2 + 17 * 2]; \
436 uint8_t * const halfH = ((uint8_t*)half) + 256; \
437 uint8_t * const halfHV = ((uint8_t*)half); \
438 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
440 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
442 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, \
446 static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
449 uint64_t half[16 * 2 + 17 * 2]; \
450 uint8_t * const halfH = ((uint8_t*)half) + 256; \
451 uint8_t * const halfHV = ((uint8_t*)half); \
452 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
454 ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
456 ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, \
460 static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
463 uint64_t half[17 * 2]; \
464 uint8_t * const halfH = ((uint8_t*)half); \
465 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
467 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
469 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
473 static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
476 uint64_t half[17 * 2]; \
477 uint8_t * const halfH = ((uint8_t*)half); \
478 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
480 ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
482 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
486 static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
489 uint64_t half[17 * 2]; \
490 uint8_t * const halfH = ((uint8_t*)half); \
491 ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
493 ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, \
497 QPEL_OP(put_, _, mmxext)
498 QPEL_OP(avg_, _, mmxext)
499 QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)
500 #endif /* HAVE_YASM */
502 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
504 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
505 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
506 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
507 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
508 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
509 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
510 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
511 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
512 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
513 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
514 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
515 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
516 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
517 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
518 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
519 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
522 static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
526 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
528 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
529 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
530 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
532 if (!high_bit_depth) {
533 c->clear_block = ff_clear_block_mmx;
534 c->clear_blocks = ff_clear_blocks_mmx;
535 c->draw_edges = ff_draw_edges_mmx;
538 #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
542 c->add_bytes = ff_add_bytes_mmx;
543 #endif /* HAVE_MMX_INLINE */
545 #if HAVE_MMX_EXTERNAL
546 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
547 #endif /* HAVE_MMX_EXTERNAL */
550 static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
553 #if HAVE_MMXEXT_INLINE
554 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
556 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
557 c->idct_put = ff_idct_xvid_mmxext_put;
558 c->idct_add = ff_idct_xvid_mmxext_add;
559 c->idct = ff_idct_xvid_mmxext;
561 #endif /* HAVE_MMXEXT_INLINE */
563 #if HAVE_MMXEXT_EXTERNAL
564 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmxext, );
565 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmxext, );
567 SET_QPEL_FUNCS(put_qpel, 0, 16, mmxext, );
568 SET_QPEL_FUNCS(put_qpel, 1, 8, mmxext, );
569 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
570 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmxext, );
572 /* slower than cmov version on AMD */
573 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
574 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmxext;
576 c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
577 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmxext;
578 #endif /* HAVE_MMXEXT_EXTERNAL */
581 static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
585 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
587 c->vector_clipf = ff_vector_clipf_sse;
589 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
590 if (CONFIG_XVMC && avctx->hwaccel && avctx->hwaccel->decode_mb)
593 if (!high_bit_depth) {
594 c->clear_block = ff_clear_block_sse;
595 c->clear_blocks = ff_clear_blocks_sse;
597 #endif /* HAVE_SSE_INLINE */
600 #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
603 #endif /* HAVE_YASM */
606 static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
610 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
612 if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
613 c->idct_put = ff_idct_xvid_sse2_put;
614 c->idct_add = ff_idct_xvid_sse2_add;
615 c->idct = ff_idct_xvid_sse2;
616 c->idct_permutation_type = FF_SSE2_IDCT_PERM;
618 #endif /* HAVE_SSE2_INLINE */
620 #if HAVE_SSE2_EXTERNAL
621 c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
622 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
623 if (cpu_flags & AV_CPU_FLAG_ATOM) {
624 c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
626 c->vector_clip_int32 = ff_vector_clip_int32_sse2;
628 c->bswap_buf = ff_bswap32_buf_sse2;
629 #endif /* HAVE_SSE2_EXTERNAL */
632 static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
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,
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)
656 int cpu_flags = av_get_cpu_flags();
658 #if HAVE_7REGS && HAVE_INLINE_ASM
659 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
660 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_cmov;
663 if (X86_MMX(cpu_flags)) {
665 const int idct_algo = avctx->idct_algo;
667 if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
668 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
669 c->idct_put = ff_simple_idct_put_mmx;
670 c->idct_add = ff_simple_idct_add_mmx;
671 c->idct = ff_simple_idct_mmx;
672 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
673 } else if (idct_algo == FF_IDCT_XVIDMMX) {
674 c->idct_put = ff_idct_xvid_mmx_put;
675 c->idct_add = ff_idct_xvid_mmx_add;
676 c->idct = ff_idct_xvid_mmx;
679 #endif /* HAVE_INLINE_ASM */
681 dsputil_init_mmx(c, avctx, cpu_flags);
684 if (X86_MMXEXT(cpu_flags))
685 dsputil_init_mmxext(c, avctx, cpu_flags);
687 if (X86_SSE(cpu_flags))
688 dsputil_init_sse(c, avctx, cpu_flags);
690 if (X86_SSE2(cpu_flags))
691 dsputil_init_sse2(c, avctx, cpu_flags);
693 if (EXTERNAL_SSSE3(cpu_flags))
694 dsputil_init_ssse3(c, avctx, cpu_flags);
696 if (EXTERNAL_SSE4(cpu_flags))
697 dsputil_init_sse4(c, avctx, cpu_flags);
700 ff_dsputilenc_init_mmx(c, avctx);