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