r5954 broke fft on cpus with 3dnow but without mm3dnow.h
[libav.git] / libavcodec / i386 / dsputil_mmx.c
CommitLineData
de6d9b64
FB
1/*
2 * MMX optimized DSP utils
ff4ec49e 3 * Copyright (c) 2000, 2001 Fabrice Bellard.
8f2ab833 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
de6d9b64 5 *
ff4ec49e
FB
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
de6d9b64 10 *
ff4ec49e 11 * This library is distributed in the hope that it will be useful,
de6d9b64 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
de6d9b64 15 *
ff4ec49e
FB
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
5509bffa 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64
FB
19 *
20 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
21 */
22
23#include "../dsputil.h"
b0368839 24#include "../simple_idct.h"
1ec4df0f 25#include "../mpegvideo.h"
9c39071d 26#include "x86_cpu.h"
f9ed9d85 27#include "mmx.h"
de6d9b64 28
622348f9
MN
29//#undef NDEBUG
30//#include <assert.h>
31
359f98de 32extern const uint8_t ff_h263_loop_filter_strength[32];
84740d59
MN
33extern void ff_idct_xvid_mmx(short *block);
34extern void ff_idct_xvid_mmx2(short *block);
359f98de 35
7d650cb5 36int mm_flags; /* multimedia extension flags */
1457ab52 37
de6d9b64 38/* pixel operations */
5c0513bd
DB
39static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
40static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
41static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
de6d9b64 42
21bb884f
MN
43static const uint64_t ff_pdw_80000000[2] attribute_used __attribute__ ((aligned(16))) =
44{0x8000000080000000ULL, 0x8000000080000000ULL};
45
5c0513bd
DB
46static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
47static const uint64_t ff_pw_3 attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
42251a2a 48static const uint64_t ff_pw_4 attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL;
437525c4 49static const uint64_t ff_pw_5 attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL;
a6624e21 50static const uint64_t ff_pw_8 attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL;
5c0513bd 51static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
437525c4 52static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL;
d2bb7db1 53static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL;
5c0513bd 54static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
826f429a 55
5cf08f23 56static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL;
5c0513bd 57static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
359f98de 58
d6a4c0b1
ZK
59#define JUMPALIGN() __asm __volatile (".balign 8"::)
60#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
61
fca0f0e5
ZK
62#define MOVQ_WONE(regd) \
63 __asm __volatile ( \
64 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
65 "psrlw $15, %%" #regd ::)
66
67#define MOVQ_BFE(regd) \
68 __asm __volatile ( \
69 "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
70 "paddb %%" #regd ", %%" #regd " \n\t" ::)
71
d6a4c0b1 72#ifndef PIC
fca0f0e5 73#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
d6a4c0b1
ZK
74#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
75#else
76// for shared library it's better to use this way for accessing constants
77// pcmpeqd -> -1
fca0f0e5 78#define MOVQ_BONE(regd) \
d6a4c0b1 79 __asm __volatile ( \
fca0f0e5
ZK
80 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
81 "psrlw $15, %%" #regd " \n\t" \
82 "packuswb %%" #regd ", %%" #regd " \n\t" ::)
d6a4c0b1
ZK
83
84#define MOVQ_WTWO(regd) \
85 __asm __volatile ( \
fca0f0e5
ZK
86 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
87 "psrlw $15, %%" #regd " \n\t" \
88 "psllw $1, %%" #regd " \n\t"::)
a7bd8797 89
d6a4c0b1
ZK
90#endif
91
fca0f0e5 92// using regr as temporary and for the output result
def60345 93// first argument is unmodifed and second is trashed
39825f31
ZK
94// regfe is supposed to contain 0xfefefefefefefefe
95#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
bb270c08
DB
96 "movq " #rega ", " #regr " \n\t"\
97 "pand " #regb ", " #regr " \n\t"\
98 "pxor " #rega ", " #regb " \n\t"\
99 "pand " #regfe "," #regb " \n\t"\
100 "psrlq $1, " #regb " \n\t"\
101 "paddb " #regb ", " #regr " \n\t"
def60345 102
39825f31 103#define PAVGB_MMX(rega, regb, regr, regfe) \
bb270c08
DB
104 "movq " #rega ", " #regr " \n\t"\
105 "por " #regb ", " #regr " \n\t"\
106 "pxor " #rega ", " #regb " \n\t"\
107 "pand " #regfe "," #regb " \n\t"\
108 "psrlq $1, " #regb " \n\t"\
109 "psubb " #regb ", " #regr " \n\t"
def60345 110
39825f31 111// mm6 is supposed to contain 0xfefefefefefefefe
6aa6ea8e 112#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
bb270c08
DB
113 "movq " #rega ", " #regr " \n\t"\
114 "movq " #regc ", " #regp " \n\t"\
115 "pand " #regb ", " #regr " \n\t"\
116 "pand " #regd ", " #regp " \n\t"\
117 "pxor " #rega ", " #regb " \n\t"\
118 "pxor " #regc ", " #regd " \n\t"\
119 "pand %%mm6, " #regb " \n\t"\
120 "pand %%mm6, " #regd " \n\t"\
121 "psrlq $1, " #regb " \n\t"\
122 "psrlq $1, " #regd " \n\t"\
123 "paddb " #regb ", " #regr " \n\t"\
124 "paddb " #regd ", " #regp " \n\t"
6aa6ea8e
ZK
125
126#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
bb270c08
DB
127 "movq " #rega ", " #regr " \n\t"\
128 "movq " #regc ", " #regp " \n\t"\
129 "por " #regb ", " #regr " \n\t"\
130 "por " #regd ", " #regp " \n\t"\
131 "pxor " #rega ", " #regb " \n\t"\
132 "pxor " #regc ", " #regd " \n\t"\
133 "pand %%mm6, " #regb " \n\t"\
134 "pand %%mm6, " #regd " \n\t"\
135 "psrlq $1, " #regd " \n\t"\
136 "psrlq $1, " #regb " \n\t"\
137 "psubb " #regb ", " #regr " \n\t"\
138 "psubb " #regd ", " #regp " \n\t"
6aa6ea8e 139
91abb473
ZK
140/***********************************/
141/* MMX no rounding */
142#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
fca0f0e5 143#define SET_RND MOVQ_WONE
bb270c08
DB
144#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
145#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
fca0f0e5 146
91abb473
ZK
147#include "dsputil_mmx_rnd.h"
148
149#undef DEF
fca0f0e5 150#undef SET_RND
6aa6ea8e 151#undef PAVGBP
39825f31 152#undef PAVGB
91abb473
ZK
153/***********************************/
154/* MMX rounding */
155
156#define DEF(x, y) x ## _ ## y ##_mmx
fca0f0e5 157#define SET_RND MOVQ_WTWO
bb270c08
DB
158#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
159#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
fca0f0e5 160
91abb473
ZK
161#include "dsputil_mmx_rnd.h"
162
163#undef DEF
fca0f0e5 164#undef SET_RND
6aa6ea8e 165#undef PAVGBP
39825f31 166#undef PAVGB
a7bd8797 167
de6d9b64
FB
168/***********************************/
169/* 3Dnow specific */
170
171#define DEF(x) x ## _3dnow
172/* for Athlons PAVGUSB is prefered */
173#define PAVGB "pavgusb"
174
175#include "dsputil_mmx_avg.h"
176
177#undef DEF
178#undef PAVGB
179
180/***********************************/
181/* MMX2 specific */
182
607dce96 183#define DEF(x) x ## _mmx2
de6d9b64
FB
184
185/* Introduced only in MMX2 set */
186#define PAVGB "pavgb"
187
188#include "dsputil_mmx_avg.h"
189
190#undef DEF
191#undef PAVGB
192
98d417cb
MR
193#define SBUTTERFLY(a,b,t,n)\
194 "movq " #a ", " #t " \n\t" /* abcd */\
195 "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
196 "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
197
de6d9b64
FB
198/***********************************/
199/* standard MMX */
200
764ef400 201#ifdef CONFIG_ENCODERS
0c1a9eda 202static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
de6d9b64 203{
607dce96 204 asm volatile(
bb270c08
DB
205 "mov $-128, %%"REG_a" \n\t"
206 "pxor %%mm7, %%mm7 \n\t"
207 ".balign 16 \n\t"
208 "1: \n\t"
209 "movq (%0), %%mm0 \n\t"
210 "movq (%0, %2), %%mm2 \n\t"
211 "movq %%mm0, %%mm1 \n\t"
212 "movq %%mm2, %%mm3 \n\t"
213 "punpcklbw %%mm7, %%mm0 \n\t"
214 "punpckhbw %%mm7, %%mm1 \n\t"
215 "punpcklbw %%mm7, %%mm2 \n\t"
216 "punpckhbw %%mm7, %%mm3 \n\t"
217 "movq %%mm0, (%1, %%"REG_a") \n\t"
218 "movq %%mm1, 8(%1, %%"REG_a") \n\t"
219 "movq %%mm2, 16(%1, %%"REG_a") \n\t"
220 "movq %%mm3, 24(%1, %%"REG_a") \n\t"
221 "add %3, %0 \n\t"
222 "add $32, %%"REG_a" \n\t"
223 "js 1b \n\t"
607dce96 224 : "+r" (pixels)
053dea12
AJ
225 : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2)
226 : "%"REG_a
607dce96 227 );
de6d9b64
FB
228}
229
0c1a9eda 230static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
9dbcbd92
MN
231{
232 asm volatile(
bb270c08
DB
233 "pxor %%mm7, %%mm7 \n\t"
234 "mov $-128, %%"REG_a" \n\t"
235 ".balign 16 \n\t"
236 "1: \n\t"
237 "movq (%0), %%mm0 \n\t"
238 "movq (%1), %%mm2 \n\t"
239 "movq %%mm0, %%mm1 \n\t"
240 "movq %%mm2, %%mm3 \n\t"
241 "punpcklbw %%mm7, %%mm0 \n\t"
242 "punpckhbw %%mm7, %%mm1 \n\t"
243 "punpcklbw %%mm7, %%mm2 \n\t"
244 "punpckhbw %%mm7, %%mm3 \n\t"
245 "psubw %%mm2, %%mm0 \n\t"
246 "psubw %%mm3, %%mm1 \n\t"
247 "movq %%mm0, (%2, %%"REG_a") \n\t"
248 "movq %%mm1, 8(%2, %%"REG_a") \n\t"
249 "add %3, %0 \n\t"
250 "add %3, %1 \n\t"
251 "add $16, %%"REG_a" \n\t"
252 "jnz 1b \n\t"
9dbcbd92 253 : "+r" (s1), "+r" (s2)
053dea12
AJ
254 : "r" (block+64), "r" ((long)stride)
255 : "%"REG_a
9dbcbd92
MN
256 );
257}
764ef400 258#endif //CONFIG_ENCODERS
9dbcbd92 259
0c1a9eda 260void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
261{
262 const DCTELEM *p;
0c1a9eda 263 uint8_t *pix;
de6d9b64
FB
264
265 /* read the pixels */
266 p = block;
267 pix = pixels;
d6a4c0b1 268 /* unrolled loop */
bb270c08
DB
269 __asm __volatile(
270 "movq %3, %%mm0 \n\t"
271 "movq 8%3, %%mm1 \n\t"
272 "movq 16%3, %%mm2 \n\t"
273 "movq 24%3, %%mm3 \n\t"
274 "movq 32%3, %%mm4 \n\t"
275 "movq 40%3, %%mm5 \n\t"
276 "movq 48%3, %%mm6 \n\t"
277 "movq 56%3, %%mm7 \n\t"
278 "packuswb %%mm1, %%mm0 \n\t"
279 "packuswb %%mm3, %%mm2 \n\t"
280 "packuswb %%mm5, %%mm4 \n\t"
281 "packuswb %%mm7, %%mm6 \n\t"
282 "movq %%mm0, (%0) \n\t"
283 "movq %%mm2, (%0, %1) \n\t"
284 "movq %%mm4, (%0, %1, 2) \n\t"
285 "movq %%mm6, (%0, %2) \n\t"
286 ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "m"(*p)
287 :"memory");
de6d9b64
FB
288 pix += line_size*4;
289 p += 32;
d6a4c0b1
ZK
290
291 // if here would be an exact copy of the code above
292 // compiler would generate some very strange code
293 // thus using "r"
294 __asm __volatile(
bb270c08
DB
295 "movq (%3), %%mm0 \n\t"
296 "movq 8(%3), %%mm1 \n\t"
297 "movq 16(%3), %%mm2 \n\t"
298 "movq 24(%3), %%mm3 \n\t"
299 "movq 32(%3), %%mm4 \n\t"
300 "movq 40(%3), %%mm5 \n\t"
301 "movq 48(%3), %%mm6 \n\t"
302 "movq 56(%3), %%mm7 \n\t"
303 "packuswb %%mm1, %%mm0 \n\t"
304 "packuswb %%mm3, %%mm2 \n\t"
305 "packuswb %%mm5, %%mm4 \n\t"
306 "packuswb %%mm7, %%mm6 \n\t"
307 "movq %%mm0, (%0) \n\t"
308 "movq %%mm2, (%0, %1) \n\t"
309 "movq %%mm4, (%0, %1, 2) \n\t"
310 "movq %%mm6, (%0, %2) \n\t"
311 ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "r"(p)
312 :"memory");
de6d9b64
FB
313}
314
68b51e58 315static DECLARE_ALIGNED_8(const unsigned char, vector128[8]) =
7daabccb
MM
316 { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
317
f9ed9d85
MM
318void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
319{
320 int i;
f9ed9d85
MM
321
322 movq_m2r(*vector128, mm1);
323 for (i = 0; i < 8; i++) {
324 movq_m2r(*(block), mm0);
325 packsswb_m2r(*(block + 4), mm0);
326 block += 8;
327 paddb_r2r(mm1, mm0);
328 movq_r2m(mm0, *pixels);
329 pixels += line_size;
330 }
331}
332
0c1a9eda 333void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
334{
335 const DCTELEM *p;
0c1a9eda 336 uint8_t *pix;
de6d9b64
FB
337 int i;
338
339 /* read the pixels */
340 p = block;
341 pix = pixels;
d6a4c0b1
ZK
342 MOVQ_ZERO(mm7);
343 i = 4;
cd8e5f96 344 do {
bb270c08
DB
345 __asm __volatile(
346 "movq (%2), %%mm0 \n\t"
347 "movq 8(%2), %%mm1 \n\t"
348 "movq 16(%2), %%mm2 \n\t"
349 "movq 24(%2), %%mm3 \n\t"
350 "movq %0, %%mm4 \n\t"
351 "movq %1, %%mm6 \n\t"
352 "movq %%mm4, %%mm5 \n\t"
353 "punpcklbw %%mm7, %%mm4 \n\t"
354 "punpckhbw %%mm7, %%mm5 \n\t"
355 "paddsw %%mm4, %%mm0 \n\t"
356 "paddsw %%mm5, %%mm1 \n\t"
357 "movq %%mm6, %%mm5 \n\t"
358 "punpcklbw %%mm7, %%mm6 \n\t"
359 "punpckhbw %%mm7, %%mm5 \n\t"
360 "paddsw %%mm6, %%mm2 \n\t"
361 "paddsw %%mm5, %%mm3 \n\t"
362 "packuswb %%mm1, %%mm0 \n\t"
363 "packuswb %%mm3, %%mm2 \n\t"
364 "movq %%mm0, %0 \n\t"
365 "movq %%mm2, %1 \n\t"
366 :"+m"(*pix), "+m"(*(pix+line_size))
367 :"r"(p)
368 :"memory");
de6d9b64
FB
369 pix += line_size*2;
370 p += 16;
cd8e5f96 371 } while (--i);
de6d9b64
FB
372}
373
437525c4
MN
374static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
375{
376 __asm __volatile(
bb270c08
DB
377 "lea (%3, %3), %%"REG_a" \n\t"
378 ".balign 8 \n\t"
379 "1: \n\t"
380 "movd (%1), %%mm0 \n\t"
381 "movd (%1, %3), %%mm1 \n\t"
382 "movd %%mm0, (%2) \n\t"
383 "movd %%mm1, (%2, %3) \n\t"
384 "add %%"REG_a", %1 \n\t"
385 "add %%"REG_a", %2 \n\t"
386 "movd (%1), %%mm0 \n\t"
387 "movd (%1, %3), %%mm1 \n\t"
388 "movd %%mm0, (%2) \n\t"
389 "movd %%mm1, (%2, %3) \n\t"
390 "add %%"REG_a", %1 \n\t"
391 "add %%"REG_a", %2 \n\t"
392 "subl $4, %0 \n\t"
393 "jnz 1b \n\t"
394 : "+g"(h), "+r" (pixels), "+r" (block)
395 : "r"((long)line_size)
396 : "%"REG_a, "memory"
397 );
437525c4
MN
398}
399
0c1a9eda 400static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 401{
39825f31 402 __asm __volatile(
bb270c08
DB
403 "lea (%3, %3), %%"REG_a" \n\t"
404 ".balign 8 \n\t"
405 "1: \n\t"
406 "movq (%1), %%mm0 \n\t"
407 "movq (%1, %3), %%mm1 \n\t"
408 "movq %%mm0, (%2) \n\t"
409 "movq %%mm1, (%2, %3) \n\t"
410 "add %%"REG_a", %1 \n\t"
411 "add %%"REG_a", %2 \n\t"
412 "movq (%1), %%mm0 \n\t"
413 "movq (%1, %3), %%mm1 \n\t"
414 "movq %%mm0, (%2) \n\t"
415 "movq %%mm1, (%2, %3) \n\t"
416 "add %%"REG_a", %1 \n\t"
417 "add %%"REG_a", %2 \n\t"
418 "subl $4, %0 \n\t"
419 "jnz 1b \n\t"
420 : "+g"(h), "+r" (pixels), "+r" (block)
421 : "r"((long)line_size)
422 : "%"REG_a, "memory"
423 );
de6d9b64
FB
424}
425
0c1a9eda 426static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
b3184779
MN
427{
428 __asm __volatile(
bb270c08
DB
429 "lea (%3, %3), %%"REG_a" \n\t"
430 ".balign 8 \n\t"
431 "1: \n\t"
432 "movq (%1), %%mm0 \n\t"
433 "movq 8(%1), %%mm4 \n\t"
434 "movq (%1, %3), %%mm1 \n\t"
435 "movq 8(%1, %3), %%mm5 \n\t"
436 "movq %%mm0, (%2) \n\t"
437 "movq %%mm4, 8(%2) \n\t"
438 "movq %%mm1, (%2, %3) \n\t"
439 "movq %%mm5, 8(%2, %3) \n\t"
440 "add %%"REG_a", %1 \n\t"
441 "add %%"REG_a", %2 \n\t"
442 "movq (%1), %%mm0 \n\t"
443 "movq 8(%1), %%mm4 \n\t"
444 "movq (%1, %3), %%mm1 \n\t"
445 "movq 8(%1, %3), %%mm5 \n\t"
446 "movq %%mm0, (%2) \n\t"
447 "movq %%mm4, 8(%2) \n\t"
448 "movq %%mm1, (%2, %3) \n\t"
449 "movq %%mm5, 8(%2, %3) \n\t"
450 "add %%"REG_a", %1 \n\t"
451 "add %%"REG_a", %2 \n\t"
452 "subl $4, %0 \n\t"
453 "jnz 1b \n\t"
454 : "+g"(h), "+r" (pixels), "+r" (block)
455 : "r"((long)line_size)
456 : "%"REG_a, "memory"
457 );
b3184779
MN
458}
459
649c00c9
MN
460static void clear_blocks_mmx(DCTELEM *blocks)
461{
39825f31 462 __asm __volatile(
bb270c08
DB
463 "pxor %%mm7, %%mm7 \n\t"
464 "mov $-128*6, %%"REG_a" \n\t"
465 "1: \n\t"
466 "movq %%mm7, (%0, %%"REG_a") \n\t"
467 "movq %%mm7, 8(%0, %%"REG_a") \n\t"
468 "movq %%mm7, 16(%0, %%"REG_a") \n\t"
469 "movq %%mm7, 24(%0, %%"REG_a") \n\t"
470 "add $32, %%"REG_a" \n\t"
471 " js 1b \n\t"
053dea12
AJ
472 : : "r" (((uint8_t *)blocks)+128*6)
473 : "%"REG_a
649c00c9
MN
474 );
475}
476
764ef400 477#ifdef CONFIG_ENCODERS
0c1a9eda 478static int pix_sum16_mmx(uint8_t * pix, int line_size){
084c726b
MN
479 const int h=16;
480 int sum;
053dea12 481 long index= -line_size*h;
084c726b
MN
482
483 __asm __volatile(
bb270c08
DB
484 "pxor %%mm7, %%mm7 \n\t"
485 "pxor %%mm6, %%mm6 \n\t"
486 "1: \n\t"
487 "movq (%2, %1), %%mm0 \n\t"
488 "movq (%2, %1), %%mm1 \n\t"
489 "movq 8(%2, %1), %%mm2 \n\t"
490 "movq 8(%2, %1), %%mm3 \n\t"
491 "punpcklbw %%mm7, %%mm0 \n\t"
492 "punpckhbw %%mm7, %%mm1 \n\t"
493 "punpcklbw %%mm7, %%mm2 \n\t"
494 "punpckhbw %%mm7, %%mm3 \n\t"
495 "paddw %%mm0, %%mm1 \n\t"
496 "paddw %%mm2, %%mm3 \n\t"
497 "paddw %%mm1, %%mm3 \n\t"
498 "paddw %%mm3, %%mm6 \n\t"
499 "add %3, %1 \n\t"
500 " js 1b \n\t"
501 "movq %%mm6, %%mm5 \n\t"
502 "psrlq $32, %%mm6 \n\t"
503 "paddw %%mm5, %%mm6 \n\t"
504 "movq %%mm6, %%mm5 \n\t"
505 "psrlq $16, %%mm6 \n\t"
506 "paddw %%mm5, %%mm6 \n\t"
507 "movd %%mm6, %0 \n\t"
508 "andl $0xFFFF, %0 \n\t"
084c726b 509 : "=&r" (sum), "+r" (index)
053dea12 510 : "r" (pix - index), "r" ((long)line_size)
084c726b
MN
511 );
512
513 return sum;
514}
764ef400 515#endif //CONFIG_ENCODERS
084c726b 516
11f18faf 517static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
053dea12 518 long i=0;
11f18faf 519 asm volatile(
bb270c08
DB
520 "1: \n\t"
521 "movq (%1, %0), %%mm0 \n\t"
522 "movq (%2, %0), %%mm1 \n\t"
523 "paddb %%mm0, %%mm1 \n\t"
524 "movq %%mm1, (%2, %0) \n\t"
525 "movq 8(%1, %0), %%mm0 \n\t"
526 "movq 8(%2, %0), %%mm1 \n\t"
527 "paddb %%mm0, %%mm1 \n\t"
528 "movq %%mm1, 8(%2, %0) \n\t"
529 "add $16, %0 \n\t"
530 "cmp %3, %0 \n\t"
531 " jb 1b \n\t"
11f18faf 532 : "+r" (i)
053dea12 533 : "r"(src), "r"(dst), "r"((long)w-15)
11f18faf
MN
534 );
535 for(; i<w; i++)
536 dst[i+0] += src[i+0];
537}
538
3615e2be 539#define H263_LOOP_FILTER \
bb270c08
DB
540 "pxor %%mm7, %%mm7 \n\t"\
541 "movq %0, %%mm0 \n\t"\
542 "movq %0, %%mm1 \n\t"\
543 "movq %3, %%mm2 \n\t"\
544 "movq %3, %%mm3 \n\t"\
545 "punpcklbw %%mm7, %%mm0 \n\t"\
546 "punpckhbw %%mm7, %%mm1 \n\t"\
547 "punpcklbw %%mm7, %%mm2 \n\t"\
548 "punpckhbw %%mm7, %%mm3 \n\t"\
549 "psubw %%mm2, %%mm0 \n\t"\
550 "psubw %%mm3, %%mm1 \n\t"\
551 "movq %1, %%mm2 \n\t"\
552 "movq %1, %%mm3 \n\t"\
553 "movq %2, %%mm4 \n\t"\
554 "movq %2, %%mm5 \n\t"\
555 "punpcklbw %%mm7, %%mm2 \n\t"\
556 "punpckhbw %%mm7, %%mm3 \n\t"\
557 "punpcklbw %%mm7, %%mm4 \n\t"\
558 "punpckhbw %%mm7, %%mm5 \n\t"\
559 "psubw %%mm2, %%mm4 \n\t"\
560 "psubw %%mm3, %%mm5 \n\t"\
561 "psllw $2, %%mm4 \n\t"\
562 "psllw $2, %%mm5 \n\t"\
563 "paddw %%mm0, %%mm4 \n\t"\
564 "paddw %%mm1, %%mm5 \n\t"\
565 "pxor %%mm6, %%mm6 \n\t"\
566 "pcmpgtw %%mm4, %%mm6 \n\t"\
567 "pcmpgtw %%mm5, %%mm7 \n\t"\
568 "pxor %%mm6, %%mm4 \n\t"\
569 "pxor %%mm7, %%mm5 \n\t"\
570 "psubw %%mm6, %%mm4 \n\t"\
571 "psubw %%mm7, %%mm5 \n\t"\
572 "psrlw $3, %%mm4 \n\t"\
573 "psrlw $3, %%mm5 \n\t"\
574 "packuswb %%mm5, %%mm4 \n\t"\
575 "packsswb %%mm7, %%mm6 \n\t"\
576 "pxor %%mm7, %%mm7 \n\t"\
577 "movd %4, %%mm2 \n\t"\
578 "punpcklbw %%mm2, %%mm2 \n\t"\
579 "punpcklbw %%mm2, %%mm2 \n\t"\
580 "punpcklbw %%mm2, %%mm2 \n\t"\
581 "psubusb %%mm4, %%mm2 \n\t"\
582 "movq %%mm2, %%mm3 \n\t"\
583 "psubusb %%mm4, %%mm3 \n\t"\
584 "psubb %%mm3, %%mm2 \n\t"\
585 "movq %1, %%mm3 \n\t"\
586 "movq %2, %%mm4 \n\t"\
587 "pxor %%mm6, %%mm3 \n\t"\
588 "pxor %%mm6, %%mm4 \n\t"\
589 "paddusb %%mm2, %%mm3 \n\t"\
590 "psubusb %%mm2, %%mm4 \n\t"\
591 "pxor %%mm6, %%mm3 \n\t"\
592 "pxor %%mm6, %%mm4 \n\t"\
593 "paddusb %%mm2, %%mm2 \n\t"\
594 "packsswb %%mm1, %%mm0 \n\t"\
595 "pcmpgtb %%mm0, %%mm7 \n\t"\
596 "pxor %%mm7, %%mm0 \n\t"\
597 "psubb %%mm7, %%mm0 \n\t"\
598 "movq %%mm0, %%mm1 \n\t"\
599 "psubusb %%mm2, %%mm0 \n\t"\
600 "psubb %%mm0, %%mm1 \n\t"\
601 "pand %5, %%mm1 \n\t"\
602 "psrlw $2, %%mm1 \n\t"\
603 "pxor %%mm7, %%mm1 \n\t"\
604 "psubb %%mm7, %%mm1 \n\t"\
605 "movq %0, %%mm5 \n\t"\
606 "movq %3, %%mm6 \n\t"\
607 "psubb %%mm1, %%mm5 \n\t"\
608 "paddb %%mm1, %%mm6 \n\t"
3615e2be 609
359f98de
MN
610static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
611 const int strength= ff_h263_loop_filter_strength[qscale];
612
613 asm volatile(
115329f1 614
3615e2be 615 H263_LOOP_FILTER
115329f1 616
bb270c08
DB
617 "movq %%mm3, %1 \n\t"
618 "movq %%mm4, %2 \n\t"
619 "movq %%mm5, %0 \n\t"
620 "movq %%mm6, %3 \n\t"
359f98de
MN
621 : "+m" (*(uint64_t*)(src - 2*stride)),
622 "+m" (*(uint64_t*)(src - 1*stride)),
623 "+m" (*(uint64_t*)(src + 0*stride)),
624 "+m" (*(uint64_t*)(src + 1*stride))
625 : "g" (2*strength), "m"(ff_pb_FC)
626 );
627}
628
3615e2be
MN
629static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
630 asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
bb270c08
DB
631 "movd %4, %%mm0 \n\t"
632 "movd %5, %%mm1 \n\t"
633 "movd %6, %%mm2 \n\t"
634 "movd %7, %%mm3 \n\t"
635 "punpcklbw %%mm1, %%mm0 \n\t"
636 "punpcklbw %%mm3, %%mm2 \n\t"
637 "movq %%mm0, %%mm1 \n\t"
638 "punpcklwd %%mm2, %%mm0 \n\t"
639 "punpckhwd %%mm2, %%mm1 \n\t"
640 "movd %%mm0, %0 \n\t"
641 "punpckhdq %%mm0, %%mm0 \n\t"
642 "movd %%mm0, %1 \n\t"
643 "movd %%mm1, %2 \n\t"
644 "punpckhdq %%mm1, %%mm1 \n\t"
645 "movd %%mm1, %3 \n\t"
115329f1 646
3615e2be
MN
647 : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
648 "=m" (*(uint32_t*)(dst + 1*dst_stride)),
649 "=m" (*(uint32_t*)(dst + 2*dst_stride)),
650 "=m" (*(uint32_t*)(dst + 3*dst_stride))
651 : "m" (*(uint32_t*)(src + 0*src_stride)),
652 "m" (*(uint32_t*)(src + 1*src_stride)),
653 "m" (*(uint32_t*)(src + 2*src_stride)),
654 "m" (*(uint32_t*)(src + 3*src_stride))
655 );
656}
657
658static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
659 const int strength= ff_h263_loop_filter_strength[qscale];
660 uint64_t temp[4] __attribute__ ((aligned(8)));
661 uint8_t *btemp= (uint8_t*)temp;
115329f1 662
3615e2be
MN
663 src -= 2;
664
665 transpose4x4(btemp , src , 8, stride);
666 transpose4x4(btemp+4, src + 4*stride, 8, stride);
667 asm volatile(
668 H263_LOOP_FILTER // 5 3 4 6
115329f1 669
3615e2be
MN
670 : "+m" (temp[0]),
671 "+m" (temp[1]),
672 "+m" (temp[2]),
673 "+m" (temp[3])
674 : "g" (2*strength), "m"(ff_pb_FC)
675 );
676
677 asm volatile(
bb270c08
DB
678 "movq %%mm5, %%mm1 \n\t"
679 "movq %%mm4, %%mm0 \n\t"
680 "punpcklbw %%mm3, %%mm5 \n\t"
681 "punpcklbw %%mm6, %%mm4 \n\t"
682 "punpckhbw %%mm3, %%mm1 \n\t"
683 "punpckhbw %%mm6, %%mm0 \n\t"
684 "movq %%mm5, %%mm3 \n\t"
685 "movq %%mm1, %%mm6 \n\t"
686 "punpcklwd %%mm4, %%mm5 \n\t"
687 "punpcklwd %%mm0, %%mm1 \n\t"
688 "punpckhwd %%mm4, %%mm3 \n\t"
689 "punpckhwd %%mm0, %%mm6 \n\t"
690 "movd %%mm5, (%0) \n\t"
691 "punpckhdq %%mm5, %%mm5 \n\t"
692 "movd %%mm5, (%0,%2) \n\t"
693 "movd %%mm3, (%0,%2,2) \n\t"
694 "punpckhdq %%mm3, %%mm3 \n\t"
695 "movd %%mm3, (%0,%3) \n\t"
696 "movd %%mm1, (%1) \n\t"
697 "punpckhdq %%mm1, %%mm1 \n\t"
698 "movd %%mm1, (%1,%2) \n\t"
699 "movd %%mm6, (%1,%2,2) \n\t"
700 "punpckhdq %%mm6, %%mm6 \n\t"
701 "movd %%mm6, (%1,%3) \n\t"
4d9ae03b
MD
702 :: "r" (src),
703 "r" (src + 4*stride),
704 "r" ((long) stride ),
705 "r" ((long)(3*stride))
3615e2be
MN
706 );
707}
708
764ef400 709#ifdef CONFIG_ENCODERS
2a006cd3
FL
710static int pix_norm1_mmx(uint8_t *pix, int line_size) {
711 int tmp;
712 asm volatile (
713 "movl $16,%%ecx\n"
714 "pxor %%mm0,%%mm0\n"
715 "pxor %%mm7,%%mm7\n"
716 "1:\n"
bb270c08
DB
717 "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
718 "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
2a006cd3 719
bb270c08 720 "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
2a006cd3 721
bb270c08
DB
722 "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
723 "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
2a006cd3 724
bb270c08
DB
725 "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
726 "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
727 "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
2a006cd3 728
bb270c08
DB
729 "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
730 "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
2a006cd3
FL
731
732 "pmaddwd %%mm3,%%mm3\n"
733 "pmaddwd %%mm4,%%mm4\n"
734
bb270c08
DB
735 "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
736 pix2^2+pix3^2+pix6^2+pix7^2) */
2a006cd3
FL
737 "paddd %%mm3,%%mm4\n"
738 "paddd %%mm2,%%mm7\n"
739
053dea12 740 "add %2, %0\n"
2a006cd3
FL
741 "paddd %%mm4,%%mm7\n"
742 "dec %%ecx\n"
743 "jnz 1b\n"
744
745 "movq %%mm7,%%mm1\n"
bb270c08 746 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
2a006cd3
FL
747 "paddd %%mm7,%%mm1\n"
748 "movd %%mm1,%1\n"
053dea12 749 : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" );
2a006cd3
FL
750 return tmp;
751}
752
1ec4df0f
MN
753static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
754 int tmp;
755 asm volatile (
756 "movl %4,%%ecx\n"
5693c083 757 "shr $1,%%ecx\n"
bb270c08
DB
758 "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
759 "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
1ec4df0f 760 "1:\n"
bb270c08
DB
761 "movq (%0),%%mm1\n" /* mm1 = pix1[0][0-7] */
762 "movq (%1),%%mm2\n" /* mm2 = pix2[0][0-7] */
763 "movq (%0,%3),%%mm3\n" /* mm3 = pix1[1][0-7] */
764 "movq (%1,%3),%%mm4\n" /* mm4 = pix2[1][0-7] */
1ec4df0f 765
5693c083
LM
766 /* todo: mm1-mm2, mm3-mm4 */
767 /* algo: substract mm1 from mm2 with saturation and vice versa */
768 /* OR the results to get absolute difference */
1ec4df0f 769 "movq %%mm1,%%mm5\n"
5693c083 770 "movq %%mm3,%%mm6\n"
1ec4df0f 771 "psubusb %%mm2,%%mm1\n"
5693c083 772 "psubusb %%mm4,%%mm3\n"
1ec4df0f 773 "psubusb %%mm5,%%mm2\n"
5693c083 774 "psubusb %%mm6,%%mm4\n"
1ec4df0f
MN
775
776 "por %%mm1,%%mm2\n"
5693c083 777 "por %%mm3,%%mm4\n"
1ec4df0f 778
5693c083 779 /* now convert to 16-bit vectors so we can square them */
1ec4df0f 780 "movq %%mm2,%%mm1\n"
5693c083 781 "movq %%mm4,%%mm3\n"
1ec4df0f
MN
782
783 "punpckhbw %%mm0,%%mm2\n"
5693c083 784 "punpckhbw %%mm0,%%mm4\n"
bb270c08
DB
785 "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
786 "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
1ec4df0f
MN
787
788 "pmaddwd %%mm2,%%mm2\n"
5693c083 789 "pmaddwd %%mm4,%%mm4\n"
1ec4df0f 790 "pmaddwd %%mm1,%%mm1\n"
5693c083 791 "pmaddwd %%mm3,%%mm3\n"
1ec4df0f 792
bb270c08
DB
793 "lea (%0,%3,2), %0\n" /* pix1 += 2*line_size */
794 "lea (%1,%3,2), %1\n" /* pix2 += 2*line_size */
1ec4df0f
MN
795
796 "paddd %%mm2,%%mm1\n"
5693c083 797 "paddd %%mm4,%%mm3\n"
1ec4df0f 798 "paddd %%mm1,%%mm7\n"
5693c083 799 "paddd %%mm3,%%mm7\n"
1ec4df0f
MN
800
801 "decl %%ecx\n"
802 "jnz 1b\n"
803
804 "movq %%mm7,%%mm1\n"
bb270c08 805 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
1ec4df0f
MN
806 "paddd %%mm7,%%mm1\n"
807 "movd %%mm1,%2\n"
115329f1 808 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
053dea12 809 : "r" ((long)line_size) , "m" (h)
1ec4df0f
MN
810 : "%ecx");
811 return tmp;
812}
813
bb198e19 814static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
2a006cd3
FL
815 int tmp;
816 asm volatile (
bb198e19 817 "movl %4,%%ecx\n"
bb270c08
DB
818 "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
819 "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
2a006cd3 820 "1:\n"
bb270c08
DB
821 "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
822 "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
823 "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
824 "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
2a006cd3
FL
825
826 /* todo: mm1-mm2, mm3-mm4 */
827 /* algo: substract mm1 from mm2 with saturation and vice versa */
828 /* OR the results to get absolute difference */
829 "movq %%mm1,%%mm5\n"
830 "movq %%mm3,%%mm6\n"
831 "psubusb %%mm2,%%mm1\n"
832 "psubusb %%mm4,%%mm3\n"
833 "psubusb %%mm5,%%mm2\n"
834 "psubusb %%mm6,%%mm4\n"
835
836 "por %%mm1,%%mm2\n"
837 "por %%mm3,%%mm4\n"
838
839 /* now convert to 16-bit vectors so we can square them */
840 "movq %%mm2,%%mm1\n"
841 "movq %%mm4,%%mm3\n"
842
843 "punpckhbw %%mm0,%%mm2\n"
844 "punpckhbw %%mm0,%%mm4\n"
bb270c08
DB
845 "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
846 "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
2a006cd3
FL
847
848 "pmaddwd %%mm2,%%mm2\n"
849 "pmaddwd %%mm4,%%mm4\n"
850 "pmaddwd %%mm1,%%mm1\n"
851 "pmaddwd %%mm3,%%mm3\n"
852
053dea12
AJ
853 "add %3,%0\n"
854 "add %3,%1\n"
2a006cd3
FL
855
856 "paddd %%mm2,%%mm1\n"
857 "paddd %%mm4,%%mm3\n"
858 "paddd %%mm1,%%mm7\n"
859 "paddd %%mm3,%%mm7\n"
860
861 "decl %%ecx\n"
862 "jnz 1b\n"
863
864 "movq %%mm7,%%mm1\n"
bb270c08 865 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
2a006cd3
FL
866 "paddd %%mm7,%%mm1\n"
867 "movd %%mm1,%2\n"
115329f1 868 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
053dea12 869 : "r" ((long)line_size) , "m" (h)
bb198e19 870 : "%ecx");
2a006cd3
FL
871 return tmp;
872}
873
5693c083
LM
874static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
875 int tmp;
876 asm volatile (
877 "shr $1,%2\n"
bb270c08
DB
878 "pxor %%xmm0,%%xmm0\n" /* mm0 = 0 */
879 "pxor %%xmm7,%%xmm7\n" /* mm7 holds the sum */
5693c083 880 "1:\n"
bb270c08
DB
881 "movdqu (%0),%%xmm1\n" /* mm1 = pix1[0][0-15] */
882 "movdqu (%1),%%xmm2\n" /* mm2 = pix2[0][0-15] */
883 "movdqu (%0,%4),%%xmm3\n" /* mm3 = pix1[1][0-15] */
884 "movdqu (%1,%4),%%xmm4\n" /* mm4 = pix2[1][0-15] */
5693c083
LM
885
886 /* todo: mm1-mm2, mm3-mm4 */
887 /* algo: substract mm1 from mm2 with saturation and vice versa */
888 /* OR the results to get absolute difference */
889 "movdqa %%xmm1,%%xmm5\n"
890 "movdqa %%xmm3,%%xmm6\n"
891 "psubusb %%xmm2,%%xmm1\n"
892 "psubusb %%xmm4,%%xmm3\n"
893 "psubusb %%xmm5,%%xmm2\n"
894 "psubusb %%xmm6,%%xmm4\n"
895
896 "por %%xmm1,%%xmm2\n"
897 "por %%xmm3,%%xmm4\n"
898
899 /* now convert to 16-bit vectors so we can square them */
900 "movdqa %%xmm2,%%xmm1\n"
901 "movdqa %%xmm4,%%xmm3\n"
902
903 "punpckhbw %%xmm0,%%xmm2\n"
904 "punpckhbw %%xmm0,%%xmm4\n"
bb270c08
DB
905 "punpcklbw %%xmm0,%%xmm1\n" /* mm1 now spread over (mm1,mm2) */
906 "punpcklbw %%xmm0,%%xmm3\n" /* mm4 now spread over (mm3,mm4) */
5693c083
LM
907
908 "pmaddwd %%xmm2,%%xmm2\n"
909 "pmaddwd %%xmm4,%%xmm4\n"
910 "pmaddwd %%xmm1,%%xmm1\n"
911 "pmaddwd %%xmm3,%%xmm3\n"
912
bb270c08
DB
913 "lea (%0,%4,2), %0\n" /* pix1 += 2*line_size */
914 "lea (%1,%4,2), %1\n" /* pix2 += 2*line_size */
5693c083
LM
915
916 "paddd %%xmm2,%%xmm1\n"
917 "paddd %%xmm4,%%xmm3\n"
918 "paddd %%xmm1,%%xmm7\n"
919 "paddd %%xmm3,%%xmm7\n"
920
921 "decl %2\n"
922 "jnz 1b\n"
923
924 "movdqa %%xmm7,%%xmm1\n"
bb270c08 925 "psrldq $8, %%xmm7\n" /* shift hi qword to lo */
5693c083
LM
926 "paddd %%xmm1,%%xmm7\n"
927 "movdqa %%xmm7,%%xmm1\n"
bb270c08 928 "psrldq $4, %%xmm7\n" /* shift hi dword to lo */
5693c083
LM
929 "paddd %%xmm1,%%xmm7\n"
930 "movd %%xmm7,%3\n"
115329f1 931 : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp)
5693c083
LM
932 : "r" ((long)line_size));
933 return tmp;
934}
935
1ec4df0f
MN
936static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
937 int tmp;
938 asm volatile (
939 "movl %3,%%ecx\n"
940 "pxor %%mm7,%%mm7\n"
941 "pxor %%mm6,%%mm6\n"
115329f1 942
1ec4df0f
MN
943 "movq (%0),%%mm0\n"
944 "movq %%mm0, %%mm1\n"
945 "psllq $8, %%mm0\n"
946 "psrlq $8, %%mm1\n"
947 "psrlq $8, %%mm0\n"
948 "movq %%mm0, %%mm2\n"
949 "movq %%mm1, %%mm3\n"
950 "punpcklbw %%mm7,%%mm0\n"
951 "punpcklbw %%mm7,%%mm1\n"
952 "punpckhbw %%mm7,%%mm2\n"
953 "punpckhbw %%mm7,%%mm3\n"
954 "psubw %%mm1, %%mm0\n"
955 "psubw %%mm3, %%mm2\n"
115329f1 956
053dea12 957 "add %2,%0\n"
115329f1 958
1ec4df0f
MN
959 "movq (%0),%%mm4\n"
960 "movq %%mm4, %%mm1\n"
961 "psllq $8, %%mm4\n"
962 "psrlq $8, %%mm1\n"
963 "psrlq $8, %%mm4\n"
964 "movq %%mm4, %%mm5\n"
965 "movq %%mm1, %%mm3\n"
966 "punpcklbw %%mm7,%%mm4\n"
967 "punpcklbw %%mm7,%%mm1\n"
968 "punpckhbw %%mm7,%%mm5\n"
969 "punpckhbw %%mm7,%%mm3\n"
970 "psubw %%mm1, %%mm4\n"
971 "psubw %%mm3, %%mm5\n"
972 "psubw %%mm4, %%mm0\n"
973 "psubw %%mm5, %%mm2\n"
974 "pxor %%mm3, %%mm3\n"
975 "pxor %%mm1, %%mm1\n"
976 "pcmpgtw %%mm0, %%mm3\n\t"
977 "pcmpgtw %%mm2, %%mm1\n\t"
978 "pxor %%mm3, %%mm0\n"
979 "pxor %%mm1, %%mm2\n"
115329f1 980 "psubw %%mm3, %%mm0\n"
1ec4df0f
MN
981 "psubw %%mm1, %%mm2\n"
982 "paddw %%mm0, %%mm2\n"
983 "paddw %%mm2, %%mm6\n"
984
053dea12 985 "add %2,%0\n"
1ec4df0f 986 "1:\n"
115329f1 987
1ec4df0f
MN
988 "movq (%0),%%mm0\n"
989 "movq %%mm0, %%mm1\n"
990 "psllq $8, %%mm0\n"
991 "psrlq $8, %%mm1\n"
992 "psrlq $8, %%mm0\n"
993 "movq %%mm0, %%mm2\n"
994 "movq %%mm1, %%mm3\n"
995 "punpcklbw %%mm7,%%mm0\n"
996 "punpcklbw %%mm7,%%mm1\n"
997 "punpckhbw %%mm7,%%mm2\n"
998 "punpckhbw %%mm7,%%mm3\n"
999 "psubw %%mm1, %%mm0\n"
1000 "psubw %%mm3, %%mm2\n"
1001 "psubw %%mm0, %%mm4\n"
1002 "psubw %%mm2, %%mm5\n"
1003 "pxor %%mm3, %%mm3\n"
1004 "pxor %%mm1, %%mm1\n"
1005 "pcmpgtw %%mm4, %%mm3\n\t"
1006 "pcmpgtw %%mm5, %%mm1\n\t"
1007 "pxor %%mm3, %%mm4\n"
1008 "pxor %%mm1, %%mm5\n"
115329f1 1009 "psubw %%mm3, %%mm4\n"
1ec4df0f
MN
1010 "psubw %%mm1, %%mm5\n"
1011 "paddw %%mm4, %%mm5\n"
1012 "paddw %%mm5, %%mm6\n"
115329f1 1013
053dea12 1014 "add %2,%0\n"
115329f1 1015
1ec4df0f
MN
1016 "movq (%0),%%mm4\n"
1017 "movq %%mm4, %%mm1\n"
1018 "psllq $8, %%mm4\n"
1019 "psrlq $8, %%mm1\n"
1020 "psrlq $8, %%mm4\n"
1021 "movq %%mm4, %%mm5\n"
1022 "movq %%mm1, %%mm3\n"
1023 "punpcklbw %%mm7,%%mm4\n"
1024 "punpcklbw %%mm7,%%mm1\n"
1025 "punpckhbw %%mm7,%%mm5\n"
1026 "punpckhbw %%mm7,%%mm3\n"
1027 "psubw %%mm1, %%mm4\n"
1028 "psubw %%mm3, %%mm5\n"
1029 "psubw %%mm4, %%mm0\n"
1030 "psubw %%mm5, %%mm2\n"
1031 "pxor %%mm3, %%mm3\n"
1032 "pxor %%mm1, %%mm1\n"
1033 "pcmpgtw %%mm0, %%mm3\n\t"
1034 "pcmpgtw %%mm2, %%mm1\n\t"
1035 "pxor %%mm3, %%mm0\n"
1036 "pxor %%mm1, %%mm2\n"
115329f1 1037 "psubw %%mm3, %%mm0\n"
1ec4df0f
MN
1038 "psubw %%mm1, %%mm2\n"
1039 "paddw %%mm0, %%mm2\n"
1040 "paddw %%mm2, %%mm6\n"
1041
053dea12 1042 "add %2,%0\n"
1ec4df0f
MN
1043 "subl $2, %%ecx\n"
1044 " jnz 1b\n"
1045
1046 "movq %%mm6, %%mm0\n"
1047 "punpcklwd %%mm7,%%mm0\n"
1048 "punpckhwd %%mm7,%%mm6\n"
1049 "paddd %%mm0, %%mm6\n"
115329f1 1050
1ec4df0f
MN
1051 "movq %%mm6,%%mm0\n"
1052 "psrlq $32, %%mm6\n"
1053 "paddd %%mm6,%%mm0\n"
1054 "movd %%mm0,%1\n"
115329f1 1055 : "+r" (pix1), "=r"(tmp)
053dea12 1056 : "r" ((long)line_size) , "g" (h-2)
1ec4df0f
MN
1057 : "%ecx");
1058 return tmp;
1059}
1060
1061static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
1062 int tmp;
1063 uint8_t * pix= pix1;
1064 asm volatile (
1065 "movl %3,%%ecx\n"
1066 "pxor %%mm7,%%mm7\n"
1067 "pxor %%mm6,%%mm6\n"
115329f1 1068
1ec4df0f
MN
1069 "movq (%0),%%mm0\n"
1070 "movq 1(%0),%%mm1\n"
1071 "movq %%mm0, %%mm2\n"
1072 "movq %%mm1, %%mm3\n"
1073 "punpcklbw %%mm7,%%mm0\n"
1074 "punpcklbw %%mm7,%%mm1\n"
1075 "punpckhbw %%mm7,%%mm2\n"
1076 "punpckhbw %%mm7,%%mm3\n"
1077 "psubw %%mm1, %%mm0\n"
1078 "psubw %%mm3, %%mm2\n"
115329f1 1079
053dea12 1080 "add %2,%0\n"
115329f1 1081
1ec4df0f
MN
1082 "movq (%0),%%mm4\n"
1083 "movq 1(%0),%%mm1\n"
1084 "movq %%mm4, %%mm5\n"
1085 "movq %%mm1, %%mm3\n"
1086 "punpcklbw %%mm7,%%mm4\n"
1087 "punpcklbw %%mm7,%%mm1\n"
1088 "punpckhbw %%mm7,%%mm5\n"
1089 "punpckhbw %%mm7,%%mm3\n"
1090 "psubw %%mm1, %%mm4\n"
1091 "psubw %%mm3, %%mm5\n"
1092 "psubw %%mm4, %%mm0\n"
1093 "psubw %%mm5, %%mm2\n"
1094 "pxor %%mm3, %%mm3\n"
1095 "pxor %%mm1, %%mm1\n"
1096 "pcmpgtw %%mm0, %%mm3\n\t"
1097 "pcmpgtw %%mm2, %%mm1\n\t"
1098 "pxor %%mm3, %%mm0\n"
1099 "pxor %%mm1, %%mm2\n"
115329f1 1100 "psubw %%mm3, %%mm0\n"
1ec4df0f
MN
1101 "psubw %%mm1, %%mm2\n"
1102 "paddw %%mm0, %%mm2\n"
1103 "paddw %%mm2, %%mm6\n"
1104
053dea12 1105 "add %2,%0\n"
1ec4df0f 1106 "1:\n"
115329f1 1107
1ec4df0f
MN
1108 "movq (%0),%%mm0\n"
1109 "movq 1(%0),%%mm1\n"
1110 "movq %%mm0, %%mm2\n"
1111 "movq %%mm1, %%mm3\n"
1112 "punpcklbw %%mm7,%%mm0\n"
1113 "punpcklbw %%mm7,%%mm1\n"
1114 "punpckhbw %%mm7,%%mm2\n"
1115 "punpckhbw %%mm7,%%mm3\n"
1116 "psubw %%mm1, %%mm0\n"
1117 "psubw %%mm3, %%mm2\n"
1118 "psubw %%mm0, %%mm4\n"
1119 "psubw %%mm2, %%mm5\n"
1120 "pxor %%mm3, %%mm3\n"
1121 "pxor %%mm1, %%mm1\n"
1122 "pcmpgtw %%mm4, %%mm3\n\t"
1123 "pcmpgtw %%mm5, %%mm1\n\t"
1124 "pxor %%mm3, %%mm4\n"
1125 "pxor %%mm1, %%mm5\n"
1126 "psubw %%mm3, %%mm4\n"
1127 "psubw %%mm1, %%mm5\n"
1128 "paddw %%mm4, %%mm5\n"
1129 "paddw %%mm5, %%mm6\n"
115329f1 1130
053dea12 1131 "add %2,%0\n"
115329f1 1132
1ec4df0f
MN
1133 "movq (%0),%%mm4\n"
1134 "movq 1(%0),%%mm1\n"
1135 "movq %%mm4, %%mm5\n"
1136 "movq %%mm1, %%mm3\n"
1137 "punpcklbw %%mm7,%%mm4\n"
1138 "punpcklbw %%mm7,%%mm1\n"
1139 "punpckhbw %%mm7,%%mm5\n"
1140 "punpckhbw %%mm7,%%mm3\n"
1141 "psubw %%mm1, %%mm4\n"
1142 "psubw %%mm3, %%mm5\n"
1143 "psubw %%mm4, %%mm0\n"
1144 "psubw %%mm5, %%mm2\n"
1145 "pxor %%mm3, %%mm3\n"
1146 "pxor %%mm1, %%mm1\n"
1147 "pcmpgtw %%mm0, %%mm3\n\t"
1148 "pcmpgtw %%mm2, %%mm1\n\t"
1149 "pxor %%mm3, %%mm0\n"
1150 "pxor %%mm1, %%mm2\n"
115329f1 1151 "psubw %%mm3, %%mm0\n"
1ec4df0f
MN
1152 "psubw %%mm1, %%mm2\n"
1153 "paddw %%mm0, %%mm2\n"
1154 "paddw %%mm2, %%mm6\n"
1155
053dea12 1156 "add %2,%0\n"
1ec4df0f
MN
1157 "subl $2, %%ecx\n"
1158 " jnz 1b\n"
1159
1160 "movq %%mm6, %%mm0\n"
1161 "punpcklwd %%mm7,%%mm0\n"
1162 "punpckhwd %%mm7,%%mm6\n"
1163 "paddd %%mm0, %%mm6\n"
115329f1 1164
1ec4df0f
MN
1165 "movq %%mm6,%%mm0\n"
1166 "psrlq $32, %%mm6\n"
1167 "paddd %%mm6,%%mm0\n"
1168 "movd %%mm0,%1\n"
115329f1 1169 : "+r" (pix1), "=r"(tmp)
053dea12 1170 : "r" ((long)line_size) , "g" (h-2)
1ec4df0f
MN
1171 : "%ecx");
1172 return tmp + hf_noise8_mmx(pix+8, line_size, h);
1173}
1174
79396ac6
MR
1175static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1176 MpegEncContext *c = p;
ea15df80
LM
1177 int score1, score2;
1178
1179 if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h);
1180 else score1 = sse16_mmx(c, pix1, pix2, line_size, h);
1181 score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
1ec4df0f
MN
1182
1183 if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1184 else return score1 + ABS(score2)*8;
1185}
1186
79396ac6
MR
1187static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1188 MpegEncContext *c = p;
1ec4df0f
MN
1189 int score1= sse8_mmx(c, pix1, pix2, line_size, h);
1190 int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
1191
1192 if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1193 else return score1 + ABS(score2)*8;
1194}
1195
622348f9
MN
1196static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1197 int tmp;
115329f1 1198
622348f9
MN
1199 assert( (((int)pix) & 7) == 0);
1200 assert((line_size &7) ==0);
115329f1 1201
622348f9
MN
1202#define SUM(in0, in1, out0, out1) \
1203 "movq (%0), %%mm2\n"\
1204 "movq 8(%0), %%mm3\n"\
053dea12 1205 "add %2,%0\n"\
622348f9
MN
1206 "movq %%mm2, " #out0 "\n"\
1207 "movq %%mm3, " #out1 "\n"\
1208 "psubusb " #in0 ", %%mm2\n"\
1209 "psubusb " #in1 ", %%mm3\n"\
1210 "psubusb " #out0 ", " #in0 "\n"\
1211 "psubusb " #out1 ", " #in1 "\n"\
1212 "por %%mm2, " #in0 "\n"\
1213 "por %%mm3, " #in1 "\n"\
1214 "movq " #in0 ", %%mm2\n"\
1215 "movq " #in1 ", %%mm3\n"\
1216 "punpcklbw %%mm7, " #in0 "\n"\
1217 "punpcklbw %%mm7, " #in1 "\n"\
1218 "punpckhbw %%mm7, %%mm2\n"\
1219 "punpckhbw %%mm7, %%mm3\n"\
1220 "paddw " #in1 ", " #in0 "\n"\
1221 "paddw %%mm3, %%mm2\n"\
1222 "paddw %%mm2, " #in0 "\n"\
1223 "paddw " #in0 ", %%mm6\n"
1224
115329f1 1225
622348f9
MN
1226 asm volatile (
1227 "movl %3,%%ecx\n"
1228 "pxor %%mm6,%%mm6\n"
1229 "pxor %%mm7,%%mm7\n"
1230 "movq (%0),%%mm0\n"
1231 "movq 8(%0),%%mm1\n"
053dea12 1232 "add %2,%0\n"
622348f9
MN
1233 "subl $2, %%ecx\n"
1234 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1235 "1:\n"
115329f1 1236
622348f9 1237 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
115329f1 1238
622348f9 1239 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
115329f1 1240
622348f9
MN
1241 "subl $2, %%ecx\n"
1242 "jnz 1b\n"
1243
1244 "movq %%mm6,%%mm0\n"
1245 "psrlq $32, %%mm6\n"
1246 "paddw %%mm6,%%mm0\n"
1247 "movq %%mm0,%%mm6\n"
1248 "psrlq $16, %%mm0\n"
1249 "paddw %%mm6,%%mm0\n"
1250 "movd %%mm0,%1\n"
115329f1 1251 : "+r" (pix), "=r"(tmp)
053dea12 1252 : "r" ((long)line_size) , "m" (h)
622348f9
MN
1253 : "%ecx");
1254 return tmp & 0xFFFF;
1255}
1256#undef SUM
1257
1258static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1259 int tmp;
115329f1 1260
622348f9
MN
1261 assert( (((int)pix) & 7) == 0);
1262 assert((line_size &7) ==0);
115329f1 1263
622348f9
MN
1264#define SUM(in0, in1, out0, out1) \
1265 "movq (%0), " #out0 "\n"\
1266 "movq 8(%0), " #out1 "\n"\
053dea12 1267 "add %2,%0\n"\
622348f9
MN
1268 "psadbw " #out0 ", " #in0 "\n"\
1269 "psadbw " #out1 ", " #in1 "\n"\
1270 "paddw " #in1 ", " #in0 "\n"\
1271 "paddw " #in0 ", %%mm6\n"
1272
1273 asm volatile (
1274 "movl %3,%%ecx\n"
1275 "pxor %%mm6,%%mm6\n"
1276 "pxor %%mm7,%%mm7\n"
1277 "movq (%0),%%mm0\n"
1278 "movq 8(%0),%%mm1\n"
053dea12 1279 "add %2,%0\n"
622348f9
MN
1280 "subl $2, %%ecx\n"
1281 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1282 "1:\n"
115329f1 1283
622348f9 1284 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
115329f1 1285
622348f9 1286 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
115329f1 1287
622348f9
MN
1288 "subl $2, %%ecx\n"
1289 "jnz 1b\n"
1290
1291 "movd %%mm6,%1\n"
115329f1 1292 : "+r" (pix), "=r"(tmp)
053dea12 1293 : "r" ((long)line_size) , "m" (h)
622348f9
MN
1294 : "%ecx");
1295 return tmp;
1296}
1297#undef SUM
1298
1299static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1300 int tmp;
115329f1 1301
622348f9
MN
1302 assert( (((int)pix1) & 7) == 0);
1303 assert( (((int)pix2) & 7) == 0);
1304 assert((line_size &7) ==0);
115329f1 1305
622348f9
MN
1306#define SUM(in0, in1, out0, out1) \
1307 "movq (%0),%%mm2\n"\
1308 "movq (%1)," #out0 "\n"\
1309 "movq 8(%0),%%mm3\n"\
1310 "movq 8(%1)," #out1 "\n"\
053dea12
AJ
1311 "add %3,%0\n"\
1312 "add %3,%1\n"\
622348f9
MN
1313 "psubb " #out0 ", %%mm2\n"\
1314 "psubb " #out1 ", %%mm3\n"\
1315 "pxor %%mm7, %%mm2\n"\
1316 "pxor %%mm7, %%mm3\n"\
1317 "movq %%mm2, " #out0 "\n"\
1318 "movq %%mm3, " #out1 "\n"\
1319 "psubusb " #in0 ", %%mm2\n"\
1320 "psubusb " #in1 ", %%mm3\n"\
1321 "psubusb " #out0 ", " #in0 "\n"\
1322 "psubusb " #out1 ", " #in1 "\n"\
1323 "por %%mm2, " #in0 "\n"\
1324 "por %%mm3, " #in1 "\n"\
1325 "movq " #in0 ", %%mm2\n"\
1326 "movq " #in1 ", %%mm3\n"\
1327 "punpcklbw %%mm7, " #in0 "\n"\
1328 "punpcklbw %%mm7, " #in1 "\n"\
1329 "punpckhbw %%mm7, %%mm2\n"\
1330 "punpckhbw %%mm7, %%mm3\n"\
1331 "paddw " #in1 ", " #in0 "\n"\
1332 "paddw %%mm3, %%mm2\n"\
1333 "paddw %%mm2, " #in0 "\n"\
1334 "paddw " #in0 ", %%mm6\n"
1335
115329f1 1336
622348f9
MN
1337 asm volatile (
1338 "movl %4,%%ecx\n"
1339 "pxor %%mm6,%%mm6\n"
1340 "pcmpeqw %%mm7,%%mm7\n"
1341 "psllw $15, %%mm7\n"
1342 "packsswb %%mm7, %%mm7\n"
1343 "movq (%0),%%mm0\n"
1344 "movq (%1),%%mm2\n"
1345 "movq 8(%0),%%mm1\n"
1346 "movq 8(%1),%%mm3\n"
053dea12
AJ
1347 "add %3,%0\n"
1348 "add %3,%1\n"
622348f9
MN
1349 "subl $2, %%ecx\n"
1350 "psubb %%mm2, %%mm0\n"
1351 "psubb %%mm3, %%mm1\n"
1352 "pxor %%mm7, %%mm0\n"
1353 "pxor %%mm7, %%mm1\n"
1354 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1355 "1:\n"
115329f1 1356
622348f9 1357 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
115329f1 1358
622348f9 1359 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
115329f1 1360
622348f9
MN
1361 "subl $2, %%ecx\n"
1362 "jnz 1b\n"
1363
1364 "movq %%mm6,%%mm0\n"
1365 "psrlq $32, %%mm6\n"
1366 "paddw %%mm6,%%mm0\n"
1367 "movq %%mm0,%%mm6\n"
1368 "psrlq $16, %%mm0\n"
1369 "paddw %%mm6,%%mm0\n"
1370 "movd %%mm0,%2\n"
115329f1 1371 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
053dea12 1372 : "r" ((long)line_size) , "m" (h)
622348f9
MN
1373 : "%ecx");
1374 return tmp & 0x7FFF;
1375}
1376#undef SUM
1377
1378static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1379 int tmp;
115329f1 1380
622348f9
MN
1381 assert( (((int)pix1) & 7) == 0);
1382 assert( (((int)pix2) & 7) == 0);
1383 assert((line_size &7) ==0);
115329f1 1384
622348f9
MN
1385#define SUM(in0, in1, out0, out1) \
1386 "movq (%0)," #out0 "\n"\
1387 "movq (%1),%%mm2\n"\
1388 "movq 8(%0)," #out1 "\n"\
1389 "movq 8(%1),%%mm3\n"\
053dea12
AJ
1390 "add %3,%0\n"\
1391 "add %3,%1\n"\
622348f9
MN
1392 "psubb %%mm2, " #out0 "\n"\
1393 "psubb %%mm3, " #out1 "\n"\
1394 "pxor %%mm7, " #out0 "\n"\
1395 "pxor %%mm7, " #out1 "\n"\
1396 "psadbw " #out0 ", " #in0 "\n"\
1397 "psadbw " #out1 ", " #in1 "\n"\
1398 "paddw " #in1 ", " #in0 "\n"\
1399 "paddw " #in0 ", %%mm6\n"
1400
1401 asm volatile (
1402 "movl %4,%%ecx\n"
1403 "pxor %%mm6,%%mm6\n"
1404 "pcmpeqw %%mm7,%%mm7\n"
1405 "psllw $15, %%mm7\n"
1406 "packsswb %%mm7, %%mm7\n"
1407 "movq (%0),%%mm0\n"
1408 "movq (%1),%%mm2\n"
1409 "movq 8(%0),%%mm1\n"
1410 "movq 8(%1),%%mm3\n"
053dea12
AJ
1411 "add %3,%0\n"
1412 "add %3,%1\n"
622348f9
MN
1413 "subl $2, %%ecx\n"
1414 "psubb %%mm2, %%mm0\n"
1415 "psubb %%mm3, %%mm1\n"
1416 "pxor %%mm7, %%mm0\n"
1417 "pxor %%mm7, %%mm1\n"
1418 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1419 "1:\n"
115329f1 1420
622348f9 1421 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
115329f1 1422
622348f9 1423 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
115329f1 1424
622348f9
MN
1425 "subl $2, %%ecx\n"
1426 "jnz 1b\n"
1427
1428 "movd %%mm6,%2\n"
115329f1 1429 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
053dea12 1430 : "r" ((long)line_size) , "m" (h)
622348f9
MN
1431 : "%ecx");
1432 return tmp;
1433}
1434#undef SUM
1435
11f18faf 1436static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
053dea12 1437 long i=0;
11f18faf 1438 asm volatile(
bb270c08
DB
1439 "1: \n\t"
1440 "movq (%2, %0), %%mm0 \n\t"
1441 "movq (%1, %0), %%mm1 \n\t"
1442 "psubb %%mm0, %%mm1 \n\t"
1443 "movq %%mm1, (%3, %0) \n\t"
1444 "movq 8(%2, %0), %%mm0 \n\t"
1445 "movq 8(%1, %0), %%mm1 \n\t"
1446 "psubb %%mm0, %%mm1 \n\t"
1447 "movq %%mm1, 8(%3, %0) \n\t"
1448 "add $16, %0 \n\t"
1449 "cmp %4, %0 \n\t"
1450 " jb 1b \n\t"
11f18faf 1451 : "+r" (i)
053dea12 1452 : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15)
11f18faf
MN
1453 );
1454 for(; i<w; i++)
1455 dst[i+0] = src1[i+0]-src2[i+0];
1456}
84705403
MN
1457
1458static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
053dea12 1459 long i=0;
84705403 1460 uint8_t l, lt;
115329f1 1461
84705403 1462 asm volatile(
bb270c08
DB
1463 "1: \n\t"
1464 "movq -1(%1, %0), %%mm0 \n\t" // LT
1465 "movq (%1, %0), %%mm1 \n\t" // T
1466 "movq -1(%2, %0), %%mm2 \n\t" // L
1467 "movq (%2, %0), %%mm3 \n\t" // X
1468 "movq %%mm2, %%mm4 \n\t" // L
1469 "psubb %%mm0, %%mm2 \n\t"
1470 "paddb %%mm1, %%mm2 \n\t" // L + T - LT
1471 "movq %%mm4, %%mm5 \n\t" // L
1472 "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
1473 "pminub %%mm5, %%mm1 \n\t" // min(T, L)
1474 "pminub %%mm2, %%mm4 \n\t"
1475 "pmaxub %%mm1, %%mm4 \n\t"
1476 "psubb %%mm4, %%mm3 \n\t" // dst - pred
1477 "movq %%mm3, (%3, %0) \n\t"
1478 "add $8, %0 \n\t"
1479 "cmp %4, %0 \n\t"
1480 " jb 1b \n\t"
84705403 1481 : "+r" (i)
053dea12 1482 : "r"(src1), "r"(src2), "r"(dst), "r"((long)w)
84705403
MN
1483 );
1484
1485 l= *left;
1486 lt= *left_top;
115329f1 1487
84705403 1488 dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
115329f1 1489
84705403
MN
1490 *left_top= src1[w-1];
1491 *left = src2[w-1];
1492}
1493
8e0a3db7 1494#define LBUTTERFLY2(a1,b1,a2,b2)\
bb270c08
DB
1495 "paddw " #b1 ", " #a1 " \n\t"\
1496 "paddw " #b2 ", " #a2 " \n\t"\
1497 "paddw " #b1 ", " #b1 " \n\t"\
1498 "paddw " #b2 ", " #b2 " \n\t"\
1499 "psubw " #a1 ", " #b1 " \n\t"\
1500 "psubw " #a2 ", " #b2 " \n\t"
1457ab52
MN
1501
1502#define HADAMARD48\
8e0a3db7
MN
1503 LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
1504 LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
1505 LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
1506 LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
1507 LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
1508 LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
1457ab52
MN
1509
1510#define MMABS(a,z)\
bb270c08
DB
1511 "pxor " #z ", " #z " \n\t"\
1512 "pcmpgtw " #a ", " #z " \n\t"\
1513 "pxor " #z ", " #a " \n\t"\
1514 "psubw " #z ", " #a " \n\t"
1457ab52
MN
1515
1516#define MMABS_SUM(a,z, sum)\
bb270c08
DB
1517 "pxor " #z ", " #z " \n\t"\
1518 "pcmpgtw " #a ", " #z " \n\t"\
1519 "pxor " #z ", " #a " \n\t"\
1520 "psubw " #z ", " #a " \n\t"\
1521 "paddusw " #a ", " #sum " \n\t"
1457ab52 1522
8e0a3db7 1523#define MMABS_MMX2(a,z)\
bb270c08
DB
1524 "pxor " #z ", " #z " \n\t"\
1525 "psubw " #a ", " #z " \n\t"\
1526 "pmaxsw " #z ", " #a " \n\t"
8e0a3db7
MN
1527
1528#define MMABS_SUM_MMX2(a,z, sum)\
bb270c08
DB
1529 "pxor " #z ", " #z " \n\t"\
1530 "psubw " #a ", " #z " \n\t"\
1531 "pmaxsw " #z ", " #a " \n\t"\
1532 "paddusw " #a ", " #sum " \n\t"
115329f1 1533
1457ab52
MN
1534#define TRANSPOSE4(a,b,c,d,t)\
1535 SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
1536 SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
1537 SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
1538 SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
1539
1540#define LOAD4(o, a, b, c, d)\
bb270c08
DB
1541 "movq "#o"(%1), " #a " \n\t"\
1542 "movq "#o"+16(%1), " #b " \n\t"\
1543 "movq "#o"+32(%1), " #c " \n\t"\
1544 "movq "#o"+48(%1), " #d " \n\t"
1457ab52
MN
1545
1546#define STORE4(o, a, b, c, d)\
bb270c08
DB
1547 "movq "#a", "#o"(%1) \n\t"\
1548 "movq "#b", "#o"+16(%1) \n\t"\
1549 "movq "#c", "#o"+32(%1) \n\t"\
1550 "movq "#d", "#o"+48(%1) \n\t"\
1457ab52 1551
bb198e19 1552static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
68b51e58 1553 DECLARE_ALIGNED_8(uint64_t, temp[16]);
1457ab52 1554 int sum=0;
115329f1 1555
bb198e19 1556 assert(h==8);
1457ab52
MN
1557
1558 diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
11f18faf 1559
1457ab52
MN
1560 asm volatile(
1561 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1562 LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1563
1457ab52 1564 HADAMARD48
115329f1 1565
bb270c08 1566 "movq %%mm7, 112(%1) \n\t"
115329f1 1567
1457ab52
MN
1568 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1569 STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
115329f1 1570
bb270c08 1571 "movq 112(%1), %%mm7 \n\t"
1457ab52
MN
1572 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1573 STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1574
1575 LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1576 LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1577
1457ab52 1578 HADAMARD48
115329f1 1579
bb270c08 1580 "movq %%mm7, 120(%1) \n\t"
115329f1 1581
1457ab52
MN
1582 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1583 STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
115329f1 1584
bb270c08 1585 "movq 120(%1), %%mm7 \n\t"
1457ab52 1586 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
bb270c08
DB
1587 "movq %%mm7, %%mm5 \n\t"//FIXME remove
1588 "movq %%mm6, %%mm7 \n\t"
1589 "movq %%mm0, %%mm6 \n\t"
1457ab52 1590// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
115329f1 1591
1457ab52
MN
1592 LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1593// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1594
1457ab52 1595 HADAMARD48
bb270c08 1596 "movq %%mm7, 64(%1) \n\t"
1457ab52
MN
1597 MMABS(%%mm0, %%mm7)
1598 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1599 MMABS_SUM(%%mm2, %%mm7, %%mm0)
1600 MMABS_SUM(%%mm3, %%mm7, %%mm0)
1601 MMABS_SUM(%%mm4, %%mm7, %%mm0)
1602 MMABS_SUM(%%mm5, %%mm7, %%mm0)
1603 MMABS_SUM(%%mm6, %%mm7, %%mm0)
bb270c08 1604 "movq 64(%1), %%mm1 \n\t"
1457ab52 1605 MMABS_SUM(%%mm1, %%mm7, %%mm0)
bb270c08 1606 "movq %%mm0, 64(%1) \n\t"
115329f1 1607
1457ab52
MN
1608 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1609 LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1610
1457ab52 1611 HADAMARD48
bb270c08 1612 "movq %%mm7, (%1) \n\t"
1457ab52
MN
1613 MMABS(%%mm0, %%mm7)
1614 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1615 MMABS_SUM(%%mm2, %%mm7, %%mm0)
1616 MMABS_SUM(%%mm3, %%mm7, %%mm0)
1617 MMABS_SUM(%%mm4, %%mm7, %%mm0)
1618 MMABS_SUM(%%mm5, %%mm7, %%mm0)
1619 MMABS_SUM(%%mm6, %%mm7, %%mm0)
bb270c08 1620 "movq (%1), %%mm1 \n\t"
1457ab52 1621 MMABS_SUM(%%mm1, %%mm7, %%mm0)
bb270c08 1622 "movq 64(%1), %%mm1 \n\t"
1457ab52 1623 MMABS_SUM(%%mm1, %%mm7, %%mm0)
115329f1 1624
bb270c08
DB
1625 "movq %%mm0, %%mm1 \n\t"
1626 "psrlq $32, %%mm0 \n\t"
1627 "paddusw %%mm1, %%mm0 \n\t"
1628 "movq %%mm0, %%mm1 \n\t"
1629 "psrlq $16, %%mm0 \n\t"
1630 "paddusw %%mm1, %%mm0 \n\t"
1631 "movd %%mm0, %0 \n\t"
115329f1 1632
1457ab52
MN
1633 : "=r" (sum)
1634 : "r"(temp)
1635 );
1636 return sum&0xFFFF;
1637}
1638
bb198e19 1639static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
68b51e58 1640 DECLARE_ALIGNED_8(uint64_t, temp[16]);
8e0a3db7 1641 int sum=0;
115329f1 1642
bb198e19 1643 assert(h==8);
8e0a3db7
MN
1644
1645 diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1646
1647 asm volatile(
1648 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1649 LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1650
8e0a3db7 1651 HADAMARD48
115329f1 1652
bb270c08 1653 "movq %%mm7, 112(%1) \n\t"
115329f1 1654
8e0a3db7
MN
1655 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1656 STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
115329f1 1657
bb270c08 1658 "movq 112(%1), %%mm7 \n\t"
8e0a3db7
MN
1659 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1660 STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1661
1662 LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1663 LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1664
8e0a3db7 1665 HADAMARD48
115329f1 1666
bb270c08 1667 "movq %%mm7, 120(%1) \n\t"
115329f1 1668
8e0a3db7
MN
1669 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1670 STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
115329f1 1671
bb270c08 1672 "movq 120(%1), %%mm7 \n\t"
8e0a3db7 1673 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
bb270c08
DB
1674 "movq %%mm7, %%mm5 \n\t"//FIXME remove
1675 "movq %%mm6, %%mm7 \n\t"
1676 "movq %%mm0, %%mm6 \n\t"
8e0a3db7 1677// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
115329f1 1678
8e0a3db7
MN
1679 LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1680// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1681
8e0a3db7 1682 HADAMARD48
bb270c08 1683 "movq %%mm7, 64(%1) \n\t"
8e0a3db7
MN
1684 MMABS_MMX2(%%mm0, %%mm7)
1685 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1686 MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1687 MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1688 MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1689 MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1690 MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
bb270c08 1691 "movq 64(%1), %%mm1 \n\t"
8e0a3db7 1692 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
bb270c08 1693 "movq %%mm0, 64(%1) \n\t"
115329f1 1694
8e0a3db7
MN
1695 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1696 LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
115329f1 1697
8e0a3db7 1698 HADAMARD48
bb270c08 1699 "movq %%mm7, (%1) \n\t"
8e0a3db7
MN
1700 MMABS_MMX2(%%mm0, %%mm7)
1701 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1702 MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1703 MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1704 MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1705 MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1706 MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
bb270c08 1707 "movq (%1), %%mm1 \n\t"
8e0a3db7 1708 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
bb270c08 1709 "movq 64(%1), %%mm1 \n\t"
8e0a3db7 1710 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
115329f1 1711
12e96681 1712 "pshufw $0x0E, %%mm0, %%mm1 \n\t"
bb270c08 1713 "paddusw %%mm1, %%mm0 \n\t"
12e96681 1714 "pshufw $0x01, %%mm0, %%mm1 \n\t"
bb270c08
DB
1715 "paddusw %%mm1, %%mm0 \n\t"
1716 "movd %%mm0, %0 \n\t"
115329f1 1717
8e0a3db7
MN
1718 : "=r" (sum)
1719 : "r"(temp)
1720 );
1721 return sum&0xFFFF;
1722}
1723
1724
bb198e19
MN
1725WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
1726WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
764ef400 1727#endif //CONFIG_ENCODERS
11f18faf 1728
3178ee4c
MN
1729#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
1730#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
1731
826f429a 1732#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
bb270c08
DB
1733 "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
1734 "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
1735 "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
1736 "movq "#in7", " #m3 " \n\t" /* d */\
1737 "movq "#in0", %%mm5 \n\t" /* D */\
1738 "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
1739 "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
1740 "movq "#in1", %%mm5 \n\t" /* C */\
1741 "movq "#in2", %%mm6 \n\t" /* B */\
1742 "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
1743 "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
1744 "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
1745 "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
1746 "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
1747 "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
1748 "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
1749 "psraw $5, %%mm5 \n\t"\
1750 "packuswb %%mm5, %%mm5 \n\t"\
826f429a
MN
1751 OP(%%mm5, out, %%mm7, d)
1752
3178ee4c 1753#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
5c91a675 1754static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
1755 uint64_t temp;\
1756\
1757 asm volatile(\
bb270c08
DB
1758 "pxor %%mm7, %%mm7 \n\t"\
1759 "1: \n\t"\
1760 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
1761 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
1762 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
1763 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
1764 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
1765 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
1766 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
1767 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
1768 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
1769 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
1770 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
1771 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
1772 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
1773 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
1774 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
1775 "paddw %%mm3, %%mm5 \n\t" /* b */\
1776 "paddw %%mm2, %%mm6 \n\t" /* c */\
1777 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1778 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
1779 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
1780 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
1781 "paddw %%mm4, %%mm0 \n\t" /* a */\
1782 "paddw %%mm1, %%mm5 \n\t" /* d */\
1783 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1784 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
1785 "paddw %6, %%mm6 \n\t"\
1786 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1787 "psraw $5, %%mm0 \n\t"\
1788 "movq %%mm0, %5 \n\t"\
826f429a
MN
1789 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1790 \
bb270c08
DB
1791 "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
1792 "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
1793 "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
1794 "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
1795 "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
1796 "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
1797 "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
1798 "paddw %%mm0, %%mm2 \n\t" /* b */\
1799 "paddw %%mm5, %%mm3 \n\t" /* c */\
1800 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
1801 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
1802 "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
1803 "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
1804 "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
1805 "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
1806 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
1807 "paddw %%mm2, %%mm1 \n\t" /* a */\
1808 "paddw %%mm6, %%mm4 \n\t" /* d */\
1809 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1810 "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
1811 "paddw %6, %%mm1 \n\t"\
1812 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
1813 "psraw $5, %%mm3 \n\t"\
1814 "movq %5, %%mm1 \n\t"\
1815 "packuswb %%mm3, %%mm1 \n\t"\
3178ee4c 1816 OP_MMX2(%%mm1, (%1),%%mm4, q)\
826f429a
MN
1817 /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1818 \
bb270c08
DB
1819 "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
1820 "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
1821 "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
1822 "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
1823 "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
1824 "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
1825 "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
1826 "paddw %%mm1, %%mm5 \n\t" /* b */\
1827 "paddw %%mm4, %%mm0 \n\t" /* c */\
1828 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1829 "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
1830 "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
1831 "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
1832 "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
1833 "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
1834 "paddw %%mm3, %%mm2 \n\t" /* d */\
1835 "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
1836 "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
1837 "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
1838 "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
1839 "paddw %%mm2, %%mm6 \n\t" /* a */\
1840 "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
1841 "paddw %6, %%mm0 \n\t"\
1842 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1843 "psraw $5, %%mm0 \n\t"\
826f429a
MN
1844 /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1845 \
bb270c08
DB
1846 "paddw %%mm5, %%mm3 \n\t" /* a */\
1847 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
1848 "paddw %%mm4, %%mm6 \n\t" /* b */\
1849 "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
1850 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
1851 "paddw %%mm1, %%mm4 \n\t" /* c */\
1852 "paddw %%mm2, %%mm5 \n\t" /* d */\
1853 "paddw %%mm6, %%mm6 \n\t" /* 2b */\
1854 "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
1855 "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1856 "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
1857 "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
1858 "paddw %6, %%mm4 \n\t"\
1859 "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
1860 "psraw $5, %%mm4 \n\t"\
1861 "packuswb %%mm4, %%mm0 \n\t"\
3178ee4c 1862 OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
826f429a 1863 \
bb270c08
DB
1864 "add %3, %0 \n\t"\
1865 "add %4, %1 \n\t"\
1866 "decl %2 \n\t"\
1867 " jnz 1b \n\t"\
5a508a98 1868 : "+a"(src), "+c"(dst), "+m"(h)\
053dea12 1869 : "d"((long)srcStride), "S"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
0b093b6f 1870 : "memory"\
826f429a
MN
1871 );\
1872}\
1873\
1874static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1875 int i;\
1876 int16_t temp[16];\
1877 /* quick HACK, XXX FIXME MUST be optimized */\
1878 for(i=0; i<h; i++)\
1879 {\
1880 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1881 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1882 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1883 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1884 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1885 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1886 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1887 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1888 temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1889 temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1890 temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1891 temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1892 temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1893 temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1894 temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1895 temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1896 asm volatile(\
bb270c08
DB
1897 "movq (%0), %%mm0 \n\t"\
1898 "movq 8(%0), %%mm1 \n\t"\
1899 "paddw %2, %%mm0 \n\t"\
1900 "paddw %2, %%mm1 \n\t"\
1901 "psraw $5, %%mm0 \n\t"\
1902 "psraw $5, %%mm1 \n\t"\
1903 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1904 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
bb270c08
DB
1905 "movq 16(%0), %%mm0 \n\t"\
1906 "movq 24(%0), %%mm1 \n\t"\
1907 "paddw %2, %%mm0 \n\t"\
1908 "paddw %2, %%mm1 \n\t"\
1909 "psraw $5, %%mm0 \n\t"\
1910 "psraw $5, %%mm1 \n\t"\
1911 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1912 OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
826f429a 1913 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1914 : "memory"\
826f429a
MN
1915 );\
1916 dst+=dstStride;\
1917 src+=srcStride;\
1918 }\
1919}\
1920\
5c91a675 1921static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
1922 uint64_t temp;\
1923\
1924 asm volatile(\
bb270c08
DB
1925 "pxor %%mm7, %%mm7 \n\t"\
1926 "1: \n\t"\
1927 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
1928 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
1929 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
1930 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
1931 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
1932 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
1933 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
1934 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
1935 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
1936 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
1937 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
1938 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
1939 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
1940 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
1941 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
1942 "paddw %%mm3, %%mm5 \n\t" /* b */\
1943 "paddw %%mm2, %%mm6 \n\t" /* c */\
1944 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1945 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
1946 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
1947 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
1948 "paddw %%mm4, %%mm0 \n\t" /* a */\
1949 "paddw %%mm1, %%mm5 \n\t" /* d */\
1950 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1951 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
1952 "paddw %6, %%mm6 \n\t"\
1953 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1954 "psraw $5, %%mm0 \n\t"\
826f429a
MN
1955 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1956 \
bb270c08
DB
1957 "movd 5(%0), %%mm5 \n\t" /* FGHI */\
1958 "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
1959 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
1960 "paddw %%mm5, %%mm1 \n\t" /* a */\
1961 "paddw %%mm6, %%mm2 \n\t" /* b */\
1962 "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
1963 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
1964 "paddw %%mm6, %%mm3 \n\t" /* c */\
1965 "paddw %%mm5, %%mm4 \n\t" /* d */\
1966 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
1967 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
1968 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1969 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
1970 "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
1971 "paddw %6, %%mm1 \n\t"\
1972 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
1973 "psraw $5, %%mm3 \n\t"\
1974 "packuswb %%mm3, %%mm0 \n\t"\
3178ee4c 1975 OP_MMX2(%%mm0, (%1), %%mm4, q)\
826f429a 1976 \
bb270c08
DB
1977 "add %3, %0 \n\t"\
1978 "add %4, %1 \n\t"\
1979 "decl %2 \n\t"\
1980 " jnz 1b \n\t"\
5a508a98 1981 : "+a"(src), "+c"(dst), "+m"(h)\
053dea12 1982 : "S"((long)srcStride), "D"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
0b093b6f 1983 : "memory"\
826f429a
MN
1984 );\
1985}\
1986\
1987static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1988 int i;\
1989 int16_t temp[8];\
1990 /* quick HACK, XXX FIXME MUST be optimized */\
1991 for(i=0; i<h; i++)\
1992 {\
1993 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1994 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1995 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1996 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1997 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1998 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1999 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
2000 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
2001 asm volatile(\
bb270c08
DB
2002 "movq (%0), %%mm0 \n\t"\
2003 "movq 8(%0), %%mm1 \n\t"\
2004 "paddw %2, %%mm0 \n\t"\
2005 "paddw %2, %%mm1 \n\t"\
2006 "psraw $5, %%mm0 \n\t"\
2007 "psraw $5, %%mm1 \n\t"\
2008 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 2009 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a 2010 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 2011 :"memory"\
826f429a
MN
2012 );\
2013 dst+=dstStride;\
2014 src+=srcStride;\
2015 }\
3178ee4c
MN
2016}
2017
2018#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
2019\
2020static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2021 uint64_t temp[17*4];\
2022 uint64_t *temp_ptr= temp;\
2023 int count= 17;\
2024\
2025 /*FIXME unroll */\
2026 asm volatile(\
bb270c08
DB
2027 "pxor %%mm7, %%mm7 \n\t"\
2028 "1: \n\t"\
2029 "movq (%0), %%mm0 \n\t"\
2030 "movq (%0), %%mm1 \n\t"\
2031 "movq 8(%0), %%mm2 \n\t"\
2032 "movq 8(%0), %%mm3 \n\t"\
2033 "punpcklbw %%mm7, %%mm0 \n\t"\
2034 "punpckhbw %%mm7, %%mm1 \n\t"\
2035 "punpcklbw %%mm7, %%mm2 \n\t"\
2036 "punpckhbw %%mm7, %%mm3 \n\t"\
2037 "movq %%mm0, (%1) \n\t"\
2038 "movq %%mm1, 17*8(%1) \n\t"\
2039 "movq %%mm2, 2*17*8(%1) \n\t"\
2040 "movq %%mm3, 3*17*8(%1) \n\t"\
2041 "add $8, %1 \n\t"\
2042 "add %3, %0 \n\t"\
2043 "decl %2 \n\t"\
2044 " jnz 1b \n\t"\
3178ee4c 2045 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
053dea12 2046 : "r" ((long)srcStride)\
0b093b6f 2047 : "memory"\
3178ee4c
MN
2048 );\
2049 \
2050 temp_ptr= temp;\
2051 count=4;\
2052 \
2053/*FIXME reorder for speed */\
3178ee4c 2054 asm volatile(\
bb270c08
DB
2055 /*"pxor %%mm7, %%mm7 \n\t"*/\
2056 "1: \n\t"\
2057 "movq (%0), %%mm0 \n\t"\
2058 "movq 8(%0), %%mm1 \n\t"\
2059 "movq 16(%0), %%mm2 \n\t"\
2060 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
2061 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
2062 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
bb270c08 2063 "add %4, %1 \n\t"\
c296f66b 2064 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
3178ee4c 2065 \
c296f66b 2066 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
bb270c08 2067 "add %4, %1 \n\t"\
c296f66b
MN
2068 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
2069 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
bb270c08 2070 "add %4, %1 \n\t"\
c296f66b
MN
2071 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
2072 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
bb270c08 2073 "add %4, %1 \n\t"\
c296f66b
MN
2074 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
2075 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
bb270c08 2076 "add %4, %1 \n\t"\
c296f66b
MN
2077 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
2078 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
bb270c08 2079 "add %4, %1 \n\t"\
c296f66b 2080 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
3178ee4c 2081 \
c296f66b 2082 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
bb270c08 2083 "add %4, %1 \n\t" \
c296f66b
MN
2084 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
2085 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
3178ee4c 2086 \
bb270c08
DB
2087 "add $136, %0 \n\t"\
2088 "add %6, %1 \n\t"\
2089 "decl %2 \n\t"\
2090 " jnz 1b \n\t"\
3178ee4c 2091 \
5a508a98 2092 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
053dea12 2093 : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(long)dstStride)\
0b093b6f 2094 :"memory"\
3178ee4c 2095 );\
826f429a
MN
2096}\
2097\
5c91a675 2098static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
437525c4 2099 uint64_t temp[9*2];\
826f429a
MN
2100 uint64_t *temp_ptr= temp;\
2101 int count= 9;\
2102\
2103 /*FIXME unroll */\
2104 asm volatile(\
bb270c08
DB
2105 "pxor %%mm7, %%mm7 \n\t"\
2106 "1: \n\t"\
2107 "movq (%0), %%mm0 \n\t"\
2108 "movq (%0), %%mm1 \n\t"\
2109 "punpcklbw %%mm7, %%mm0 \n\t"\
2110 "punpckhbw %%mm7, %%mm1 \n\t"\
2111 "movq %%mm0, (%1) \n\t"\
2112 "movq %%mm1, 9*8(%1) \n\t"\
2113 "add $8, %1 \n\t"\
2114 "add %3, %0 \n\t"\
2115 "decl %2 \n\t"\
2116 " jnz 1b \n\t"\
826f429a 2117 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
053dea12 2118 : "r" ((long)srcStride)\
0b093b6f 2119 : "memory"\
826f429a
MN
2120 );\
2121 \
2122 temp_ptr= temp;\
2123 count=2;\
2124 \
2125/*FIXME reorder for speed */\
2126 asm volatile(\
bb270c08
DB
2127 /*"pxor %%mm7, %%mm7 \n\t"*/\
2128 "1: \n\t"\
2129 "movq (%0), %%mm0 \n\t"\
2130 "movq 8(%0), %%mm1 \n\t"\
2131 "movq 16(%0), %%mm2 \n\t"\
2132 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
2133 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
2134 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
bb270c08 2135 "add %4, %1 \n\t"\
c296f66b 2136 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
826f429a 2137 \
c296f66b 2138 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
bb270c08 2139 "add %4, %1 \n\t"\
c296f66b 2140 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
826f429a 2141 \
c296f66b 2142 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
bb270c08 2143 "add %4, %1 \n\t"\
c296f66b
MN
2144 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
2145 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
826f429a 2146 \
bb270c08
DB
2147 "add $72, %0 \n\t"\
2148 "add %6, %1 \n\t"\
2149 "decl %2 \n\t"\
2150 " jnz 1b \n\t"\
826f429a 2151 \
c296f66b 2152 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
053dea12 2153 : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(long)dstStride)\
0b093b6f
MN
2154 : "memory"\
2155 );\
3178ee4c 2156}\
826f429a 2157\
0c1a9eda 2158static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2159 OPNAME ## pixels8_mmx(dst, src, stride, 8);\
826f429a
MN
2160}\
2161\
0c1a9eda 2162static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2163 uint64_t temp[8];\
826f429a
MN
2164 uint8_t * const half= (uint8_t*)temp;\
2165 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
d6af6b03 2166 OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
826f429a
MN
2167}\
2168\
0c1a9eda 2169static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2170 OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
2171}\
2172\
0c1a9eda 2173static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2174 uint64_t temp[8];\
826f429a
MN
2175 uint8_t * const half= (uint8_t*)temp;\
2176 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
d6af6b03 2177 OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
826f429a
MN
2178}\
2179\
0c1a9eda 2180static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2181 uint64_t temp[8];\
826f429a 2182 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2183 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
d6af6b03 2184 OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
826f429a
MN
2185}\
2186\
0c1a9eda 2187static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2188 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
2189}\
2190\
0c1a9eda 2191static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2192 uint64_t temp[8];\
826f429a 2193 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2194 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
d6af6b03 2195 OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
826f429a 2196}\
0c1a9eda 2197static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2198 uint64_t half[8 + 9];\
2199 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2200 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2201 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2202 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
3178ee4c 2203 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2204 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
826f429a 2205}\
0c1a9eda 2206static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2207 uint64_t half[8 + 9];\
2208 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2209 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2210 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2211 put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 2212 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2213 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
826f429a 2214}\
0c1a9eda 2215static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2216 uint64_t half[8 + 9];\
2217 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2218 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2219 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2220 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
3178ee4c 2221 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2222 OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 2223}\
0c1a9eda 2224static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2225 uint64_t half[8 + 9];\
2226 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2227 uint8_t * const halfHV= ((uint8_t*)half);\
2228 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2229 put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 2230 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2231 OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 2232}\
0c1a9eda 2233static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2234 uint64_t half[8 + 9];\
826f429a
MN
2235 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2236 uint8_t * const halfHV= ((uint8_t*)half);\
2237 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2238 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2239 OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
826f429a 2240}\
0c1a9eda 2241static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2242 uint64_t half[8 + 9];\
826f429a
MN
2243 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2244 uint8_t * const halfHV= ((uint8_t*)half);\
2245 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2246 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
d6af6b03 2247 OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 2248}\
0c1a9eda 2249static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2250 uint64_t half[8 + 9];\
2251 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2252 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2253 put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
db794953 2254 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2255}\
0c1a9eda 2256static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2257 uint64_t half[8 + 9];\
2258 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2259 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
d6af6b03 2260 put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
db794953 2261 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2262}\
0c1a9eda 2263static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2264 uint64_t half[9];\
826f429a
MN
2265 uint8_t * const halfH= ((uint8_t*)half);\
2266 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2267 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2268}\
0c1a9eda 2269static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2270 OPNAME ## pixels16_mmx(dst, src, stride, 16);\
826f429a
MN
2271}\
2272\
0c1a9eda 2273static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2274 uint64_t temp[32];\
2275 uint8_t * const half= (uint8_t*)temp;\
2276 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
d6af6b03 2277 OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
826f429a
MN
2278}\
2279\
0c1a9eda 2280static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2281 OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
2282}\
2283\
0c1a9eda 2284static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2285 uint64_t temp[32];\
2286 uint8_t * const half= (uint8_t*)temp;\
2287 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
d6af6b03 2288 OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
826f429a
MN
2289}\
2290\
0c1a9eda 2291static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2292 uint64_t temp[32];\
2293 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2294 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
d6af6b03 2295 OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
826f429a
MN
2296}\
2297\
0c1a9eda 2298static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2299 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
2300}\
2301\
0c1a9eda 2302static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2303 uint64_t temp[32];\
2304 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2305 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
d6af6b03 2306 OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
826f429a 2307}\
0c1a9eda 2308static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2309 uint64_t half[16*2 + 17*2];\
2310 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2311 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2312 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2313 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
3178ee4c 2314 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2315 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
826f429a 2316}\
0c1a9eda 2317static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2318 uint64_t half[16*2 + 17*2];\
2319 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2320 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2321 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2322 put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 2323 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2324 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
826f429a 2325}\
0c1a9eda 2326static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2327 uint64_t half[16*2 + 17*2];\
2328 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2329 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2330 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2331 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
3178ee4c 2332 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2333 OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 2334}\
0c1a9eda 2335static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2336 uint64_t half[16*2 + 17*2];\
2337 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2338 uint8_t * const halfHV= ((uint8_t*)half);\
2339 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2340 put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 2341 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2342 OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 2343}\
0c1a9eda 2344static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2345 uint64_t half[16*2 + 17*2];\
2346 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2347 uint8_t * const halfHV= ((uint8_t*)half);\
2348 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2349 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2350 OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
826f429a 2351}\
0c1a9eda 2352static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2353 uint64_t half[16*2 + 17*2];\
2354 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2355 uint8_t * const halfHV= ((uint8_t*)half);\
2356 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2357 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
d6af6b03 2358 OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 2359}\
0c1a9eda 2360static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2361 uint64_t half[17*2];\
2362 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2363 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2364 put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
db794953 2365 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 2366}\
0c1a9eda 2367static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2368 uint64_t half[17*2];\
2369 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2370 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
d6af6b03 2371 put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
db794953 2372 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 2373}\
0c1a9eda 2374static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2375 uint64_t half[17*2];\
2376 uint8_t * const halfH= ((uint8_t*)half);\
2377 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2378 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a
MN
2379}
2380
bb270c08 2381#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
3178ee4c 2382#define AVG_3DNOW_OP(a,b,temp, size) \
bb270c08
DB
2383"mov" #size " " #b ", " #temp " \n\t"\
2384"pavgusb " #temp ", " #a " \n\t"\
2385"mov" #size " " #a ", " #b " \n\t"
3178ee4c 2386#define AVG_MMX2_OP(a,b,temp, size) \
bb270c08
DB
2387"mov" #size " " #b ", " #temp " \n\t"\
2388"pavgb " #temp ", " #a " \n\t"\
2389"mov" #size " " #a ", " #b " \n\t"
3178ee4c
MN
2390
2391QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
2392QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
2393QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
2394QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
2395QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
2396QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
826f429a 2397QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
3178ee4c 2398QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
826f429a
MN
2399QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
2400
61a4e8ae 2401#if 0
d6a4c0b1 2402static void just_return() { return; }
61a4e8ae 2403#endif
d6a4c0b1 2404
826f429a
MN
2405#define SET_QPEL_FUNC(postfix1, postfix2) \
2406 c->put_ ## postfix1 = put_ ## postfix2;\
2407 c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
2408 c->avg_ ## postfix1 = avg_ ## postfix2;
b0368839 2409
703c8195
LM
2410static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
2411 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){
2412 const int w = 8;
703c8195
LM
2413 const int ix = ox>>(16+shift);
2414 const int iy = oy>>(16+shift);
2415 const int oxs = ox>>4;
2416 const int oys = oy>>4;
2417 const int dxxs = dxx>>4;
2418 const int dxys = dxy>>4;
2419 const int dyxs = dyx>>4;
2420 const int dyys = dyy>>4;
2421 const uint16_t r4[4] = {r,r,r,r};
2422 const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
2423 const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
2424 const uint64_t shift2 = 2*shift;
2425 uint8_t edge_buf[(h+1)*stride];
2426 int x, y;
2427
2428 const int dxw = (dxx-(1<<(16+shift)))*(w-1);
2429 const int dyh = (dyy-(1<<(16+shift)))*(h-1);
2430 const int dxh = dxy*(h-1);
2431 const int dyw = dyx*(w-1);
2432 if( // non-constant fullpel offset (3% of blocks)
2433 (ox^(ox+dxw) | ox^(ox+dxh) | ox^(ox+dxw+dxh) |
2434 oy^(oy+dyw) | oy^(oy+dyh) | oy^(oy+dyw+dyh)) >> (16+shift)
2435 // uses more than 16 bits of subpel mv (only at huge resolution)
2436 || (dxx|dxy|dyx|dyy)&15 )
2437 {
2438 //FIXME could still use mmx for some of the rows
2439 ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
2440 return;
2441 }
2442
75ca1a5f 2443 src += ix + iy*stride;
703c8195
LM
2444 if( (unsigned)ix >= width-w ||
2445 (unsigned)iy >= height-h )
2446 {
75ca1a5f 2447 ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
703c8195
LM
2448 src = edge_buf;
2449 }
75ca1a5f
LM
2450
2451 asm volatile(
2452 "movd %0, %%mm6 \n\t"
2453 "pxor %%mm7, %%mm7 \n\t"
2454 "punpcklwd %%mm6, %%mm6 \n\t"
2455 "punpcklwd %%mm6, %%mm6 \n\t"
2456 :: "r"(1<<shift)
2457 );
703c8195
LM
2458
2459 for(x=0; x<w; x+=4){
2460 uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
2461 oxs - dxys + dxxs*(x+1),
2462 oxs - dxys + dxxs*(x+2),
2463 oxs - dxys + dxxs*(x+3) };
2464 uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
2465 oys - dyys + dyxs*(x+1),
2466 oys - dyys + dyxs*(x+2),
2467 oys - dyys + dyxs*(x+3) };
2468
703c8195
LM
2469 for(y=0; y<h; y++){
2470 asm volatile(
2471 "movq %0, %%mm4 \n\t"
2472 "movq %1, %%mm5 \n\t"
2473 "paddw %2, %%mm4 \n\t"
2474 "paddw %3, %%mm5 \n\t"
2475 "movq %%mm4, %0 \n\t"
2476 "movq %%mm5, %1 \n\t"
2477 "psrlw $12, %%mm4 \n\t"
2478 "psrlw $12, %%mm5 \n\t"
2479 : "+m"(*dx4), "+m"(*dy4)
2480 : "m"(*dxy4), "m"(*dyy4)
2481 );
2482
2483 asm volatile(
2484 "movq %%mm6, %%mm2 \n\t"
2485 "movq %%mm6, %%mm1 \n\t"
2486 "psubw %%mm4, %%mm2 \n\t"
2487 "psubw %%mm5, %%mm1 \n\t"
2488 "movq %%mm2, %%mm0 \n\t"
2489 "movq %%mm4, %%mm3 \n\t"
2490 "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
2491 "pmullw %%mm5, %%mm3 \n\t" // dx*dy
2492 "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
2493 "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
2494
2495 "movd %4, %%mm5 \n\t"
2496 "movd %3, %%mm4 \n\t"
2497 "punpcklbw %%mm7, %%mm5 \n\t"
2498 "punpcklbw %%mm7, %%mm4 \n\t"
2499 "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
2500 "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
2501
2502 "movd %2, %%mm5 \n\t"
2503 "movd %1, %%mm4 \n\t"
2504 "punpcklbw %%mm7, %%mm5 \n\t"
2505 "punpcklbw %%mm7, %%mm4 \n\t"
2506 "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
2507 "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
75ca1a5f 2508 "paddw %5, %%mm1 \n\t"
703c8195
LM
2509 "paddw %%mm3, %%mm2 \n\t"
2510 "paddw %%mm1, %%mm0 \n\t"
2511 "paddw %%mm2, %%mm0 \n\t"
703c8195
LM
2512
2513 "psrlw %6, %%mm0 \n\t"
2514 "packuswb %%mm0, %%mm0 \n\t"
2515 "movd %%mm0, %0 \n\t"
2516
2517 : "=m"(dst[x+y*stride])
2518 : "m"(src[0]), "m"(src[1]),
2519 "m"(src[stride]), "m"(src[stride+1]),
2520 "m"(*r4), "m"(shift2)
2521 );
2522 src += stride;
2523 }
2524 src += 4-h*stride;
2525 }
2526}
2527
364a1797 2528static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
053dea12 2529 long i=0;
115329f1 2530
364a1797
MN
2531 assert(ABS(scale) < 256);
2532 scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2533
2534 asm volatile(
bb270c08
DB
2535 "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
2536 "psrlw $15, %%mm6 \n\t" // 1w
2537 "pxor %%mm7, %%mm7 \n\t"
2538 "movd %4, %%mm5 \n\t"
2539 "punpcklwd %%mm5, %%mm5 \n\t"
2540 "punpcklwd %%mm5, %%mm5 \n\t"
2541 "1: \n\t"
2542 "movq (%1, %0), %%mm0 \n\t"
2543 "movq 8(%1, %0), %%mm1 \n\t"
2544 "pmulhw %%mm5, %%mm0 \n\t"
2545 "pmulhw %%mm5, %%mm1 \n\t"
2546 "paddw %%mm6, %%mm0 \n\t"
2547 "paddw %%mm6, %%mm1 \n\t"
2548 "psraw $1, %%mm0 \n\t"
2549 "psraw $1, %%mm1 \n\t"
2550 "paddw (%2, %0), %%mm0 \n\t"
2551 "paddw 8(%2, %0), %%mm1 \n\t"
2552 "psraw $6, %%mm0 \n\t"
2553 "psraw $6, %%mm1 \n\t"
2554 "pmullw (%3, %0), %%mm0 \n\t"
2555 "pmullw 8(%3, %0), %%mm1 \n\t"
2556 "pmaddwd %%mm0, %%mm0 \n\t"
2557 "pmaddwd %%mm1, %%mm1 \n\t"
2558 "paddd %%mm1, %%mm0 \n\t"
2559 "psrld $4, %%mm0 \n\t"
2560 "paddd %%mm0, %%mm7 \n\t"
2561 "add $16, %0 \n\t"
2562 "cmp $128, %0 \n\t" //FIXME optimize & bench
2563 " jb 1b \n\t"
2564 "movq %%mm7, %%mm6 \n\t"
2565 "psrlq $32, %%mm7 \n\t"
2566 "paddd %%mm6, %%mm7 \n\t"
2567 "psrld $2, %%mm7 \n\t"
2568 "movd %%mm7, %0 \n\t"
115329f1 2569
364a1797
MN
2570 : "+r" (i)
2571 : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
2572 );
2573 return i;
2574}
2575
2576static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){
053dea12 2577 long i=0;
115329f1 2578
364a1797
MN
2579 if(ABS(scale) < 256){
2580 scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2581 asm volatile(
bb270c08
DB
2582 "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
2583 "psrlw $15, %%mm6 \n\t" // 1w
2584 "movd %3, %%mm5 \n\t"
2585 "punpcklwd %%mm5, %%mm5 \n\t"
2586 "punpcklwd %%mm5, %%mm5 \n\t"
2587 "1: \n\t"
2588 "movq (%1, %0), %%mm0 \n\t"
2589 "movq 8(%1, %0), %%mm1 \n\t"
2590 "pmulhw %%mm5, %%mm0 \n\t"
2591 "pmulhw %%mm5, %%mm1 \n\t"
2592 "paddw %%mm6, %%mm0 \n\t"
2593 "paddw %%mm6, %%mm1 \n\t"
2594 "psraw $1, %%mm0 \n\t"
2595 "psraw $1, %%mm1 \n\t"
2596 "paddw (%2, %0), %%mm0 \n\t"
2597 "paddw 8(%2, %0), %%mm1 \n\t"
2598 "movq %%mm0, (%2, %0) \n\t"
2599 "movq %%mm1, 8(%2, %0) \n\t"
2600 "add $16, %0 \n\t"
2601 "cmp $128, %0 \n\t" //FIXME optimize & bench
2602 " jb 1b \n\t"
115329f1 2603
364a1797
MN
2604 : "+r" (i)
2605 : "r"(basis), "r"(rem), "g"(scale)
2606 );
2607 }else{
2608 for(i=0; i<8*8; i++){
2609 rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
115329f1 2610 }
364a1797
MN
2611 }
2612}
d2bb7db1 2613
513fbd8e
LM
2614#define PREFETCH(name, op) \
2615void name(void *mem, int stride, int h){\
2616 const uint8_t *p= mem;\
2617 do{\
2618 asm volatile(#op" %0" :: "m"(*p));\
2619 p+= stride;\
2620 }while(--h);\
2621}
2622PREFETCH(prefetch_mmx2, prefetcht0)
2623PREFETCH(prefetch_3dnow, prefetch)
2624#undef PREFETCH
2625
d2bb7db1 2626#include "h264dsp_mmx.c"
115329f1 2627
595e7bd9
SG
2628/* AVS specific */
2629void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx);
2630
2631void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
2632 put_pixels8_mmx(dst, src, stride, 8);
2633}
2634void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
2635 avg_pixels8_mmx(dst, src, stride, 8);
2636}
2637void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
2638 put_pixels16_mmx(dst, src, stride, 16);
2639}
2640void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
2641 avg_pixels16_mmx(dst, src, stride, 16);
2642}
2643
b0368839
MN
2644/* external functions, from idct_mmx.c */
2645void ff_mmx_idct(DCTELEM *block);
2646void ff_mmxext_idct(DCTELEM *block);
2647
5773a746
MN
2648void ff_vp3_idct_sse2(int16_t *input_data);
2649void ff_vp3_idct_mmx(int16_t *data);
2650void ff_vp3_dsp_init_mmx(void);
2651
b0368839
MN
2652/* XXX: those functions should be suppressed ASAP when all IDCTs are
2653 converted */
2654static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2655{
2656 ff_mmx_idct (block);
2657 put_pixels_clamped_mmx(block, dest, line_size);
2658}
2659static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2660{
2661 ff_mmx_idct (block);
2662 add_pixels_clamped_mmx(block, dest, line_size);
2663}
2664static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2665{
2666 ff_mmxext_idct (block);
2667 put_pixels_clamped_mmx(block, dest, line_size);
2668}
2669static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2670{
2671 ff_mmxext_idct (block);
2672 add_pixels_clamped_mmx(block, dest, line_size);
2673}
5773a746
MN
2674static void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
2675{
2676 ff_vp3_idct_sse2(block);
2677 put_signed_pixels_clamped_mmx(block, dest, line_size);
2678}
2679static void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
2680{
2681 ff_vp3_idct_sse2(block);
2682 add_pixels_clamped_mmx(block, dest, line_size);
2683}
2684static void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
2685{
2686 ff_vp3_idct_mmx(block);
2687 put_signed_pixels_clamped_mmx(block, dest, line_size);
2688}
2689static void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block)
2690{
2691 ff_vp3_idct_mmx(block);
2692 add_pixels_clamped_mmx(block, dest, line_size);
2693}
84740d59
MN
2694#ifdef CONFIG_GPL
2695static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
2696{
2697 ff_idct_xvid_mmx (block);
2698 put_pixels_clamped_mmx(block, dest, line_size);
2699}
2700static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
2701{
2702 ff_idct_xvid_mmx (block);
2703 add_pixels_clamped_mmx(block, dest, line_size);
2704}
2705static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
2706{
2707 ff_idct_xvid_mmx2 (block);
2708 put_pixels_clamped_mmx(block, dest, line_size);
2709}
2710static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
2711{
2712 ff_idct_xvid_mmx2 (block);
2713 add_pixels_clamped_mmx(block, dest, line_size);
2714}
2715#endif
115329f1 2716
cd035a60 2717static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
2dac4acf
LM
2718{
2719 int i;
2720 asm volatile("pxor %%mm7, %%mm7":);
2721 for(i=0; i<blocksize; i+=2) {
2722 asm volatile(
2723 "movq %0, %%mm0 \n\t"
2724 "movq %1, %%mm1 \n\t"
2725 "movq %%mm0, %%mm2 \n\t"
2726 "movq %%mm1, %%mm3 \n\t"
2727 "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
2728 "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
2729 "pslld $31, %%mm2 \n\t" // keep only the sign bit
2730 "pxor %%mm2, %%mm1 \n\t"
2731 "movq %%mm3, %%mm4 \n\t"
2732 "pand %%mm1, %%mm3 \n\t"
2733 "pandn %%mm1, %%mm4 \n\t"
2734 "pfadd %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
2735 "pfsub %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
2736 "movq %%mm3, %1 \n\t"
2737 "movq %%mm0, %0 \n\t"
2738 :"+m"(mag[i]), "+m"(ang[i])
2739 ::"memory"
2740 );
2741 }
ee5df927 2742 asm volatile("femms");
2dac4acf 2743}
21bb884f 2744static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
2dac4acf
LM
2745{
2746 int i;
21bb884f
MN
2747
2748 asm volatile(
2749 "movaps %0, %%xmm5 \n\t"
2750 ::"m"(ff_pdw_80000000[0])
2751 );
2dac4acf
LM
2752 for(i=0; i<blocksize; i+=4) {
2753 asm volatile(
2754 "movaps %0, %%xmm0 \n\t"
2755 "movaps %1, %%xmm1 \n\t"
21bb884f
MN
2756 "xorps %%xmm2, %%xmm2 \n\t"
2757 "xorps %%xmm3, %%xmm3 \n\t"
2dac4acf
LM
2758 "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
2759 "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
21bb884f
MN
2760 "andps %%xmm5, %%xmm2 \n\t" // keep only the sign bit
2761 "xorps %%xmm2, %%xmm1 \n\t"
2dac4acf 2762 "movaps %%xmm3, %%xmm4 \n\t"
21bb884f
MN
2763 "andps %%xmm1, %%xmm3 \n\t"
2764 "andnps %%xmm1, %%xmm4 \n\t"
2dac4acf
LM
2765 "addps %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
2766 "subps %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
2767 "movaps %%xmm3, %1 \n\t"
2768 "movaps %%xmm0, %0 \n\t"
2769 :"+m"(mag[i]), "+m"(ang[i])
2770 ::"memory"
2771 );
2772 }
2773}
2774
2c9a0285
RE
2775#ifdef CONFIG_SNOW_ENCODER
2776extern void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width);
2777extern void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width);
4567b4bd
RE
2778extern void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
2779extern void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width);
e8600e5e
RE
2780extern void ff_snow_inner_add_yblock_sse2(uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
2781 int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
2782extern void ff_snow_inner_add_yblock_mmx(uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
2783 int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
2c9a0285 2784#endif
4567b4bd 2785
b0368839 2786void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
de6d9b64
FB
2787{
2788 mm_flags = mm_support();
63f60826 2789
e5247b5f 2790 if (avctx->dsp_mask) {
bb270c08
DB
2791 if (avctx->dsp_mask & FF_MM_FORCE)
2792 mm_flags |= (avctx->dsp_mask & 0xffff);
2793 else
2794 mm_flags &= ~(avctx->dsp_mask & 0xffff);
e5247b5f 2795 }
63f60826 2796
1565dabc 2797#if 0
01456e8e 2798 av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
de6d9b64 2799 if (mm_flags & MM_MMX)
01456e8e 2800 av_log(avctx, AV_LOG_INFO, " mmx");
de6d9b64 2801 if (mm_flags & MM_MMXEXT)
01456e8e 2802 av_log(avctx, AV_LOG_INFO, " mmxext");
de6d9b64 2803 if (mm_flags & MM_3DNOW)
01456e8e 2804 av_log(avctx, AV_LOG_INFO, " 3dnow");
de6d9b64 2805 if (mm_flags & MM_SSE)
01456e8e 2806 av_log(avctx, AV_LOG_INFO, " sse");
de6d9b64 2807 if (mm_flags & MM_SSE2)
01456e8e
MM
2808 av_log(avctx, AV_LOG_INFO, " sse2");
2809 av_log(avctx, AV_LOG_INFO, "\n");
de6d9b64
FB
2810#endif
2811
2812 if (mm_flags & MM_MMX) {
b0368839
MN
2813 const int idct_algo= avctx->idct_algo;
2814
5fd74135 2815#ifdef CONFIG_ENCODERS
e96682e6 2816 const int dct_algo = avctx->dct_algo;
cf3bf5bb 2817 if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
8fd19ab2
MN
2818 if(mm_flags & MM_SSE2){
2819 c->fdct = ff_fdct_sse2;
bb270c08 2820 }else if(mm_flags & MM_MMXEXT){
cf3bf5bb
MN
2821 c->fdct = ff_fdct_mmx2;
2822 }else{
2823 c->fdct = ff_fdct_mmx;
2824 }
2825 }
5fd74135 2826#endif //CONFIG_ENCODERS
178fcca8
MN
2827 if(avctx->lowres==0){
2828 if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
2829 c->idct_put= ff_simple_idct_put_mmx;
2830 c->idct_add= ff_simple_idct_add_mmx;
2831 c->idct = ff_simple_idct_mmx;
2832 c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
2833 }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
2834 if(mm_flags & MM_MMXEXT){
2835 c->idct_put= ff_libmpeg2mmx2_idct_put;
2836 c->idct_add= ff_libmpeg2mmx2_idct_add;
2837 c->idct = ff_mmxext_idct;
2838 }else{
2839 c->idct_put= ff_libmpeg2mmx_idct_put;
2840 c->idct_add= ff_libmpeg2mmx_idct_add;
2841 c->idct = ff_mmx_idct;
2842 }
2843 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
5ced7b80 2844#if 0
5773a746
MN
2845 }else if(idct_algo==FF_IDCT_VP3){
2846 if(mm_flags & MM_SSE2){
2847 c->idct_put= ff_vp3_idct_put_sse2;
2848 c->idct_add= ff_vp3_idct_add_sse2;
2849 c->idct = ff_vp3_idct_sse2;
2850 c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2851 }else{
2852 ff_vp3_dsp_init_mmx();
2853 c->idct_put= ff_vp3_idct_put_mmx;
2854 c->idct_add= ff_vp3_idct_add_mmx;
2855 c->idct = ff_vp3_idct_mmx;
2856 c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
2857 }
5ced7b80 2858#endif
595e7bd9
SG
2859 }else if(idct_algo==FF_IDCT_CAVS){
2860 c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
84740d59
MN
2861#ifdef CONFIG_GPL
2862 }else if(idct_algo==FF_IDCT_XVIDMMX){
2863 if(mm_flags & MM_MMXEXT){
2864 c->idct_put= ff_idct_xvid_mmx2_put;
2865 c->idct_add= ff_idct_xvid_mmx2_add;
2866 c->idct = ff_idct_xvid_mmx2;
2867 }else{
2868 c->idct_put= ff_idct_xvid_mmx_put;
2869 c->idct_add= ff_idct_xvid_mmx_add;
2870 c->idct = ff_idct_xvid_mmx;
2871 }
84740d59 2872#endif
cd7af76d 2873 }
b0368839 2874 }
01456e8e 2875
764ef400 2876#ifdef CONFIG_ENCODERS
eb4b3dd3
ZK
2877 c->get_pixels = get_pixels_mmx;
2878 c->diff_pixels = diff_pixels_mmx;
764ef400 2879#endif //CONFIG_ENCODERS
eb4b3dd3 2880 c->put_pixels_clamped = put_pixels_clamped_mmx;
f9ed9d85 2881 c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
eb4b3dd3
ZK
2882 c->add_pixels_clamped = add_pixels_clamped_mmx;
2883 c->clear_blocks = clear_blocks_mmx;
764ef400 2884#ifdef CONFIG_ENCODERS
eb4b3dd3 2885 c->pix_sum = pix_sum16_mmx;
764ef400 2886#endif //CONFIG_ENCODERS
eb4b3dd3 2887
eb4b3dd3
ZK
2888 c->put_pixels_tab[0][0] = put_pixels16_mmx;
2889 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
2890 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
2891 c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
2892
2893 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
2894 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
2895 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
2896 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
2897
2898 c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
2899 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
2900 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
2901 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
2902
2903 c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
2904 c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
2905 c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
2906 c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
2907
2908 c->put_pixels_tab[1][0] = put_pixels8_mmx;
2909 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
2910 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
2911 c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
2912
2913 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
2914 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
2915 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
2916 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
2917
2918 c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
2919 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
2920 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
2921 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
2922
2923 c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
2924 c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
2925 c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
2926 c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
115329f1 2927
703c8195
LM
2928 c->gmc= gmc_mmx;
2929
11f18faf 2930 c->add_bytes= add_bytes_mmx;
764ef400 2931#ifdef CONFIG_ENCODERS
11f18faf 2932 c->diff_bytes= diff_bytes_mmx;
115329f1 2933
1457ab52
MN
2934 c->hadamard8_diff[0]= hadamard8_diff16_mmx;
2935 c->hadamard8_diff[1]= hadamard8_diff_mmx;
115329f1 2936
bb270c08
DB
2937 c->pix_norm1 = pix_norm1_mmx;
2938 c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx;
2939 c->sse[1] = sse8_mmx;
622348f9
MN
2940 c->vsad[4]= vsad_intra16_mmx;
2941
bb270c08
DB
2942 c->nsse[0] = nsse16_mmx;
2943 c->nsse[1] = nsse8_mmx;
622348f9
MN
2944 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2945 c->vsad[0] = vsad16_mmx;
2946 }
115329f1 2947
364a1797
MN
2948 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2949 c->try_8x8basis= try_8x8basis_mmx;
2950 }
2951 c->add_8x8basis= add_8x8basis_mmx;
115329f1 2952
764ef400 2953#endif //CONFIG_ENCODERS
359f98de
MN
2954
2955 c->h263_v_loop_filter= h263_v_loop_filter_mmx;
115329f1 2956 c->h263_h_loop_filter= h263_h_loop_filter_mmx;
bb270c08 2957 c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx;
a6624e21 2958 c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx;
115329f1 2959
6da971f1
LM
2960 c->h264_idct_dc_add=
2961 c->h264_idct_add= ff_h264_idct_add_mmx;
548a1c8a
LM
2962 c->h264_idct8_dc_add=
2963 c->h264_idct8_add= ff_h264_idct8_add_mmx;
6da971f1 2964
de6d9b64 2965 if (mm_flags & MM_MMXEXT) {
513fbd8e
LM
2966 c->prefetch = prefetch_mmx2;
2967
eb4b3dd3
ZK
2968 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2969 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
eb4b3dd3
ZK
2970
2971 c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2972 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2973 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
eb4b3dd3
ZK
2974
2975 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2976 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
eb4b3dd3
ZK
2977
2978 c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2979 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2980 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
b0368839 2981
764ef400 2982#ifdef CONFIG_ENCODERS
8e0a3db7
MN
2983 c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
2984 c->hadamard8_diff[1]= hadamard8_diff_mmx2;
622348f9 2985 c->vsad[4]= vsad_intra16_mmx2;
764ef400 2986#endif //CONFIG_ENCODERS
8e0a3db7 2987
ef9d1d15
LM
2988 c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2;
2989 c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2;
1d62fc85 2990
b0368839
MN
2991 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2992 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2993 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2994 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2995 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2996 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2997 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
fb85b027 2998#ifdef CONFIG_ENCODERS
622348f9 2999 c->vsad[0] = vsad16_mmx2;
fb85b027 3000#endif //CONFIG_ENCODERS
b0368839 3001 }
3178ee4c 3002
c296f66b 3003#if 1
826f429a
MN
3004 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
3005 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
3006 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
3007 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
3008 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
3009 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
3010 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
3011 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
3012 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
3013 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
3014 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
3015 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
3016 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
3017 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
3018 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
3019 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
3020 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
3021 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
3022 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
3023 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
3024 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
3025 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
3026 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
3027 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
3028 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
3029 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
3030 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
3031 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
3032 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
3033 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
3034 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
3035 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
c296f66b 3036#endif
84705403 3037
437525c4
MN
3038//FIXME 3dnow too
3039#define dspfunc(PFX, IDX, NUM) \
3040 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_mmx2; \
3041 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_mmx2; \
3042 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_mmx2; \
3043 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_mmx2; \
3044 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_mmx2; \
3045 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_mmx2; \
3046 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_mmx2; \
3047 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_mmx2; \
3048 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_mmx2; \
3049 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_mmx2; \
3050 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_mmx2; \
3051 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_mmx2; \
3052 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_mmx2; \
3053 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_mmx2; \
3054 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_mmx2; \
3055 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_mmx2
3056
3057 dspfunc(put_h264_qpel, 0, 16);
3058 dspfunc(put_h264_qpel, 1, 8);
3059 dspfunc(put_h264_qpel, 2, 4);
3060 dspfunc(avg_h264_qpel, 0, 16);
3061 dspfunc(avg_h264_qpel, 1, 8);
3062 dspfunc(avg_h264_qpel, 2, 4);
3063#undef dspfunc
3064
bb270c08 3065 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2;
a6624e21 3066 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2;
fdd30579
LM
3067 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2;
3068 c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2;
42251a2a
LM
3069 c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2;
3070 c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2;
3071 c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2;
3072 c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2;
5cf08f23
LM
3073 c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2;
3074 c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2;
42251a2a 3075
b926572a
LM
3076 c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2;
3077 c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2;
3078 c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2;
3079 c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2;
3080 c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2;
3081 c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2;
3082 c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2;
3083 c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2;
3084
3085 c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2;
3086 c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2;
3087 c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2;
3088 c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2;
3089 c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2;
3090 c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2;
3091 c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
3092 c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
3093
595e7bd9
SG
3094#ifdef CONFIG_CAVS_DECODER
3095 ff_cavsdsp_init_mmx2(c, avctx);
3096#endif
3097
0c11692a 3098#ifdef CONFIG_ENCODERS
84705403 3099 c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2;
0c11692a 3100#endif //CONFIG_ENCODERS
de6d9b64 3101 } else if (mm_flags & MM_3DNOW) {
513fbd8e
LM
3102 c->prefetch = prefetch_3dnow;
3103
eb4b3dd3
ZK
3104 c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
3105 c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
eb4b3dd3
ZK
3106
3107 c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
3108 c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
3109 c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
eb4b3dd3
ZK
3110
3111 c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
3112 c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
eb4b3dd3
ZK
3113
3114 c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
3115 c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
3116 c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
b0368839
MN
3117
3118 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
3119 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
3120 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
3121 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
3122 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
3123 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
3124 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
3125 }
db794953 3126
826f429a
MN
3127 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
3128 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
3129 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
3130 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
3131 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
3132 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
3133 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
3134 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
3135 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
3136 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
3137 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
3138 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
3139 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
3140 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
3141 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
3142 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
3143 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
3144 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
3145 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
3146 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
3147 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
3148 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
3149 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
3150 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
3151 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
3152 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
3153 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
3154 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
3155 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
3156 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
3157 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
3158 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
437525c4
MN
3159
3160#define dspfunc(PFX, IDX, NUM) \
3161 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_3dnow; \
3162 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_3dnow; \
3163 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_3dnow; \
3164 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_3dnow; \
3165 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_3dnow; \
3166 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_3dnow; \
3167 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_3dnow; \
3168 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_3dnow; \
3169 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_3dnow; \
3170 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_3dnow; \
3171 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_3dnow; \
3172 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_3dnow; \
3173 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_3dnow; \
3174 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_3dnow; \
3175 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_3dnow; \
3176 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_3dnow
3177
3178 dspfunc(put_h264_qpel, 0, 16);
3179 dspfunc(put_h264_qpel, 1, 8);
3180 dspfunc(put_h264_qpel, 2, 4);
3181 dspfunc(avg_h264_qpel, 0, 16);
3182 dspfunc(avg_h264_qpel, 1, 8);
3183 dspfunc(avg_h264_qpel, 2, 4);
3072f0cb 3184
bb270c08 3185 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow;
a6624e21 3186 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
de6d9b64 3187 }
4567b4bd
RE
3188
3189#ifdef CONFIG_SNOW_ENCODER
3190 if(mm_flags & MM_SSE2){
2c9a0285 3191 c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2;
4567b4bd 3192 c->vertical_compose97i = ff_snow_vertical_compose97i_sse2;