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