20% faster predict_plane()
[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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
f9ed9d85 26#include "mmx.h"
de6d9b64 27
622348f9
MN
28//#undef NDEBUG
29//#include <assert.h>
30
359f98de
MN
31extern const uint8_t ff_h263_loop_filter_strength[32];
32
7d650cb5 33int mm_flags; /* multimedia extension flags */
1457ab52 34
de6d9b64 35/* pixel operations */
5c0513bd
DB
36static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
37static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
38static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
de6d9b64 39
5c0513bd
DB
40static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
41static const uint64_t ff_pw_3 attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
42static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
43static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
826f429a 44
5c0513bd 45static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
359f98de 46
d6a4c0b1
ZK
47#define JUMPALIGN() __asm __volatile (".balign 8"::)
48#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
49
fca0f0e5
ZK
50#define MOVQ_WONE(regd) \
51 __asm __volatile ( \
52 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
53 "psrlw $15, %%" #regd ::)
54
55#define MOVQ_BFE(regd) \
56 __asm __volatile ( \
57 "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
58 "paddb %%" #regd ", %%" #regd " \n\t" ::)
59
d6a4c0b1 60#ifndef PIC
fca0f0e5 61#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
d6a4c0b1
ZK
62#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
63#else
64// for shared library it's better to use this way for accessing constants
65// pcmpeqd -> -1
fca0f0e5 66#define MOVQ_BONE(regd) \
d6a4c0b1 67 __asm __volatile ( \
fca0f0e5
ZK
68 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
69 "psrlw $15, %%" #regd " \n\t" \
70 "packuswb %%" #regd ", %%" #regd " \n\t" ::)
d6a4c0b1
ZK
71
72#define MOVQ_WTWO(regd) \
73 __asm __volatile ( \
fca0f0e5
ZK
74 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
75 "psrlw $15, %%" #regd " \n\t" \
76 "psllw $1, %%" #regd " \n\t"::)
a7bd8797 77
d6a4c0b1
ZK
78#endif
79
fca0f0e5 80// using regr as temporary and for the output result
def60345 81// first argument is unmodifed and second is trashed
39825f31
ZK
82// regfe is supposed to contain 0xfefefefefefefefe
83#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
91abb473
ZK
84 "movq " #rega ", " #regr " \n\t"\
85 "pand " #regb ", " #regr " \n\t"\
def60345 86 "pxor " #rega ", " #regb " \n\t"\
39825f31 87 "pand " #regfe "," #regb " \n\t"\
def60345 88 "psrlq $1, " #regb " \n\t"\
91abb473 89 "paddb " #regb ", " #regr " \n\t"
def60345 90
39825f31 91#define PAVGB_MMX(rega, regb, regr, regfe) \
91abb473
ZK
92 "movq " #rega ", " #regr " \n\t"\
93 "por " #regb ", " #regr " \n\t"\
def60345 94 "pxor " #rega ", " #regb " \n\t"\
39825f31 95 "pand " #regfe "," #regb " \n\t"\
def60345 96 "psrlq $1, " #regb " \n\t"\
91abb473 97 "psubb " #regb ", " #regr " \n\t"
def60345 98
39825f31 99// mm6 is supposed to contain 0xfefefefefefefefe
6aa6ea8e
ZK
100#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
101 "movq " #rega ", " #regr " \n\t"\
102 "movq " #regc ", " #regp " \n\t"\
103 "pand " #regb ", " #regr " \n\t"\
104 "pand " #regd ", " #regp " \n\t"\
105 "pxor " #rega ", " #regb " \n\t"\
106 "pxor " #regc ", " #regd " \n\t"\
fca0f0e5
ZK
107 "pand %%mm6, " #regb " \n\t"\
108 "pand %%mm6, " #regd " \n\t"\
6aa6ea8e
ZK
109 "psrlq $1, " #regb " \n\t"\
110 "psrlq $1, " #regd " \n\t"\
111 "paddb " #regb ", " #regr " \n\t"\
112 "paddb " #regd ", " #regp " \n\t"
113
114#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
115 "movq " #rega ", " #regr " \n\t"\
116 "movq " #regc ", " #regp " \n\t"\
117 "por " #regb ", " #regr " \n\t"\
118 "por " #regd ", " #regp " \n\t"\
119 "pxor " #rega ", " #regb " \n\t"\
120 "pxor " #regc ", " #regd " \n\t"\
fca0f0e5
ZK
121 "pand %%mm6, " #regb " \n\t"\
122 "pand %%mm6, " #regd " \n\t"\
6aa6ea8e
ZK
123 "psrlq $1, " #regd " \n\t"\
124 "psrlq $1, " #regb " \n\t"\
125 "psubb " #regb ", " #regr " \n\t"\
126 "psubb " #regd ", " #regp " \n\t"
127
91abb473
ZK
128/***********************************/
129/* MMX no rounding */
130#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
fca0f0e5 131#define SET_RND MOVQ_WONE
6aa6ea8e 132#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
39825f31 133#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
fca0f0e5 134
91abb473
ZK
135#include "dsputil_mmx_rnd.h"
136
137#undef DEF
fca0f0e5 138#undef SET_RND
6aa6ea8e 139#undef PAVGBP
39825f31 140#undef PAVGB
91abb473
ZK
141/***********************************/
142/* MMX rounding */
143
144#define DEF(x, y) x ## _ ## y ##_mmx
fca0f0e5 145#define SET_RND MOVQ_WTWO
6aa6ea8e 146#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
39825f31 147#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
fca0f0e5 148
91abb473
ZK
149#include "dsputil_mmx_rnd.h"
150
151#undef DEF
fca0f0e5 152#undef SET_RND
6aa6ea8e 153#undef PAVGBP
39825f31 154#undef PAVGB
a7bd8797 155
de6d9b64
FB
156/***********************************/
157/* 3Dnow specific */
158
159#define DEF(x) x ## _3dnow
160/* for Athlons PAVGUSB is prefered */
161#define PAVGB "pavgusb"
162
163#include "dsputil_mmx_avg.h"
164
165#undef DEF
166#undef PAVGB
167
168/***********************************/
169/* MMX2 specific */
170
607dce96 171#define DEF(x) x ## _mmx2
de6d9b64
FB
172
173/* Introduced only in MMX2 set */
174#define PAVGB "pavgb"
175
176#include "dsputil_mmx_avg.h"
177
178#undef DEF
179#undef PAVGB
180
181/***********************************/
182/* standard MMX */
183
764ef400 184#ifdef CONFIG_ENCODERS
0c1a9eda 185static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
de6d9b64 186{
607dce96
MN
187 asm volatile(
188 "movl $-128, %%eax \n\t"
189 "pxor %%mm7, %%mm7 \n\t"
190 ".balign 16 \n\t"
191 "1: \n\t"
192 "movq (%0), %%mm0 \n\t"
193 "movq (%0, %2), %%mm2 \n\t"
194 "movq %%mm0, %%mm1 \n\t"
195 "movq %%mm2, %%mm3 \n\t"
196 "punpcklbw %%mm7, %%mm0 \n\t"
197 "punpckhbw %%mm7, %%mm1 \n\t"
198 "punpcklbw %%mm7, %%mm2 \n\t"
199 "punpckhbw %%mm7, %%mm3 \n\t"
200 "movq %%mm0, (%1, %%eax)\n\t"
201 "movq %%mm1, 8(%1, %%eax)\n\t"
202 "movq %%mm2, 16(%1, %%eax)\n\t"
203 "movq %%mm3, 24(%1, %%eax)\n\t"
204 "addl %3, %0 \n\t"
205 "addl $32, %%eax \n\t"
206 "js 1b \n\t"
207 : "+r" (pixels)
208 : "r" (block+64), "r" (line_size), "r" (line_size*2)
209 : "%eax"
210 );
de6d9b64
FB
211}
212
0c1a9eda 213static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
9dbcbd92
MN
214{
215 asm volatile(
607dce96 216 "pxor %%mm7, %%mm7 \n\t"
9dbcbd92 217 "movl $-128, %%eax \n\t"
607dce96 218 ".balign 16 \n\t"
9dbcbd92
MN
219 "1: \n\t"
220 "movq (%0), %%mm0 \n\t"
221 "movq (%1), %%mm2 \n\t"
222 "movq %%mm0, %%mm1 \n\t"
223 "movq %%mm2, %%mm3 \n\t"
224 "punpcklbw %%mm7, %%mm0 \n\t"
225 "punpckhbw %%mm7, %%mm1 \n\t"
226 "punpcklbw %%mm7, %%mm2 \n\t"
227 "punpckhbw %%mm7, %%mm3 \n\t"
228 "psubw %%mm2, %%mm0 \n\t"
229 "psubw %%mm3, %%mm1 \n\t"
230 "movq %%mm0, (%2, %%eax)\n\t"
231 "movq %%mm1, 8(%2, %%eax)\n\t"
232 "addl %3, %0 \n\t"
233 "addl %3, %1 \n\t"
234 "addl $16, %%eax \n\t"
235 "jnz 1b \n\t"
236 : "+r" (s1), "+r" (s2)
237 : "r" (block+64), "r" (stride)
238 : "%eax"
239 );
240}
764ef400 241#endif //CONFIG_ENCODERS
9dbcbd92 242
0c1a9eda 243void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
244{
245 const DCTELEM *p;
0c1a9eda 246 uint8_t *pix;
de6d9b64
FB
247
248 /* read the pixels */
249 p = block;
250 pix = pixels;
d6a4c0b1 251 /* unrolled loop */
de6d9b64 252 __asm __volatile(
a822a479
NK
253 "movq %3, %%mm0\n\t"
254 "movq 8%3, %%mm1\n\t"
255 "movq 16%3, %%mm2\n\t"
256 "movq 24%3, %%mm3\n\t"
257 "movq 32%3, %%mm4\n\t"
258 "movq 40%3, %%mm5\n\t"
259 "movq 48%3, %%mm6\n\t"
260 "movq 56%3, %%mm7\n\t"
de6d9b64
FB
261 "packuswb %%mm1, %%mm0\n\t"
262 "packuswb %%mm3, %%mm2\n\t"
263 "packuswb %%mm5, %%mm4\n\t"
264 "packuswb %%mm7, %%mm6\n\t"
a822a479
NK
265 "movq %%mm0, (%0)\n\t"
266 "movq %%mm2, (%0, %1)\n\t"
267 "movq %%mm4, (%0, %1, 2)\n\t"
268 "movq %%mm6, (%0, %2)\n\t"
269 ::"r" (pix), "r" (line_size), "r" (line_size*3), "m"(*p)
de6d9b64
FB
270 :"memory");
271 pix += line_size*4;
272 p += 32;
d6a4c0b1
ZK
273
274 // if here would be an exact copy of the code above
275 // compiler would generate some very strange code
276 // thus using "r"
277 __asm __volatile(
278 "movq (%3), %%mm0\n\t"
279 "movq 8(%3), %%mm1\n\t"
280 "movq 16(%3), %%mm2\n\t"
281 "movq 24(%3), %%mm3\n\t"
282 "movq 32(%3), %%mm4\n\t"
283 "movq 40(%3), %%mm5\n\t"
284 "movq 48(%3), %%mm6\n\t"
285 "movq 56(%3), %%mm7\n\t"
286 "packuswb %%mm1, %%mm0\n\t"
287 "packuswb %%mm3, %%mm2\n\t"
288 "packuswb %%mm5, %%mm4\n\t"
289 "packuswb %%mm7, %%mm6\n\t"
290 "movq %%mm0, (%0)\n\t"
291 "movq %%mm2, (%0, %1)\n\t"
292 "movq %%mm4, (%0, %1, 2)\n\t"
293 "movq %%mm6, (%0, %2)\n\t"
294 ::"r" (pix), "r" (line_size), "r" (line_size*3), "r"(p)
295 :"memory");
de6d9b64
FB
296}
297
7daabccb
MM
298static unsigned char __align8 vector128[8] =
299 { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
300
f9ed9d85
MM
301void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
302{
303 int i;
f9ed9d85
MM
304
305 movq_m2r(*vector128, mm1);
306 for (i = 0; i < 8; i++) {
307 movq_m2r(*(block), mm0);
308 packsswb_m2r(*(block + 4), mm0);
309 block += 8;
310 paddb_r2r(mm1, mm0);
311 movq_r2m(mm0, *pixels);
312 pixels += line_size;
313 }
314}
315
0c1a9eda 316void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
317{
318 const DCTELEM *p;
0c1a9eda 319 uint8_t *pix;
de6d9b64
FB
320 int i;
321
322 /* read the pixels */
323 p = block;
324 pix = pixels;
d6a4c0b1
ZK
325 MOVQ_ZERO(mm7);
326 i = 4;
cd8e5f96 327 do {
de6d9b64 328 __asm __volatile(
cd8e5f96
ZK
329 "movq (%2), %%mm0\n\t"
330 "movq 8(%2), %%mm1\n\t"
331 "movq 16(%2), %%mm2\n\t"
332 "movq 24(%2), %%mm3\n\t"
de6d9b64
FB
333 "movq %0, %%mm4\n\t"
334 "movq %1, %%mm6\n\t"
335 "movq %%mm4, %%mm5\n\t"
336 "punpcklbw %%mm7, %%mm4\n\t"
337 "punpckhbw %%mm7, %%mm5\n\t"
338 "paddsw %%mm4, %%mm0\n\t"
339 "paddsw %%mm5, %%mm1\n\t"
340 "movq %%mm6, %%mm5\n\t"
341 "punpcklbw %%mm7, %%mm6\n\t"
342 "punpckhbw %%mm7, %%mm5\n\t"
343 "paddsw %%mm6, %%mm2\n\t"
344 "paddsw %%mm5, %%mm3\n\t"
345 "packuswb %%mm1, %%mm0\n\t"
346 "packuswb %%mm3, %%mm2\n\t"
347 "movq %%mm0, %0\n\t"
348 "movq %%mm2, %1\n\t"
a822a479 349 :"+m"(*pix), "+m"(*(pix+line_size))
cd8e5f96 350 :"r"(p)
de6d9b64
FB
351 :"memory");
352 pix += line_size*2;
353 p += 16;
cd8e5f96 354 } while (--i);
de6d9b64
FB
355}
356
0c1a9eda 357static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 358{
39825f31 359 __asm __volatile(
31ddcf98 360 "lea (%3, %3), %%eax \n\t"
52af45ad 361 ".balign 8 \n\t"
31ddcf98
ZK
362 "1: \n\t"
363 "movq (%1), %%mm0 \n\t"
364 "movq (%1, %3), %%mm1 \n\t"
365 "movq %%mm0, (%2) \n\t"
366 "movq %%mm1, (%2, %3) \n\t"
367 "addl %%eax, %1 \n\t"
368 "addl %%eax, %2 \n\t"
369 "movq (%1), %%mm0 \n\t"
370 "movq (%1, %3), %%mm1 \n\t"
371 "movq %%mm0, (%2) \n\t"
372 "movq %%mm1, (%2, %3) \n\t"
373 "addl %%eax, %1 \n\t"
374 "addl %%eax, %2 \n\t"
375 "subl $4, %0 \n\t"
376 "jnz 1b \n\t"
377 : "+g"(h), "+r" (pixels), "+r" (block)
378 : "r"(line_size)
379 : "%eax", "memory"
380 );
de6d9b64
FB
381}
382
0c1a9eda 383static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
b3184779
MN
384{
385 __asm __volatile(
386 "lea (%3, %3), %%eax \n\t"
387 ".balign 8 \n\t"
388 "1: \n\t"
389 "movq (%1), %%mm0 \n\t"
390 "movq 8(%1), %%mm4 \n\t"
391 "movq (%1, %3), %%mm1 \n\t"
392 "movq 8(%1, %3), %%mm5 \n\t"
393 "movq %%mm0, (%2) \n\t"
394 "movq %%mm4, 8(%2) \n\t"
395 "movq %%mm1, (%2, %3) \n\t"
396 "movq %%mm5, 8(%2, %3) \n\t"
397 "addl %%eax, %1 \n\t"
398 "addl %%eax, %2 \n\t"
399 "movq (%1), %%mm0 \n\t"
400 "movq 8(%1), %%mm4 \n\t"
401 "movq (%1, %3), %%mm1 \n\t"
402 "movq 8(%1, %3), %%mm5 \n\t"
403 "movq %%mm0, (%2) \n\t"
404 "movq %%mm4, 8(%2) \n\t"
405 "movq %%mm1, (%2, %3) \n\t"
406 "movq %%mm5, 8(%2, %3) \n\t"
407 "addl %%eax, %1 \n\t"
408 "addl %%eax, %2 \n\t"
409 "subl $4, %0 \n\t"
410 "jnz 1b \n\t"
411 : "+g"(h), "+r" (pixels), "+r" (block)
412 : "r"(line_size)
413 : "%eax", "memory"
414 );
415}
416
649c00c9
MN
417static void clear_blocks_mmx(DCTELEM *blocks)
418{
39825f31 419 __asm __volatile(
649c00c9
MN
420 "pxor %%mm7, %%mm7 \n\t"
421 "movl $-128*6, %%eax \n\t"
422 "1: \n\t"
423 "movq %%mm7, (%0, %%eax) \n\t"
424 "movq %%mm7, 8(%0, %%eax) \n\t"
425 "movq %%mm7, 16(%0, %%eax) \n\t"
426 "movq %%mm7, 24(%0, %%eax) \n\t"
427 "addl $32, %%eax \n\t"
428 " js 1b \n\t"
429 : : "r" (((int)blocks)+128*6)
430 : "%eax"
431 );
432}
433
764ef400 434#ifdef CONFIG_ENCODERS
0c1a9eda 435static int pix_sum16_mmx(uint8_t * pix, int line_size){
084c726b
MN
436 const int h=16;
437 int sum;
438 int index= -line_size*h;
439
440 __asm __volatile(
441 "pxor %%mm7, %%mm7 \n\t"
442 "pxor %%mm6, %%mm6 \n\t"
443 "1: \n\t"
444 "movq (%2, %1), %%mm0 \n\t"
445 "movq (%2, %1), %%mm1 \n\t"
446 "movq 8(%2, %1), %%mm2 \n\t"
447 "movq 8(%2, %1), %%mm3 \n\t"
448 "punpcklbw %%mm7, %%mm0 \n\t"
449 "punpckhbw %%mm7, %%mm1 \n\t"
450 "punpcklbw %%mm7, %%mm2 \n\t"
451 "punpckhbw %%mm7, %%mm3 \n\t"
452 "paddw %%mm0, %%mm1 \n\t"
453 "paddw %%mm2, %%mm3 \n\t"
454 "paddw %%mm1, %%mm3 \n\t"
455 "paddw %%mm3, %%mm6 \n\t"
456 "addl %3, %1 \n\t"
457 " js 1b \n\t"
458 "movq %%mm6, %%mm5 \n\t"
459 "psrlq $32, %%mm6 \n\t"
460 "paddw %%mm5, %%mm6 \n\t"
461 "movq %%mm6, %%mm5 \n\t"
462 "psrlq $16, %%mm6 \n\t"
463 "paddw %%mm5, %%mm6 \n\t"
464 "movd %%mm6, %0 \n\t"
465 "andl $0xFFFF, %0 \n\t"
466 : "=&r" (sum), "+r" (index)
467 : "r" (pix - index), "r" (line_size)
468 );
469
470 return sum;
471}
764ef400 472#endif //CONFIG_ENCODERS
084c726b 473
11f18faf
MN
474static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
475 int i=0;
476 asm volatile(
477 "1: \n\t"
478 "movq (%1, %0), %%mm0 \n\t"
479 "movq (%2, %0), %%mm1 \n\t"
480 "paddb %%mm0, %%mm1 \n\t"
481 "movq %%mm1, (%2, %0) \n\t"
482 "movq 8(%1, %0), %%mm0 \n\t"
483 "movq 8(%2, %0), %%mm1 \n\t"
484 "paddb %%mm0, %%mm1 \n\t"
485 "movq %%mm1, 8(%2, %0) \n\t"
486 "addl $16, %0 \n\t"
487 "cmpl %3, %0 \n\t"
488 " jb 1b \n\t"
489 : "+r" (i)
490 : "r"(src), "r"(dst), "r"(w-15)
491 );
492 for(; i<w; i++)
493 dst[i+0] += src[i+0];
494}
495
3615e2be
MN
496#define H263_LOOP_FILTER \
497 "pxor %%mm7, %%mm7 \n\t"\
498 "movq %0, %%mm0 \n\t"\
499 "movq %0, %%mm1 \n\t"\
500 "movq %3, %%mm2 \n\t"\
501 "movq %3, %%mm3 \n\t"\
502 "punpcklbw %%mm7, %%mm0 \n\t"\
503 "punpckhbw %%mm7, %%mm1 \n\t"\
504 "punpcklbw %%mm7, %%mm2 \n\t"\
505 "punpckhbw %%mm7, %%mm3 \n\t"\
506 "psubw %%mm2, %%mm0 \n\t"\
507 "psubw %%mm3, %%mm1 \n\t"\
508 "movq %1, %%mm2 \n\t"\
509 "movq %1, %%mm3 \n\t"\
510 "movq %2, %%mm4 \n\t"\
511 "movq %2, %%mm5 \n\t"\
512 "punpcklbw %%mm7, %%mm2 \n\t"\
513 "punpckhbw %%mm7, %%mm3 \n\t"\
514 "punpcklbw %%mm7, %%mm4 \n\t"\
515 "punpckhbw %%mm7, %%mm5 \n\t"\
516 "psubw %%mm2, %%mm4 \n\t"\
517 "psubw %%mm3, %%mm5 \n\t"\
518 "psllw $2, %%mm4 \n\t"\
519 "psllw $2, %%mm5 \n\t"\
520 "paddw %%mm0, %%mm4 \n\t"\
521 "paddw %%mm1, %%mm5 \n\t"\
522 "pxor %%mm6, %%mm6 \n\t"\
523 "pcmpgtw %%mm4, %%mm6 \n\t"\
524 "pcmpgtw %%mm5, %%mm7 \n\t"\
525 "pxor %%mm6, %%mm4 \n\t"\
526 "pxor %%mm7, %%mm5 \n\t"\
527 "psubw %%mm6, %%mm4 \n\t"\
528 "psubw %%mm7, %%mm5 \n\t"\
529 "psrlw $3, %%mm4 \n\t"\
530 "psrlw $3, %%mm5 \n\t"\
531 "packuswb %%mm5, %%mm4 \n\t"\
532 "packsswb %%mm7, %%mm6 \n\t"\
533 "pxor %%mm7, %%mm7 \n\t"\
534 "movd %4, %%mm2 \n\t"\
535 "punpcklbw %%mm2, %%mm2 \n\t"\
536 "punpcklbw %%mm2, %%mm2 \n\t"\
537 "punpcklbw %%mm2, %%mm2 \n\t"\
538 "psubusb %%mm4, %%mm2 \n\t"\
539 "movq %%mm2, %%mm3 \n\t"\
540 "psubusb %%mm4, %%mm3 \n\t"\
541 "psubb %%mm3, %%mm2 \n\t"\
542 "movq %1, %%mm3 \n\t"\
543 "movq %2, %%mm4 \n\t"\
544 "pxor %%mm6, %%mm3 \n\t"\
545 "pxor %%mm6, %%mm4 \n\t"\
546 "paddusb %%mm2, %%mm3 \n\t"\
547 "psubusb %%mm2, %%mm4 \n\t"\
548 "pxor %%mm6, %%mm3 \n\t"\
549 "pxor %%mm6, %%mm4 \n\t"\
550 "paddusb %%mm2, %%mm2 \n\t"\
551 "packsswb %%mm1, %%mm0 \n\t"\
552 "pcmpgtb %%mm0, %%mm7 \n\t"\
553 "pxor %%mm7, %%mm0 \n\t"\
554 "psubb %%mm7, %%mm0 \n\t"\
555 "movq %%mm0, %%mm1 \n\t"\
556 "psubusb %%mm2, %%mm0 \n\t"\
557 "psubb %%mm0, %%mm1 \n\t"\
558 "pand %5, %%mm1 \n\t"\
559 "psrlw $2, %%mm1 \n\t"\
560 "pxor %%mm7, %%mm1 \n\t"\
561 "psubb %%mm7, %%mm1 \n\t"\
562 "movq %0, %%mm5 \n\t"\
563 "movq %3, %%mm6 \n\t"\
564 "psubb %%mm1, %%mm5 \n\t"\
565 "paddb %%mm1, %%mm6 \n\t"
566
359f98de
MN
567static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
568 const int strength= ff_h263_loop_filter_strength[qscale];
569
570 asm volatile(
3615e2be
MN
571
572 H263_LOOP_FILTER
573
359f98de
MN
574 "movq %%mm3, %1 \n\t"
575 "movq %%mm4, %2 \n\t"
3615e2be
MN
576 "movq %%mm5, %0 \n\t"
577 "movq %%mm6, %3 \n\t"
359f98de
MN
578 : "+m" (*(uint64_t*)(src - 2*stride)),
579 "+m" (*(uint64_t*)(src - 1*stride)),
580 "+m" (*(uint64_t*)(src + 0*stride)),
581 "+m" (*(uint64_t*)(src + 1*stride))
582 : "g" (2*strength), "m"(ff_pb_FC)
583 );
584}
585
3615e2be
MN
586static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
587 asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
588 "movd %4, %%mm0 \n\t"
589 "movd %5, %%mm1 \n\t"
590 "movd %6, %%mm2 \n\t"
591 "movd %7, %%mm3 \n\t"
592 "punpcklbw %%mm1, %%mm0 \n\t"
593 "punpcklbw %%mm3, %%mm2 \n\t"
594 "movq %%mm0, %%mm1 \n\t"
595 "punpcklwd %%mm2, %%mm0 \n\t"
596 "punpckhwd %%mm2, %%mm1 \n\t"
597 "movd %%mm0, %0 \n\t"
598 "punpckhdq %%mm0, %%mm0 \n\t"
599 "movd %%mm0, %1 \n\t"
600 "movd %%mm1, %2 \n\t"
601 "punpckhdq %%mm1, %%mm1 \n\t"
602 "movd %%mm1, %3 \n\t"
603
604 : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
605 "=m" (*(uint32_t*)(dst + 1*dst_stride)),
606 "=m" (*(uint32_t*)(dst + 2*dst_stride)),
607 "=m" (*(uint32_t*)(dst + 3*dst_stride))
608 : "m" (*(uint32_t*)(src + 0*src_stride)),
609 "m" (*(uint32_t*)(src + 1*src_stride)),
610 "m" (*(uint32_t*)(src + 2*src_stride)),
611 "m" (*(uint32_t*)(src + 3*src_stride))
612 );
613}
614
615static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
616 const int strength= ff_h263_loop_filter_strength[qscale];
617 uint64_t temp[4] __attribute__ ((aligned(8)));
618 uint8_t *btemp= (uint8_t*)temp;
619
620 src -= 2;
621
622 transpose4x4(btemp , src , 8, stride);
623 transpose4x4(btemp+4, src + 4*stride, 8, stride);
624 asm volatile(
625 H263_LOOP_FILTER // 5 3 4 6
626
627 : "+m" (temp[0]),
628 "+m" (temp[1]),
629 "+m" (temp[2]),
630 "+m" (temp[3])
631 : "g" (2*strength), "m"(ff_pb_FC)
632 );
633
634 asm volatile(
635 "movq %%mm5, %%mm1 \n\t"
636 "movq %%mm4, %%mm0 \n\t"
637 "punpcklbw %%mm3, %%mm5 \n\t"
638 "punpcklbw %%mm6, %%mm4 \n\t"
639 "punpckhbw %%mm3, %%mm1 \n\t"
640 "punpckhbw %%mm6, %%mm0 \n\t"
641 "movq %%mm5, %%mm3 \n\t"
642 "movq %%mm1, %%mm6 \n\t"
643 "punpcklwd %%mm4, %%mm5 \n\t"
644 "punpcklwd %%mm0, %%mm1 \n\t"
645 "punpckhwd %%mm4, %%mm3 \n\t"
646 "punpckhwd %%mm0, %%mm6 \n\t"
647 "movd %%mm5, %0 \n\t"
648 "punpckhdq %%mm5, %%mm5 \n\t"
649 "movd %%mm5, %1 \n\t"
650 "movd %%mm3, %2 \n\t"
651 "punpckhdq %%mm3, %%mm3 \n\t"
652 "movd %%mm3, %3 \n\t"
653 "movd %%mm1, %4 \n\t"
654 "punpckhdq %%mm1, %%mm1 \n\t"
655 "movd %%mm1, %5 \n\t"
656 "movd %%mm6, %6 \n\t"
657 "punpckhdq %%mm6, %%mm6 \n\t"
658 "movd %%mm6, %7 \n\t"
659 : "=m" (*(uint32_t*)(src + 0*stride)),
660 "=m" (*(uint32_t*)(src + 1*stride)),
661 "=m" (*(uint32_t*)(src + 2*stride)),
662 "=m" (*(uint32_t*)(src + 3*stride)),
663 "=m" (*(uint32_t*)(src + 4*stride)),
664 "=m" (*(uint32_t*)(src + 5*stride)),
665 "=m" (*(uint32_t*)(src + 6*stride)),
666 "=m" (*(uint32_t*)(src + 7*stride))
667 );
668}
669
764ef400 670#ifdef CONFIG_ENCODERS
2a006cd3
FL
671static int pix_norm1_mmx(uint8_t *pix, int line_size) {
672 int tmp;
673 asm volatile (
674 "movl $16,%%ecx\n"
675 "pxor %%mm0,%%mm0\n"
676 "pxor %%mm7,%%mm7\n"
677 "1:\n"
678 "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
679 "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
680
681 "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
682
683 "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
684 "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
685
686 "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
687 "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
688 "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
689
690 "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
691 "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
692
693 "pmaddwd %%mm3,%%mm3\n"
694 "pmaddwd %%mm4,%%mm4\n"
695
696 "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
697 pix2^2+pix3^2+pix6^2+pix7^2) */
698 "paddd %%mm3,%%mm4\n"
699 "paddd %%mm2,%%mm7\n"
700
701 "addl %2, %0\n"
702 "paddd %%mm4,%%mm7\n"
703 "dec %%ecx\n"
704 "jnz 1b\n"
705
706 "movq %%mm7,%%mm1\n"
707 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
708 "paddd %%mm7,%%mm1\n"
709 "movd %%mm1,%1\n"
710 : "+r" (pix), "=r"(tmp) : "r" (line_size) : "%ecx" );
711 return tmp;
712}
713
1ec4df0f
MN
714static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
715 int tmp;
716 asm volatile (
717 "movl %4,%%ecx\n"
718 "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
719 "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
720 "1:\n"
721 "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
722 "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
723
724 "movq %%mm1,%%mm5\n"
725 "psubusb %%mm2,%%mm1\n"
726 "psubusb %%mm5,%%mm2\n"
727
728 "por %%mm1,%%mm2\n"
729
730 "movq %%mm2,%%mm1\n"
731
732 "punpckhbw %%mm0,%%mm2\n"
733 "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
734
735 "pmaddwd %%mm2,%%mm2\n"
736 "pmaddwd %%mm1,%%mm1\n"
737
738 "addl %3,%0\n"
739 "addl %3,%1\n"
740
741 "paddd %%mm2,%%mm1\n"
742 "paddd %%mm1,%%mm7\n"
743
744 "decl %%ecx\n"
745 "jnz 1b\n"
746
747 "movq %%mm7,%%mm1\n"
748 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
749 "paddd %%mm7,%%mm1\n"
750 "movd %%mm1,%2\n"
751 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
752 : "r" (line_size) , "m" (h)
753 : "%ecx");
754 return tmp;
755}
756
bb198e19 757static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
2a006cd3
FL
758 int tmp;
759 asm volatile (
bb198e19 760 "movl %4,%%ecx\n"
2a006cd3
FL
761 "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
762 "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
763 "1:\n"
764 "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
765 "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
766 "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
767 "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
768
769 /* todo: mm1-mm2, mm3-mm4 */
770 /* algo: substract mm1 from mm2 with saturation and vice versa */
771 /* OR the results to get absolute difference */
772 "movq %%mm1,%%mm5\n"
773 "movq %%mm3,%%mm6\n"
774 "psubusb %%mm2,%%mm1\n"
775 "psubusb %%mm4,%%mm3\n"
776 "psubusb %%mm5,%%mm2\n"
777 "psubusb %%mm6,%%mm4\n"
778
779 "por %%mm1,%%mm2\n"
780 "por %%mm3,%%mm4\n"
781
782 /* now convert to 16-bit vectors so we can square them */
783 "movq %%mm2,%%mm1\n"
784 "movq %%mm4,%%mm3\n"
785
786 "punpckhbw %%mm0,%%mm2\n"
787 "punpckhbw %%mm0,%%mm4\n"
788 "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
789 "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
790
791 "pmaddwd %%mm2,%%mm2\n"
792 "pmaddwd %%mm4,%%mm4\n"
793 "pmaddwd %%mm1,%%mm1\n"
794 "pmaddwd %%mm3,%%mm3\n"
795
796 "addl %3,%0\n"
797 "addl %3,%1\n"
798
799 "paddd %%mm2,%%mm1\n"
800 "paddd %%mm4,%%mm3\n"
801 "paddd %%mm1,%%mm7\n"
802 "paddd %%mm3,%%mm7\n"
803
804 "decl %%ecx\n"
805 "jnz 1b\n"
806
807 "movq %%mm7,%%mm1\n"
808 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
809 "paddd %%mm7,%%mm1\n"
810 "movd %%mm1,%2\n"
bb198e19
MN
811 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
812 : "r" (line_size) , "m" (h)
813 : "%ecx");
2a006cd3
FL
814 return tmp;
815}
816
1ec4df0f
MN
817static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
818 int tmp;
819 asm volatile (
820 "movl %3,%%ecx\n"
821 "pxor %%mm7,%%mm7\n"
822 "pxor %%mm6,%%mm6\n"
823
824 "movq (%0),%%mm0\n"
825 "movq %%mm0, %%mm1\n"
826 "psllq $8, %%mm0\n"
827 "psrlq $8, %%mm1\n"
828 "psrlq $8, %%mm0\n"
829 "movq %%mm0, %%mm2\n"
830 "movq %%mm1, %%mm3\n"
831 "punpcklbw %%mm7,%%mm0\n"
832 "punpcklbw %%mm7,%%mm1\n"
833 "punpckhbw %%mm7,%%mm2\n"
834 "punpckhbw %%mm7,%%mm3\n"
835 "psubw %%mm1, %%mm0\n"
836 "psubw %%mm3, %%mm2\n"
837
838 "addl %2,%0\n"
839
840 "movq (%0),%%mm4\n"
841 "movq %%mm4, %%mm1\n"
842 "psllq $8, %%mm4\n"
843 "psrlq $8, %%mm1\n"
844 "psrlq $8, %%mm4\n"
845 "movq %%mm4, %%mm5\n"
846 "movq %%mm1, %%mm3\n"
847 "punpcklbw %%mm7,%%mm4\n"
848 "punpcklbw %%mm7,%%mm1\n"
849 "punpckhbw %%mm7,%%mm5\n"
850 "punpckhbw %%mm7,%%mm3\n"
851 "psubw %%mm1, %%mm4\n"
852 "psubw %%mm3, %%mm5\n"
853 "psubw %%mm4, %%mm0\n"
854 "psubw %%mm5, %%mm2\n"
855 "pxor %%mm3, %%mm3\n"
856 "pxor %%mm1, %%mm1\n"
857 "pcmpgtw %%mm0, %%mm3\n\t"
858 "pcmpgtw %%mm2, %%mm1\n\t"
859 "pxor %%mm3, %%mm0\n"
860 "pxor %%mm1, %%mm2\n"
861 "psubw %%mm3, %%mm0\n"
862 "psubw %%mm1, %%mm2\n"
863 "paddw %%mm0, %%mm2\n"
864 "paddw %%mm2, %%mm6\n"
865
866 "addl %2,%0\n"
867 "1:\n"
868
869 "movq (%0),%%mm0\n"
870 "movq %%mm0, %%mm1\n"
871 "psllq $8, %%mm0\n"
872 "psrlq $8, %%mm1\n"
873 "psrlq $8, %%mm0\n"
874 "movq %%mm0, %%mm2\n"
875 "movq %%mm1, %%mm3\n"
876 "punpcklbw %%mm7,%%mm0\n"
877 "punpcklbw %%mm7,%%mm1\n"
878 "punpckhbw %%mm7,%%mm2\n"
879 "punpckhbw %%mm7,%%mm3\n"
880 "psubw %%mm1, %%mm0\n"
881 "psubw %%mm3, %%mm2\n"
882 "psubw %%mm0, %%mm4\n"
883 "psubw %%mm2, %%mm5\n"
884 "pxor %%mm3, %%mm3\n"
885 "pxor %%mm1, %%mm1\n"
886 "pcmpgtw %%mm4, %%mm3\n\t"
887 "pcmpgtw %%mm5, %%mm1\n\t"
888 "pxor %%mm3, %%mm4\n"
889 "pxor %%mm1, %%mm5\n"
890 "psubw %%mm3, %%mm4\n"
891 "psubw %%mm1, %%mm5\n"
892 "paddw %%mm4, %%mm5\n"
893 "paddw %%mm5, %%mm6\n"
894
895 "addl %2,%0\n"
896
897 "movq (%0),%%mm4\n"
898 "movq %%mm4, %%mm1\n"
899 "psllq $8, %%mm4\n"
900 "psrlq $8, %%mm1\n"
901 "psrlq $8, %%mm4\n"
902 "movq %%mm4, %%mm5\n"
903 "movq %%mm1, %%mm3\n"
904 "punpcklbw %%mm7,%%mm4\n"
905 "punpcklbw %%mm7,%%mm1\n"
906 "punpckhbw %%mm7,%%mm5\n"
907 "punpckhbw %%mm7,%%mm3\n"
908 "psubw %%mm1, %%mm4\n"
909 "psubw %%mm3, %%mm5\n"
910 "psubw %%mm4, %%mm0\n"
911 "psubw %%mm5, %%mm2\n"
912 "pxor %%mm3, %%mm3\n"
913 "pxor %%mm1, %%mm1\n"
914 "pcmpgtw %%mm0, %%mm3\n\t"
915 "pcmpgtw %%mm2, %%mm1\n\t"
916 "pxor %%mm3, %%mm0\n"
917 "pxor %%mm1, %%mm2\n"
918 "psubw %%mm3, %%mm0\n"
919 "psubw %%mm1, %%mm2\n"
920 "paddw %%mm0, %%mm2\n"
921 "paddw %%mm2, %%mm6\n"
922
923 "addl %2,%0\n"
924 "subl $2, %%ecx\n"
925 " jnz 1b\n"
926
927 "movq %%mm6, %%mm0\n"
928 "punpcklwd %%mm7,%%mm0\n"
929 "punpckhwd %%mm7,%%mm6\n"
930 "paddd %%mm0, %%mm6\n"
931
932 "movq %%mm6,%%mm0\n"
933 "psrlq $32, %%mm6\n"
934 "paddd %%mm6,%%mm0\n"
935 "movd %%mm0,%1\n"
936 : "+r" (pix1), "=r"(tmp)
937 : "r" (line_size) , "g" (h-2)
938 : "%ecx");
939 return tmp;
940}
941
942static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
943 int tmp;
944 uint8_t * pix= pix1;
945 asm volatile (
946 "movl %3,%%ecx\n"
947 "pxor %%mm7,%%mm7\n"
948 "pxor %%mm6,%%mm6\n"
949
950 "movq (%0),%%mm0\n"
951 "movq 1(%0),%%mm1\n"
952 "movq %%mm0, %%mm2\n"
953 "movq %%mm1, %%mm3\n"
954 "punpcklbw %%mm7,%%mm0\n"
955 "punpcklbw %%mm7,%%mm1\n"
956 "punpckhbw %%mm7,%%mm2\n"
957 "punpckhbw %%mm7,%%mm3\n"
958 "psubw %%mm1, %%mm0\n"
959 "psubw %%mm3, %%mm2\n"
960
961 "addl %2,%0\n"
962
963 "movq (%0),%%mm4\n"
964 "movq 1(%0),%%mm1\n"
965 "movq %%mm4, %%mm5\n"
966 "movq %%mm1, %%mm3\n"
967 "punpcklbw %%mm7,%%mm4\n"
968 "punpcklbw %%mm7,%%mm1\n"
969 "punpckhbw %%mm7,%%mm5\n"
970 "punpckhbw %%mm7,%%mm3\n"
971 "psubw %%mm1, %%mm4\n"
972 "psubw %%mm3, %%mm5\n"
973 "psubw %%mm4, %%mm0\n"
974 "psubw %%mm5, %%mm2\n"
975 "pxor %%mm3, %%mm3\n"
976 "pxor %%mm1, %%mm1\n"
977 "pcmpgtw %%mm0, %%mm3\n\t"
978 "pcmpgtw %%mm2, %%mm1\n\t"
979 "pxor %%mm3, %%mm0\n"
980 "pxor %%mm1, %%mm2\n"
981 "psubw %%mm3, %%mm0\n"
982 "psubw %%mm1, %%mm2\n"
983 "paddw %%mm0, %%mm2\n"
984 "paddw %%mm2, %%mm6\n"
985
986 "addl %2,%0\n"
987 "1:\n"
988
989 "movq (%0),%%mm0\n"
990 "movq 1(%0),%%mm1\n"
991 "movq %%mm0, %%mm2\n"
992 "movq %%mm1, %%mm3\n"
993 "punpcklbw %%mm7,%%mm0\n"
994 "punpcklbw %%mm7,%%mm1\n"
995 "punpckhbw %%mm7,%%mm2\n"
996 "punpckhbw %%mm7,%%mm3\n"
997 "psubw %%mm1, %%mm0\n"
998 "psubw %%mm3, %%mm2\n"
999 "psubw %%mm0, %%mm4\n"
1000 "psubw %%mm2, %%mm5\n"
1001 "pxor %%mm3, %%mm3\n"
1002 "pxor %%mm1, %%mm1\n"
1003 "pcmpgtw %%mm4, %%mm3\n\t"
1004 "pcmpgtw %%mm5, %%mm1\n\t"
1005 "pxor %%mm3, %%mm4\n"
1006 "pxor %%mm1, %%mm5\n"
1007 "psubw %%mm3, %%mm4\n"
1008 "psubw %%mm1, %%mm5\n"
1009 "paddw %%mm4, %%mm5\n"
1010 "paddw %%mm5, %%mm6\n"
1011
1012 "addl %2,%0\n"
1013
1014 "movq (%0),%%mm4\n"
1015 "movq 1(%0),%%mm1\n"
1016 "movq %%mm4, %%mm5\n"
1017 "movq %%mm1, %%mm3\n"
1018 "punpcklbw %%mm7,%%mm4\n"
1019 "punpcklbw %%mm7,%%mm1\n"
1020 "punpckhbw %%mm7,%%mm5\n"
1021 "punpckhbw %%mm7,%%mm3\n"
1022 "psubw %%mm1, %%mm4\n"
1023 "psubw %%mm3, %%mm5\n"
1024 "psubw %%mm4, %%mm0\n"
1025 "psubw %%mm5, %%mm2\n"
1026 "pxor %%mm3, %%mm3\n"
1027 "pxor %%mm1, %%mm1\n"
1028 "pcmpgtw %%mm0, %%mm3\n\t"
1029 "pcmpgtw %%mm2, %%mm1\n\t"
1030 "pxor %%mm3, %%mm0\n"
1031 "pxor %%mm1, %%mm2\n"
1032 "psubw %%mm3, %%mm0\n"
1033 "psubw %%mm1, %%mm2\n"
1034 "paddw %%mm0, %%mm2\n"
1035 "paddw %%mm2, %%mm6\n"
1036
1037 "addl %2,%0\n"
1038 "subl $2, %%ecx\n"
1039 " jnz 1b\n"
1040
1041 "movq %%mm6, %%mm0\n"
1042 "punpcklwd %%mm7,%%mm0\n"
1043 "punpckhwd %%mm7,%%mm6\n"
1044 "paddd %%mm0, %%mm6\n"
1045
1046 "movq %%mm6,%%mm0\n"
1047 "psrlq $32, %%mm6\n"
1048 "paddd %%mm6,%%mm0\n"
1049 "movd %%mm0,%1\n"
1050 : "+r" (pix1), "=r"(tmp)
1051 : "r" (line_size) , "g" (h-2)
1052 : "%ecx");
1053 return tmp + hf_noise8_mmx(pix+8, line_size, h);
1054}
1055
1056static int nsse16_mmx(MpegEncContext *c, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1057 int score1= sse16_mmx(c, pix1, pix2, line_size, h);
1058 int score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
1059
1060 if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1061 else return score1 + ABS(score2)*8;
1062}
1063
1064static int nsse8_mmx(MpegEncContext *c, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1065 int score1= sse8_mmx(c, pix1, pix2, line_size, h);
1066 int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
1067
1068 if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1069 else return score1 + ABS(score2)*8;
1070}
1071
622348f9
MN
1072static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1073 int tmp;
1074
1075 assert( (((int)pix) & 7) == 0);
1076 assert((line_size &7) ==0);
1077
1078#define SUM(in0, in1, out0, out1) \
1079 "movq (%0), %%mm2\n"\
1080 "movq 8(%0), %%mm3\n"\
1081 "addl %2,%0\n"\
1082 "movq %%mm2, " #out0 "\n"\
1083 "movq %%mm3, " #out1 "\n"\
1084 "psubusb " #in0 ", %%mm2\n"\
1085 "psubusb " #in1 ", %%mm3\n"\
1086 "psubusb " #out0 ", " #in0 "\n"\
1087 "psubusb " #out1 ", " #in1 "\n"\
1088 "por %%mm2, " #in0 "\n"\
1089 "por %%mm3, " #in1 "\n"\
1090 "movq " #in0 ", %%mm2\n"\
1091 "movq " #in1 ", %%mm3\n"\
1092 "punpcklbw %%mm7, " #in0 "\n"\
1093 "punpcklbw %%mm7, " #in1 "\n"\
1094 "punpckhbw %%mm7, %%mm2\n"\
1095 "punpckhbw %%mm7, %%mm3\n"\
1096 "paddw " #in1 ", " #in0 "\n"\
1097 "paddw %%mm3, %%mm2\n"\
1098 "paddw %%mm2, " #in0 "\n"\
1099 "paddw " #in0 ", %%mm6\n"
1100
1101
1102 asm volatile (
1103 "movl %3,%%ecx\n"
1104 "pxor %%mm6,%%mm6\n"
1105 "pxor %%mm7,%%mm7\n"
1106 "movq (%0),%%mm0\n"
1107 "movq 8(%0),%%mm1\n"
1108 "addl %2,%0\n"
1109 "subl $2, %%ecx\n"
1110 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1111 "1:\n"
1112
1113 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1114
1115 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1116
1117 "subl $2, %%ecx\n"
1118 "jnz 1b\n"
1119
1120 "movq %%mm6,%%mm0\n"
1121 "psrlq $32, %%mm6\n"
1122 "paddw %%mm6,%%mm0\n"
1123 "movq %%mm0,%%mm6\n"
1124 "psrlq $16, %%mm0\n"
1125 "paddw %%mm6,%%mm0\n"
1126 "movd %%mm0,%1\n"
1127 : "+r" (pix), "=r"(tmp)
1128 : "r" (line_size) , "m" (h)
1129 : "%ecx");
1130 return tmp & 0xFFFF;
1131}
1132#undef SUM
1133
1134static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1135 int tmp;
1136
1137 assert( (((int)pix) & 7) == 0);
1138 assert((line_size &7) ==0);
1139
1140#define SUM(in0, in1, out0, out1) \
1141 "movq (%0), " #out0 "\n"\
1142 "movq 8(%0), " #out1 "\n"\
1143 "addl %2,%0\n"\
1144 "psadbw " #out0 ", " #in0 "\n"\
1145 "psadbw " #out1 ", " #in1 "\n"\
1146 "paddw " #in1 ", " #in0 "\n"\
1147 "paddw " #in0 ", %%mm6\n"
1148
1149 asm volatile (
1150 "movl %3,%%ecx\n"
1151 "pxor %%mm6,%%mm6\n"
1152 "pxor %%mm7,%%mm7\n"
1153 "movq (%0),%%mm0\n"
1154 "movq 8(%0),%%mm1\n"
1155 "addl %2,%0\n"
1156 "subl $2, %%ecx\n"
1157 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1158 "1:\n"
1159
1160 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1161
1162 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1163
1164 "subl $2, %%ecx\n"
1165 "jnz 1b\n"
1166
1167 "movd %%mm6,%1\n"
1168 : "+r" (pix), "=r"(tmp)
1169 : "r" (line_size) , "m" (h)
1170 : "%ecx");
1171 return tmp;
1172}
1173#undef SUM
1174
1175static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1176 int tmp;
1177
1178 assert( (((int)pix1) & 7) == 0);
1179 assert( (((int)pix2) & 7) == 0);
1180 assert((line_size &7) ==0);
1181
1182#define SUM(in0, in1, out0, out1) \
1183 "movq (%0),%%mm2\n"\
1184 "movq (%1)," #out0 "\n"\
1185 "movq 8(%0),%%mm3\n"\
1186 "movq 8(%1)," #out1 "\n"\
1187 "addl %3,%0\n"\
1188 "addl %3,%1\n"\
1189 "psubb " #out0 ", %%mm2\n"\
1190 "psubb " #out1 ", %%mm3\n"\
1191 "pxor %%mm7, %%mm2\n"\
1192 "pxor %%mm7, %%mm3\n"\
1193 "movq %%mm2, " #out0 "\n"\
1194 "movq %%mm3, " #out1 "\n"\
1195 "psubusb " #in0 ", %%mm2\n"\
1196 "psubusb " #in1 ", %%mm3\n"\
1197 "psubusb " #out0 ", " #in0 "\n"\
1198 "psubusb " #out1 ", " #in1 "\n"\
1199 "por %%mm2, " #in0 "\n"\
1200 "por %%mm3, " #in1 "\n"\
1201 "movq " #in0 ", %%mm2\n"\
1202 "movq " #in1 ", %%mm3\n"\
1203 "punpcklbw %%mm7, " #in0 "\n"\
1204 "punpcklbw %%mm7, " #in1 "\n"\
1205 "punpckhbw %%mm7, %%mm2\n"\
1206 "punpckhbw %%mm7, %%mm3\n"\
1207 "paddw " #in1 ", " #in0 "\n"\
1208 "paddw %%mm3, %%mm2\n"\
1209 "paddw %%mm2, " #in0 "\n"\
1210 "paddw " #in0 ", %%mm6\n"
1211
1212
1213 asm volatile (
1214 "movl %4,%%ecx\n"
1215 "pxor %%mm6,%%mm6\n"
1216 "pcmpeqw %%mm7,%%mm7\n"
1217 "psllw $15, %%mm7\n"
1218 "packsswb %%mm7, %%mm7\n"
1219 "movq (%0),%%mm0\n"
1220 "movq (%1),%%mm2\n"
1221 "movq 8(%0),%%mm1\n"
1222 "movq 8(%1),%%mm3\n"
1223 "addl %3,%0\n"
1224 "addl %3,%1\n"
1225 "subl $2, %%ecx\n"
1226 "psubb %%mm2, %%mm0\n"
1227 "psubb %%mm3, %%mm1\n"
1228 "pxor %%mm7, %%mm0\n"
1229 "pxor %%mm7, %%mm1\n"
1230 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1231 "1:\n"
1232
1233 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1234
1235 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1236
1237 "subl $2, %%ecx\n"
1238 "jnz 1b\n"
1239
1240 "movq %%mm6,%%mm0\n"
1241 "psrlq $32, %%mm6\n"
1242 "paddw %%mm6,%%mm0\n"
1243 "movq %%mm0,%%mm6\n"
1244 "psrlq $16, %%mm0\n"
1245 "paddw %%mm6,%%mm0\n"
1246 "movd %%mm0,%2\n"
1247 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
1248 : "r" (line_size) , "m" (h)
1249 : "%ecx");
1250 return tmp & 0x7FFF;
1251}
1252#undef SUM
1253
1254static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1255 int tmp;
1256
1257 assert( (((int)pix1) & 7) == 0);
1258 assert( (((int)pix2) & 7) == 0);
1259 assert((line_size &7) ==0);
1260
1261#define SUM(in0, in1, out0, out1) \
1262 "movq (%0)," #out0 "\n"\
1263 "movq (%1),%%mm2\n"\
1264 "movq 8(%0)," #out1 "\n"\
1265 "movq 8(%1),%%mm3\n"\
1266 "addl %3,%0\n"\
1267 "addl %3,%1\n"\
1268 "psubb %%mm2, " #out0 "\n"\
1269 "psubb %%mm3, " #out1 "\n"\
1270 "pxor %%mm7, " #out0 "\n"\
1271 "pxor %%mm7, " #out1 "\n"\
1272 "psadbw " #out0 ", " #in0 "\n"\
1273 "psadbw " #out1 ", " #in1 "\n"\
1274 "paddw " #in1 ", " #in0 "\n"\
1275 "paddw " #in0 ", %%mm6\n"
1276
1277 asm volatile (
1278 "movl %4,%%ecx\n"
1279 "pxor %%mm6,%%mm6\n"
1280 "pcmpeqw %%mm7,%%mm7\n"
1281 "psllw $15, %%mm7\n"
1282 "packsswb %%mm7, %%mm7\n"
1283 "movq (%0),%%mm0\n"
1284 "movq (%1),%%mm2\n"
1285 "movq 8(%0),%%mm1\n"
1286 "movq 8(%1),%%mm3\n"
1287 "addl %3,%0\n"
1288 "addl %3,%1\n"
1289 "subl $2, %%ecx\n"
1290 "psubb %%mm2, %%mm0\n"
1291 "psubb %%mm3, %%mm1\n"
1292 "pxor %%mm7, %%mm0\n"
1293 "pxor %%mm7, %%mm1\n"
1294 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1295 "1:\n"
1296
1297 SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1298
1299 SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1300
1301 "subl $2, %%ecx\n"
1302 "jnz 1b\n"
1303
1304 "movd %%mm6,%2\n"
1305 : "+r" (pix1), "+r" (pix2), "=r"(tmp)
1306 : "r" (line_size) , "m" (h)
1307 : "%ecx");
1308 return tmp;
1309}
1310#undef SUM
1311
11f18faf
MN
1312static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
1313 int i=0;
1314 asm volatile(
1315 "1: \n\t"
1316 "movq (%2, %0), %%mm0 \n\t"
1317 "movq (%1, %0), %%mm1 \n\t"
1318 "psubb %%mm0, %%mm1 \n\t"
1319 "movq %%mm1, (%3, %0) \n\t"
1320 "movq 8(%2, %0), %%mm0 \n\t"
1321 "movq 8(%1, %0), %%mm1 \n\t"
1322 "psubb %%mm0, %%mm1 \n\t"
1323 "movq %%mm1, 8(%3, %0) \n\t"
1324 "addl $16, %0 \n\t"
1325 "cmpl %4, %0 \n\t"
1326 " jb 1b \n\t"
1327 : "+r" (i)
1328 : "r"(src1), "r"(src2), "r"(dst), "r"(w-15)
1329 );
1330 for(; i<w; i++)
1331 dst[i+0] = src1[i+0]-src2[i+0];
1332}
84705403
MN
1333
1334static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
1335 int i=0;
1336 uint8_t l, lt;
1337
1338 asm volatile(
1339 "1: \n\t"
1340 "movq -1(%1, %0), %%mm0 \n\t" // LT
1341 "movq (%1, %0), %%mm1 \n\t" // T
1342 "movq -1(%2, %0), %%mm2 \n\t" // L
1343 "movq (%2, %0), %%mm3 \n\t" // X
1344 "movq %%mm2, %%mm4 \n\t" // L
1345 "psubb %%mm0, %%mm2 \n\t"
1346 "paddb %%mm1, %%mm2 \n\t" // L + T - LT
1347 "movq %%mm4, %%mm5 \n\t" // L
1348 "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
1349 "pminub %%mm5, %%mm1 \n\t" // min(T, L)
1350 "pminub %%mm2, %%mm4 \n\t"
1351 "pmaxub %%mm1, %%mm4 \n\t"
1352 "psubb %%mm4, %%mm3 \n\t" // dst - pred
1353 "movq %%mm3, (%3, %0) \n\t"
1354 "addl $8, %0 \n\t"
1355 "cmpl %4, %0 \n\t"
1356 " jb 1b \n\t"
1357 : "+r" (i)
1358 : "r"(src1), "r"(src2), "r"(dst), "r"(w)
1359 );
1360
1361 l= *left;
1362 lt= *left_top;
1363
1364 dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
1365
1366 *left_top= src1[w-1];
1367 *left = src2[w-1];
1368}
1369
8e0a3db7
MN
1370#define LBUTTERFLY2(a1,b1,a2,b2)\
1371 "paddw " #b1 ", " #a1 " \n\t"\
1372 "paddw " #b2 ", " #a2 " \n\t"\
1373 "paddw " #b1 ", " #b1 " \n\t"\
1374 "paddw " #b2 ", " #b2 " \n\t"\
1375 "psubw " #a1 ", " #b1 " \n\t"\
7db52b63 1376 "psubw " #a2 ", " #b2 " \n\t"
1457ab52
MN
1377
1378#define HADAMARD48\
8e0a3db7
MN
1379 LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
1380 LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
1381 LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
1382 LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
1383 LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
1384 LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
1457ab52
MN
1385
1386#define MMABS(a,z)\
1387 "pxor " #z ", " #z " \n\t"\
1388 "pcmpgtw " #a ", " #z " \n\t"\
1389 "pxor " #z ", " #a " \n\t"\
1390 "psubw " #z ", " #a " \n\t"
1391
1392#define MMABS_SUM(a,z, sum)\
1393 "pxor " #z ", " #z " \n\t"\
1394 "pcmpgtw " #a ", " #z " \n\t"\
1395 "pxor " #z ", " #a " \n\t"\
1396 "psubw " #z ", " #a " \n\t"\
1397 "paddusw " #a ", " #sum " \n\t"
1398
8e0a3db7
MN
1399#define MMABS_MMX2(a,z)\
1400 "pxor " #z ", " #z " \n\t"\
1401 "psubw " #a ", " #z " \n\t"\
1402 "pmaxsw " #z ", " #a " \n\t"
1403
1404#define MMABS_SUM_MMX2(a,z, sum)\
1405 "pxor " #z ", " #z " \n\t"\
1406 "psubw " #a ", " #z " \n\t"\
1407 "pmaxsw " #z ", " #a " \n\t"\
1408 "paddusw " #a ", " #sum " \n\t"
1409
1457ab52
MN
1410#define SBUTTERFLY(a,b,t,n)\
1411 "movq " #a ", " #t " \n\t" /* abcd */\
1412 "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
1413 "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
8e0a3db7 1414
1457ab52
MN
1415#define TRANSPOSE4(a,b,c,d,t)\
1416 SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
1417 SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
1418 SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
1419 SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
1420
1421#define LOAD4(o, a, b, c, d)\
1422 "movq "#o"(%1), " #a " \n\t"\
1423 "movq "#o"+16(%1), " #b " \n\t"\
1424 "movq "#o"+32(%1), " #c " \n\t"\
1425 "movq "#o"+48(%1), " #d " \n\t"
1426
1427#define STORE4(o, a, b, c, d)\
1428 "movq "#a", "#o"(%1) \n\t"\
1429 "movq "#b", "#o"+16(%1) \n\t"\
1430 "movq "#c", "#o"+32(%1) \n\t"\
1431 "movq "#d", "#o"+48(%1) \n\t"\
1432
bb198e19 1433static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
1457ab52
MN
1434 uint64_t temp[16] __align8;
1435 int sum=0;
bb198e19
MN
1436
1437 assert(h==8);
1457ab52
MN
1438
1439 diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
11f18faf 1440
1457ab52
MN
1441 asm volatile(
1442 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1443 LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1444
1445 HADAMARD48
1446
1447 "movq %%mm7, 112(%1) \n\t"
1448
1449 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1450 STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1451
1452 "movq 112(%1), %%mm7 \n\t"
1453 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1454 STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1455
1456 LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1457 LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1458
1459 HADAMARD48
1460
1461 "movq %%mm7, 120(%1) \n\t"
1462
1463 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1464 STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1465
1466 "movq 120(%1), %%mm7 \n\t"
1467 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1468 "movq %%mm7, %%mm5 \n\t"//FIXME remove
1469 "movq %%mm6, %%mm7 \n\t"
1470 "movq %%mm0, %%mm6 \n\t"
1471// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1472
1473 LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1474// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1475
1476 HADAMARD48
1477 "movq %%mm7, 64(%1) \n\t"
1478 MMABS(%%mm0, %%mm7)
1479 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1480 MMABS_SUM(%%mm2, %%mm7, %%mm0)
1481 MMABS_SUM(%%mm3, %%mm7, %%mm0)
1482 MMABS_SUM(%%mm4, %%mm7, %%mm0)
1483 MMABS_SUM(%%mm5, %%mm7, %%mm0)
1484 MMABS_SUM(%%mm6, %%mm7, %%mm0)
1485 "movq 64(%1), %%mm1 \n\t"
1486 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1487 "movq %%mm0, 64(%1) \n\t"
1488
1489 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1490 LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1491
1492 HADAMARD48
1493 "movq %%mm7, (%1) \n\t"
1494 MMABS(%%mm0, %%mm7)
1495 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1496 MMABS_SUM(%%mm2, %%mm7, %%mm0)
1497 MMABS_SUM(%%mm3, %%mm7, %%mm0)
1498 MMABS_SUM(%%mm4, %%mm7, %%mm0)
1499 MMABS_SUM(%%mm5, %%mm7, %%mm0)
1500 MMABS_SUM(%%mm6, %%mm7, %%mm0)
1501 "movq (%1), %%mm1 \n\t"
1502 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1503 "movq 64(%1), %%mm1 \n\t"
1504 MMABS_SUM(%%mm1, %%mm7, %%mm0)
1505
1506 "movq %%mm0, %%mm1 \n\t"
1507 "psrlq $32, %%mm0 \n\t"
1508 "paddusw %%mm1, %%mm0 \n\t"
1509 "movq %%mm0, %%mm1 \n\t"
1510 "psrlq $16, %%mm0 \n\t"
1511 "paddusw %%mm1, %%mm0 \n\t"
1512 "movd %%mm0, %0 \n\t"
1513
1514 : "=r" (sum)
1515 : "r"(temp)
1516 );
1517 return sum&0xFFFF;
1518}
1519
bb198e19 1520static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
8e0a3db7
MN
1521 uint64_t temp[16] __align8;
1522 int sum=0;
bb198e19
MN
1523
1524 assert(h==8);
8e0a3db7
MN
1525
1526 diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1527
1528 asm volatile(
1529 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1530 LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1531
1532 HADAMARD48
1533
1534 "movq %%mm7, 112(%1) \n\t"
1535
1536 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1537 STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1538
1539 "movq 112(%1), %%mm7 \n\t"
1540 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1541 STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1542
1543 LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1544 LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1545
1546 HADAMARD48
1547
1548 "movq %%mm7, 120(%1) \n\t"
1549
1550 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1551 STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1552
1553 "movq 120(%1), %%mm7 \n\t"
1554 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1555 "movq %%mm7, %%mm5 \n\t"//FIXME remove
1556 "movq %%mm6, %%mm7 \n\t"
1557 "movq %%mm0, %%mm6 \n\t"
1558// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1559
1560 LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1561// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1562
1563 HADAMARD48
1564 "movq %%mm7, 64(%1) \n\t"
1565 MMABS_MMX2(%%mm0, %%mm7)
1566 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1567 MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1568 MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1569 MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1570 MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1571 MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1572 "movq 64(%1), %%mm1 \n\t"
1573 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1574 "movq %%mm0, 64(%1) \n\t"
1575
1576 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1577 LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1578
1579 HADAMARD48
1580 "movq %%mm7, (%1) \n\t"
1581 MMABS_MMX2(%%mm0, %%mm7)
1582 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1583 MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1584 MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1585 MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1586 MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1587 MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1588 "movq (%1), %%mm1 \n\t"
1589 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1590 "movq 64(%1), %%mm1 \n\t"
1591 MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1592
1593 "movq %%mm0, %%mm1 \n\t"
1594 "psrlq $32, %%mm0 \n\t"
1595 "paddusw %%mm1, %%mm0 \n\t"
1596 "movq %%mm0, %%mm1 \n\t"
1597 "psrlq $16, %%mm0 \n\t"
1598 "paddusw %%mm1, %%mm0 \n\t"
1599 "movd %%mm0, %0 \n\t"
1600
1601 : "=r" (sum)
1602 : "r"(temp)
1603 );
1604 return sum&0xFFFF;
1605}
1606
1607
bb198e19
MN
1608WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
1609WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
764ef400 1610#endif //CONFIG_ENCODERS
11f18faf 1611
3178ee4c
MN
1612#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
1613#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
1614
826f429a
MN
1615#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
1616 "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
c296f66b 1617 "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
826f429a
MN
1618 "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
1619 "movq "#in7", " #m3 " \n\t" /* d */\
1620 "movq "#in0", %%mm5 \n\t" /* D */\
1621 "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
1622 "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
1623 "movq "#in1", %%mm5 \n\t" /* C */\
1624 "movq "#in2", %%mm6 \n\t" /* B */\
1625 "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
1626 "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
1627 "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
1628 "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
c296f66b 1629 "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
826f429a
MN
1630 "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
1631 "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
1632 "psraw $5, %%mm5 \n\t"\
1633 "packuswb %%mm5, %%mm5 \n\t"\
1634 OP(%%mm5, out, %%mm7, d)
1635
3178ee4c 1636#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
5c91a675 1637static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
1638 uint64_t temp;\
1639\
1640 asm volatile(\
1641 "pxor %%mm7, %%mm7 \n\t"\
1642 "1: \n\t"\
1643 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
1644 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
1645 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
1646 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
1647 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
1648 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
1649 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
1650 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
1651 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
1652 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
1653 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
1654 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
1655 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
1656 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
1657 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
1658 "paddw %%mm3, %%mm5 \n\t" /* b */\
1659 "paddw %%mm2, %%mm6 \n\t" /* c */\
1660 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1661 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
1662 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
c296f66b 1663 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
826f429a
MN
1664 "paddw %%mm4, %%mm0 \n\t" /* a */\
1665 "paddw %%mm1, %%mm5 \n\t" /* d */\
c296f66b 1666 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
826f429a 1667 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
c296f66b 1668 "paddw %6, %%mm6 \n\t"\
826f429a
MN
1669 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1670 "psraw $5, %%mm0 \n\t"\
c296f66b 1671 "movq %%mm0, %5 \n\t"\
826f429a
MN
1672 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1673 \
1674 "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
1675 "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
1676 "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
1677 "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
1678 "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
1679 "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
1680 "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
1681 "paddw %%mm0, %%mm2 \n\t" /* b */\
1682 "paddw %%mm5, %%mm3 \n\t" /* c */\
1683 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
1684 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
1685 "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
1686 "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
1687 "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
1688 "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
c296f66b 1689 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
826f429a
MN
1690 "paddw %%mm2, %%mm1 \n\t" /* a */\
1691 "paddw %%mm6, %%mm4 \n\t" /* d */\
c296f66b 1692 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
826f429a 1693 "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
c296f66b 1694 "paddw %6, %%mm1 \n\t"\
826f429a
MN
1695 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
1696 "psraw $5, %%mm3 \n\t"\
c296f66b 1697 "movq %5, %%mm1 \n\t"\
826f429a 1698 "packuswb %%mm3, %%mm1 \n\t"\
3178ee4c 1699 OP_MMX2(%%mm1, (%1),%%mm4, q)\
826f429a
MN
1700 /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1701 \
1702 "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
1703 "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
1704 "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
1705 "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
1706 "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
1707 "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
1708 "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
1709 "paddw %%mm1, %%mm5 \n\t" /* b */\
1710 "paddw %%mm4, %%mm0 \n\t" /* c */\
1711 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1712 "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
1713 "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
1714 "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
c296f66b 1715 "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
826f429a
MN
1716 "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
1717 "paddw %%mm3, %%mm2 \n\t" /* d */\
1718 "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
1719 "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
1720 "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
1721 "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
1722 "paddw %%mm2, %%mm6 \n\t" /* a */\
c296f66b
MN
1723 "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
1724 "paddw %6, %%mm0 \n\t"\
826f429a
MN
1725 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1726 "psraw $5, %%mm0 \n\t"\
1727 /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1728 \
1729 "paddw %%mm5, %%mm3 \n\t" /* a */\
1730 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
1731 "paddw %%mm4, %%mm6 \n\t" /* b */\
1732 "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
1733 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
1734 "paddw %%mm1, %%mm4 \n\t" /* c */\
1735 "paddw %%mm2, %%mm5 \n\t" /* d */\
1736 "paddw %%mm6, %%mm6 \n\t" /* 2b */\
1737 "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
c296f66b
MN
1738 "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1739 "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
826f429a 1740 "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
c296f66b 1741 "paddw %6, %%mm4 \n\t"\
826f429a
MN
1742 "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
1743 "psraw $5, %%mm4 \n\t"\
1744 "packuswb %%mm4, %%mm0 \n\t"\
3178ee4c 1745 OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
826f429a
MN
1746 \
1747 "addl %3, %0 \n\t"\
1748 "addl %4, %1 \n\t"\
1749 "decl %2 \n\t"\
1750 " jnz 1b \n\t"\
5a508a98 1751 : "+a"(src), "+c"(dst), "+m"(h)\
0b093b6f
MN
1752 : "d"(srcStride), "S"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1753 : "memory"\
826f429a
MN
1754 );\
1755}\
1756\
1757static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1758 int i;\
1759 int16_t temp[16];\
1760 /* quick HACK, XXX FIXME MUST be optimized */\
1761 for(i=0; i<h; i++)\
1762 {\
1763 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1764 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1765 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1766 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1767 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1768 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1769 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1770 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1771 temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1772 temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1773 temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1774 temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1775 temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1776 temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1777 temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1778 temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1779 asm volatile(\
1780 "movq (%0), %%mm0 \n\t"\
1781 "movq 8(%0), %%mm1 \n\t"\
1782 "paddw %2, %%mm0 \n\t"\
1783 "paddw %2, %%mm1 \n\t"\
1784 "psraw $5, %%mm0 \n\t"\
1785 "psraw $5, %%mm1 \n\t"\
1786 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1787 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a
MN
1788 "movq 16(%0), %%mm0 \n\t"\
1789 "movq 24(%0), %%mm1 \n\t"\
1790 "paddw %2, %%mm0 \n\t"\
1791 "paddw %2, %%mm1 \n\t"\
1792 "psraw $5, %%mm0 \n\t"\
1793 "psraw $5, %%mm1 \n\t"\
1794 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1795 OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
826f429a 1796 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1797 : "memory"\
826f429a
MN
1798 );\
1799 dst+=dstStride;\
1800 src+=srcStride;\
1801 }\
1802}\
1803\
5c91a675 1804static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
1805 uint64_t temp;\
1806\
1807 asm volatile(\
1808 "pxor %%mm7, %%mm7 \n\t"\
1809 "1: \n\t"\
1810 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
1811 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
1812 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
1813 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
1814 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
1815 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
1816 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
1817 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
1818 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
1819 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
1820 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
1821 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
1822 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
1823 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
1824 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
1825 "paddw %%mm3, %%mm5 \n\t" /* b */\
1826 "paddw %%mm2, %%mm6 \n\t" /* c */\
1827 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
1828 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
1829 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
c296f66b 1830 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
826f429a
MN
1831 "paddw %%mm4, %%mm0 \n\t" /* a */\
1832 "paddw %%mm1, %%mm5 \n\t" /* d */\
c296f66b 1833 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
826f429a 1834 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
c296f66b 1835 "paddw %6, %%mm6 \n\t"\
826f429a
MN
1836 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
1837 "psraw $5, %%mm0 \n\t"\
1838 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1839 \
1840 "movd 5(%0), %%mm5 \n\t" /* FGHI */\
1841 "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
1842 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
1843 "paddw %%mm5, %%mm1 \n\t" /* a */\
1844 "paddw %%mm6, %%mm2 \n\t" /* b */\
1845 "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
1846 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
1847 "paddw %%mm6, %%mm3 \n\t" /* c */\
1848 "paddw %%mm5, %%mm4 \n\t" /* d */\
1849 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
1850 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
c296f66b
MN
1851 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1852 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
826f429a 1853 "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
c296f66b 1854 "paddw %6, %%mm1 \n\t"\
826f429a
MN
1855 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
1856 "psraw $5, %%mm3 \n\t"\
1857 "packuswb %%mm3, %%mm0 \n\t"\
3178ee4c 1858 OP_MMX2(%%mm0, (%1), %%mm4, q)\
826f429a
MN
1859 \
1860 "addl %3, %0 \n\t"\
1861 "addl %4, %1 \n\t"\
1862 "decl %2 \n\t"\
c296f66b 1863 " jnz 1b \n\t"\
5a508a98 1864 : "+a"(src), "+c"(dst), "+m"(h)\
0b093b6f
MN
1865 : "S"(srcStride), "D"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1866 : "memory"\
826f429a
MN
1867 );\
1868}\
1869\
1870static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1871 int i;\
1872 int16_t temp[8];\
1873 /* quick HACK, XXX FIXME MUST be optimized */\
1874 for(i=0; i<h; i++)\
1875 {\
1876 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1877 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1878 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1879 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1880 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1881 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1882 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
1883 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
1884 asm volatile(\
1885 "movq (%0), %%mm0 \n\t"\
1886 "movq 8(%0), %%mm1 \n\t"\
1887 "paddw %2, %%mm0 \n\t"\
1888 "paddw %2, %%mm1 \n\t"\
1889 "psraw $5, %%mm0 \n\t"\
1890 "psraw $5, %%mm1 \n\t"\
1891 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1892 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a 1893 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1894 :"memory"\
826f429a
MN
1895 );\
1896 dst+=dstStride;\
1897 src+=srcStride;\
1898 }\
3178ee4c
MN
1899}
1900
1901#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
1902\
1903static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1904 uint64_t temp[17*4];\
1905 uint64_t *temp_ptr= temp;\
1906 int count= 17;\
1907\
1908 /*FIXME unroll */\
1909 asm volatile(\
1910 "pxor %%mm7, %%mm7 \n\t"\
1911 "1: \n\t"\
1912 "movq (%0), %%mm0 \n\t"\
1913 "movq (%0), %%mm1 \n\t"\
1914 "movq 8(%0), %%mm2 \n\t"\
1915 "movq 8(%0), %%mm3 \n\t"\
1916 "punpcklbw %%mm7, %%mm0 \n\t"\
1917 "punpckhbw %%mm7, %%mm1 \n\t"\
1918 "punpcklbw %%mm7, %%mm2 \n\t"\
1919 "punpckhbw %%mm7, %%mm3 \n\t"\
1920 "movq %%mm0, (%1) \n\t"\
1921 "movq %%mm1, 17*8(%1) \n\t"\
5a508a98
MN
1922 "movq %%mm2, 2*17*8(%1) \n\t"\
1923 "movq %%mm3, 3*17*8(%1) \n\t"\
3178ee4c
MN
1924 "addl $8, %1 \n\t"\
1925 "addl %3, %0 \n\t"\
1926 "decl %2 \n\t"\
1927 " jnz 1b \n\t"\
1928 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
5a508a98 1929 : "r" (srcStride)\
0b093b6f 1930 : "memory"\
3178ee4c
MN
1931 );\
1932 \
1933 temp_ptr= temp;\
1934 count=4;\
1935 \
1936/*FIXME reorder for speed */\
3178ee4c
MN
1937 asm volatile(\
1938 /*"pxor %%mm7, %%mm7 \n\t"*/\
3178ee4c
MN
1939 "1: \n\t"\
1940 "movq (%0), %%mm0 \n\t"\
1941 "movq 8(%0), %%mm1 \n\t"\
1942 "movq 16(%0), %%mm2 \n\t"\
1943 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
1944 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
1945 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
3178ee4c 1946 "addl %4, %1 \n\t"\
c296f66b 1947 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
3178ee4c 1948 \
c296f66b 1949 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
3178ee4c 1950 "addl %4, %1 \n\t"\
c296f66b
MN
1951 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1952 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
3178ee4c 1953 "addl %4, %1 \n\t"\
c296f66b
MN
1954 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
1955 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
3178ee4c 1956 "addl %4, %1 \n\t"\
c296f66b
MN
1957 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
1958 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
3178ee4c 1959 "addl %4, %1 \n\t"\
c296f66b
MN
1960 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
1961 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
3178ee4c 1962 "addl %4, %1 \n\t"\
c296f66b 1963 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
3178ee4c 1964 \
c296f66b 1965 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
3178ee4c 1966 "addl %4, %1 \n\t" \
c296f66b
MN
1967 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
1968 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
3178ee4c
MN
1969 \
1970 "addl $136, %0 \n\t"\
c296f66b 1971 "addl %6, %1 \n\t"\
3178ee4c
MN
1972 "decl %2 \n\t"\
1973 " jnz 1b \n\t"\
3178ee4c 1974 \
5a508a98 1975 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
c296f66b 1976 : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*dstStride)\
0b093b6f 1977 :"memory"\
3178ee4c 1978 );\
826f429a
MN
1979}\
1980\
5c91a675 1981static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
826f429a
MN
1982 uint64_t temp[9*4];\
1983 uint64_t *temp_ptr= temp;\
1984 int count= 9;\
1985\
1986 /*FIXME unroll */\
1987 asm volatile(\
1988 "pxor %%mm7, %%mm7 \n\t"\
1989 "1: \n\t"\
1990 "movq (%0), %%mm0 \n\t"\
1991 "movq (%0), %%mm1 \n\t"\
1992 "punpcklbw %%mm7, %%mm0 \n\t"\
1993 "punpckhbw %%mm7, %%mm1 \n\t"\
1994 "movq %%mm0, (%1) \n\t"\
1995 "movq %%mm1, 9*8(%1) \n\t"\
1996 "addl $8, %1 \n\t"\
1997 "addl %3, %0 \n\t"\
1998 "decl %2 \n\t"\
1999 " jnz 1b \n\t"\
2000 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
2001 : "r" (srcStride)\
0b093b6f 2002 : "memory"\
826f429a
MN
2003 );\
2004 \
2005 temp_ptr= temp;\
2006 count=2;\
2007 \
2008/*FIXME reorder for speed */\
2009 asm volatile(\
2010 /*"pxor %%mm7, %%mm7 \n\t"*/\
2011 "1: \n\t"\
2012 "movq (%0), %%mm0 \n\t"\
2013 "movq 8(%0), %%mm1 \n\t"\
2014 "movq 16(%0), %%mm2 \n\t"\
2015 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
2016 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
2017 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
826f429a 2018 "addl %4, %1 \n\t"\
c296f66b 2019 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
826f429a 2020 \
c296f66b 2021 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
826f429a 2022 "addl %4, %1 \n\t"\
c296f66b 2023 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
826f429a 2024 \
c296f66b 2025 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
826f429a 2026 "addl %4, %1 \n\t"\
c296f66b
MN
2027 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
2028 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
826f429a
MN
2029 \
2030 "addl $72, %0 \n\t"\
c296f66b 2031 "addl %6, %1 \n\t"\
826f429a
MN
2032 "decl %2 \n\t"\
2033 " jnz 1b \n\t"\
2034 \
c296f66b
MN
2035 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
2036 : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*dstStride)\
0b093b6f
MN
2037 : "memory"\
2038 );\
3178ee4c 2039}\
826f429a 2040\
0c1a9eda 2041static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2042 OPNAME ## pixels8_mmx(dst, src, stride, 8);\
826f429a
MN
2043}\
2044\
0c1a9eda 2045static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2046 uint64_t temp[8];\
826f429a
MN
2047 uint8_t * const half= (uint8_t*)temp;\
2048 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
2049 OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
2050}\
2051\
0c1a9eda 2052static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2053 OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
2054}\
2055\
0c1a9eda 2056static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2057 uint64_t temp[8];\
826f429a
MN
2058 uint8_t * const half= (uint8_t*)temp;\
2059 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
2060 OPNAME ## pixels8_l2_mmx(dst, src+1, half, stride, stride, 8);\
2061}\
2062\
0c1a9eda 2063static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2064 uint64_t temp[8];\
826f429a 2065 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2066 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
826f429a
MN
2067 OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
2068}\
2069\
0c1a9eda 2070static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2071 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
2072}\
2073\
0c1a9eda 2074static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2075 uint64_t temp[8];\
826f429a 2076 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2077 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
826f429a
MN
2078 OPNAME ## pixels8_l2_mmx(dst, src+stride, half, stride, stride, 8);\
2079}\
0c1a9eda 2080static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2081 uint64_t half[8 + 9];\
2082 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2083 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2084 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 2085 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
3178ee4c 2086 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 2087 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
826f429a 2088}\
0c1a9eda 2089static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2090 uint64_t half[8 + 9];\
2091 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2092 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2093 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 2094 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 2095 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 2096 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
826f429a 2097}\
0c1a9eda 2098static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2099 uint64_t half[8 + 9];\
2100 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2101 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2102 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 2103 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
3178ee4c 2104 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 2105 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 2106}\
0c1a9eda 2107static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2108 uint64_t half[8 + 9];\
2109 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2110 uint8_t * const halfHV= ((uint8_t*)half);\
2111 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2112 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 2113 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 2114 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 2115}\
0c1a9eda 2116static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2117 uint64_t half[8 + 9];\
826f429a
MN
2118 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2119 uint8_t * const halfHV= ((uint8_t*)half);\
2120 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2121 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
826f429a
MN
2122 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
2123}\
0c1a9eda 2124static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2125 uint64_t half[8 + 9];\
826f429a
MN
2126 uint8_t * const halfH= ((uint8_t*)half) + 64;\
2127 uint8_t * const halfHV= ((uint8_t*)half);\
2128 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2129 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
826f429a
MN
2130 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
2131}\
0c1a9eda 2132static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2133 uint64_t half[8 + 9];\
2134 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2135 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953
MN
2136 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
2137 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2138}\
0c1a9eda 2139static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2140 uint64_t half[8 + 9];\
2141 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2142 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953
MN
2143 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
2144 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2145}\
0c1a9eda 2146static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 2147 uint64_t half[9];\
826f429a
MN
2148 uint8_t * const halfH= ((uint8_t*)half);\
2149 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 2150 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 2151}\
0c1a9eda 2152static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2153 OPNAME ## pixels16_mmx(dst, src, stride, 16);\
826f429a
MN
2154}\
2155\
0c1a9eda 2156static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2157 uint64_t temp[32];\
2158 uint8_t * const half= (uint8_t*)temp;\
2159 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
2160 OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
2161}\
2162\
0c1a9eda 2163static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2164 OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
2165}\
2166\
0c1a9eda 2167static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2168 uint64_t temp[32];\
2169 uint8_t * const half= (uint8_t*)temp;\
2170 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
2171 OPNAME ## pixels16_l2_mmx(dst, src+1, half, stride, stride, 16);\
2172}\
2173\
0c1a9eda 2174static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2175 uint64_t temp[32];\
2176 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2177 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
826f429a
MN
2178 OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
2179}\
2180\
0c1a9eda 2181static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 2182 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
2183}\
2184\
0c1a9eda 2185static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2186 uint64_t temp[32];\
2187 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 2188 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
826f429a
MN
2189 OPNAME ## pixels16_l2_mmx(dst, src+stride, half, stride, stride, 16);\
2190}\
0c1a9eda 2191static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2192 uint64_t half[16*2 + 17*2];\
2193 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2194 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2195 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 2196 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
3178ee4c 2197 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 2198 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
826f429a 2199}\
0c1a9eda 2200static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2201 uint64_t half[16*2 + 17*2];\
2202 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2203 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2204 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 2205 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 2206 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 2207 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
826f429a 2208}\
0c1a9eda 2209static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2210 uint64_t half[16*2 + 17*2];\
2211 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2212 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 2213 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 2214 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
3178ee4c 2215 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 2216 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 2217}\
0c1a9eda 2218static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2219 uint64_t half[16*2 + 17*2];\
2220 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2221 uint8_t * const halfHV= ((uint8_t*)half);\
2222 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2223 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 2224 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 2225 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 2226}\
0c1a9eda 2227static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2228 uint64_t half[16*2 + 17*2];\
2229 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2230 uint8_t * const halfHV= ((uint8_t*)half);\
2231 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2232 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
826f429a
MN
2233 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
2234}\
0c1a9eda 2235static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2236 uint64_t half[16*2 + 17*2];\
2237 uint8_t * const halfH= ((uint8_t*)half) + 256;\
2238 uint8_t * const halfHV= ((uint8_t*)half);\
2239 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2240 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
826f429a
MN
2241 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
2242}\
0c1a9eda 2243static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2244 uint64_t half[17*2];\
2245 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2246 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953
MN
2247 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
2248 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 2249}\
0c1a9eda 2250static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
2251 uint64_t half[17*2];\
2252 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 2253 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953
MN
2254 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
2255 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 2256}\
0c1a9eda 2257static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
2258 uint64_t half[17*2];\
2259 uint8_t * const halfH= ((uint8_t*)half);\
2260 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 2261 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a
MN
2262}
2263
2264
2265#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
3178ee4c 2266#define AVG_3DNOW_OP(a,b,temp, size) \
826f429a
MN
2267"mov" #size " " #b ", " #temp " \n\t"\
2268"pavgusb " #temp ", " #a " \n\t"\
2269"mov" #size " " #a ", " #b " \n\t"
3178ee4c 2270#define AVG_MMX2_OP(a,b,temp, size) \
826f429a
MN
2271"mov" #size " " #b ", " #temp " \n\t"\
2272"pavgb " #temp ", " #a " \n\t"\
2273"mov" #size " " #a ", " #b " \n\t"
3178ee4c
MN
2274
2275QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
2276QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
2277QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
2278QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
2279QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
2280QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
826f429a 2281QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
3178ee4c 2282QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
826f429a
MN
2283QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
2284
61a4e8ae 2285#if 0
d6a4c0b1 2286static void just_return() { return; }
61a4e8ae 2287#endif
d6a4c0b1 2288
826f429a
MN
2289#define SET_QPEL_FUNC(postfix1, postfix2) \
2290 c->put_ ## postfix1 = put_ ## postfix2;\
2291 c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
2292 c->avg_ ## postfix1 = avg_ ## postfix2;
b0368839 2293
364a1797
MN
2294static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
2295 int i=0;
2296
2297 assert(ABS(scale) < 256);
2298 scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2299
2300 asm volatile(
2301 "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
2302 "psrlw $15, %%mm6 \n\t" // 1w
2303 "pxor %%mm7, %%mm7 \n\t"
2304 "movd %4, %%mm5 \n\t"
2305 "punpcklwd %%mm5, %%mm5 \n\t"
2306 "punpcklwd %%mm5, %%mm5 \n\t"
2307 "1: \n\t"
2308 "movq (%1, %0), %%mm0 \n\t"
2309 "movq 8(%1, %0), %%mm1 \n\t"
2310 "pmulhw %%mm5, %%mm0 \n\t"
2311 "pmulhw %%mm5, %%mm1 \n\t"
2312 "paddw %%mm6, %%mm0 \n\t"
2313 "paddw %%mm6, %%mm1 \n\t"
2314 "psraw $1, %%mm0 \n\t"
2315 "psraw $1, %%mm1 \n\t"
2316 "paddw (%2, %0), %%mm0 \n\t"
2317 "paddw 8(%2, %0), %%mm1 \n\t"
2318 "psraw $6, %%mm0 \n\t"
2319 "psraw $6, %%mm1 \n\t"
2320 "pmullw (%3, %0), %%mm0 \n\t"
2321 "pmullw 8(%3, %0), %%mm1 \n\t"
2322 "pmaddwd %%mm0, %%mm0 \n\t"
2323 "pmaddwd %%mm1, %%mm1 \n\t"
2324 "paddd %%mm1, %%mm0 \n\t"
2325 "psrld $4, %%mm0 \n\t"
2326 "paddd %%mm0, %%mm7 \n\t"
2327 "addl $16, %0 \n\t"
2328 "cmpl $128, %0 \n\t" //FIXME optimize & bench
2329 " jb 1b \n\t"
2330 "movq %%mm7, %%mm6 \n\t"
2331 "psrlq $32, %%mm7 \n\t"
2332 "paddd %%mm6, %%mm7 \n\t"
2333 "psrld $2, %%mm7 \n\t"
2334 "movd %%mm7, %0 \n\t"
2335
2336 : "+r" (i)
2337 : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
2338 );
2339 return i;
2340}
2341
2342static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){
2343 int i=0;
2344
2345 if(ABS(scale) < 256){
2346 scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2347 asm volatile(
2348 "pcmpeqw %%mm6, %%mm6 \n\t" // -1w
2349 "psrlw $15, %%mm6 \n\t" // 1w
2350 "movd %3, %%mm5 \n\t"
2351 "punpcklwd %%mm5, %%mm5 \n\t"
2352 "punpcklwd %%mm5, %%mm5 \n\t"
2353 "1: \n\t"
2354 "movq (%1, %0), %%mm0 \n\t"
2355 "movq 8(%1, %0), %%mm1 \n\t"
2356 "pmulhw %%mm5, %%mm0 \n\t"
2357 "pmulhw %%mm5, %%mm1 \n\t"
2358 "paddw %%mm6, %%mm0 \n\t"
2359 "paddw %%mm6, %%mm1 \n\t"
2360 "psraw $1, %%mm0 \n\t"
2361 "psraw $1, %%mm1 \n\t"
2362 "paddw (%2, %0), %%mm0 \n\t"
2363 "paddw 8(%2, %0), %%mm1 \n\t"
2364 "movq %%mm0, (%2, %0) \n\t"
2365 "movq %%mm1, 8(%2, %0) \n\t"
2366 "addl $16, %0 \n\t"
2367 "cmpl $128, %0 \n\t" //FIXME optimize & bench
2368 " jb 1b \n\t"
2369
2370 : "+r" (i)
2371 : "r"(basis), "r"(rem), "g"(scale)
2372 );
2373 }else{
2374 for(i=0; i<8*8; i++){
2375 rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
2376 }
2377 }
2378}
2379
b0368839
MN
2380/* external functions, from idct_mmx.c */
2381void ff_mmx_idct(DCTELEM *block);
2382void ff_mmxext_idct(DCTELEM *block);
2383
2384/* XXX: those functions should be suppressed ASAP when all IDCTs are
2385 converted */
2386static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2387{
2388 ff_mmx_idct (block);
2389 put_pixels_clamped_mmx(block, dest, line_size);
2390}
2391static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2392{
2393 ff_mmx_idct (block);
2394 add_pixels_clamped_mmx(block, dest, line_size);
2395}
2396static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2397{
2398 ff_mmxext_idct (block);
2399 put_pixels_clamped_mmx(block, dest, line_size);
2400}
2401static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2402{
2403 ff_mmxext_idct (block);
2404 add_pixels_clamped_mmx(block, dest, line_size);
2405}
826f429a 2406
b0368839 2407void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
de6d9b64
FB
2408{
2409 mm_flags = mm_support();
63f60826 2410
e5247b5f
ZK
2411 if (avctx->dsp_mask) {
2412 if (avctx->dsp_mask & FF_MM_FORCE)
2413 mm_flags |= (avctx->dsp_mask & 0xffff);
2414 else
2415 mm_flags &= ~(avctx->dsp_mask & 0xffff);
2416 }
63f60826 2417
1565dabc 2418#if 0
01456e8e 2419 av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
de6d9b64 2420 if (mm_flags & MM_MMX)
01456e8e 2421 av_log(avctx, AV_LOG_INFO, " mmx");
de6d9b64 2422 if (mm_flags & MM_MMXEXT)
01456e8e 2423 av_log(avctx, AV_LOG_INFO, " mmxext");
de6d9b64 2424 if (mm_flags & MM_3DNOW)
01456e8e 2425 av_log(avctx, AV_LOG_INFO, " 3dnow");
de6d9b64 2426 if (mm_flags & MM_SSE)
01456e8e 2427 av_log(avctx, AV_LOG_INFO, " sse");
de6d9b64 2428 if (mm_flags & MM_SSE2)
01456e8e
MM
2429 av_log(avctx, AV_LOG_INFO, " sse2");
2430 av_log(avctx, AV_LOG_INFO, "\n");
de6d9b64
FB
2431#endif
2432
2433 if (mm_flags & MM_MMX) {
b0368839
MN
2434 const int idct_algo= avctx->idct_algo;
2435
5fd74135 2436#ifdef CONFIG_ENCODERS
e96682e6 2437 const int dct_algo = avctx->dct_algo;
cf3bf5bb 2438 if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
8fd19ab2
MN
2439 if(mm_flags & MM_SSE2){
2440 c->fdct = ff_fdct_sse2;
2441 }else if(mm_flags & MM_MMXEXT){
cf3bf5bb
MN
2442 c->fdct = ff_fdct_mmx2;
2443 }else{
2444 c->fdct = ff_fdct_mmx;
2445 }
2446 }
5fd74135 2447#endif //CONFIG_ENCODERS
b0368839
MN
2448
2449 if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
2450 c->idct_put= ff_simple_idct_put_mmx;
2451 c->idct_add= ff_simple_idct_add_mmx;
4fb518c3 2452 c->idct = ff_simple_idct_mmx;
b0368839
MN
2453 c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
2454 }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
2455 if(mm_flags & MM_MMXEXT){
2456 c->idct_put= ff_libmpeg2mmx2_idct_put;
2457 c->idct_add= ff_libmpeg2mmx2_idct_add;
4fb518c3 2458 c->idct = ff_mmxext_idct;
b0368839
MN
2459 }else{
2460 c->idct_put= ff_libmpeg2mmx_idct_put;
2461 c->idct_add= ff_libmpeg2mmx_idct_add;
4fb518c3 2462 c->idct = ff_mmx_idct;
b0368839
MN
2463 }
2464 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
2465 }
01456e8e
MM
2466
2467 /* VP3 optimized DSP functions */
38acbc3c
MM
2468 if (mm_flags & MM_SSE2) {
2469 c->vp3_dsp_init = vp3_dsp_init_sse2;
116824d0 2470 c->vp3_idct = vp3_idct_sse2;
38acbc3c
MM
2471 } else {
2472 c->vp3_dsp_init = vp3_dsp_init_mmx;
116824d0 2473 c->vp3_idct = vp3_idct_mmx;
38acbc3c 2474 }
116824d0 2475
764ef400 2476#ifdef CONFIG_ENCODERS
eb4b3dd3
ZK
2477 c->get_pixels = get_pixels_mmx;
2478 c->diff_pixels = diff_pixels_mmx;
764ef400 2479#endif //CONFIG_ENCODERS
eb4b3dd3 2480 c->put_pixels_clamped = put_pixels_clamped_mmx;
f9ed9d85 2481 c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
eb4b3dd3
ZK
2482 c->add_pixels_clamped = add_pixels_clamped_mmx;
2483 c->clear_blocks = clear_blocks_mmx;
764ef400 2484#ifdef CONFIG_ENCODERS
eb4b3dd3 2485 c->pix_sum = pix_sum16_mmx;
764ef400 2486#endif //CONFIG_ENCODERS
eb4b3dd3 2487
eb4b3dd3
ZK
2488 c->put_pixels_tab[0][0] = put_pixels16_mmx;
2489 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
2490 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
2491 c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
2492
2493 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
2494 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
2495 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
2496 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
2497
2498 c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
2499 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
2500 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
2501 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
2502
2503 c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
2504 c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
2505 c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
2506 c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
2507
2508 c->put_pixels_tab[1][0] = put_pixels8_mmx;
2509 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
2510 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
2511 c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
2512
2513 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
2514 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
2515 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
2516 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
2517
2518 c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
2519 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
2520 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
2521 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
2522
2523 c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
2524 c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
2525 c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
2526 c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
826f429a 2527
11f18faf 2528 c->add_bytes= add_bytes_mmx;
764ef400 2529#ifdef CONFIG_ENCODERS
11f18faf 2530 c->diff_bytes= diff_bytes_mmx;
1457ab52
MN
2531
2532 c->hadamard8_diff[0]= hadamard8_diff16_mmx;
2533 c->hadamard8_diff[1]= hadamard8_diff_mmx;
2534
2a006cd3
FL
2535 c->pix_norm1 = pix_norm1_mmx;
2536 c->sse[0] = sse16_mmx;
1ec4df0f 2537 c->sse[1] = sse8_mmx;
622348f9
MN
2538 c->vsad[4]= vsad_intra16_mmx;
2539
1ec4df0f
MN
2540 c->nsse[0] = nsse16_mmx;
2541 c->nsse[1] = nsse8_mmx;
622348f9
MN
2542 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2543 c->vsad[0] = vsad16_mmx;
2544 }
364a1797
MN
2545
2546 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2547 c->try_8x8basis= try_8x8basis_mmx;
2548 }
2549 c->add_8x8basis= add_8x8basis_mmx;
2550
764ef400 2551#endif //CONFIG_ENCODERS
359f98de
MN
2552
2553 c->h263_v_loop_filter= h263_v_loop_filter_mmx;
364a1797 2554 c->h263_h_loop_filter= h263_h_loop_filter_mmx;
1457ab52 2555
de6d9b64 2556 if (mm_flags & MM_MMXEXT) {
eb4b3dd3
ZK
2557 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2558 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
eb4b3dd3
ZK
2559
2560 c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2561 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2562 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
eb4b3dd3
ZK
2563
2564 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2565 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
eb4b3dd3
ZK
2566
2567 c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2568 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2569 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
b0368839 2570
764ef400 2571#ifdef CONFIG_ENCODERS
8e0a3db7
MN
2572 c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
2573 c->hadamard8_diff[1]= hadamard8_diff_mmx2;
622348f9 2574 c->vsad[4]= vsad_intra16_mmx2;
764ef400 2575#endif //CONFIG_ENCODERS
8e0a3db7 2576
b0368839
MN
2577 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2578 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2579 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2580 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2581 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2582 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2583 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
fb85b027 2584#ifdef CONFIG_ENCODERS
622348f9 2585 c->vsad[0] = vsad16_mmx2;
fb85b027 2586#endif //CONFIG_ENCODERS
b0368839 2587 }
3178ee4c 2588
c296f66b 2589#if 1
826f429a
MN
2590 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
2591 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
2592 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
2593 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
2594 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
2595 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
2596 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
2597 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
2598 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
2599 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
2600 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
2601 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
2602 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
2603 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
2604 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
2605 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
2606 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
2607 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
2608 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
2609 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
2610 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
2611 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
2612 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
2613 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
2614 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
2615 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
2616 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
2617 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
2618 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
2619 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
2620 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
2621 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
c296f66b 2622#endif
84705403 2623
0c11692a 2624#ifdef CONFIG_ENCODERS
84705403 2625 c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2;
0c11692a 2626#endif //CONFIG_ENCODERS
de6d9b64 2627 } else if (mm_flags & MM_3DNOW) {
eb4b3dd3
ZK
2628 c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
2629 c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
eb4b3dd3
ZK
2630
2631 c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
2632 c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
2633 c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
eb4b3dd3
ZK
2634
2635 c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
2636 c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
eb4b3dd3
ZK
2637
2638 c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
2639 c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
2640 c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
b0368839
MN
2641
2642 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2643 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
2644 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
2645 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
2646 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
2647 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
2648 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
2649 }
db794953 2650
826f429a
MN
2651 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
2652 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
2653 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
2654 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
2655 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
2656 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
2657 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
2658 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
2659 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
2660 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
2661 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
2662 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
2663 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
2664 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
2665 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
2666 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
2667 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
2668 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
2669 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
2670 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
2671 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
2672 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
2673 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
2674 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
2675 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
2676 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
2677 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
2678 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
2679 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
2680 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
2681 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
2682 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
de6d9b64
FB
2683 }
2684 }
b0368839 2685
764ef400 2686#ifdef CONFIG_ENCODERS
b0368839 2687 dsputil_init_pix_mmx(c, avctx);
764ef400 2688#endif //CONFIG_ENCODERS
d6a4c0b1
ZK
2689#if 0
2690 // for speed testing
2691 get_pixels = just_return;
2692 put_pixels_clamped = just_return;
2693 add_pixels_clamped = just_return;
2694
2695 pix_abs16x16 = just_return;
2696 pix_abs16x16_x2 = just_return;
2697 pix_abs16x16_y2 = just_return;
2698 pix_abs16x16_xy2 = just_return;
2699
2700 put_pixels_tab[0] = just_return;
2701 put_pixels_tab[1] = just_return;
2702 put_pixels_tab[2] = just_return;
2703 put_pixels_tab[3] = just_return;
2704
2705 put_no_rnd_pixels_tab[0] = just_return;
2706 put_no_rnd_pixels_tab[1] = just_return;
2707 put_no_rnd_pixels_tab[2] = just_return;
2708 put_no_rnd_pixels_tab[3] = just_return;
2709
2710 avg_pixels_tab[0] = just_return;
2711 avg_pixels_tab[1] = just_return;
2712 avg_pixels_tab[2] = just_return;
2713 avg_pixels_tab[3] = just_return;
2714
2715 avg_no_rnd_pixels_tab[0] = just_return;
2716 avg_no_rnd_pixels_tab[1] = just_return;
2717 avg_no_rnd_pixels_tab[2] = just_return;
2718 avg_no_rnd_pixels_tab[3] = just_return;
2719
d6a4c0b1
ZK
2720 //av_fdct = just_return;
2721 //ff_idct = just_return;
2722#endif
de6d9b64 2723}