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