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