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