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