x86: K&R prettyprinting cosmetics for dsputil_mmx.c
[libav.git] / libavcodec / x86 / dsputil_mmx.c
CommitLineData
de6d9b64
FB
1/*
2 * MMX optimized DSP utils
406792e7 3 * Copyright (c) 2000, 2001 Fabrice Bellard
8f2ab833 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
de6d9b64 5 *
3b549121
DB
6 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
7 *
2912e87a 8 * This file is part of Libav.
b78e7197 9 *
2912e87a 10 * Libav is free software; you can redistribute it and/or
ff4ec49e
FB
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
b78e7197 13 * version 2.1 of the License, or (at your option) any later version.
de6d9b64 14 *
2912e87a 15 * Libav is distributed in the hope that it will be useful,
de6d9b64 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
de6d9b64 19 *
ff4ec49e 20 * You should have received a copy of the GNU Lesser General Public
2912e87a 21 * License along with Libav; if not, write to the Free Software
5509bffa 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64
FB
23 */
24
7160bb71 25#include "libavutil/cpu.h"
245976da
DB
26#include "libavutil/x86_cpu.h"
27#include "libavcodec/dsputil.h"
4693b031 28#include "libavcodec/h264dsp.h"
245976da
DB
29#include "libavcodec/mpegvideo.h"
30#include "libavcodec/simple_idct.h"
ac3c9d01 31#include "libavcodec/ac3dec.h"
182f56cb 32#include "dsputil_mmx.h"
54a0b6e5 33#include "idct_xvid.h"
de6d9b64 34
622348f9
MN
35//#undef NDEBUG
36//#include <assert.h>
37
de6d9b64 38/* pixel operations */
84dc2d8a
MR
39DECLARE_ALIGNED(8, const uint64_t, ff_bone) = 0x0101010101010101ULL;
40DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
de6d9b64 41
84dc2d8a 42DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
3b549121
DB
43 { 0x8000000080000000ULL, 0x8000000080000000ULL };
44
45DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1) = { 0x0001000100010001ULL, 0x0001000100010001ULL };
46DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2) = { 0x0002000200020002ULL, 0x0002000200020002ULL };
47DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3) = { 0x0003000300030003ULL, 0x0003000300030003ULL };
48DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4) = { 0x0004000400040004ULL, 0x0004000400040004ULL };
49DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5) = { 0x0005000500050005ULL, 0x0005000500050005ULL };
50DECLARE_ALIGNED(16, const xmm_reg, ff_pw_8) = { 0x0008000800080008ULL, 0x0008000800080008ULL };
51DECLARE_ALIGNED(16, const xmm_reg, ff_pw_9) = { 0x0009000900090009ULL, 0x0009000900090009ULL };
52DECLARE_ALIGNED(8, const uint64_t, ff_pw_15) = 0x000F000F000F000FULL;
53DECLARE_ALIGNED(16, const xmm_reg, ff_pw_16) = { 0x0010001000100010ULL, 0x0010001000100010ULL };
54DECLARE_ALIGNED(16, const xmm_reg, ff_pw_17) = { 0x0011001100110011ULL, 0x0011001100110011ULL };
55DECLARE_ALIGNED(16, const xmm_reg, ff_pw_18) = { 0x0012001200120012ULL, 0x0012001200120012ULL };
56DECLARE_ALIGNED(8, const uint64_t, ff_pw_20) = 0x0014001400140014ULL;
57DECLARE_ALIGNED(16, const xmm_reg, ff_pw_27) = { 0x001B001B001B001BULL, 0x001B001B001B001BULL };
58DECLARE_ALIGNED(16, const xmm_reg, ff_pw_28) = { 0x001C001C001C001CULL, 0x001C001C001C001CULL };
59DECLARE_ALIGNED(16, const xmm_reg, ff_pw_32) = { 0x0020002000200020ULL, 0x0020002000200020ULL };
60DECLARE_ALIGNED(8, const uint64_t, ff_pw_42) = 0x002A002A002A002AULL;
61DECLARE_ALIGNED(8, const uint64_t, ff_pw_53) = 0x0035003500350035ULL;
62DECLARE_ALIGNED(16, const xmm_reg, ff_pw_63) = { 0x003F003F003F003FULL, 0x003F003F003F003FULL };
63DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64) = { 0x0040004000400040ULL, 0x0040004000400040ULL };
64DECLARE_ALIGNED(8, const uint64_t, ff_pw_96) = 0x0060006000600060ULL;
65DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
66DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
67DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = { 0x0200020002000200ULL, 0x0200020002000200ULL };
68DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019) = { 0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL };
69
70DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0) = { 0x0000000000000000ULL, 0x0000000000000000ULL };
71DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1) = { 0x0101010101010101ULL, 0x0101010101010101ULL };
72DECLARE_ALIGNED(16, const xmm_reg, ff_pb_3) = { 0x0303030303030303ULL, 0x0303030303030303ULL };
73DECLARE_ALIGNED(16, const xmm_reg, ff_pb_4) = { 0x0404040404040404ULL, 0x0404040404040404ULL };
74DECLARE_ALIGNED(8, const uint64_t, ff_pb_7) = 0x0707070707070707ULL;
75DECLARE_ALIGNED(8, const uint64_t, ff_pb_1F) = 0x1F1F1F1F1F1F1F1FULL;
76DECLARE_ALIGNED(8, const uint64_t, ff_pb_3F) = 0x3F3F3F3F3F3F3F3FULL;
77DECLARE_ALIGNED(16, const xmm_reg, ff_pb_80) = { 0x8080808080808080ULL, 0x8080808080808080ULL };
78DECLARE_ALIGNED(8, const uint64_t, ff_pb_81) = 0x8181818181818181ULL;
79DECLARE_ALIGNED(16, const xmm_reg, ff_pb_A1) = { 0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL };
80DECLARE_ALIGNED(16, const xmm_reg, ff_pb_F8) = { 0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL };
81DECLARE_ALIGNED(8, const uint64_t, ff_pb_FC) = 0xFCFCFCFCFCFCFCFCULL;
82DECLARE_ALIGNED(16, const xmm_reg, ff_pb_FE) = { 0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL };
84dc2d8a
MR
83
84DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
85DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
6810b93a 86
ef4a6514 87#define JUMPALIGN() __asm__ volatile (".p2align 3"::)
be449fca 88#define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
d6a4c0b1 89
fca0f0e5 90#define MOVQ_BFE(regd) \
be449fca 91 __asm__ volatile ( \
fca0f0e5
ZK
92 "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
93 "paddb %%" #regd ", %%" #regd " \n\t" ::)
94
d6a4c0b1 95#ifndef PIC
be449fca
DP
96#define MOVQ_BONE(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
97#define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
d6a4c0b1
ZK
98#else
99// for shared library it's better to use this way for accessing constants
100// pcmpeqd -> -1
fca0f0e5 101#define MOVQ_BONE(regd) \
be449fca 102 __asm__ volatile ( \
fca0f0e5
ZK
103 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
104 "psrlw $15, %%" #regd " \n\t" \
105 "packuswb %%" #regd ", %%" #regd " \n\t" ::)
d6a4c0b1
ZK
106
107#define MOVQ_WTWO(regd) \
be449fca 108 __asm__ volatile ( \
fca0f0e5
ZK
109 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
110 "psrlw $15, %%" #regd " \n\t" \
111 "psllw $1, %%" #regd " \n\t"::)
a7bd8797 112
d6a4c0b1
ZK
113#endif
114
fca0f0e5 115// using regr as temporary and for the output result
def60345 116// first argument is unmodifed and second is trashed
39825f31
ZK
117// regfe is supposed to contain 0xfefefefefefefefe
118#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
bb270c08
DB
119 "movq " #rega ", " #regr " \n\t"\
120 "pand " #regb ", " #regr " \n\t"\
121 "pxor " #rega ", " #regb " \n\t"\
122 "pand " #regfe "," #regb " \n\t"\
123 "psrlq $1, " #regb " \n\t"\
124 "paddb " #regb ", " #regr " \n\t"
def60345 125
39825f31 126#define PAVGB_MMX(rega, regb, regr, regfe) \
bb270c08
DB
127 "movq " #rega ", " #regr " \n\t"\
128 "por " #regb ", " #regr " \n\t"\
129 "pxor " #rega ", " #regb " \n\t"\
130 "pand " #regfe "," #regb " \n\t"\
131 "psrlq $1, " #regb " \n\t"\
132 "psubb " #regb ", " #regr " \n\t"
def60345 133
39825f31 134// mm6 is supposed to contain 0xfefefefefefefefe
6aa6ea8e 135#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
bb270c08
DB
136 "movq " #rega ", " #regr " \n\t"\
137 "movq " #regc ", " #regp " \n\t"\
138 "pand " #regb ", " #regr " \n\t"\
139 "pand " #regd ", " #regp " \n\t"\
140 "pxor " #rega ", " #regb " \n\t"\
141 "pxor " #regc ", " #regd " \n\t"\
142 "pand %%mm6, " #regb " \n\t"\
143 "pand %%mm6, " #regd " \n\t"\
144 "psrlq $1, " #regb " \n\t"\
145 "psrlq $1, " #regd " \n\t"\
146 "paddb " #regb ", " #regr " \n\t"\
147 "paddb " #regd ", " #regp " \n\t"
6aa6ea8e
ZK
148
149#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
bb270c08
DB
150 "movq " #rega ", " #regr " \n\t"\
151 "movq " #regc ", " #regp " \n\t"\
152 "por " #regb ", " #regr " \n\t"\
153 "por " #regd ", " #regp " \n\t"\
154 "pxor " #rega ", " #regb " \n\t"\
155 "pxor " #regc ", " #regd " \n\t"\
156 "pand %%mm6, " #regb " \n\t"\
157 "pand %%mm6, " #regd " \n\t"\
158 "psrlq $1, " #regd " \n\t"\
159 "psrlq $1, " #regb " \n\t"\
160 "psubb " #regb ", " #regr " \n\t"\
161 "psubb " #regd ", " #regp " \n\t"
6aa6ea8e 162
91abb473
ZK
163/***********************************/
164/* MMX no rounding */
3b549121 165#define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
fca0f0e5 166#define SET_RND MOVQ_WONE
bb270c08
DB
167#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
168#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
c21c835b 169#define OP_AVG(a, b, c, e) PAVGB_MMX(a, b, c, e)
fca0f0e5 170
782fc0c3 171#include "dsputil_mmx_rnd_template.c"
91abb473
ZK
172
173#undef DEF
fca0f0e5 174#undef SET_RND
6aa6ea8e 175#undef PAVGBP
39825f31 176#undef PAVGB
91abb473
ZK
177/***********************************/
178/* MMX rounding */
179
3b549121 180#define DEF(x, y) x ## _ ## y ## _mmx
fca0f0e5 181#define SET_RND MOVQ_WTWO
bb270c08
DB
182#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
183#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
fca0f0e5 184
782fc0c3 185#include "dsputil_mmx_rnd_template.c"
91abb473
ZK
186
187#undef DEF
fca0f0e5 188#undef SET_RND
6aa6ea8e 189#undef PAVGBP
39825f31 190#undef PAVGB
c21c835b 191#undef OP_AVG
a7bd8797 192
de6d9b64
FB
193/***********************************/
194/* 3Dnow specific */
195
196#define DEF(x) x ## _3dnow
de6d9b64 197#define PAVGB "pavgusb"
c21c835b 198#define OP_AVG PAVGB
de6d9b64 199
782fc0c3 200#include "dsputil_mmx_avg_template.c"
de6d9b64
FB
201
202#undef DEF
203#undef PAVGB
c21c835b 204#undef OP_AVG
de6d9b64
FB
205
206/***********************************/
207/* MMX2 specific */
208
607dce96 209#define DEF(x) x ## _mmx2
de6d9b64
FB
210
211/* Introduced only in MMX2 set */
212#define PAVGB "pavgb"
c21c835b 213#define OP_AVG PAVGB
de6d9b64 214
782fc0c3 215#include "dsputil_mmx_avg_template.c"
de6d9b64
FB
216
217#undef DEF
218#undef PAVGB
c21c835b 219#undef OP_AVG
de6d9b64 220
b2f77586
LM
221#define put_no_rnd_pixels16_mmx put_pixels16_mmx
222#define put_no_rnd_pixels8_mmx put_pixels8_mmx
6c01d006
LM
223#define put_pixels16_mmx2 put_pixels16_mmx
224#define put_pixels8_mmx2 put_pixels8_mmx
225#define put_pixels4_mmx2 put_pixels4_mmx
6c01d006
LM
226#define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
227#define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
228#define put_pixels16_3dnow put_pixels16_mmx
229#define put_pixels8_3dnow put_pixels8_mmx
230#define put_pixels4_3dnow put_pixels4_mmx
6c01d006
LM
231#define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
232#define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
233
de6d9b64
FB
234/***********************************/
235/* standard MMX */
236
3b549121
DB
237void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
238 int line_size)
de6d9b64
FB
239{
240 const DCTELEM *p;
0c1a9eda 241 uint8_t *pix;
de6d9b64
FB
242
243 /* read the pixels */
3b549121 244 p = block;
de6d9b64 245 pix = pixels;
d6a4c0b1 246 /* unrolled loop */
be449fca 247 __asm__ volatile(
bb270c08
DB
248 "movq %3, %%mm0 \n\t"
249 "movq 8%3, %%mm1 \n\t"
250 "movq 16%3, %%mm2 \n\t"
251 "movq 24%3, %%mm3 \n\t"
252 "movq 32%3, %%mm4 \n\t"
253 "movq 40%3, %%mm5 \n\t"
254 "movq 48%3, %%mm6 \n\t"
255 "movq 56%3, %%mm7 \n\t"
256 "packuswb %%mm1, %%mm0 \n\t"
257 "packuswb %%mm3, %%mm2 \n\t"
258 "packuswb %%mm5, %%mm4 \n\t"
259 "packuswb %%mm7, %%mm6 \n\t"
260 "movq %%mm0, (%0) \n\t"
261 "movq %%mm2, (%0, %1) \n\t"
262 "movq %%mm4, (%0, %1, 2) \n\t"
263 "movq %%mm6, (%0, %2) \n\t"
40d0e665 264 ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
bb270c08 265 :"memory");
3b549121
DB
266 pix += line_size * 4;
267 p += 32;
d6a4c0b1
ZK
268
269 // if here would be an exact copy of the code above
270 // compiler would generate some very strange code
271 // thus using "r"
be449fca 272 __asm__ volatile(
bb270c08
DB
273 "movq (%3), %%mm0 \n\t"
274 "movq 8(%3), %%mm1 \n\t"
275 "movq 16(%3), %%mm2 \n\t"
276 "movq 24(%3), %%mm3 \n\t"
277 "movq 32(%3), %%mm4 \n\t"
278 "movq 40(%3), %%mm5 \n\t"
279 "movq 48(%3), %%mm6 \n\t"
280 "movq 56(%3), %%mm7 \n\t"
281 "packuswb %%mm1, %%mm0 \n\t"
282 "packuswb %%mm3, %%mm2 \n\t"
283 "packuswb %%mm5, %%mm4 \n\t"
284 "packuswb %%mm7, %%mm6 \n\t"
285 "movq %%mm0, (%0) \n\t"
286 "movq %%mm2, (%0, %1) \n\t"
287 "movq %%mm4, (%0, %1, 2) \n\t"
288 "movq %%mm6, (%0, %2) \n\t"
40d0e665 289 ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
bb270c08 290 :"memory");
de6d9b64
FB
291}
292
3dd65312
AC
293#define put_signed_pixels_clamped_mmx_half(off) \
294 "movq "#off"(%2), %%mm1 \n\t"\
295 "movq 16+"#off"(%2), %%mm2 \n\t"\
296 "movq 32+"#off"(%2), %%mm3 \n\t"\
297 "movq 48+"#off"(%2), %%mm4 \n\t"\
298 "packsswb 8+"#off"(%2), %%mm1 \n\t"\
299 "packsswb 24+"#off"(%2), %%mm2 \n\t"\
300 "packsswb 40+"#off"(%2), %%mm3 \n\t"\
301 "packsswb 56+"#off"(%2), %%mm4 \n\t"\
302 "paddb %%mm0, %%mm1 \n\t"\
303 "paddb %%mm0, %%mm2 \n\t"\
304 "paddb %%mm0, %%mm3 \n\t"\
305 "paddb %%mm0, %%mm4 \n\t"\
306 "movq %%mm1, (%0) \n\t"\
307 "movq %%mm2, (%0, %3) \n\t"\
308 "movq %%mm3, (%0, %3, 2) \n\t"\
309 "movq %%mm4, (%0, %1) \n\t"
310
3b549121
DB
311void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
312 int line_size)
f9ed9d85 313{
3dd65312 314 x86_reg line_skip = line_size;
0be9e73e 315 x86_reg line_skip3;
3dd65312
AC
316
317 __asm__ volatile (
bf6fa732 318 "movq "MANGLE(ff_pb_80)", %%mm0 \n\t"
3dd65312
AC
319 "lea (%3, %3, 2), %1 \n\t"
320 put_signed_pixels_clamped_mmx_half(0)
321 "lea (%0, %3, 4), %0 \n\t"
322 put_signed_pixels_clamped_mmx_half(64)
0be9e73e 323 :"+&r" (pixels), "=&r" (line_skip3)
3dd65312
AC
324 :"r" (block), "r"(line_skip)
325 :"memory");
f9ed9d85
MM
326}
327
3b549121
DB
328void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels,
329 int line_size)
de6d9b64
FB
330{
331 const DCTELEM *p;
0c1a9eda 332 uint8_t *pix;
de6d9b64
FB
333 int i;
334
335 /* read the pixels */
3b549121 336 p = block;
de6d9b64 337 pix = pixels;
d6a4c0b1
ZK
338 MOVQ_ZERO(mm7);
339 i = 4;
cd8e5f96 340 do {
be449fca 341 __asm__ volatile(
bb270c08
DB
342 "movq (%2), %%mm0 \n\t"
343 "movq 8(%2), %%mm1 \n\t"
344 "movq 16(%2), %%mm2 \n\t"
345 "movq 24(%2), %%mm3 \n\t"
346 "movq %0, %%mm4 \n\t"
347 "movq %1, %%mm6 \n\t"
348 "movq %%mm4, %%mm5 \n\t"
349 "punpcklbw %%mm7, %%mm4 \n\t"
350 "punpckhbw %%mm7, %%mm5 \n\t"
351 "paddsw %%mm4, %%mm0 \n\t"
352 "paddsw %%mm5, %%mm1 \n\t"
353 "movq %%mm6, %%mm5 \n\t"
354 "punpcklbw %%mm7, %%mm6 \n\t"
355 "punpckhbw %%mm7, %%mm5 \n\t"
356 "paddsw %%mm6, %%mm2 \n\t"
357 "paddsw %%mm5, %%mm3 \n\t"
358 "packuswb %%mm1, %%mm0 \n\t"
359 "packuswb %%mm3, %%mm2 \n\t"
360 "movq %%mm0, %0 \n\t"
361 "movq %%mm2, %1 \n\t"
362 :"+m"(*pix), "+m"(*(pix+line_size))
363 :"r"(p)
364 :"memory");
3b549121
DB
365 pix += line_size * 2;
366 p += 16;
cd8e5f96 367 } while (--i);
de6d9b64
FB
368}
369
3b549121
DB
370static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels,
371 int line_size, int h)
437525c4 372{
be449fca 373 __asm__ volatile(
bb270c08 374 "lea (%3, %3), %%"REG_a" \n\t"
ef4a6514 375 ".p2align 3 \n\t"
bb270c08
DB
376 "1: \n\t"
377 "movd (%1), %%mm0 \n\t"
378 "movd (%1, %3), %%mm1 \n\t"
379 "movd %%mm0, (%2) \n\t"
380 "movd %%mm1, (%2, %3) \n\t"
381 "add %%"REG_a", %1 \n\t"
382 "add %%"REG_a", %2 \n\t"
383 "movd (%1), %%mm0 \n\t"
384 "movd (%1, %3), %%mm1 \n\t"
385 "movd %%mm0, (%2) \n\t"
386 "movd %%mm1, (%2, %3) \n\t"
387 "add %%"REG_a", %1 \n\t"
388 "add %%"REG_a", %2 \n\t"
389 "subl $4, %0 \n\t"
390 "jnz 1b \n\t"
391 : "+g"(h), "+r" (pixels), "+r" (block)
40d0e665 392 : "r"((x86_reg)line_size)
bb270c08
DB
393 : "%"REG_a, "memory"
394 );
437525c4
MN
395}
396
3b549121
DB
397static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels,
398 int line_size, int h)
de6d9b64 399{
be449fca 400 __asm__ volatile(
bb270c08 401 "lea (%3, %3), %%"REG_a" \n\t"
ef4a6514 402 ".p2align 3 \n\t"
bb270c08
DB
403 "1: \n\t"
404 "movq (%1), %%mm0 \n\t"
405 "movq (%1, %3), %%mm1 \n\t"
406 "movq %%mm0, (%2) \n\t"
407 "movq %%mm1, (%2, %3) \n\t"
408 "add %%"REG_a", %1 \n\t"
409 "add %%"REG_a", %2 \n\t"
410 "movq (%1), %%mm0 \n\t"
411 "movq (%1, %3), %%mm1 \n\t"
412 "movq %%mm0, (%2) \n\t"
413 "movq %%mm1, (%2, %3) \n\t"
414 "add %%"REG_a", %1 \n\t"
415 "add %%"REG_a", %2 \n\t"
416 "subl $4, %0 \n\t"
417 "jnz 1b \n\t"
418 : "+g"(h), "+r" (pixels), "+r" (block)
40d0e665 419 : "r"((x86_reg)line_size)
bb270c08
DB
420 : "%"REG_a, "memory"
421 );
de6d9b64
FB
422}
423
3b549121
DB
424static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels,
425 int line_size, int h)
b3184779 426{
be449fca 427 __asm__ volatile(
bb270c08 428 "lea (%3, %3), %%"REG_a" \n\t"
ef4a6514 429 ".p2align 3 \n\t"
bb270c08
DB
430 "1: \n\t"
431 "movq (%1), %%mm0 \n\t"
432 "movq 8(%1), %%mm4 \n\t"
433 "movq (%1, %3), %%mm1 \n\t"
434 "movq 8(%1, %3), %%mm5 \n\t"
435 "movq %%mm0, (%2) \n\t"
436 "movq %%mm4, 8(%2) \n\t"
437 "movq %%mm1, (%2, %3) \n\t"
438 "movq %%mm5, 8(%2, %3) \n\t"
439 "add %%"REG_a", %1 \n\t"
440 "add %%"REG_a", %2 \n\t"
441 "movq (%1), %%mm0 \n\t"
442 "movq 8(%1), %%mm4 \n\t"
443 "movq (%1, %3), %%mm1 \n\t"
444 "movq 8(%1, %3), %%mm5 \n\t"
445 "movq %%mm0, (%2) \n\t"
446 "movq %%mm4, 8(%2) \n\t"
447 "movq %%mm1, (%2, %3) \n\t"
448 "movq %%mm5, 8(%2, %3) \n\t"
449 "add %%"REG_a", %1 \n\t"
450 "add %%"REG_a", %2 \n\t"
451 "subl $4, %0 \n\t"
452 "jnz 1b \n\t"
453 : "+g"(h), "+r" (pixels), "+r" (block)
40d0e665 454 : "r"((x86_reg)line_size)
bb270c08
DB
455 : "%"REG_a, "memory"
456 );
b3184779
MN
457}
458
3b549121
DB
459static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
460 int line_size, int h)
ddf96970 461{
be449fca 462 __asm__ volatile(
ddf96970
LM
463 "1: \n\t"
464 "movdqu (%1), %%xmm0 \n\t"
465 "movdqu (%1,%3), %%xmm1 \n\t"
466 "movdqu (%1,%3,2), %%xmm2 \n\t"
467 "movdqu (%1,%4), %%xmm3 \n\t"
a3bf7b86 468 "lea (%1,%3,4), %1 \n\t"
ddf96970
LM
469 "movdqa %%xmm0, (%2) \n\t"
470 "movdqa %%xmm1, (%2,%3) \n\t"
471 "movdqa %%xmm2, (%2,%3,2) \n\t"
472 "movdqa %%xmm3, (%2,%4) \n\t"
473 "subl $4, %0 \n\t"
ddf96970
LM
474 "lea (%2,%3,4), %2 \n\t"
475 "jnz 1b \n\t"
476 : "+g"(h), "+r" (pixels), "+r" (block)
40d0e665 477 : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
ddf96970
LM
478 : "memory"
479 );
480}
481
3b549121
DB
482static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels,
483 int line_size, int h)
ddf96970 484{
be449fca 485 __asm__ volatile(
ddf96970
LM
486 "1: \n\t"
487 "movdqu (%1), %%xmm0 \n\t"
488 "movdqu (%1,%3), %%xmm1 \n\t"
489 "movdqu (%1,%3,2), %%xmm2 \n\t"
490 "movdqu (%1,%4), %%xmm3 \n\t"
a3bf7b86 491 "lea (%1,%3,4), %1 \n\t"
ddf96970
LM
492 "pavgb (%2), %%xmm0 \n\t"
493 "pavgb (%2,%3), %%xmm1 \n\t"
494 "pavgb (%2,%3,2), %%xmm2 \n\t"
495 "pavgb (%2,%4), %%xmm3 \n\t"
496 "movdqa %%xmm0, (%2) \n\t"
497 "movdqa %%xmm1, (%2,%3) \n\t"
498 "movdqa %%xmm2, (%2,%3,2) \n\t"
499 "movdqa %%xmm3, (%2,%4) \n\t"
500 "subl $4, %0 \n\t"
ddf96970
LM
501 "lea (%2,%3,4), %2 \n\t"
502 "jnz 1b \n\t"
503 : "+g"(h), "+r" (pixels), "+r" (block)
40d0e665 504 : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
ddf96970
LM
505 : "memory"
506 );
507}
508
5fecfb7d
LM
509#define CLEAR_BLOCKS(name,n) \
510static void name(DCTELEM *blocks)\
511{\
512 __asm__ volatile(\
513 "pxor %%mm7, %%mm7 \n\t"\
514 "mov %1, %%"REG_a" \n\t"\
515 "1: \n\t"\
516 "movq %%mm7, (%0, %%"REG_a") \n\t"\
517 "movq %%mm7, 8(%0, %%"REG_a") \n\t"\
518 "movq %%mm7, 16(%0, %%"REG_a") \n\t"\
519 "movq %%mm7, 24(%0, %%"REG_a") \n\t"\
520 "add $32, %%"REG_a" \n\t"\
521 " js 1b \n\t"\
522 : : "r" (((uint8_t *)blocks)+128*n),\
523 "i" (-128*n)\
524 : "%"REG_a\
525 );\
526}
527CLEAR_BLOCKS(clear_blocks_mmx, 6)
528CLEAR_BLOCKS(clear_block_mmx, 1)
529
530static void clear_block_sse(DCTELEM *block)
649c00c9 531{
be449fca 532 __asm__ volatile(
5fecfb7d
LM
533 "xorps %%xmm0, %%xmm0 \n"
534 "movaps %%xmm0, (%0) \n"
535 "movaps %%xmm0, 16(%0) \n"
536 "movaps %%xmm0, 32(%0) \n"
537 "movaps %%xmm0, 48(%0) \n"
538 "movaps %%xmm0, 64(%0) \n"
539 "movaps %%xmm0, 80(%0) \n"
540 "movaps %%xmm0, 96(%0) \n"
541 "movaps %%xmm0, 112(%0) \n"
542 :: "r"(block)
543 : "memory"
544 );
649c00c9
MN
545}
546
73b02e24 547static void clear_blocks_sse(DCTELEM *blocks)
3b549121 548{
73b02e24
JGG
549 __asm__ volatile(
550 "xorps %%xmm0, %%xmm0 \n"
551 "mov %1, %%"REG_a" \n"
552 "1: \n"
553 "movaps %%xmm0, (%0, %%"REG_a") \n"
554 "movaps %%xmm0, 16(%0, %%"REG_a") \n"
555 "movaps %%xmm0, 32(%0, %%"REG_a") \n"
556 "movaps %%xmm0, 48(%0, %%"REG_a") \n"
557 "movaps %%xmm0, 64(%0, %%"REG_a") \n"
558 "movaps %%xmm0, 80(%0, %%"REG_a") \n"
559 "movaps %%xmm0, 96(%0, %%"REG_a") \n"
560 "movaps %%xmm0, 112(%0, %%"REG_a") \n"
561 "add $128, %%"REG_a" \n"
562 " js 1b \n"
563 : : "r" (((uint8_t *)blocks)+128*6),
564 "i" (-128*6)
565 : "%"REG_a
566 );
567}
568
3b549121
DB
569static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w)
570{
571 x86_reg i = 0;
be449fca 572 __asm__ volatile(
00eebe3d 573 "jmp 2f \n\t"
bb270c08
DB
574 "1: \n\t"
575 "movq (%1, %0), %%mm0 \n\t"
576 "movq (%2, %0), %%mm1 \n\t"
577 "paddb %%mm0, %%mm1 \n\t"
578 "movq %%mm1, (%2, %0) \n\t"
579 "movq 8(%1, %0), %%mm0 \n\t"
580 "movq 8(%2, %0), %%mm1 \n\t"
581 "paddb %%mm0, %%mm1 \n\t"
582 "movq %%mm1, 8(%2, %0) \n\t"
583 "add $16, %0 \n\t"
00eebe3d 584 "2: \n\t"
bb270c08 585 "cmp %3, %0 \n\t"
00eebe3d 586 " js 1b \n\t"
11f18faf 587 : "+r" (i)
40d0e665 588 : "r"(src), "r"(dst), "r"((x86_reg)w-15)
11f18faf 589 );
3b549121
DB
590 for ( ; i < w; i++)
591 dst[i + 0] += src[i + 0];
11f18faf
MN
592}
593
d2ee495f 594#if HAVE_7REGS
3b549121
DB
595static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top,
596 const uint8_t *diff, int w,
597 int *left, int *left_top)
598{
3daa434a
LM
599 x86_reg w2 = -w;
600 x86_reg x;
3b549121 601 int l = *left & 0xff;
3daa434a
LM
602 int tl = *left_top & 0xff;
603 int t;
604 __asm__ volatile(
605 "mov %7, %3 \n"
606 "1: \n"
80e33d24 607 "movzbl (%3,%4), %2 \n"
3daa434a
LM
608 "mov %2, %k3 \n"
609 "sub %b1, %b3 \n"
610 "add %b0, %b3 \n"
611 "mov %2, %1 \n"
612 "cmp %0, %2 \n"
613 "cmovg %0, %2 \n"
614 "cmovg %1, %0 \n"
615 "cmp %k3, %0 \n"
616 "cmovg %k3, %0 \n"
617 "mov %7, %3 \n"
618 "cmp %2, %0 \n"
619 "cmovl %2, %0 \n"
620 "add (%6,%4), %b0 \n"
621 "mov %b0, (%5,%4) \n"
622 "inc %4 \n"
623 "jl 1b \n"
624 :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
625 :"r"(dst+w), "r"(diff+w), "rm"(top+w)
626 );
3b549121 627 *left = l;
3daa434a
LM
628 *left_top = tl;
629}
630#endif
631
3615e2be 632#define H263_LOOP_FILTER \
bb270c08
DB
633 "pxor %%mm7, %%mm7 \n\t"\
634 "movq %0, %%mm0 \n\t"\
635 "movq %0, %%mm1 \n\t"\
636 "movq %3, %%mm2 \n\t"\
637 "movq %3, %%mm3 \n\t"\
638 "punpcklbw %%mm7, %%mm0 \n\t"\
639 "punpckhbw %%mm7, %%mm1 \n\t"\
640 "punpcklbw %%mm7, %%mm2 \n\t"\
641 "punpckhbw %%mm7, %%mm3 \n\t"\
642 "psubw %%mm2, %%mm0 \n\t"\
643 "psubw %%mm3, %%mm1 \n\t"\
644 "movq %1, %%mm2 \n\t"\
645 "movq %1, %%mm3 \n\t"\
646 "movq %2, %%mm4 \n\t"\
647 "movq %2, %%mm5 \n\t"\
648 "punpcklbw %%mm7, %%mm2 \n\t"\
649 "punpckhbw %%mm7, %%mm3 \n\t"\
650 "punpcklbw %%mm7, %%mm4 \n\t"\
651 "punpckhbw %%mm7, %%mm5 \n\t"\
652 "psubw %%mm2, %%mm4 \n\t"\
653 "psubw %%mm3, %%mm5 \n\t"\
654 "psllw $2, %%mm4 \n\t"\
655 "psllw $2, %%mm5 \n\t"\
656 "paddw %%mm0, %%mm4 \n\t"\
657 "paddw %%mm1, %%mm5 \n\t"\
658 "pxor %%mm6, %%mm6 \n\t"\
659 "pcmpgtw %%mm4, %%mm6 \n\t"\
660 "pcmpgtw %%mm5, %%mm7 \n\t"\
661 "pxor %%mm6, %%mm4 \n\t"\
662 "pxor %%mm7, %%mm5 \n\t"\
663 "psubw %%mm6, %%mm4 \n\t"\
664 "psubw %%mm7, %%mm5 \n\t"\
665 "psrlw $3, %%mm4 \n\t"\
666 "psrlw $3, %%mm5 \n\t"\
667 "packuswb %%mm5, %%mm4 \n\t"\
668 "packsswb %%mm7, %%mm6 \n\t"\
669 "pxor %%mm7, %%mm7 \n\t"\
670 "movd %4, %%mm2 \n\t"\
671 "punpcklbw %%mm2, %%mm2 \n\t"\
672 "punpcklbw %%mm2, %%mm2 \n\t"\
673 "punpcklbw %%mm2, %%mm2 \n\t"\
674 "psubusb %%mm4, %%mm2 \n\t"\
675 "movq %%mm2, %%mm3 \n\t"\
676 "psubusb %%mm4, %%mm3 \n\t"\
677 "psubb %%mm3, %%mm2 \n\t"\
678 "movq %1, %%mm3 \n\t"\
679 "movq %2, %%mm4 \n\t"\
680 "pxor %%mm6, %%mm3 \n\t"\
681 "pxor %%mm6, %%mm4 \n\t"\
682 "paddusb %%mm2, %%mm3 \n\t"\
683 "psubusb %%mm2, %%mm4 \n\t"\
684 "pxor %%mm6, %%mm3 \n\t"\
685 "pxor %%mm6, %%mm4 \n\t"\
686 "paddusb %%mm2, %%mm2 \n\t"\
687 "packsswb %%mm1, %%mm0 \n\t"\
688 "pcmpgtb %%mm0, %%mm7 \n\t"\
689 "pxor %%mm7, %%mm0 \n\t"\
690 "psubb %%mm7, %%mm0 \n\t"\
691 "movq %%mm0, %%mm1 \n\t"\
692 "psubusb %%mm2, %%mm0 \n\t"\
693 "psubb %%mm0, %%mm1 \n\t"\
694 "pand %5, %%mm1 \n\t"\
695 "psrlw $2, %%mm1 \n\t"\
696 "pxor %%mm7, %%mm1 \n\t"\
697 "psubb %%mm7, %%mm1 \n\t"\
698 "movq %0, %%mm5 \n\t"\
699 "movq %3, %%mm6 \n\t"\
700 "psubb %%mm1, %%mm5 \n\t"\
701 "paddb %%mm1, %%mm6 \n\t"
3615e2be 702
3b549121
DB
703static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale)
704{
705 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
706 const int strength = ff_h263_loop_filter_strength[qscale];
359f98de 707
be449fca 708 __asm__ volatile(
115329f1 709
3615e2be 710 H263_LOOP_FILTER
115329f1 711
bb270c08
DB
712 "movq %%mm3, %1 \n\t"
713 "movq %%mm4, %2 \n\t"
714 "movq %%mm5, %0 \n\t"
715 "movq %%mm6, %3 \n\t"
359f98de
MN
716 : "+m" (*(uint64_t*)(src - 2*stride)),
717 "+m" (*(uint64_t*)(src - 1*stride)),
718 "+m" (*(uint64_t*)(src + 0*stride)),
719 "+m" (*(uint64_t*)(src + 1*stride))
720 : "g" (2*strength), "m"(ff_pb_FC)
721 );
73f51a4d 722 }
359f98de
MN
723}
724
3b549121
DB
725static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale)
726{
727 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
728 const int strength = ff_h263_loop_filter_strength[qscale];
729 DECLARE_ALIGNED(8, uint64_t, temp)[4];
730 uint8_t *btemp = (uint8_t*)temp;
115329f1 731
3b549121 732 src -= 2;
3615e2be 733
3b549121
DB
734 transpose4x4(btemp, src, 8, stride);
735 transpose4x4(btemp + 4, src + 4 * stride, 8, stride);
be449fca 736 __asm__ volatile(
3615e2be 737 H263_LOOP_FILTER // 5 3 4 6
115329f1 738
3615e2be
MN
739 : "+m" (temp[0]),
740 "+m" (temp[1]),
741 "+m" (temp[2]),
742 "+m" (temp[3])
743 : "g" (2*strength), "m"(ff_pb_FC)
744 );
745
be449fca 746 __asm__ volatile(
bb270c08
DB
747 "movq %%mm5, %%mm1 \n\t"
748 "movq %%mm4, %%mm0 \n\t"
749 "punpcklbw %%mm3, %%mm5 \n\t"
750 "punpcklbw %%mm6, %%mm4 \n\t"
751 "punpckhbw %%mm3, %%mm1 \n\t"
752 "punpckhbw %%mm6, %%mm0 \n\t"
753 "movq %%mm5, %%mm3 \n\t"
754 "movq %%mm1, %%mm6 \n\t"
755 "punpcklwd %%mm4, %%mm5 \n\t"
756 "punpcklwd %%mm0, %%mm1 \n\t"
757 "punpckhwd %%mm4, %%mm3 \n\t"
758 "punpckhwd %%mm0, %%mm6 \n\t"
759 "movd %%mm5, (%0) \n\t"
760 "punpckhdq %%mm5, %%mm5 \n\t"
761 "movd %%mm5, (%0,%2) \n\t"
762 "movd %%mm3, (%0,%2,2) \n\t"
763 "punpckhdq %%mm3, %%mm3 \n\t"
764 "movd %%mm3, (%0,%3) \n\t"
765 "movd %%mm1, (%1) \n\t"
766 "punpckhdq %%mm1, %%mm1 \n\t"
767 "movd %%mm1, (%1,%2) \n\t"
768 "movd %%mm6, (%1,%2,2) \n\t"
769 "punpckhdq %%mm6, %%mm6 \n\t"
770 "movd %%mm6, (%1,%3) \n\t"
4d9ae03b
MD
771 :: "r" (src),
772 "r" (src + 4*stride),
40d0e665
RP
773 "r" ((x86_reg) stride ),
774 "r" ((x86_reg)(3*stride))
3615e2be 775 );
73f51a4d 776 }
3615e2be
MN
777}
778
3b549121
DB
779/* Draw the edges of width 'w' of an image of size width, height
780 * this MMX version can only handle w == 8 || w == 16. */
781static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
782 int w, int h, int sides)
5a6a9e78
AJ
783{
784 uint8_t *ptr, *last_line;
785 int i;
786
787 last_line = buf + (height - 1) * wrap;
788 /* left and right */
789 ptr = buf;
3b549121 790 if (w == 8) {
be449fca 791 __asm__ volatile(
5a6a9e78
AJ
792 "1: \n\t"
793 "movd (%0), %%mm0 \n\t"
794 "punpcklbw %%mm0, %%mm0 \n\t"
795 "punpcklwd %%mm0, %%mm0 \n\t"
796 "punpckldq %%mm0, %%mm0 \n\t"
797 "movq %%mm0, -8(%0) \n\t"
798 "movq -8(%0, %2), %%mm1 \n\t"
799 "punpckhbw %%mm1, %%mm1 \n\t"
800 "punpckhwd %%mm1, %%mm1 \n\t"
801 "punpckhdq %%mm1, %%mm1 \n\t"
802 "movq %%mm1, (%0, %2) \n\t"
803 "add %1, %0 \n\t"
804 "cmp %3, %0 \n\t"
805 " jb 1b \n\t"
806 : "+r" (ptr)
40d0e665 807 : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
5a6a9e78 808 );
3b549121 809 } else {
be449fca 810 __asm__ volatile(
5a6a9e78
AJ
811 "1: \n\t"
812 "movd (%0), %%mm0 \n\t"
813 "punpcklbw %%mm0, %%mm0 \n\t"
814 "punpcklwd %%mm0, %%mm0 \n\t"
815 "punpckldq %%mm0, %%mm0 \n\t"
816 "movq %%mm0, -8(%0) \n\t"
817 "movq %%mm0, -16(%0) \n\t"
818 "movq -8(%0, %2), %%mm1 \n\t"
819 "punpckhbw %%mm1, %%mm1 \n\t"
820 "punpckhwd %%mm1, %%mm1 \n\t"
821 "punpckhdq %%mm1, %%mm1 \n\t"
822 "movq %%mm1, (%0, %2) \n\t"
823 "movq %%mm1, 8(%0, %2) \n\t"
824 "add %1, %0 \n\t"
825 "cmp %3, %0 \n\t"
826 " jb 1b \n\t"
827 : "+r" (ptr)
40d0e665 828 : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
5a6a9e78
AJ
829 );
830 }
831
1500be13 832 /* top and bottom (and hopefully also the corners) */
3b549121
DB
833 if (sides & EDGE_TOP) {
834 for (i = 0; i < h; i += 4) {
835 ptr = buf - (i + 1) * wrap - w;
1500be13
AS
836 __asm__ volatile(
837 "1: \n\t"
838 "movq (%1, %0), %%mm0 \n\t"
839 "movq %%mm0, (%0) \n\t"
840 "movq %%mm0, (%0, %2) \n\t"
841 "movq %%mm0, (%0, %2, 2) \n\t"
842 "movq %%mm0, (%0, %3) \n\t"
843 "add $8, %0 \n\t"
844 "cmp %4, %0 \n\t"
845 " jb 1b \n\t"
846 : "+r" (ptr)
847 : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
848 );
849 }
850 }
851
3b549121
DB
852 if (sides & EDGE_BOTTOM) {
853 for (i = 0; i < h; i += 4) {
854 ptr = last_line + (i + 1) * wrap - w;
1500be13
AS
855 __asm__ volatile(
856 "1: \n\t"
857 "movq (%1, %0), %%mm0 \n\t"
858 "movq %%mm0, (%0) \n\t"
859 "movq %%mm0, (%0, %2) \n\t"
860 "movq %%mm0, (%0, %2, 2) \n\t"
861 "movq %%mm0, (%0, %3) \n\t"
862 "add $8, %0 \n\t"
863 "cmp %4, %0 \n\t"
864 " jb 1b \n\t"
865 : "+r" (ptr)
866 : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
867 );
868 }
5a6a9e78
AJ
869 }
870}
871
826f429a 872#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
bb270c08
DB
873 "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
874 "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
875 "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
876 "movq "#in7", " #m3 " \n\t" /* d */\
877 "movq "#in0", %%mm5 \n\t" /* D */\
878 "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
879 "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
880 "movq "#in1", %%mm5 \n\t" /* C */\
881 "movq "#in2", %%mm6 \n\t" /* B */\
882 "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
883 "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
884 "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
885 "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
886 "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
887 "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
888 "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
889 "psraw $5, %%mm5 \n\t"\
890 "packuswb %%mm5, %%mm5 \n\t"\
826f429a
MN
891 OP(%%mm5, out, %%mm7, d)
892
3b549121
DB
893#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW) \
894static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, \
895 uint8_t *src, \
896 int dstStride, \
897 int srcStride, \
898 int h) \
899{ \
900 uint64_t temp; \
901 \
be449fca 902 __asm__ volatile(\
bb270c08
DB
903 "pxor %%mm7, %%mm7 \n\t"\
904 "1: \n\t"\
905 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
906 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
907 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
908 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
909 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
910 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
911 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
912 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
913 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
914 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
915 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
916 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
917 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
918 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
919 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
920 "paddw %%mm3, %%mm5 \n\t" /* b */\
921 "paddw %%mm2, %%mm6 \n\t" /* c */\
922 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
923 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
924 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
925 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
926 "paddw %%mm4, %%mm0 \n\t" /* a */\
927 "paddw %%mm1, %%mm5 \n\t" /* d */\
928 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
929 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
930 "paddw %6, %%mm6 \n\t"\
931 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
932 "psraw $5, %%mm0 \n\t"\
933 "movq %%mm0, %5 \n\t"\
826f429a
MN
934 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
935 \
bb270c08
DB
936 "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
937 "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
938 "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
939 "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
940 "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
941 "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
942 "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
943 "paddw %%mm0, %%mm2 \n\t" /* b */\
944 "paddw %%mm5, %%mm3 \n\t" /* c */\
945 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
946 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
947 "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
948 "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
949 "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
950 "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
951 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
952 "paddw %%mm2, %%mm1 \n\t" /* a */\
953 "paddw %%mm6, %%mm4 \n\t" /* d */\
954 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
955 "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
956 "paddw %6, %%mm1 \n\t"\
957 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
958 "psraw $5, %%mm3 \n\t"\
959 "movq %5, %%mm1 \n\t"\
960 "packuswb %%mm3, %%mm1 \n\t"\
3178ee4c 961 OP_MMX2(%%mm1, (%1),%%mm4, q)\
826f429a
MN
962 /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
963 \
bb270c08
DB
964 "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
965 "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
966 "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
967 "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
968 "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
969 "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
970 "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
971 "paddw %%mm1, %%mm5 \n\t" /* b */\
972 "paddw %%mm4, %%mm0 \n\t" /* c */\
973 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
974 "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
975 "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
976 "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
977 "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
978 "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
979 "paddw %%mm3, %%mm2 \n\t" /* d */\
980 "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
981 "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
982 "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
983 "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
984 "paddw %%mm2, %%mm6 \n\t" /* a */\
985 "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
986 "paddw %6, %%mm0 \n\t"\
987 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
988 "psraw $5, %%mm0 \n\t"\
826f429a
MN
989 /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
990 \
bb270c08
DB
991 "paddw %%mm5, %%mm3 \n\t" /* a */\
992 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
993 "paddw %%mm4, %%mm6 \n\t" /* b */\
994 "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
995 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
996 "paddw %%mm1, %%mm4 \n\t" /* c */\
997 "paddw %%mm2, %%mm5 \n\t" /* d */\
998 "paddw %%mm6, %%mm6 \n\t" /* 2b */\
999 "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
1000 "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1001 "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
1002 "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
1003 "paddw %6, %%mm4 \n\t"\
1004 "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
1005 "psraw $5, %%mm4 \n\t"\
1006 "packuswb %%mm4, %%mm0 \n\t"\
3178ee4c 1007 OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
826f429a 1008 \
bb270c08
DB
1009 "add %3, %0 \n\t"\
1010 "add %4, %1 \n\t"\
1011 "decl %2 \n\t"\
1012 " jnz 1b \n\t"\
943032b1 1013 : "+a"(src), "+c"(dst), "+D"(h)\
40d0e665 1014 : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
0b093b6f 1015 : "memory"\
826f429a 1016 );\
3b549121
DB
1017} \
1018 \
1019static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, \
1020 uint8_t *src, \
1021 int dstStride, \
1022 int srcStride, \
1023 int h) \
1024{ \
1025 int i; \
1026 int16_t temp[16]; \
1027 /* quick HACK, XXX FIXME MUST be optimized */ \
1028 for (i = 0; i < h; i++) { \
1029 temp[ 0] = (src[ 0] + src[ 1]) * 20 - (src[ 0] + src[ 2]) * 6 + \
1030 (src[ 1] + src[ 3]) * 3 - (src[ 2] + src[ 4]); \
1031 temp[ 1] = (src[ 1] + src[ 2]) * 20 - (src[ 0] + src[ 3]) * 6 + \
1032 (src[ 0] + src[ 4]) * 3 - (src[ 1] + src[ 5]); \
1033 temp[ 2] = (src[ 2] + src[ 3]) * 20 - (src[ 1] + src[ 4]) * 6 + \
1034 (src[ 0] + src[ 5]) * 3 - (src[ 0] + src[ 6]); \
1035 temp[ 3] = (src[ 3] + src[ 4]) * 20 - (src[ 2] + src[ 5]) * 6 + \
1036 (src[ 1] + src[ 6]) * 3 - (src[ 0] + src[ 7]); \
1037 temp[ 4] = (src[ 4] + src[ 5]) * 20 - (src[ 3] + src[ 6]) * 6 + \
1038 (src[ 2] + src[ 7]) * 3 - (src[ 1] + src[ 8]); \
1039 temp[ 5] = (src[ 5] + src[ 6]) * 20 - (src[ 4] + src[ 7]) * 6 + \
1040 (src[ 3] + src[ 8]) * 3 - (src[ 2] + src[ 9]); \
1041 temp[ 6] = (src[ 6] + src[ 7]) * 20 - (src[ 5] + src[ 8]) * 6 + \
1042 (src[ 4] + src[ 9]) * 3 - (src[ 3] + src[10]); \
1043 temp[ 7] = (src[ 7] + src[ 8]) * 20 - (src[ 6] + src[ 9]) * 6 + \
1044 (src[ 5] + src[10]) * 3 - (src[ 4] + src[11]); \
1045 temp[ 8] = (src[ 8] + src[ 9]) * 20 - (src[ 7] + src[10]) * 6 + \
1046 (src[ 6] + src[11]) * 3 - (src[ 5] + src[12]); \
1047 temp[ 9] = (src[ 9] + src[10]) * 20 - (src[ 8] + src[11]) * 6 + \
1048 (src[ 7] + src[12]) * 3 - (src[ 6] + src[13]); \
1049 temp[10] = (src[10] + src[11]) * 20 - (src[ 9] + src[12]) * 6 + \
1050 (src[ 8] + src[13]) * 3 - (src[ 7] + src[14]); \
1051 temp[11] = (src[11] + src[12]) * 20 - (src[10] + src[13]) * 6 + \
1052 (src[ 9] + src[14]) * 3 - (src[ 8] + src[15]); \
1053 temp[12] = (src[12] + src[13]) * 20 - (src[11] + src[14]) * 6 + \
1054 (src[10] + src[15]) * 3 - (src[ 9] + src[16]); \
1055 temp[13] = (src[13] + src[14]) * 20 - (src[12] + src[15]) * 6 + \
1056 (src[11] + src[16]) * 3 - (src[10] + src[16]); \
1057 temp[14] = (src[14] + src[15]) * 20 - (src[13] + src[16]) * 6 + \
1058 (src[12] + src[16]) * 3 - (src[11] + src[15]); \
1059 temp[15] = (src[15] + src[16]) * 20 - (src[14] + src[16]) * 6 + \
1060 (src[13] + src[15]) * 3 - (src[12] + src[14]); \
be449fca 1061 __asm__ volatile(\
bb270c08
DB
1062 "movq (%0), %%mm0 \n\t"\
1063 "movq 8(%0), %%mm1 \n\t"\
1064 "paddw %2, %%mm0 \n\t"\
1065 "paddw %2, %%mm1 \n\t"\
1066 "psraw $5, %%mm0 \n\t"\
1067 "psraw $5, %%mm1 \n\t"\
1068 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1069 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
bb270c08
DB
1070 "movq 16(%0), %%mm0 \n\t"\
1071 "movq 24(%0), %%mm1 \n\t"\
1072 "paddw %2, %%mm0 \n\t"\
1073 "paddw %2, %%mm1 \n\t"\
1074 "psraw $5, %%mm0 \n\t"\
1075 "psraw $5, %%mm1 \n\t"\
1076 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1077 OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
826f429a 1078 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1079 : "memory"\
826f429a 1080 );\
3b549121
DB
1081 dst += dstStride; \
1082 src += srcStride; \
1083 } \
1084} \
1085 \
1086static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, \
1087 uint8_t *src, \
1088 int dstStride, \
1089 int srcStride, \
1090 int h) \
1091{ \
be449fca 1092 __asm__ volatile(\
bb270c08
DB
1093 "pxor %%mm7, %%mm7 \n\t"\
1094 "1: \n\t"\
1095 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
1096 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
1097 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
1098 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
1099 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
1100 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
1101 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
1102 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
1103 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
1104 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
1105 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
1106 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
1107 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
1108 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
1109 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
1110 "paddw %%mm3, %%mm5 \n\t" /* b */\
1111 "paddw %%mm2, %%mm6 \n\t" /* c */\
1112 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1113 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
1114 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
1115 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
1116 "paddw %%mm4, %%mm0 \n\t" /* a */\
1117 "paddw %%mm1, %%mm5 \n\t" /* d */\
1118 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1119 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
dea00a46 1120 "paddw %5, %%mm6 \n\t"\
bb270c08
DB
1121 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1122 "psraw $5, %%mm0 \n\t"\
826f429a
MN
1123 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1124 \
bb270c08
DB
1125 "movd 5(%0), %%mm5 \n\t" /* FGHI */\
1126 "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
1127 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
1128 "paddw %%mm5, %%mm1 \n\t" /* a */\
1129 "paddw %%mm6, %%mm2 \n\t" /* b */\
1130 "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
1131 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
1132 "paddw %%mm6, %%mm3 \n\t" /* c */\
1133 "paddw %%mm5, %%mm4 \n\t" /* d */\
1134 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
1135 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
1136 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1137 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
1138 "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
dea00a46 1139 "paddw %5, %%mm1 \n\t"\
bb270c08
DB
1140 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
1141 "psraw $5, %%mm3 \n\t"\
1142 "packuswb %%mm3, %%mm0 \n\t"\
3178ee4c 1143 OP_MMX2(%%mm0, (%1), %%mm4, q)\
826f429a 1144 \
bb270c08
DB
1145 "add %3, %0 \n\t"\
1146 "add %4, %1 \n\t"\
1147 "decl %2 \n\t"\
1148 " jnz 1b \n\t"\
943032b1 1149 : "+a"(src), "+c"(dst), "+d"(h)\
40d0e665 1150 : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
0b093b6f 1151 : "memory"\
826f429a 1152 );\
3b549121
DB
1153} \
1154 \
1155static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, \
1156 uint8_t *src, \
1157 int dstStride, \
1158 int srcStride, \
1159 int h) \
1160{ \
1161 int i; \
1162 int16_t temp[8]; \
1163 /* quick HACK, XXX FIXME MUST be optimized */ \
1164 for (i = 0; i < h; i++) { \
1165 temp[0] = (src[0] + src[1]) * 20 - (src[0] + src[2]) * 6 + \
1166 (src[1] + src[3]) * 3 - (src[2] + src[4]); \
1167 temp[1] = (src[1] + src[2]) * 20 - (src[0] + src[3]) * 6 + \
1168 (src[0] + src[4]) * 3 - (src[1] + src[5]); \
1169 temp[2] = (src[2] + src[3]) * 20 - (src[1] + src[4]) * 6 + \
1170 (src[0] + src[5]) * 3 - (src[0] + src[6]); \
1171 temp[3] = (src[3] + src[4]) * 20 - (src[2] + src[5]) * 6 + \
1172 (src[1] + src[6]) * 3 - (src[0] + src[7]); \
1173 temp[4] = (src[4] + src[5]) * 20 - (src[3] + src[6]) * 6 + \
1174 (src[2] + src[7]) * 3 - (src[1] + src[8]); \
1175 temp[5] = (src[5] + src[6]) * 20 - (src[4] + src[7]) * 6 + \
1176 (src[3] + src[8]) * 3 - (src[2] + src[8]); \
1177 temp[6] = (src[6] + src[7]) * 20 - (src[5] + src[8]) * 6 + \
1178 (src[4] + src[8]) * 3 - (src[3] + src[7]); \
1179 temp[7] = (src[7] + src[8]) * 20 - (src[6] + src[8]) * 6 + \
1180 (src[5] + src[7]) * 3 - (src[4] + src[6]); \
be449fca 1181 __asm__ volatile(\
bb270c08
DB
1182 "movq (%0), %%mm0 \n\t"\
1183 "movq 8(%0), %%mm1 \n\t"\
1184 "paddw %2, %%mm0 \n\t"\
1185 "paddw %2, %%mm1 \n\t"\
1186 "psraw $5, %%mm0 \n\t"\
1187 "psraw $5, %%mm1 \n\t"\
1188 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1189 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a 1190 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1191 :"memory"\
826f429a 1192 );\
3b549121
DB
1193 dst += dstStride; \
1194 src += srcStride; \
1195 } \
1196}
1197
1198#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX) \
1199static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, \
1200 uint8_t *src, \
1201 int dstStride, \
1202 int srcStride) \
1203{ \
1204 uint64_t temp[17 * 4]; \
1205 uint64_t *temp_ptr = temp; \
1206 int count = 17; \
1207 \
3178ee4c 1208 /*FIXME unroll */\
be449fca 1209 __asm__ volatile(\
bb270c08
DB
1210 "pxor %%mm7, %%mm7 \n\t"\
1211 "1: \n\t"\
1212 "movq (%0), %%mm0 \n\t"\
1213 "movq (%0), %%mm1 \n\t"\
1214 "movq 8(%0), %%mm2 \n\t"\
1215 "movq 8(%0), %%mm3 \n\t"\
1216 "punpcklbw %%mm7, %%mm0 \n\t"\
1217 "punpckhbw %%mm7, %%mm1 \n\t"\
1218 "punpcklbw %%mm7, %%mm2 \n\t"\
1219 "punpckhbw %%mm7, %%mm3 \n\t"\
1220 "movq %%mm0, (%1) \n\t"\
1221 "movq %%mm1, 17*8(%1) \n\t"\
1222 "movq %%mm2, 2*17*8(%1) \n\t"\
1223 "movq %%mm3, 3*17*8(%1) \n\t"\
1224 "add $8, %1 \n\t"\
1225 "add %3, %0 \n\t"\
1226 "decl %2 \n\t"\
1227 " jnz 1b \n\t"\
3178ee4c 1228 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
40d0e665 1229 : "r" ((x86_reg)srcStride)\
0b093b6f 1230 : "memory"\
3178ee4c 1231 );\
3b549121
DB
1232 \
1233 temp_ptr = temp; \
1234 count = 4; \
1235 \
3178ee4c 1236/*FIXME reorder for speed */\
be449fca 1237 __asm__ volatile(\
bb270c08
DB
1238 /*"pxor %%mm7, %%mm7 \n\t"*/\
1239 "1: \n\t"\
1240 "movq (%0), %%mm0 \n\t"\
1241 "movq 8(%0), %%mm1 \n\t"\
1242 "movq 16(%0), %%mm2 \n\t"\
1243 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
1244 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
1245 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
bb270c08 1246 "add %4, %1 \n\t"\
c296f66b 1247 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
3178ee4c 1248 \
c296f66b 1249 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
bb270c08 1250 "add %4, %1 \n\t"\
c296f66b
MN
1251 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1252 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
bb270c08 1253 "add %4, %1 \n\t"\
c296f66b
MN
1254 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
1255 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
bb270c08 1256 "add %4, %1 \n\t"\
c296f66b
MN
1257 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
1258 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
bb270c08 1259 "add %4, %1 \n\t"\
c296f66b
MN
1260 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
1261 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
bb270c08 1262 "add %4, %1 \n\t"\
c296f66b 1263 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
3178ee4c 1264 \
c296f66b 1265 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
bb270c08 1266 "add %4, %1 \n\t" \
c296f66b
MN
1267 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
1268 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
3178ee4c 1269 \
bb270c08
DB
1270 "add $136, %0 \n\t"\
1271 "add %6, %1 \n\t"\
1272 "decl %2 \n\t"\
1273 " jnz 1b \n\t"\
3178ee4c 1274 \
5a508a98 1275 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
40d0e665 1276 : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(x86_reg)dstStride)\
0b093b6f 1277 :"memory"\
3178ee4c 1278 );\
3b549121
DB
1279} \
1280 \
1281static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, \
1282 uint8_t *src, \
1283 int dstStride, \
1284 int srcStride) \
1285{ \
1286 uint64_t temp[9 * 2]; \
1287 uint64_t *temp_ptr = temp; \
1288 int count = 9; \
1289 \
826f429a 1290 /*FIXME unroll */\
be449fca 1291 __asm__ volatile(\
bb270c08
DB
1292 "pxor %%mm7, %%mm7 \n\t"\
1293 "1: \n\t"\
1294 "movq (%0), %%mm0 \n\t"\
1295 "movq (%0), %%mm1 \n\t"\
1296 "punpcklbw %%mm7, %%mm0 \n\t"\
1297 "punpckhbw %%mm7, %%mm1 \n\t"\
1298 "movq %%mm0, (%1) \n\t"\
1299 "movq %%mm1, 9*8(%1) \n\t"\
1300 "add $8, %1 \n\t"\
1301 "add %3, %0 \n\t"\
1302 "decl %2 \n\t"\
1303 " jnz 1b \n\t"\
826f429a 1304 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
40d0e665 1305 : "r" ((x86_reg)srcStride)\
0b093b6f 1306 : "memory"\
826f429a 1307 );\
3b549121
DB
1308 \
1309 temp_ptr = temp; \
1310 count = 2; \
1311 \
826f429a 1312/*FIXME reorder for speed */\
be449fca 1313 __asm__ volatile(\
bb270c08
DB
1314 /*"pxor %%mm7, %%mm7 \n\t"*/\
1315 "1: \n\t"\
1316 "movq (%0), %%mm0 \n\t"\
1317 "movq 8(%0), %%mm1 \n\t"\
1318 "movq 16(%0), %%mm2 \n\t"\
1319 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
1320 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
1321 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
bb270c08 1322 "add %4, %1 \n\t"\
c296f66b 1323 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
826f429a 1324 \
c296f66b 1325 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
bb270c08 1326 "add %4, %1 \n\t"\
c296f66b 1327 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
826f429a 1328 \
c296f66b 1329 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
bb270c08 1330 "add %4, %1 \n\t"\
c296f66b
MN
1331 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
1332 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
826f429a 1333 \
bb270c08
DB
1334 "add $72, %0 \n\t"\
1335 "add %6, %1 \n\t"\
1336 "decl %2 \n\t"\
1337 " jnz 1b \n\t"\
826f429a 1338 \
c296f66b 1339 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
40d0e665 1340 : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(x86_reg)dstStride)\
0b093b6f
MN
1341 : "memory"\
1342 );\
3b549121
DB
1343} \
1344 \
1345static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
1346 int stride) \
1347{ \
1348 OPNAME ## pixels8_ ## MMX(dst, src, stride, 8); \
1349} \
1350 \
1351static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
1352 int stride) \
1353{ \
1354 uint64_t temp[8]; \
1355 uint8_t * const half = (uint8_t*)temp; \
1356 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
1357 stride, 8); \
1358 OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8); \
1359} \
1360 \
1361static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
1362 int stride) \
1363{ \
1364 OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, \
1365 stride, 8); \
1366} \
1367 \
1368static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
1369 int stride) \
1370{ \
1371 uint64_t temp[8]; \
1372 uint8_t * const half = (uint8_t*)temp; \
1373 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, \
1374 stride, 8); \
1375 OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride, \
1376 stride, 8); \
1377} \
1378 \
1379static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
1380 int stride) \
1381{ \
1382 uint64_t temp[8]; \
1383 uint8_t * const half = (uint8_t*)temp; \
1384 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride); \
1385 OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8); \
1386} \
1387 \
1388static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
1389 int stride) \
1390{ \
1391 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride); \
1392} \
1393 \
1394static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
1395 int stride) \
1396{ \
1397 uint64_t temp[8]; \
1398 uint8_t * const half = (uint8_t*)temp; \
1399 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride); \
1400 OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride, \
1401 stride, 8); \
1402} \
1403 \
1404static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
1405 int stride) \
1406{ \
1407 uint64_t half[8 + 9]; \
1408 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1409 uint8_t * const halfHV = ((uint8_t*)half); \
1410 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1411 stride, 9); \
1412 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
1413 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1414 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
1415} \
1416 \
1417static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
1418 int stride) \
1419{ \
1420 uint64_t half[8 + 9]; \
1421 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1422 uint8_t * const halfHV = ((uint8_t*)half); \
1423 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1424 stride, 9); \
1425 put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
1426 stride, 9); \
1427 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1428 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
1429} \
1430 \
1431static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
1432 int stride) \
1433{ \
1434 uint64_t half[8 + 9]; \
1435 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1436 uint8_t * const halfHV = ((uint8_t*)half); \
1437 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1438 stride, 9); \
1439 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
1440 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1441 OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
1442} \
1443 \
1444static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
1445 int stride) \
1446{ \
1447 uint64_t half[8 + 9]; \
1448 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1449 uint8_t * const halfHV = ((uint8_t*)half); \
1450 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1451 stride, 9); \
1452 put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
1453 stride, 9); \
1454 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1455 OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
1456} \
1457 \
1458static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
1459 int stride) \
1460{ \
1461 uint64_t half[8 + 9]; \
1462 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1463 uint8_t * const halfHV = ((uint8_t*)half); \
1464 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1465 stride, 9); \
1466 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1467 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8); \
1468} \
1469 \
1470static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
1471 int stride) \
1472{ \
1473 uint64_t half[8 + 9]; \
1474 uint8_t * const halfH = ((uint8_t*)half) + 64; \
1475 uint8_t * const halfHV = ((uint8_t*)half); \
1476 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1477 stride, 9); \
1478 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8); \
1479 OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV, stride, 8, 8); \
1480} \
1481 \
1482static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
1483 int stride) \
1484{ \
1485 uint64_t half[8 + 9]; \
1486 uint8_t * const halfH = ((uint8_t*)half); \
1487 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1488 stride, 9); \
1489 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9); \
1490 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
1491} \
1492 \
1493static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
1494 int stride) \
1495{ \
1496 uint64_t half[8 + 9]; \
1497 uint8_t * const halfH = ((uint8_t*)half); \
1498 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1499 stride, 9); \
1500 put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8, \
1501 stride, 9); \
1502 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
1503} \
1504 \
1505static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
1506 int stride) \
1507{ \
1508 uint64_t half[9]; \
1509 uint8_t * const halfH = ((uint8_t*)half); \
1510 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, \
1511 stride, 9); \
1512 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8); \
1513} \
1514 \
1515static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, \
1516 int stride) \
1517{ \
1518 OPNAME ## pixels16_ ## MMX(dst, src, stride, 16); \
1519} \
1520 \
1521static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, \
1522 int stride) \
1523{ \
1524 uint64_t temp[32]; \
1525 uint8_t * const half = (uint8_t*)temp; \
1526 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
1527 stride, 16); \
1528 OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16); \
1529} \
1530 \
1531static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, \
1532 int stride) \
1533{ \
1534 OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, \
1535 stride, stride, 16); \
1536} \
1537 \
1538static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, \
1539 int stride) \
1540{ \
1541 uint64_t temp[32]; \
1542 uint8_t * const half = (uint8_t*)temp; \
1543 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, \
1544 stride, 16); \
1545 OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half, \
1546 stride, stride, 16); \
1547} \
1548 \
1549static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, \
1550 int stride) \
1551{ \
1552 uint64_t temp[32]; \
1553 uint8_t * const half = (uint8_t*)temp; \
1554 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
1555 stride); \
1556 OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16); \
1557} \
1558 \
1559static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, \
1560 int stride) \
1561{ \
1562 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride); \
1563} \
1564 \
1565static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, \
1566 int stride) \
1567{ \
1568 uint64_t temp[32]; \
1569 uint8_t * const half = (uint8_t*)temp; \
1570 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, \
1571 stride); \
1572 OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, \
1573 stride, stride, 16); \
1574} \
1575 \
1576static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, \
1577 int stride) \
1578{ \
1579 uint64_t half[16 * 2 + 17 * 2]; \
1580 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1581 uint8_t * const halfHV = ((uint8_t*)half); \
1582 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1583 stride, 17); \
1584 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
1585 stride, 17); \
1586 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1587 16, 16); \
1588 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
1589} \
1590 \
1591static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, \
1592 int stride) \
1593{ \
1594 uint64_t half[16 * 2 + 17 * 2]; \
1595 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1596 uint8_t * const halfHV = ((uint8_t*)half); \
1597 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1598 stride, 17); \
1599 put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
1600 stride, 17); \
1601 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1602 16, 16); \
1603 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
1604} \
1605 \
1606static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, \
1607 int stride) \
1608{ \
1609 uint64_t half[16 * 2 + 17 * 2]; \
1610 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1611 uint8_t * const halfHV = ((uint8_t*)half); \
1612 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1613 stride, 17); \
1614 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
1615 stride, 17); \
1616 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1617 16, 16); \
1618 OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
1619 16, 16); \
1620} \
1621 \
1622static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, \
1623 int stride) \
1624{ \
1625 uint64_t half[16 * 2 + 17 * 2]; \
1626 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1627 uint8_t * const halfHV = ((uint8_t*)half); \
1628 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1629 stride, 17); \
1630 put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
1631 stride, 17); \
1632 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1633 16, 16); \
1634 OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
1635 16, 16); \
1636} \
1637 \
1638static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, \
1639 int stride) \
1640{ \
1641 uint64_t half[16 * 2 + 17 * 2]; \
1642 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1643 uint8_t * const halfHV = ((uint8_t*)half); \
1644 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1645 stride, 17); \
1646 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1647 16, 16); \
1648 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16); \
1649} \
1650 \
1651static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, \
1652 int stride) \
1653{ \
1654 uint64_t half[16 * 2 + 17 * 2]; \
1655 uint8_t * const halfH = ((uint8_t*)half) + 256; \
1656 uint8_t * const halfHV = ((uint8_t*)half); \
1657 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1658 stride, 17); \
1659 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, \
1660 16, 16); \
1661 OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV, stride, \
1662 16, 16); \
1663} \
1664 \
1665static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, \
1666 int stride) \
1667{ \
1668 uint64_t half[17 * 2]; \
1669 uint8_t * const halfH = ((uint8_t*)half); \
1670 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1671 stride, 17); \
1672 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, \
1673 stride, 17); \
1674 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
1675} \
1676 \
1677static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, \
1678 int stride) \
1679{ \
1680 uint64_t half[17 * 2]; \
1681 uint8_t * const halfH = ((uint8_t*)half); \
1682 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1683 stride, 17); \
1684 put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16, \
1685 stride, 17); \
1686 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
1687} \
1688 \
1689static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, \
1690 int stride) \
1691{ \
1692 uint64_t half[17 * 2]; \
1693 uint8_t * const halfH = ((uint8_t*)half); \
1694 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, \
1695 stride, 17); \
1696 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16); \
826f429a
MN
1697}
1698
bb270c08 1699#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
3178ee4c 1700#define AVG_3DNOW_OP(a,b,temp, size) \
bb270c08
DB
1701"mov" #size " " #b ", " #temp " \n\t"\
1702"pavgusb " #temp ", " #a " \n\t"\
1703"mov" #size " " #a ", " #b " \n\t"
3178ee4c 1704#define AVG_MMX2_OP(a,b,temp, size) \
bb270c08
DB
1705"mov" #size " " #b ", " #temp " \n\t"\
1706"pavgb " #temp ", " #a " \n\t"\
1707"mov" #size " " #a ", " #b " \n\t"
3178ee4c
MN
1708
1709QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
1710QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
1711QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
1712QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
1713QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
1714QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
826f429a 1715QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
3178ee4c 1716QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
826f429a
MN
1717QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
1718
2833fc46
LM
1719/***********************************/
1720/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
1721
3b549121
DB
1722#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL) \
1723static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
1724 uint8_t *src, \
1725 int stride) \
1726{ \
1727 OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE); \
1728}
1729
1730#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2) \
1731static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, \
1732 uint8_t *src, \
1733 int stride) \
1734{ \
1735 OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src + S0, stride, SIZE, \
1736 S1, S2); \
1737}
1738
1739#define QPEL_2TAP(OPNAME, SIZE, MMX) \
1740QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX) \
1741QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX) \
1742QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx) \
1743static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX = \
1744 OPNAME ## qpel ## SIZE ## _mc00_ ## MMX; \
1745static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX = \
1746 OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX; \
1747static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX = \
1748 OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX; \
1749static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, \
1750 uint8_t *src, \
1751 int stride) \
1752{ \
1753 OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src + 1, stride, SIZE); \
1754} \
1755static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, \
1756 uint8_t *src, \
1757 int stride) \
1758{ \
1759 OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src + stride, \
1760 stride, SIZE); \
1761} \
1762QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0, 1, 0) \
1763QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1, -1, 0) \
1764QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0, stride, 0) \
1765QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride, -stride, 0) \
1766QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0, stride, 1) \
1767QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1, stride, -1) \
1768QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride, -stride, 1) \
1769QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride + 1, -stride, -1) \
2833fc46
LM
1770
1771QPEL_2TAP(put_, 16, mmx2)
1772QPEL_2TAP(avg_, 16, mmx2)
1773QPEL_2TAP(put_, 8, mmx2)
1774QPEL_2TAP(avg_, 8, mmx2)
1775QPEL_2TAP(put_, 16, 3dnow)
1776QPEL_2TAP(avg_, 16, 3dnow)
1777QPEL_2TAP(put_, 8, 3dnow)
1778QPEL_2TAP(avg_, 8, 3dnow)
1779
1780
81f2a3f4 1781#if HAVE_YASM
3b549121
DB
1782typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
1783 x86_reg linesize, x86_reg start_y,
1784 x86_reg end_y, x86_reg block_h,
1785 x86_reg start_x, x86_reg end_x,
1786 x86_reg block_w);
81f2a3f4
RB
1787extern emu_edge_core_func ff_emu_edge_core_mmx;
1788extern emu_edge_core_func ff_emu_edge_core_sse;
1789
3b549121
DB
1790static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
1791 int linesize,
1792 int block_w, int block_h,
1793 int src_x, int src_y,
1794 int w, int h,
1795 emu_edge_core_func *core_fn)
81f2a3f4 1796{
3b549121
DB
1797 int start_y, start_x, end_y, end_x, src_y_add = 0;
1798
1799 if (src_y >= h) {
1800 src_y_add = h - 1 - src_y;
1801 src_y = h - 1;
1802 } else if (src_y <= -block_h) {
1803 src_y_add = 1 - block_h - src_y;
1804 src_y = 1 - block_h;
81f2a3f4 1805 }
3b549121
DB
1806 if (src_x >= w) {
1807 src += w - 1 - src_x;
1808 src_x = w - 1;
1809 } else if (src_x <= -block_w) {
1810 src += 1 - block_w - src_x;
1811 src_x = 1 - block_w;
81f2a3f4
RB
1812 }
1813
3b549121
DB
1814 start_y = FFMAX(0, -src_y);
1815 start_x = FFMAX(0, -src_x);
1816 end_y = FFMIN(block_h, h-src_y);
1817 end_x = FFMIN(block_w, w-src_x);
81f2a3f4
RB
1818 assert(start_x < end_x && block_w > 0);
1819 assert(start_y < end_y && block_h > 0);
1820
1821 // fill in the to-be-copied part plus all above/below
3b549121 1822 src += (src_y_add + start_y) * linesize + start_x;
81f2a3f4 1823 buf += start_x;
3b549121
DB
1824 core_fn(buf, src, linesize, start_y, end_y,
1825 block_h, start_x, end_x, block_w);
81f2a3f4
RB
1826}
1827
1828#if ARCH_X86_32
3b549121
DB
1829static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src,
1830 int linesize,
1831 int block_w, int block_h,
1832 int src_x, int src_y, int w, int h)
81f2a3f4
RB
1833{
1834 emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
1835 w, h, &ff_emu_edge_core_mmx);
1836}
1837#endif
3b549121
DB
1838
1839static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
1840 int linesize,
1841 int block_w, int block_h,
1842 int src_x, int src_y, int w, int h)
81f2a3f4
RB
1843{
1844 emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
1845 w, h, &ff_emu_edge_core_sse);
1846}
1847#endif /* HAVE_YASM */
1848
3b549121
DB
1849typedef void emulated_edge_mc_func(uint8_t *dst, const uint8_t *src,
1850 int linesize, int block_w, int block_h,
1851 int src_x, int src_y, int w, int h);
81f2a3f4 1852
3b549121
DB
1853static av_always_inline void gmc(uint8_t *dst, uint8_t *src,
1854 int stride, int h, int ox, int oy,
1855 int dxx, int dxy, int dyx, int dyy,
1856 int shift, int r, int width, int height,
1857 emulated_edge_mc_func *emu_edge_fn)
81f2a3f4 1858{
3b549121
DB
1859 const int w = 8;
1860 const int ix = ox >> (16 + shift);
1861 const int iy = oy >> (16 + shift);
1862 const int oxs = ox >> 4;
1863 const int oys = oy >> 4;
1864 const int dxxs = dxx >> 4;
1865 const int dxys = dxy >> 4;
1866 const int dyxs = dyx >> 4;
1867 const int dyys = dyy >> 4;
1868 const uint16_t r4[4] = { r, r, r, r };
1869 const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };
1870 const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };
1871 const uint64_t shift2 = 2 * shift;
1872 uint8_t edge_buf[(h + 1) * stride];
703c8195
LM
1873 int x, y;
1874
3b549121
DB
1875 const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);
1876 const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);
1877 const int dxh = dxy * (h - 1);
1878 const int dyw = dyx * (w - 1);
1879 if ( // non-constant fullpel offset (3% of blocks)
1880 ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |
1881 (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift)
703c8195 1882 // uses more than 16 bits of subpel mv (only at huge resolution)
3b549121 1883 || (dxx | dxy | dyx | dyy) & 15) {
703c8195 1884 //FIXME could still use mmx for some of the rows
3b549121
DB
1885 ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,
1886 shift, r, width, height);
703c8195
LM
1887 return;
1888 }
1889
3b549121
DB
1890 src += ix + iy * stride;
1891 if ((unsigned)ix >= width - w ||
1892 (unsigned)iy >= height - h) {
1893 emu_edge_fn(edge_buf, src, stride, w + 1, h + 1, ix, iy, width, height);
703c8195
LM
1894 src = edge_buf;
1895 }
75ca1a5f 1896
be449fca 1897 __asm__ volatile(
75ca1a5f
LM
1898 "movd %0, %%mm6 \n\t"
1899 "pxor %%mm7, %%mm7 \n\t"
1900 "punpcklwd %%mm6, %%mm6 \n\t"
1901 "punpcklwd %%mm6, %%mm6 \n\t"
1902 :: "r"(1<<shift)
1903 );
703c8195 1904
3b549121
DB
1905 for (x = 0; x < w; x += 4) {
1906 uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),
1907 oxs - dxys + dxxs * (x + 1),
1908 oxs - dxys + dxxs * (x + 2),
1909 oxs - dxys + dxxs * (x + 3) };
1910 uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),
1911 oys - dyys + dyxs * (x + 1),
1912 oys - dyys + dyxs * (x + 2),
1913 oys - dyys + dyxs * (x + 3) };
1914
1915 for (y = 0; y < h; y++) {
be449fca 1916 __asm__ volatile(
703c8195
LM
1917 "movq %0, %%mm4 \n\t"
1918 "movq %1, %%mm5 \n\t"
1919 "paddw %2, %%mm4 \n\t"
1920 "paddw %3, %%mm5 \n\t"
1921 "movq %%mm4, %0 \n\t"
1922 "movq %%mm5, %1 \n\t"
1923 "psrlw $12, %%mm4 \n\t"
1924 "psrlw $12, %%mm5 \n\t"
1925 : "+m"(*dx4), "+m"(*dy4)
1926 : "m"(*dxy4), "m"(*dyy4)
1927 );
1928
be449fca 1929 __asm__ volatile(
703c8195
LM
1930 "movq %%mm6, %%mm2 \n\t"
1931 "movq %%mm6, %%mm1 \n\t"
1932 "psubw %%mm4, %%mm2 \n\t"
1933 "psubw %%mm5, %%mm1 \n\t"
1934 "movq %%mm2, %%mm0 \n\t"
1935 "movq %%mm4, %%mm3 \n\t"
1936 "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
1937 "pmullw %%mm5, %%mm3 \n\t" // dx*dy
1938 "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
1939 "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
1940
1941 "movd %4, %%mm5 \n\t"
1942 "movd %3, %%mm4 \n\t"
1943 "punpcklbw %%mm7, %%mm5 \n\t"
1944 "punpcklbw %%mm7, %%mm4 \n\t"
1945 "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
1946 "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
1947
1948 "movd %2, %%mm5 \n\t"
1949 "movd %1, %%mm4 \n\t"
1950 "punpcklbw %%mm7, %%mm5 \n\t"
1951 "punpcklbw %%mm7, %%mm4 \n\t"
1952 "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
1953 "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
75ca1a5f 1954 "paddw %5, %%mm1 \n\t"
703c8195
LM
1955 "paddw %%mm3, %%mm2 \n\t"
1956 "paddw %%mm1, %%mm0 \n\t"
1957 "paddw %%mm2, %%mm0 \n\t"
703c8195
LM
1958
1959 "psrlw %6, %%mm0 \n\t"
1960 "packuswb %%mm0, %%mm0 \n\t"
1961 "movd %%mm0, %0 \n\t"
1962
1963 : "=m"(dst[x+y*stride])
1964 : "m"(src[0]), "m"(src[1]),
1965 "m"(src[stride]), "m"(src[stride+1]),
1966 "m"(*r4), "m"(shift2)
1967 );
1968 src += stride;
1969 }
3b549121 1970 src += 4 - h * stride;
703c8195
LM
1971 }
1972}
1973
81f2a3f4
RB
1974#if HAVE_YASM
1975#if ARCH_X86_32
3b549121
DB
1976static void gmc_mmx(uint8_t *dst, uint8_t *src,
1977 int stride, int h, int ox, int oy,
1978 int dxx, int dxy, int dyx, int dyy,
1979 int shift, int r, int width, int height)
81f2a3f4
RB
1980{
1981 gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
1982 width, height, &emulated_edge_mc_mmx);
1983}
1984#endif
3b549121
DB
1985static void gmc_sse(uint8_t *dst, uint8_t *src,
1986 int stride, int h, int ox, int oy,
1987 int dxx, int dxy, int dyx, int dyy,
1988 int shift, int r, int width, int height)
81f2a3f4
RB
1989{
1990 gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
1991 width, height, &emulated_edge_mc_sse);
1992}
1993#else
3b549121
DB
1994static void gmc_mmx(uint8_t *dst, uint8_t *src,
1995 int stride, int h, int ox, int oy,
1996 int dxx, int dxy, int dyx, int dyy,
1997 int shift, int r, int width, int height)
81f2a3f4
RB
1998{
1999 gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
710b8df9 2000 width, height, &ff_emulated_edge_mc_8);
81f2a3f4
RB
2001}
2002#endif
2003
3b549121
DB
2004#define PREFETCH(name, op) \
2005static void name(void *mem, int stride, int h) \
2006{ \
2007 const uint8_t *p = mem; \
2008 do { \
2009 __asm__ volatile(#op" %0" :: "m"(*p)); \
2010 p += stride; \
2011 } while (--h); \
513fbd8e 2012}
3b549121 2013
513fbd8e
LM
2014PREFETCH(prefetch_mmx2, prefetcht0)
2015PREFETCH(prefetch_3dnow, prefetch)
2016#undef PREFETCH
2017
14bc1f24 2018#include "h264_qpel_mmx.c"
d0eb5a11 2019
3b549121
DB
2020void ff_put_h264_chroma_mc8_mmx_rnd (uint8_t *dst, uint8_t *src,
2021 int stride, int h, int x, int y);
2022void ff_avg_h264_chroma_mc8_mmx2_rnd (uint8_t *dst, uint8_t *src,
2023 int stride, int h, int x, int y);
2024void ff_avg_h264_chroma_mc8_3dnow_rnd(uint8_t *dst, uint8_t *src,
2025 int stride, int h, int x, int y);
2026
2027void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
2028 int stride, int h, int x, int y);
2029void ff_avg_h264_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
2030 int stride, int h, int x, int y);
2031void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
2032 int stride, int h, int x, int y);
2033
2034void ff_put_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
2035 int stride, int h, int x, int y);
2036void ff_avg_h264_chroma_mc2_mmx2 (uint8_t *dst, uint8_t *src,
2037 int stride, int h, int x, int y);
2038
2039void ff_put_h264_chroma_mc8_ssse3_rnd(uint8_t *dst, uint8_t *src,
2040 int stride, int h, int x, int y);
2041void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
2042 int stride, int h, int x, int y);
2043
2044void ff_avg_h264_chroma_mc8_ssse3_rnd(uint8_t *dst, uint8_t *src,
2045 int stride, int h, int x, int y);
2046void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
2047 int stride, int h, int x, int y);
2048
2049#define CHROMA_MC(OP, NUM, DEPTH, OPT) \
2050void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
2051 (uint8_t *dst, uint8_t *src, \
f188a1e0
DK
2052 int stride, int h, int x, int y);
2053
2054CHROMA_MC(put, 2, 10, mmxext)
2055CHROMA_MC(avg, 2, 10, mmxext)
2056CHROMA_MC(put, 4, 10, mmxext)
2057CHROMA_MC(avg, 4, 10, mmxext)
2058CHROMA_MC(put, 8, 10, sse2)
2059CHROMA_MC(avg, 8, 10, sse2)
2060CHROMA_MC(put, 8, 10, avx)
2061CHROMA_MC(avg, 8, 10, avx)
115329f1 2062
3b549121
DB
2063/* CAVS-specific */
2064void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride)
2065{
595e7bd9
SG
2066 put_pixels8_mmx(dst, src, stride, 8);
2067}
3b549121
DB
2068
2069void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride)
2070{
595e7bd9
SG
2071 avg_pixels8_mmx(dst, src, stride, 8);
2072}
3b549121
DB
2073
2074void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride)
2075{
595e7bd9
SG
2076 put_pixels16_mmx(dst, src, stride, 16);
2077}
3b549121
DB
2078
2079void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride)
2080{
595e7bd9
SG
2081 avg_pixels16_mmx(dst, src, stride, 16);
2082}
2083
3b549121
DB
2084/* VC-1-specific */
2085void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src,
2086 int stride, int rnd)
2087{
5b67ce2a
AJ
2088 put_pixels8_mmx(dst, src, stride, 8);
2089}
3b549121
DB
2090
2091void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src,
2092 int stride, int rnd)
2093{
9bf0fdf3
DC
2094 avg_pixels8_mmx2(dst, src, stride, 8);
2095}
5b67ce2a 2096
3b549121
DB
2097/* XXX: Those functions should be suppressed ASAP when all IDCTs are
2098 * converted. */
b250f9c6 2099#if CONFIG_GPL
3b549121
DB
2100static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size,
2101 DCTELEM *block)
b0368839 2102{
3b549121 2103 ff_mmx_idct(block);
7e7c4b60 2104 ff_put_pixels_clamped_mmx(block, dest, line_size);
b0368839 2105}
3b549121
DB
2106
2107static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size,
2108 DCTELEM *block)
b0368839 2109{
3b549121 2110 ff_mmx_idct(block);
7e7c4b60 2111 ff_add_pixels_clamped_mmx(block, dest, line_size);
b0368839 2112}
3b549121
DB
2113
2114static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size,
2115 DCTELEM *block)
b0368839 2116{
3b549121 2117 ff_mmxext_idct(block);
7e7c4b60 2118 ff_put_pixels_clamped_mmx(block, dest, line_size);
b0368839 2119}
3b549121
DB
2120
2121static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size,
2122 DCTELEM *block)
b0368839 2123{
3b549121 2124 ff_mmxext_idct(block);
7e7c4b60 2125 ff_add_pixels_clamped_mmx(block, dest, line_size);
b0368839 2126}
7c428ea6 2127#endif
3b549121 2128
84740d59
MN
2129static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
2130{
3b549121 2131 ff_idct_xvid_mmx(block);
7e7c4b60 2132 ff_put_pixels_clamped_mmx(block, dest, line_size);
84740d59 2133}
3b549121 2134
84740d59
MN
2135static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
2136{
3b549121 2137 ff_idct_xvid_mmx(block);
7e7c4b60 2138 ff_add_pixels_clamped_mmx(block, dest, line_size);
84740d59 2139}
3b549121 2140
84740d59
MN
2141static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
2142{
3b549121 2143 ff_idct_xvid_mmx2(block);
7e7c4b60 2144 ff_put_pixels_clamped_mmx(block, dest, line_size);
84740d59 2145}
3b549121 2146
84740d59
MN
2147static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
2148{
3b549121 2149 ff_idct_xvid_mmx2(block);
7e7c4b60 2150 ff_add_pixels_clamped_mmx(block, dest, line_size);
84740d59 2151}
115329f1 2152
cd035a60 2153static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
2dac4acf
LM
2154{
2155 int i;
be449fca 2156 __asm__ volatile("pxor %%mm7, %%mm7":);
3b549121 2157 for (i = 0; i < blocksize; i += 2) {
be449fca 2158 __asm__ volatile(
2dac4acf
LM
2159 "movq %0, %%mm0 \n\t"
2160 "movq %1, %%mm1 \n\t"
2161 "movq %%mm0, %%mm2 \n\t"
2162 "movq %%mm1, %%mm3 \n\t"
2163 "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
2164 "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
2165 "pslld $31, %%mm2 \n\t" // keep only the sign bit
2166 "pxor %%mm2, %%mm1 \n\t"
2167 "movq %%mm3, %%mm4 \n\t"
2168 "pand %%mm1, %%mm3 \n\t"
2169 "pandn %%mm1, %%mm4 \n\t"
2170 "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
2171 "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
2172 "movq %%mm3, %1 \n\t"
2173 "movq %%mm0, %0 \n\t"
2174 :"+m"(mag[i]), "+m"(ang[i])
2175 ::"memory"
2176 );
2177 }
be449fca 2178 __asm__ volatile("femms");
2dac4acf 2179}
3b549121 2180
21bb884f 2181static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
2dac4acf
LM
2182{
2183 int i;
21bb884f 2184
be449fca 2185 __asm__ volatile(
21bb884f
MN
2186 "movaps %0, %%xmm5 \n\t"
2187 ::"m"(ff_pdw_80000000[0])
2188 );
3b549121 2189 for (i = 0; i < blocksize; i += 4) {
be449fca 2190 __asm__ volatile(
2dac4acf
LM
2191 "movaps %0, %%xmm0 \n\t"
2192 "movaps %1, %%xmm1 \n\t"
21bb884f
MN
2193 "xorps %%xmm2, %%xmm2 \n\t"
2194 "xorps %%xmm3, %%xmm3 \n\t"
2dac4acf
LM
2195 "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
2196 "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
21bb884f
MN
2197 "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
2198 "xorps %%xmm2, %%xmm1 \n\t"
2dac4acf 2199 "movaps %%xmm3, %%xmm4 \n\t"
21bb884f
MN
2200 "andps %%xmm1, %%xmm3 \n\t"
2201 "andnps %%xmm1, %%xmm4 \n\t"
2dac4acf
LM
2202 "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
2203 "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
2204 "movaps %%xmm3, %1 \n\t"
2205 "movaps %%xmm0, %0 \n\t"
2206 :"+m"(mag[i]), "+m"(ang[i])
2207 ::"memory"
2208 );
2209 }
2210}
2211
ac2e5564
LM
2212#define IF1(x) x
2213#define IF0(x)
2214
2215#define MIX5(mono,stereo)\
be449fca 2216 __asm__ volatile(\
ac2e5564
LM
2217 "movss 0(%2), %%xmm5 \n"\
2218 "movss 8(%2), %%xmm6 \n"\
2219 "movss 24(%2), %%xmm7 \n"\
2220 "shufps $0, %%xmm5, %%xmm5 \n"\
2221 "shufps $0, %%xmm6, %%xmm6 \n"\
2222 "shufps $0, %%xmm7, %%xmm7 \n"\
2223 "1: \n"\
2224 "movaps (%0,%1), %%xmm0 \n"\
2225 "movaps 0x400(%0,%1), %%xmm1 \n"\
2226 "movaps 0x800(%0,%1), %%xmm2 \n"\
2227 "movaps 0xc00(%0,%1), %%xmm3 \n"\
2228 "movaps 0x1000(%0,%1), %%xmm4 \n"\
2229 "mulps %%xmm5, %%xmm0 \n"\
2230 "mulps %%xmm6, %%xmm1 \n"\
2231 "mulps %%xmm5, %%xmm2 \n"\
2232 "mulps %%xmm7, %%xmm3 \n"\
2233 "mulps %%xmm7, %%xmm4 \n"\
2234 stereo("addps %%xmm1, %%xmm0 \n")\
2235 "addps %%xmm1, %%xmm2 \n"\
2236 "addps %%xmm3, %%xmm0 \n"\
2237 "addps %%xmm4, %%xmm2 \n"\
2238 mono("addps %%xmm2, %%xmm0 \n")\
2239 "movaps %%xmm0, (%0,%1) \n"\
2240 stereo("movaps %%xmm2, 0x400(%0,%1) \n")\
2241 "add $16, %0 \n"\
2242 "jl 1b \n"\
2243 :"+&r"(i)\
2244 :"r"(samples[0]+len), "r"(matrix)\
153ca56b
RP
2245 :XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
2246 "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\
2247 "memory"\
ac2e5564
LM
2248 );
2249
2250#define MIX_MISC(stereo)\
be449fca 2251 __asm__ volatile(\
ac2e5564
LM
2252 "1: \n"\
2253 "movaps (%3,%0), %%xmm0 \n"\
2254 stereo("movaps %%xmm0, %%xmm1 \n")\
559738ef
RP
2255 "mulps %%xmm4, %%xmm0 \n"\
2256 stereo("mulps %%xmm5, %%xmm1 \n")\
ac2e5564
LM
2257 "lea 1024(%3,%0), %1 \n"\
2258 "mov %5, %2 \n"\
2259 "2: \n"\
2260 "movaps (%1), %%xmm2 \n"\
2261 stereo("movaps %%xmm2, %%xmm3 \n")\
2262 "mulps (%4,%2), %%xmm2 \n"\
2263 stereo("mulps 16(%4,%2), %%xmm3 \n")\
2264 "addps %%xmm2, %%xmm0 \n"\
2265 stereo("addps %%xmm3, %%xmm1 \n")\
2266 "add $1024, %1 \n"\
2267 "add $32, %2 \n"\
2268 "jl 2b \n"\
2269 "movaps %%xmm0, (%3,%0) \n"\
2270 stereo("movaps %%xmm1, 1024(%3,%0) \n")\
2271 "add $16, %0 \n"\
2272 "jl 1b \n"\
2273 :"+&r"(i), "=&r"(j), "=&r"(k)\
2274 :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
2275 :"memory"\
2276 );
2277
3b549121
DB
2278static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2],
2279 int out_ch, int in_ch, int len)
ac2e5564
LM
2280{
2281 int (*matrix_cmp)[2] = (int(*)[2])matrix;
3b549121
DB
2282 intptr_t i, j, k;
2283
2284 i = -len * sizeof(float);
2285 if (in_ch == 5 && out_ch == 2 &&
2286 !(matrix_cmp[0][1] | matrix_cmp[2][0] |
2287 matrix_cmp[3][1] | matrix_cmp[4][0] |
2288 (matrix_cmp[1][0] ^ matrix_cmp[1][1]) |
2289 (matrix_cmp[0][0] ^ matrix_cmp[2][1]))) {
2290 MIX5(IF0, IF1);
2291 } else if (in_ch == 5 && out_ch == 1 &&
2292 matrix_cmp[0][0] == matrix_cmp[2][0] &&
2293 matrix_cmp[3][0] == matrix_cmp[4][0]) {
2294 MIX5(IF1, IF0);
ac2e5564 2295 } else {
ac3c9d01 2296 DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
3b549121 2297 j = 2 * in_ch * sizeof(float);
be449fca 2298 __asm__ volatile(
ac2e5564
LM
2299 "1: \n"
2300 "sub $8, %0 \n"
559738ef
RP
2301 "movss (%2,%0), %%xmm4 \n"
2302 "movss 4(%2,%0), %%xmm5 \n"
2303 "shufps $0, %%xmm4, %%xmm4 \n"
2304 "shufps $0, %%xmm5, %%xmm5 \n"
2305 "movaps %%xmm4, (%1,%0,4) \n"
2306 "movaps %%xmm5, 16(%1,%0,4) \n"
ac2e5564
LM
2307 "jg 1b \n"
2308 :"+&r"(j)
2309 :"r"(matrix_simd), "r"(matrix)
2310 :"memory"
2311 );
3b549121 2312 if (out_ch == 2) {
ac2e5564
LM
2313 MIX_MISC(IF1);
2314 } else {
2315 MIX_MISC(IF0);
2316 }
2317 }
2318}
2319
3b549121
DB
2320static void vector_fmul_3dnow(float *dst, const float *src0, const float *src1,
2321 int len)
2322{
2323 x86_reg i = (len - 4) * 4;
be449fca 2324 __asm__ volatile(
06972056 2325 "1: \n\t"
6eabb0d3
JR
2326 "movq (%2,%0), %%mm0 \n\t"
2327 "movq 8(%2,%0), %%mm1 \n\t"
2328 "pfmul (%3,%0), %%mm0 \n\t"
2329 "pfmul 8(%3,%0), %%mm1 \n\t"
06972056
LM
2330 "movq %%mm0, (%1,%0) \n\t"
2331 "movq %%mm1, 8(%1,%0) \n\t"
2332 "sub $16, %0 \n\t"
2333 "jge 1b \n\t"
2334 "femms \n\t"
2335 :"+r"(i)
6eabb0d3 2336 :"r"(dst), "r"(src0), "r"(src1)
06972056
LM
2337 :"memory"
2338 );
eb4825b5 2339}
3b549121
DB
2340
2341static void vector_fmul_sse(float *dst, const float *src0, const float *src1,
2342 int len)
2343{
2344 x86_reg i = (len - 8) * 4;
be449fca 2345 __asm__ volatile(
06972056 2346 "1: \n\t"
6eabb0d3
JR
2347 "movaps (%2,%0), %%xmm0 \n\t"
2348 "movaps 16(%2,%0), %%xmm1 \n\t"
2349 "mulps (%3,%0), %%xmm0 \n\t"
2350 "mulps 16(%3,%0), %%xmm1 \n\t"
06972056
LM
2351 "movaps %%xmm0, (%1,%0) \n\t"
2352 "movaps %%xmm1, 16(%1,%0) \n\t"
2353 "sub $32, %0 \n\t"
2354 "jge 1b \n\t"
2355 :"+r"(i)
6eabb0d3 2356 :"r"(dst), "r"(src0), "r"(src1)
06972056
LM
2357 :"memory"
2358 );
eb4825b5
LM
2359}
2360
3b549121
DB
2361static void vector_fmul_reverse_3dnow2(float *dst, const float *src0,
2362 const float *src1, int len)
2363{
2364 x86_reg i = len * 4 - 16;
be449fca 2365 __asm__ volatile(
eb4825b5
LM
2366 "1: \n\t"
2367 "pswapd 8(%1), %%mm0 \n\t"
2368 "pswapd (%1), %%mm1 \n\t"
2369 "pfmul (%3,%0), %%mm0 \n\t"
2370 "pfmul 8(%3,%0), %%mm1 \n\t"
2371 "movq %%mm0, (%2,%0) \n\t"
2372 "movq %%mm1, 8(%2,%0) \n\t"
2373 "add $16, %1 \n\t"
2374 "sub $16, %0 \n\t"
2375 "jge 1b \n\t"
2376 :"+r"(i), "+r"(src1)
2377 :"r"(dst), "r"(src0)
2378 );
be449fca 2379 __asm__ volatile("femms");
eb4825b5 2380}
3b549121
DB
2381
2382static void vector_fmul_reverse_sse(float *dst, const float *src0,
2383 const float *src1, int len)
2384{
2385 x86_reg i = len * 4 - 32;
be449fca 2386 __asm__ volatile(
eb4825b5 2387 "1: \n\t"
1f1aa1d9
MN
2388 "movaps 16(%1), %%xmm0 \n\t"
2389 "movaps (%1), %%xmm1 \n\t"
2390 "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
2391 "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
eb4825b5
LM
2392 "mulps (%3,%0), %%xmm0 \n\t"
2393 "mulps 16(%3,%0), %%xmm1 \n\t"
2394 "movaps %%xmm0, (%2,%0) \n\t"
2395 "movaps %%xmm1, 16(%2,%0) \n\t"
2396 "add $32, %1 \n\t"
2397 "sub $32, %0 \n\t"
2398 "jge 1b \n\t"
2399 :"+r"(i), "+r"(src1)
2400 :"r"(dst), "r"(src0)
2401 );
2402}
2403
3b549121
DB
2404static void vector_fmul_add_3dnow(float *dst, const float *src0,
2405 const float *src1, const float *src2, int len)
2406{
2407 x86_reg i = (len - 4) * 4;
35de5d24
MR
2408 __asm__ volatile(
2409 "1: \n\t"
2410 "movq (%2,%0), %%mm0 \n\t"
2411 "movq 8(%2,%0), %%mm1 \n\t"
2412 "pfmul (%3,%0), %%mm0 \n\t"
2413 "pfmul 8(%3,%0), %%mm1 \n\t"
2414 "pfadd (%4,%0), %%mm0 \n\t"
2415 "pfadd 8(%4,%0), %%mm1 \n\t"
2416 "movq %%mm0, (%1,%0) \n\t"
2417 "movq %%mm1, 8(%1,%0) \n\t"
2418 "sub $16, %0 \n\t"
2419 "jge 1b \n\t"
2420 :"+r"(i)
2421 :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2422 :"memory"
2423 );
be449fca 2424 __asm__ volatile("femms");
eb4825b5 2425}
3b549121
DB
2426
2427static void vector_fmul_add_sse(float *dst, const float *src0,
2428 const float *src1, const float *src2, int len)
2429{
2430 x86_reg i = (len - 8) * 4;
35de5d24
MR
2431 __asm__ volatile(
2432 "1: \n\t"
2433 "movaps (%2,%0), %%xmm0 \n\t"
2434 "movaps 16(%2,%0), %%xmm1 \n\t"
2435 "mulps (%3,%0), %%xmm0 \n\t"
2436 "mulps 16(%3,%0), %%xmm1 \n\t"
2437 "addps (%4,%0), %%xmm0 \n\t"
2438 "addps 16(%4,%0), %%xmm1 \n\t"
2439 "movaps %%xmm0, (%1,%0) \n\t"
2440 "movaps %%xmm1, 16(%1,%0) \n\t"
2441 "sub $32, %0 \n\t"
2442 "jge 1b \n\t"
2443 :"+r"(i)
2444 :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2445 :"memory"
2446 );
eb4825b5
LM
2447}
2448
b250f9c6 2449#if HAVE_6REGS
3b549121
DB
2450static void vector_fmul_window_3dnow2(float *dst, const float *src0,
2451 const float *src1, const float *win,
2452 int len)
2453{
2454 x86_reg i = -len * 4;
2455 x86_reg j = len * 4 - 8;
d19b744a
JR
2456 __asm__ volatile(
2457 "1: \n"
2458 "pswapd (%5,%1), %%mm1 \n"
2459 "movq (%5,%0), %%mm0 \n"
2460 "pswapd (%4,%1), %%mm5 \n"
2461 "movq (%3,%0), %%mm4 \n"
2462 "movq %%mm0, %%mm2 \n"
2463 "movq %%mm1, %%mm3 \n"
2464 "pfmul %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
2465 "pfmul %%mm5, %%mm3 \n" // src1[ j]*win[len+j]
2466 "pfmul %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
2467 "pfmul %%mm5, %%mm0 \n" // src1[ j]*win[len+i]
2468 "pfadd %%mm3, %%mm2 \n"
2469 "pfsub %%mm0, %%mm1 \n"
2470 "pswapd %%mm2, %%mm2 \n"
2471 "movq %%mm1, (%2,%0) \n"
2472 "movq %%mm2, (%2,%1) \n"
2473 "sub $8, %1 \n"
2474 "add $8, %0 \n"
2475 "jl 1b \n"
2476 "femms \n"
2477 :"+r"(i), "+r"(j)
2478 :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2479 );
b9fa3208
LM
2480}
2481
3b549121
DB
2482static void vector_fmul_window_sse(float *dst, const float *src0,
2483 const float *src1, const float *win, int len)
2484{
2485 x86_reg i = -len * 4;
2486 x86_reg j = len * 4 - 16;
d19b744a
JR
2487 __asm__ volatile(
2488 "1: \n"
2489 "movaps (%5,%1), %%xmm1 \n"
2490 "movaps (%5,%0), %%xmm0 \n"
2491 "movaps (%4,%1), %%xmm5 \n"
2492 "movaps (%3,%0), %%xmm4 \n"
2493 "shufps $0x1b, %%xmm1, %%xmm1 \n"
2494 "shufps $0x1b, %%xmm5, %%xmm5 \n"
2495 "movaps %%xmm0, %%xmm2 \n"
2496 "movaps %%xmm1, %%xmm3 \n"
2497 "mulps %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
2498 "mulps %%xmm5, %%xmm3 \n" // src1[ j]*win[len+j]
2499 "mulps %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
2500 "mulps %%xmm5, %%xmm0 \n" // src1[ j]*win[len+i]
2501 "addps %%xmm3, %%xmm2 \n"
2502 "subps %%xmm0, %%xmm1 \n"
2503 "shufps $0x1b, %%xmm2, %%xmm2 \n"
2504 "movaps %%xmm1, (%2,%0) \n"
2505 "movaps %%xmm2, (%2,%1) \n"
2506 "sub $16, %1 \n"
2507 "add $16, %0 \n"
2508 "jl 1b \n"
2509 :"+r"(i), "+r"(j)
2510 :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2511 );
f27e1d64 2512}
80ba1ddb 2513#endif /* HAVE_6REGS */
f27e1d64 2514
3b549121
DB
2515static void vector_clipf_sse(float *dst, const float *src,
2516 float min, float max, int len)
0a68cd87 2517{
3b549121 2518 x86_reg i = (len - 16) * 4;
0a68cd87
VS
2519 __asm__ volatile(
2520 "movss %3, %%xmm4 \n"
2521 "movss %4, %%xmm5 \n"
2522 "shufps $0, %%xmm4, %%xmm4 \n"
2523 "shufps $0, %%xmm5, %%xmm5 \n"
2524 "1: \n\t"
2525 "movaps (%2,%0), %%xmm0 \n\t" // 3/1 on intel
2526 "movaps 16(%2,%0), %%xmm1 \n\t"
2527 "movaps 32(%2,%0), %%xmm2 \n\t"
2528 "movaps 48(%2,%0), %%xmm3 \n\t"
2529 "maxps %%xmm4, %%xmm0 \n\t"
2530 "maxps %%xmm4, %%xmm1 \n\t"
2531 "maxps %%xmm4, %%xmm2 \n\t"
2532 "maxps %%xmm4, %%xmm3 \n\t"
2533 "minps %%xmm5, %%xmm0 \n\t"
2534 "minps %%xmm5, %%xmm1 \n\t"
2535 "minps %%xmm5, %%xmm2 \n\t"
2536 "minps %%xmm5, %%xmm3 \n\t"
2537 "movaps %%xmm0, (%1,%0) \n\t"
2538 "movaps %%xmm1, 16(%1,%0) \n\t"
2539 "movaps %%xmm2, 32(%1,%0) \n\t"
2540 "movaps %%xmm3, 48(%1,%0) \n\t"
2541 "sub $64, %0 \n\t"
2542 "jge 1b \n\t"
9263a05a 2543 :"+&r"(i)
0a68cd87
VS
2544 :"r"(dst), "r"(src), "m"(min), "m"(max)
2545 :"memory"
2546 );
2547}
2548
e9f5f020
RB
2549void ff_vp3_idct_mmx(int16_t *input_data);
2550void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2551void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2552
3b549121
DB
2553void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size,
2554 const DCTELEM *block);
e9f5f020
RB
2555
2556void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2557void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2558
2559void ff_vp3_idct_sse2(int16_t *input_data);
2560void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2561void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2562
3b549121
DB
2563int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2,
2564 int order, int shift);
2565int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
2566 int order, int shift);
2567int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2,
2568 const int16_t *v3,
2569 int order, int mul);
2570int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2,
2571 const int16_t *v3,
2572 int order, int mul);
2573int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2,
2574 const int16_t *v3,
2575 int order, int mul);
e6e98234
JR
2576
2577void ff_apply_window_int16_mmxext (int16_t *output, const int16_t *input,
2578 const int16_t *window, unsigned int len);
2579void ff_apply_window_int16_mmxext_ba (int16_t *output, const int16_t *input,
2580 const int16_t *window, unsigned int len);
2581void ff_apply_window_int16_sse2 (int16_t *output, const int16_t *input,
2582 const int16_t *window, unsigned int len);
2583void ff_apply_window_int16_sse2_ba (int16_t *output, const int16_t *input,
2584 const int16_t *window, unsigned int len);
2585void ff_apply_window_int16_ssse3 (int16_t *output, const int16_t *input,
2586 const int16_t *window, unsigned int len);
2587void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
2588 const int16_t *window, unsigned int len);
2589
6b039003
CG
2590void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
2591void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
2592
3b549121
DB
2593void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top,
2594 const uint8_t *diff, int w,
2595 int *left, int *left_top);
2596int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src,
2597 int w, int left);
2598int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
2599 int w, int left);
14bc1f24 2600
3deb5384
AC
2601float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
2602
3b549121
DB
2603void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
2604 int32_t min, int32_t max, unsigned int len);
2605void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
2606 int32_t min, int32_t max, unsigned int len);
2607void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
2608 int32_t min, int32_t max, unsigned int len);
2609void ff_vector_clip_int32_sse4 (int32_t *dst, const int32_t *src,
2610 int32_t min, int32_t max, unsigned int len);
6054cd25 2611
9d06037d
JR
2612extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0,
2613 const float *src1, int len);
2614extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
2615 const float *src1, int len);
2616
3b549121 2617#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
3816642e 2618 do { \
356ee8d7
MR
2619 c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
2620 c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
2621 c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
2622 c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
2623 c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
2624 c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
2625 c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
2626 c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
2627 c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
2628 c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
2629 c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
2630 c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
2631 c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
2632 c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
2633 c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
3816642e
DB
2634 c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
2635 } while (0)
356ee8d7 2636
3b549121
DB
2637#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
2638 do { \
2639 c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
2640 c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
2641 c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
2642 c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
3816642e 2643 } while (0)
356ee8d7 2644
3b549121
DB
2645#define H264_QPEL_FUNCS(x, y, CPU) \
2646 do { \
2647 c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
2648 c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc ## x ## y ## _ ## CPU; \
2649 c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
2650 c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc ## x ## y ## _ ## CPU; \
3816642e 2651 } while (0)
356ee8d7 2652
3b549121
DB
2653#define H264_QPEL_FUNCS_10(x, y, CPU) \
2654 do { \
2655 c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
2656 c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
2657 c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
2658 c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
3816642e 2659 } while (0)
356ee8d7
MR
2660
2661static void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
2662{
2663 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
2664
2665 c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
2666 c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
2667 c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
2668
2669 if (!high_bit_depth) {
2670 c->clear_block = clear_block_mmx;
2671 c->clear_blocks = clear_blocks_mmx;
2672 c->draw_edges = draw_edges_mmx;
2673
3b549121 2674 SET_HPEL_FUNCS(put, 0, 16, mmx);
356ee8d7 2675 SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
3b549121 2676 SET_HPEL_FUNCS(avg, 0, 16, mmx);
356ee8d7 2677 SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
3b549121
DB
2678 SET_HPEL_FUNCS(put, 1, 8, mmx);
2679 SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
2680 SET_HPEL_FUNCS(avg, 1, 8, mmx);
2681 SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
356ee8d7
MR
2682 }
2683
2684#if ARCH_X86_32 || !HAVE_YASM
3b549121 2685 c->gmc = gmc_mmx;
356ee8d7
MR
2686#endif
2687#if ARCH_X86_32 && HAVE_YASM
2688 if (!high_bit_depth)
2689 c->emulated_edge_mc = emulated_edge_mc_mmx;
2690#endif
2691
2692 c->add_bytes = add_bytes_mmx;
2693
2694 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2695 c->h263_v_loop_filter = h263_v_loop_filter_mmx;
2696 c->h263_h_loop_filter = h263_h_loop_filter_mmx;
2697 }
2698
2699#if HAVE_YASM
2700 if (!high_bit_depth && CONFIG_H264CHROMA) {
2701 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_mmx_rnd;
2702 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
2703 }
2704
2705 c->vector_clip_int32 = ff_vector_clip_int32_mmx;
2706#endif
2707
2708}
2709
2710static void dsputil_init_mmx2(DSPContext *c, AVCodecContext *avctx,
2711 int mm_flags)
2712{
2713 const int bit_depth = avctx->bits_per_raw_sample;
2714 const int high_bit_depth = bit_depth > 8;
2715
2716 c->prefetch = prefetch_mmx2;
2717
2718 if (!high_bit_depth) {
2719 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2720 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
2721
2722 c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2723 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2724 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
2725
2726 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2727 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
2728
2729 c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2730 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2731 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
2732 }
2733
2734 if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
2735 if (!high_bit_depth) {
2736 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2737 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2738 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2739 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2740
2741 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2742 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
2743 }
2744
2745 if (CONFIG_VP3_DECODER && HAVE_YASM) {
2746 c->vp3_v_loop_filter = ff_vp3_v_loop_filter_mmx2;
2747 c->vp3_h_loop_filter = ff_vp3_h_loop_filter_mmx2;
2748 }
2749 }
3b549121 2750 if (CONFIG_VP3_DECODER && HAVE_YASM)
356ee8d7 2751 c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
356ee8d7 2752
3b549121
DB
2753 if (CONFIG_VP3_DECODER && (avctx->codec_id == CODEC_ID_VP3 ||
2754 avctx->codec_id == CODEC_ID_THEORA)) {
356ee8d7
MR
2755 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
2756 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
2757 }
2758
915a2a0a 2759 if (CONFIG_H264QPEL) {
3b549121
DB
2760 SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2, );
2761 SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2, );
2762 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2, );
2763 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2, );
2764 SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2, );
2765 SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2, );
356ee8d7 2766
3b549121
DB
2767 if (!high_bit_depth) {
2768 SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2, );
2769 SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2, );
2770 SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2, );
2771 SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2, );
2772 SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2, );
2773 SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2, );
2774 } else if (bit_depth == 10) {
356ee8d7
MR
2775#if HAVE_YASM
2776#if !ARCH_X86_64
3b549121
DB
2777 SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
2778 SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
2779 SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
2780 SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
356ee8d7 2781#endif
3b549121
DB
2782 SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
2783 SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
356ee8d7 2784#endif
3b549121 2785 }
356ee8d7 2786
3b549121
DB
2787 SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2, );
2788 SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2, );
2789 SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2, );
2790 SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2, );
915a2a0a 2791 }
356ee8d7
MR
2792
2793#if HAVE_YASM
2794 if (!high_bit_depth && CONFIG_H264CHROMA) {
2795 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_mmx2_rnd;
2796 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmx2;
2797 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmx2;
2798 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmx2;
2799 }
2800 if (bit_depth == 10 && CONFIG_H264CHROMA) {
2801 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
2802 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
2803 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
2804 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
2805 }
2806
3b549121 2807 c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
356ee8d7
MR
2808
2809 c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
2810 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
2811
2812 if (avctx->flags & CODEC_FLAG_BITEXACT) {
2813 c->apply_window_int16 = ff_apply_window_int16_mmxext_ba;
2814 } else {
2815 c->apply_window_int16 = ff_apply_window_int16_mmxext;
2816 }
2817#endif
2818}
2819
2820static void dsputil_init_3dnow(DSPContext *c, AVCodecContext *avctx,
2821 int mm_flags)
2822{
2823 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
2824
2825 c->prefetch = prefetch_3dnow;
2826
2827 if (!high_bit_depth) {
2828 c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
2829 c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
2830
2831 c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
2832 c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
2833 c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
2834
2835 c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
2836 c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
2837
2838 c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
2839 c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
2840 c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
2841
2842 if (!(avctx->flags & CODEC_FLAG_BITEXACT)){
2843 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
2844 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
2845 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
2846 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
2847
2848 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
2849 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
2850 }
2851 }
2852
3b549121
DB
2853 if (CONFIG_VP3_DECODER && (avctx->codec_id == CODEC_ID_VP3 ||
2854 avctx->codec_id == CODEC_ID_THEORA)) {
356ee8d7
MR
2855 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
2856 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
2857 }
2858
915a2a0a 2859 if (CONFIG_H264QPEL) {
3b549121
DB
2860 SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow, );
2861 SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow, );
2862 SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow, );
2863 SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow, );
2864 SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow, );
2865 SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow, );
356ee8d7 2866
3b549121
DB
2867 if (!high_bit_depth) {
2868 SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow, );
2869 SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow, );
2870 SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow, );
2871 SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow, );
2872 SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow, );
2873 SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow, );
2874 }
356ee8d7 2875
3b549121
DB
2876 SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow, );
2877 SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow, );
2878 SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow, );
2879 SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow, );
915a2a0a 2880 }
356ee8d7
MR
2881
2882#if HAVE_YASM
2883 if (!high_bit_depth && CONFIG_H264CHROMA) {
2884 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_3dnow_rnd;
2885 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
2886 }
2887#endif
2888
2889 c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
2890 c->vector_fmul = vector_fmul_3dnow;
2891 c->vector_fmul_add = vector_fmul_add_3dnow;
2892
2893#if HAVE_7REGS
2894 c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
2895#endif
2896}
2897
2898static void dsputil_init_3dnow2(DSPContext *c, AVCodecContext *avctx,
2899 int mm_flags)
2900{
2901 c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
2902#if HAVE_6REGS
2903 c->vector_fmul_window = vector_fmul_window_3dnow2;
2904#endif
2905}
2906
2907static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags)
de6d9b64 2908{
a617c6aa 2909 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
356ee8d7
MR
2910
2911 if (!high_bit_depth) {
3b549121 2912 if (!(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)) {
356ee8d7
MR
2913 /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
2914 c->clear_block = clear_block_sse;
2915 c->clear_blocks = clear_blocks_sse;
2916 }
2917 }
2918
2919 c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
2920 c->ac3_downmix = ac3_downmix_sse;
2921 c->vector_fmul = vector_fmul_sse;
2922 c->vector_fmul_reverse = vector_fmul_reverse_sse;
2923
2924 if (!(mm_flags & AV_CPU_FLAG_3DNOW))
2925 c->vector_fmul_add = vector_fmul_add_sse;
2926
2927#if HAVE_6REGS
2928 c->vector_fmul_window = vector_fmul_window_sse;
2929#endif
2930
2931 c->vector_clipf = vector_clipf_sse;
2932
2933#if HAVE_YASM
2934 c->scalarproduct_float = ff_scalarproduct_float_sse;
2935 c->butterflies_float_interleave = ff_butterflies_float_interleave_sse;
2936
2937 if (!high_bit_depth)
2938 c->emulated_edge_mc = emulated_edge_mc_sse;
2939 c->gmc = gmc_sse;
2940#endif
2941}
2942
2943static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
2944 int mm_flags)
2945{
2946 const int bit_depth = avctx->bits_per_raw_sample;
2947 const int high_bit_depth = bit_depth > 8;
2948
2949 if (mm_flags & AV_CPU_FLAG_3DNOW) {
2950 // these functions are slower than mmx on AMD, but faster on Intel
2951 if (!high_bit_depth) {
2952 c->put_pixels_tab[0][0] = put_pixels16_sse2;
2953 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2;
2954 c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
915a2a0a
DB
2955 if (CONFIG_H264QPEL)
2956 H264_QPEL_FUNCS(0, 0, sse2);
356ee8d7
MR
2957 }
2958 }
2959
915a2a0a 2960 if (!high_bit_depth && CONFIG_H264QPEL) {
356ee8d7
MR
2961 H264_QPEL_FUNCS(0, 1, sse2);
2962 H264_QPEL_FUNCS(0, 2, sse2);
2963 H264_QPEL_FUNCS(0, 3, sse2);
2964 H264_QPEL_FUNCS(1, 1, sse2);
2965 H264_QPEL_FUNCS(1, 2, sse2);
2966 H264_QPEL_FUNCS(1, 3, sse2);
2967 H264_QPEL_FUNCS(2, 1, sse2);
2968 H264_QPEL_FUNCS(2, 2, sse2);
2969 H264_QPEL_FUNCS(2, 3, sse2);
2970 H264_QPEL_FUNCS(3, 1, sse2);
2971 H264_QPEL_FUNCS(3, 2, sse2);
2972 H264_QPEL_FUNCS(3, 3, sse2);
2973 }
2974
2975#if HAVE_YASM
2976 if (bit_depth == 10) {
915a2a0a 2977 if (CONFIG_H264QPEL) {
3b549121
DB
2978 SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
2979 SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
2980 SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
2981 SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
2982 H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
2983 H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
2984 H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
915a2a0a 2985 }
356ee8d7
MR
2986 if (CONFIG_H264CHROMA) {
2987 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
2988 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
2989 }
2990 }
2991
2992 c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
2993 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
2994 if (mm_flags & AV_CPU_FLAG_ATOM) {
2995 c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
2996 } else {
2997 c->vector_clip_int32 = ff_vector_clip_int32_sse2;
2998 }
2999 if (avctx->flags & CODEC_FLAG_BITEXACT) {
3000 c->apply_window_int16 = ff_apply_window_int16_sse2_ba;
3b549121 3001 } else if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
356ee8d7
MR
3002 c->apply_window_int16 = ff_apply_window_int16_sse2;
3003 }
3004 c->bswap_buf = ff_bswap32_buf_sse2;
3005#endif
3006}
3007
3008static void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
3009 int mm_flags)
3010{
3011#if HAVE_SSSE3
3012 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
3013 const int bit_depth = avctx->bits_per_raw_sample;
3014
915a2a0a 3015 if (!high_bit_depth && CONFIG_H264QPEL) {
356ee8d7
MR
3016 H264_QPEL_FUNCS(1, 0, ssse3);
3017 H264_QPEL_FUNCS(1, 1, ssse3);
3018 H264_QPEL_FUNCS(1, 2, ssse3);
3019 H264_QPEL_FUNCS(1, 3, ssse3);
3020 H264_QPEL_FUNCS(2, 0, ssse3);
3021 H264_QPEL_FUNCS(2, 1, ssse3);
3022 H264_QPEL_FUNCS(2, 2, ssse3);
3023 H264_QPEL_FUNCS(2, 3, ssse3);
3024 H264_QPEL_FUNCS(3, 0, ssse3);
3025 H264_QPEL_FUNCS(3, 1, ssse3);
3026 H264_QPEL_FUNCS(3, 2, ssse3);
3027 H264_QPEL_FUNCS(3, 3, ssse3);
3028 }
3029#if HAVE_YASM
915a2a0a 3030 else if (bit_depth == 10 && CONFIG_H264QPEL) {
356ee8d7
MR
3031 H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
3032 H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
3033 H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
3034 }
3035 if (!high_bit_depth && CONFIG_H264CHROMA) {
3036 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_ssse3_rnd;
3037 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_ssse3_rnd;
3038 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
3039 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
3040 }
3041 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
3042 if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
3043 c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
3044
3b549121 3045 if (mm_flags & AV_CPU_FLAG_ATOM)
356ee8d7 3046 c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
3b549121 3047 else
356ee8d7 3048 c->apply_window_int16 = ff_apply_window_int16_ssse3;
3b549121 3049 if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) // cachesplit
356ee8d7 3050 c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
356ee8d7
MR
3051 c->bswap_buf = ff_bswap32_buf_ssse3;
3052#endif
3053#endif
3054}
3055
3056static void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
3057 int mm_flags)
3058{
3059#if HAVE_YASM
3060 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
3061#endif
3062}
3063
3064static void dsputil_init_avx(DSPContext *c, AVCodecContext *avctx, int mm_flags)
3065{
3066#if HAVE_AVX && HAVE_YASM
f188a1e0 3067 const int bit_depth = avctx->bits_per_raw_sample;
63f60826 3068
356ee8d7
MR
3069 if (bit_depth == 10) {
3070 // AVX implies !cache64.
3071 // TODO: Port cache(32|64) detection from x264.
915a2a0a 3072 if (CONFIG_H264QPEL) {
3b549121
DB
3073 H264_QPEL_FUNCS_10(1, 0, sse2);
3074 H264_QPEL_FUNCS_10(2, 0, sse2);
3075 H264_QPEL_FUNCS_10(3, 0, sse2);
915a2a0a 3076 }
356ee8d7
MR
3077
3078 if (CONFIG_H264CHROMA) {
3079 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
3080 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
3081 }
3082 }
3083 c->butterflies_float_interleave = ff_butterflies_float_interleave_avx;
3084#endif
3085}
3086
3b549121 3087void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx)
356ee8d7
MR
3088{
3089 int mm_flags = av_get_cpu_flags();
3090
e5247b5f 3091 if (avctx->dsp_mask) {
7160bb71 3092 if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
3b549121 3093 mm_flags |= avctx->dsp_mask & 0xffff;
bb270c08 3094 else
486497e0 3095 mm_flags &= ~(avctx->dsp_mask & 0xffff);
e5247b5f 3096 }
63f60826 3097
1565dabc 3098#if 0
01456e8e 3099 av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
7160bb71 3100 if (mm_flags & AV_CPU_FLAG_MMX)
01456e8e 3101 av_log(avctx, AV_LOG_INFO, " mmx");
7160bb71 3102 if (mm_flags & AV_CPU_FLAG_MMX2)
6b434361 3103 av_log(avctx, AV_LOG_INFO, " mmx2");
7160bb71 3104 if (mm_flags & AV_CPU_FLAG_3DNOW)
01456e8e 3105 av_log(avctx, AV_LOG_INFO, " 3dnow");
7160bb71 3106 if (mm_flags & AV_CPU_FLAG_SSE)
01456e8e 3107 av_log(avctx, AV_LOG_INFO, " sse");
7160bb71 3108 if (mm_flags & AV_CPU_FLAG_SSE2)
01456e8e
MM
3109 av_log(avctx, AV_LOG_INFO, " sse2");
3110 av_log(avctx, AV_LOG_INFO, "\n");
de6d9b64
FB
3111#endif
3112
7160bb71 3113 if (mm_flags & AV_CPU_FLAG_MMX) {
3b549121 3114 const int idct_algo = avctx->idct_algo;
b0368839 3115
e7a972e1 3116 if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) {
3b549121
DB
3117 if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
3118 c->idct_put = ff_simple_idct_put_mmx;
3119 c->idct_add = ff_simple_idct_add_mmx;
3120 c->idct = ff_simple_idct_mmx;
3121 c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
b250f9c6 3122#if CONFIG_GPL
3b549121
DB
3123 } else if (idct_algo == FF_IDCT_LIBMPEG2MMX) {
3124 if (mm_flags & AV_CPU_FLAG_MMX2) {
3125 c->idct_put = ff_libmpeg2mmx2_idct_put;
3126 c->idct_add = ff_libmpeg2mmx2_idct_add;
3127 c->idct = ff_mmxext_idct;
3128 } else {
3129 c->idct_put = ff_libmpeg2mmx_idct_put;
3130 c->idct_add = ff_libmpeg2mmx_idct_add;
3131 c->idct = ff_mmx_idct;
178fcca8 3132 }
3b549121 3133 c->idct_permutation_type = FF_LIBMPEG2_IDCT_PERM;
7f889a76 3134#endif
3b549121
DB
3135 } else if ((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER ||
3136 CONFIG_VP6_DECODER) &&
3137 idct_algo == FF_IDCT_VP3 && HAVE_YASM) {
3138 if (mm_flags & AV_CPU_FLAG_SSE2) {
3139 c->idct_put = ff_vp3_idct_put_sse2;
3140 c->idct_add = ff_vp3_idct_add_sse2;
3141 c->idct = ff_vp3_idct_sse2;
3142 c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
3143 } else {
3144 c->idct_put = ff_vp3_idct_put_mmx;
3145 c->idct_add = ff_vp3_idct_add_mmx;
3146 c->idct = ff_vp3_idct_mmx;
3147 c->idct_permutation_type = FF_PARTTRANS_IDCT_PERM;
5773a746 3148 }
3b549121
DB
3149 } else if (idct_algo == FF_IDCT_CAVS) {
3150 c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
3151 } else if (idct_algo == FF_IDCT_XVIDMMX) {
3152 if (mm_flags & AV_CPU_FLAG_SSE2) {
3153 c->idct_put = ff_idct_xvid_sse2_put;
3154 c->idct_add = ff_idct_xvid_sse2_add;
3155 c->idct = ff_idct_xvid_sse2;
3156 c->idct_permutation_type = FF_SSE2_IDCT_PERM;
3157 } else if (mm_flags & AV_CPU_FLAG_MMX2) {
3158 c->idct_put = ff_idct_xvid_mmx2_put;
3159 c->idct_add = ff_idct_xvid_mmx2_add;
3160 c->idct = ff_idct_xvid_mmx2;
3161 } else {
3162 c->idct_put = ff_idct_xvid_mmx_put;
3163 c->idct_add = ff_idct_xvid_mmx_add;
3164 c->idct = ff_idct_xvid_mmx;
84740d59 3165 }
cd7af76d 3166 }
b0368839 3167 }
01456e8e 3168
356ee8d7
MR
3169 dsputil_init_mmx(c, avctx, mm_flags);
3170 }
2833fc46 3171
356ee8d7
MR
3172 if (mm_flags & AV_CPU_FLAG_MMX2)
3173 dsputil_init_mmx2(c, avctx, mm_flags);
9e8e6d31 3174
3b549121 3175 if (mm_flags & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW)
356ee8d7 3176 dsputil_init_3dnow(c, avctx, mm_flags);
4567b4bd 3177
3b549121 3178 if (mm_flags & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT)
356ee8d7 3179 dsputil_init_3dnow2(c, avctx, mm_flags);
1d67b037 3180
3b549121 3181 if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE)
356ee8d7 3182 dsputil_init_sse(c, avctx, mm_flags);
ddf96970 3183
356ee8d7
MR
3184 if (mm_flags & AV_CPU_FLAG_SSE2)
3185 dsputil_init_sse2(c, avctx, mm_flags);
395f2e70 3186
356ee8d7
MR
3187 if (mm_flags & AV_CPU_FLAG_SSSE3)
3188 dsputil_init_ssse3(c, avctx, mm_flags);
6054cd25 3189
356ee8d7
MR
3190 if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE)
3191 dsputil_init_sse4(c, avctx, mm_flags);
6054cd25 3192
356ee8d7
MR
3193 if (mm_flags & AV_CPU_FLAG_AVX)
3194 dsputil_init_avx(c, avctx, mm_flags);
115329f1 3195
49fb20cb 3196 if (CONFIG_ENCODERS)
9cf0841e 3197 ff_dsputilenc_init_mmx(c, avctx);
de6d9b64 3198}