10l
[libav.git] / libavcodec / i386 / dsputil_mmx.c
CommitLineData
de6d9b64
FB
1/*
2 * MMX optimized DSP utils
ff4ec49e 3 * Copyright (c) 2000, 2001 Fabrice Bellard.
de6d9b64 4 *
ff4ec49e
FB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
de6d9b64 9 *
ff4ec49e 10 * This library is distributed in the hope that it will be useful,
de6d9b64 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
de6d9b64 14 *
ff4ec49e
FB
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
de6d9b64
FB
18 *
19 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
20 */
21
22#include "../dsputil.h"
b0368839 23#include "../simple_idct.h"
de6d9b64 24
7d650cb5 25int mm_flags; /* multimedia extension flags */
1457ab52 26
de6d9b64 27/* pixel operations */
a7bd8797
MN
28static const uint64_t mm_bone __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
29static const uint64_t mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
30static const uint64_t mm_wtwo __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
de6d9b64 31
826f429a
MN
32static const uint64_t ff_pw_20 __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
33static const uint64_t ff_pw_3 __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
34static const uint64_t ff_pw_16 __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
35static const uint64_t ff_pw_15 __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
36
d6a4c0b1
ZK
37#define JUMPALIGN() __asm __volatile (".balign 8"::)
38#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
39
fca0f0e5
ZK
40#define MOVQ_WONE(regd) \
41 __asm __volatile ( \
42 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
43 "psrlw $15, %%" #regd ::)
44
45#define MOVQ_BFE(regd) \
46 __asm __volatile ( \
47 "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
48 "paddb %%" #regd ", %%" #regd " \n\t" ::)
49
d6a4c0b1 50#ifndef PIC
fca0f0e5 51#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
d6a4c0b1
ZK
52#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
53#else
54// for shared library it's better to use this way for accessing constants
55// pcmpeqd -> -1
fca0f0e5 56#define MOVQ_BONE(regd) \
d6a4c0b1 57 __asm __volatile ( \
fca0f0e5
ZK
58 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
59 "psrlw $15, %%" #regd " \n\t" \
60 "packuswb %%" #regd ", %%" #regd " \n\t" ::)
d6a4c0b1
ZK
61
62#define MOVQ_WTWO(regd) \
63 __asm __volatile ( \
fca0f0e5
ZK
64 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
65 "psrlw $15, %%" #regd " \n\t" \
66 "psllw $1, %%" #regd " \n\t"::)
a7bd8797 67
d6a4c0b1
ZK
68#endif
69
fca0f0e5 70// using regr as temporary and for the output result
def60345 71// first argument is unmodifed and second is trashed
39825f31
ZK
72// regfe is supposed to contain 0xfefefefefefefefe
73#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
91abb473
ZK
74 "movq " #rega ", " #regr " \n\t"\
75 "pand " #regb ", " #regr " \n\t"\
def60345 76 "pxor " #rega ", " #regb " \n\t"\
39825f31 77 "pand " #regfe "," #regb " \n\t"\
def60345 78 "psrlq $1, " #regb " \n\t"\
91abb473 79 "paddb " #regb ", " #regr " \n\t"
def60345 80
39825f31 81#define PAVGB_MMX(rega, regb, regr, regfe) \
91abb473
ZK
82 "movq " #rega ", " #regr " \n\t"\
83 "por " #regb ", " #regr " \n\t"\
def60345 84 "pxor " #rega ", " #regb " \n\t"\
39825f31 85 "pand " #regfe "," #regb " \n\t"\
def60345 86 "psrlq $1, " #regb " \n\t"\
91abb473 87 "psubb " #regb ", " #regr " \n\t"
def60345 88
39825f31 89// mm6 is supposed to contain 0xfefefefefefefefe
6aa6ea8e
ZK
90#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
91 "movq " #rega ", " #regr " \n\t"\
92 "movq " #regc ", " #regp " \n\t"\
93 "pand " #regb ", " #regr " \n\t"\
94 "pand " #regd ", " #regp " \n\t"\
95 "pxor " #rega ", " #regb " \n\t"\
96 "pxor " #regc ", " #regd " \n\t"\
fca0f0e5
ZK
97 "pand %%mm6, " #regb " \n\t"\
98 "pand %%mm6, " #regd " \n\t"\
6aa6ea8e
ZK
99 "psrlq $1, " #regb " \n\t"\
100 "psrlq $1, " #regd " \n\t"\
101 "paddb " #regb ", " #regr " \n\t"\
102 "paddb " #regd ", " #regp " \n\t"
103
104#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
105 "movq " #rega ", " #regr " \n\t"\
106 "movq " #regc ", " #regp " \n\t"\
107 "por " #regb ", " #regr " \n\t"\
108 "por " #regd ", " #regp " \n\t"\
109 "pxor " #rega ", " #regb " \n\t"\
110 "pxor " #regc ", " #regd " \n\t"\
fca0f0e5
ZK
111 "pand %%mm6, " #regb " \n\t"\
112 "pand %%mm6, " #regd " \n\t"\
6aa6ea8e
ZK
113 "psrlq $1, " #regd " \n\t"\
114 "psrlq $1, " #regb " \n\t"\
115 "psubb " #regb ", " #regr " \n\t"\
116 "psubb " #regd ", " #regp " \n\t"
117
91abb473
ZK
118/***********************************/
119/* MMX no rounding */
120#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
fca0f0e5 121#define SET_RND MOVQ_WONE
6aa6ea8e 122#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
39825f31 123#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
fca0f0e5 124
91abb473
ZK
125#include "dsputil_mmx_rnd.h"
126
127#undef DEF
fca0f0e5 128#undef SET_RND
6aa6ea8e 129#undef PAVGBP
39825f31 130#undef PAVGB
91abb473
ZK
131/***********************************/
132/* MMX rounding */
133
134#define DEF(x, y) x ## _ ## y ##_mmx
fca0f0e5 135#define SET_RND MOVQ_WTWO
6aa6ea8e 136#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
39825f31 137#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
fca0f0e5 138
91abb473
ZK
139#include "dsputil_mmx_rnd.h"
140
141#undef DEF
fca0f0e5 142#undef SET_RND
6aa6ea8e 143#undef PAVGBP
39825f31 144#undef PAVGB
a7bd8797 145
de6d9b64
FB
146/***********************************/
147/* 3Dnow specific */
148
149#define DEF(x) x ## _3dnow
150/* for Athlons PAVGUSB is prefered */
151#define PAVGB "pavgusb"
152
153#include "dsputil_mmx_avg.h"
154
155#undef DEF
156#undef PAVGB
157
158/***********************************/
159/* MMX2 specific */
160
607dce96 161#define DEF(x) x ## _mmx2
de6d9b64
FB
162
163/* Introduced only in MMX2 set */
164#define PAVGB "pavgb"
165
166#include "dsputil_mmx_avg.h"
167
168#undef DEF
169#undef PAVGB
170
171/***********************************/
172/* standard MMX */
173
0c1a9eda 174static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
de6d9b64 175{
607dce96
MN
176 asm volatile(
177 "movl $-128, %%eax \n\t"
178 "pxor %%mm7, %%mm7 \n\t"
179 ".balign 16 \n\t"
180 "1: \n\t"
181 "movq (%0), %%mm0 \n\t"
182 "movq (%0, %2), %%mm2 \n\t"
183 "movq %%mm0, %%mm1 \n\t"
184 "movq %%mm2, %%mm3 \n\t"
185 "punpcklbw %%mm7, %%mm0 \n\t"
186 "punpckhbw %%mm7, %%mm1 \n\t"
187 "punpcklbw %%mm7, %%mm2 \n\t"
188 "punpckhbw %%mm7, %%mm3 \n\t"
189 "movq %%mm0, (%1, %%eax)\n\t"
190 "movq %%mm1, 8(%1, %%eax)\n\t"
191 "movq %%mm2, 16(%1, %%eax)\n\t"
192 "movq %%mm3, 24(%1, %%eax)\n\t"
193 "addl %3, %0 \n\t"
194 "addl $32, %%eax \n\t"
195 "js 1b \n\t"
196 : "+r" (pixels)
197 : "r" (block+64), "r" (line_size), "r" (line_size*2)
198 : "%eax"
199 );
de6d9b64
FB
200}
201
0c1a9eda 202static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
9dbcbd92
MN
203{
204 asm volatile(
607dce96 205 "pxor %%mm7, %%mm7 \n\t"
9dbcbd92 206 "movl $-128, %%eax \n\t"
607dce96 207 ".balign 16 \n\t"
9dbcbd92
MN
208 "1: \n\t"
209 "movq (%0), %%mm0 \n\t"
210 "movq (%1), %%mm2 \n\t"
211 "movq %%mm0, %%mm1 \n\t"
212 "movq %%mm2, %%mm3 \n\t"
213 "punpcklbw %%mm7, %%mm0 \n\t"
214 "punpckhbw %%mm7, %%mm1 \n\t"
215 "punpcklbw %%mm7, %%mm2 \n\t"
216 "punpckhbw %%mm7, %%mm3 \n\t"
217 "psubw %%mm2, %%mm0 \n\t"
218 "psubw %%mm3, %%mm1 \n\t"
219 "movq %%mm0, (%2, %%eax)\n\t"
220 "movq %%mm1, 8(%2, %%eax)\n\t"
221 "addl %3, %0 \n\t"
222 "addl %3, %1 \n\t"
223 "addl $16, %%eax \n\t"
224 "jnz 1b \n\t"
225 : "+r" (s1), "+r" (s2)
226 : "r" (block+64), "r" (stride)
227 : "%eax"
228 );
229}
230
0c1a9eda 231void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
232{
233 const DCTELEM *p;
0c1a9eda 234 uint8_t *pix;
de6d9b64
FB
235
236 /* read the pixels */
237 p = block;
238 pix = pixels;
d6a4c0b1 239 /* unrolled loop */
de6d9b64 240 __asm __volatile(
a822a479
NK
241 "movq %3, %%mm0\n\t"
242 "movq 8%3, %%mm1\n\t"
243 "movq 16%3, %%mm2\n\t"
244 "movq 24%3, %%mm3\n\t"
245 "movq 32%3, %%mm4\n\t"
246 "movq 40%3, %%mm5\n\t"
247 "movq 48%3, %%mm6\n\t"
248 "movq 56%3, %%mm7\n\t"
de6d9b64
FB
249 "packuswb %%mm1, %%mm0\n\t"
250 "packuswb %%mm3, %%mm2\n\t"
251 "packuswb %%mm5, %%mm4\n\t"
252 "packuswb %%mm7, %%mm6\n\t"
a822a479
NK
253 "movq %%mm0, (%0)\n\t"
254 "movq %%mm2, (%0, %1)\n\t"
255 "movq %%mm4, (%0, %1, 2)\n\t"
256 "movq %%mm6, (%0, %2)\n\t"
257 ::"r" (pix), "r" (line_size), "r" (line_size*3), "m"(*p)
de6d9b64
FB
258 :"memory");
259 pix += line_size*4;
260 p += 32;
d6a4c0b1
ZK
261
262 // if here would be an exact copy of the code above
263 // compiler would generate some very strange code
264 // thus using "r"
265 __asm __volatile(
266 "movq (%3), %%mm0\n\t"
267 "movq 8(%3), %%mm1\n\t"
268 "movq 16(%3), %%mm2\n\t"
269 "movq 24(%3), %%mm3\n\t"
270 "movq 32(%3), %%mm4\n\t"
271 "movq 40(%3), %%mm5\n\t"
272 "movq 48(%3), %%mm6\n\t"
273 "movq 56(%3), %%mm7\n\t"
274 "packuswb %%mm1, %%mm0\n\t"
275 "packuswb %%mm3, %%mm2\n\t"
276 "packuswb %%mm5, %%mm4\n\t"
277 "packuswb %%mm7, %%mm6\n\t"
278 "movq %%mm0, (%0)\n\t"
279 "movq %%mm2, (%0, %1)\n\t"
280 "movq %%mm4, (%0, %1, 2)\n\t"
281 "movq %%mm6, (%0, %2)\n\t"
282 ::"r" (pix), "r" (line_size), "r" (line_size*3), "r"(p)
283 :"memory");
de6d9b64
FB
284}
285
0c1a9eda 286void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
de6d9b64
FB
287{
288 const DCTELEM *p;
0c1a9eda 289 uint8_t *pix;
de6d9b64
FB
290 int i;
291
292 /* read the pixels */
293 p = block;
294 pix = pixels;
d6a4c0b1
ZK
295 MOVQ_ZERO(mm7);
296 i = 4;
cd8e5f96 297 do {
de6d9b64 298 __asm __volatile(
cd8e5f96
ZK
299 "movq (%2), %%mm0\n\t"
300 "movq 8(%2), %%mm1\n\t"
301 "movq 16(%2), %%mm2\n\t"
302 "movq 24(%2), %%mm3\n\t"
de6d9b64
FB
303 "movq %0, %%mm4\n\t"
304 "movq %1, %%mm6\n\t"
305 "movq %%mm4, %%mm5\n\t"
306 "punpcklbw %%mm7, %%mm4\n\t"
307 "punpckhbw %%mm7, %%mm5\n\t"
308 "paddsw %%mm4, %%mm0\n\t"
309 "paddsw %%mm5, %%mm1\n\t"
310 "movq %%mm6, %%mm5\n\t"
311 "punpcklbw %%mm7, %%mm6\n\t"
312 "punpckhbw %%mm7, %%mm5\n\t"
313 "paddsw %%mm6, %%mm2\n\t"
314 "paddsw %%mm5, %%mm3\n\t"
315 "packuswb %%mm1, %%mm0\n\t"
316 "packuswb %%mm3, %%mm2\n\t"
317 "movq %%mm0, %0\n\t"
318 "movq %%mm2, %1\n\t"
a822a479 319 :"+m"(*pix), "+m"(*(pix+line_size))
cd8e5f96 320 :"r"(p)
de6d9b64
FB
321 :"memory");
322 pix += line_size*2;
323 p += 16;
cd8e5f96 324 } while (--i);
de6d9b64
FB
325}
326
0c1a9eda 327static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 328{
39825f31 329 __asm __volatile(
31ddcf98 330 "lea (%3, %3), %%eax \n\t"
52af45ad 331 ".balign 8 \n\t"
31ddcf98
ZK
332 "1: \n\t"
333 "movq (%1), %%mm0 \n\t"
334 "movq (%1, %3), %%mm1 \n\t"
335 "movq %%mm0, (%2) \n\t"
336 "movq %%mm1, (%2, %3) \n\t"
337 "addl %%eax, %1 \n\t"
338 "addl %%eax, %2 \n\t"
339 "movq (%1), %%mm0 \n\t"
340 "movq (%1, %3), %%mm1 \n\t"
341 "movq %%mm0, (%2) \n\t"
342 "movq %%mm1, (%2, %3) \n\t"
343 "addl %%eax, %1 \n\t"
344 "addl %%eax, %2 \n\t"
345 "subl $4, %0 \n\t"
346 "jnz 1b \n\t"
347 : "+g"(h), "+r" (pixels), "+r" (block)
348 : "r"(line_size)
349 : "%eax", "memory"
350 );
de6d9b64
FB
351}
352
0c1a9eda 353static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
b3184779
MN
354{
355 __asm __volatile(
356 "lea (%3, %3), %%eax \n\t"
357 ".balign 8 \n\t"
358 "1: \n\t"
359 "movq (%1), %%mm0 \n\t"
360 "movq 8(%1), %%mm4 \n\t"
361 "movq (%1, %3), %%mm1 \n\t"
362 "movq 8(%1, %3), %%mm5 \n\t"
363 "movq %%mm0, (%2) \n\t"
364 "movq %%mm4, 8(%2) \n\t"
365 "movq %%mm1, (%2, %3) \n\t"
366 "movq %%mm5, 8(%2, %3) \n\t"
367 "addl %%eax, %1 \n\t"
368 "addl %%eax, %2 \n\t"
369 "movq (%1), %%mm0 \n\t"
370 "movq 8(%1), %%mm4 \n\t"
371 "movq (%1, %3), %%mm1 \n\t"
372 "movq 8(%1, %3), %%mm5 \n\t"
373 "movq %%mm0, (%2) \n\t"
374 "movq %%mm4, 8(%2) \n\t"
375 "movq %%mm1, (%2, %3) \n\t"
376 "movq %%mm5, 8(%2, %3) \n\t"
377 "addl %%eax, %1 \n\t"
378 "addl %%eax, %2 \n\t"
379 "subl $4, %0 \n\t"
380 "jnz 1b \n\t"
381 : "+g"(h), "+r" (pixels), "+r" (block)
382 : "r"(line_size)
383 : "%eax", "memory"
384 );
385}
386
649c00c9
MN
387static void clear_blocks_mmx(DCTELEM *blocks)
388{
39825f31 389 __asm __volatile(
649c00c9
MN
390 "pxor %%mm7, %%mm7 \n\t"
391 "movl $-128*6, %%eax \n\t"
392 "1: \n\t"
393 "movq %%mm7, (%0, %%eax) \n\t"
394 "movq %%mm7, 8(%0, %%eax) \n\t"
395 "movq %%mm7, 16(%0, %%eax) \n\t"
396 "movq %%mm7, 24(%0, %%eax) \n\t"
397 "addl $32, %%eax \n\t"
398 " js 1b \n\t"
399 : : "r" (((int)blocks)+128*6)
400 : "%eax"
401 );
402}
403
0c1a9eda 404static int pix_sum16_mmx(uint8_t * pix, int line_size){
084c726b
MN
405 const int h=16;
406 int sum;
407 int index= -line_size*h;
408
409 __asm __volatile(
410 "pxor %%mm7, %%mm7 \n\t"
411 "pxor %%mm6, %%mm6 \n\t"
412 "1: \n\t"
413 "movq (%2, %1), %%mm0 \n\t"
414 "movq (%2, %1), %%mm1 \n\t"
415 "movq 8(%2, %1), %%mm2 \n\t"
416 "movq 8(%2, %1), %%mm3 \n\t"
417 "punpcklbw %%mm7, %%mm0 \n\t"
418 "punpckhbw %%mm7, %%mm1 \n\t"
419 "punpcklbw %%mm7, %%mm2 \n\t"
420 "punpckhbw %%mm7, %%mm3 \n\t"
421 "paddw %%mm0, %%mm1 \n\t"
422 "paddw %%mm2, %%mm3 \n\t"
423 "paddw %%mm1, %%mm3 \n\t"
424 "paddw %%mm3, %%mm6 \n\t"
425 "addl %3, %1 \n\t"
426 " js 1b \n\t"
427 "movq %%mm6, %%mm5 \n\t"
428 "psrlq $32, %%mm6 \n\t"
429 "paddw %%mm5, %%mm6 \n\t"
430 "movq %%mm6, %%mm5 \n\t"
431 "psrlq $16, %%mm6 \n\t"
432 "paddw %%mm5, %%mm6 \n\t"
433 "movd %%mm6, %0 \n\t"
434 "andl $0xFFFF, %0 \n\t"
435 : "=&r" (sum), "+r" (index)
436 : "r" (pix - index), "r" (line_size)
437 );
438
439 return sum;
440}
441
11f18faf
MN
442static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
443 int i=0;
444 asm volatile(
445 "1: \n\t"
446 "movq (%1, %0), %%mm0 \n\t"
447 "movq (%2, %0), %%mm1 \n\t"
448 "paddb %%mm0, %%mm1 \n\t"
449 "movq %%mm1, (%2, %0) \n\t"
450 "movq 8(%1, %0), %%mm0 \n\t"
451 "movq 8(%2, %0), %%mm1 \n\t"
452 "paddb %%mm0, %%mm1 \n\t"
453 "movq %%mm1, 8(%2, %0) \n\t"
454 "addl $16, %0 \n\t"
455 "cmpl %3, %0 \n\t"
456 " jb 1b \n\t"
457 : "+r" (i)
458 : "r"(src), "r"(dst), "r"(w-15)
459 );
460 for(; i<w; i++)
461 dst[i+0] += src[i+0];
462}
463
2a006cd3
FL
464static int pix_norm1_mmx(uint8_t *pix, int line_size) {
465 int tmp;
466 asm volatile (
467 "movl $16,%%ecx\n"
468 "pxor %%mm0,%%mm0\n"
469 "pxor %%mm7,%%mm7\n"
470 "1:\n"
471 "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
472 "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
473
474 "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
475
476 "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
477 "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
478
479 "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
480 "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
481 "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
482
483 "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
484 "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
485
486 "pmaddwd %%mm3,%%mm3\n"
487 "pmaddwd %%mm4,%%mm4\n"
488
489 "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
490 pix2^2+pix3^2+pix6^2+pix7^2) */
491 "paddd %%mm3,%%mm4\n"
492 "paddd %%mm2,%%mm7\n"
493
494 "addl %2, %0\n"
495 "paddd %%mm4,%%mm7\n"
496 "dec %%ecx\n"
497 "jnz 1b\n"
498
499 "movq %%mm7,%%mm1\n"
500 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
501 "paddd %%mm7,%%mm1\n"
502 "movd %%mm1,%1\n"
503 : "+r" (pix), "=r"(tmp) : "r" (line_size) : "%ecx" );
504 return tmp;
505}
506
0c1a9eda 507static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size) {
2a006cd3
FL
508 int tmp;
509 asm volatile (
510 "movl $16,%%ecx\n"
511 "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
512 "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
513 "1:\n"
514 "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
515 "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
516 "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
517 "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
518
519 /* todo: mm1-mm2, mm3-mm4 */
520 /* algo: substract mm1 from mm2 with saturation and vice versa */
521 /* OR the results to get absolute difference */
522 "movq %%mm1,%%mm5\n"
523 "movq %%mm3,%%mm6\n"
524 "psubusb %%mm2,%%mm1\n"
525 "psubusb %%mm4,%%mm3\n"
526 "psubusb %%mm5,%%mm2\n"
527 "psubusb %%mm6,%%mm4\n"
528
529 "por %%mm1,%%mm2\n"
530 "por %%mm3,%%mm4\n"
531
532 /* now convert to 16-bit vectors so we can square them */
533 "movq %%mm2,%%mm1\n"
534 "movq %%mm4,%%mm3\n"
535
536 "punpckhbw %%mm0,%%mm2\n"
537 "punpckhbw %%mm0,%%mm4\n"
538 "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
539 "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
540
541 "pmaddwd %%mm2,%%mm2\n"
542 "pmaddwd %%mm4,%%mm4\n"
543 "pmaddwd %%mm1,%%mm1\n"
544 "pmaddwd %%mm3,%%mm3\n"
545
546 "addl %3,%0\n"
547 "addl %3,%1\n"
548
549 "paddd %%mm2,%%mm1\n"
550 "paddd %%mm4,%%mm3\n"
551 "paddd %%mm1,%%mm7\n"
552 "paddd %%mm3,%%mm7\n"
553
554 "decl %%ecx\n"
555 "jnz 1b\n"
556
557 "movq %%mm7,%%mm1\n"
558 "psrlq $32, %%mm7\n" /* shift hi dword to lo */
559 "paddd %%mm7,%%mm1\n"
560 "movd %%mm1,%2\n"
561 : "+r" (pix1), "+r" (pix2), "=r"(tmp) : "r" (line_size) : "ecx");
562 return tmp;
563}
564
11f18faf
MN
565static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
566 int i=0;
567 asm volatile(
568 "1: \n\t"
569 "movq (%2, %0), %%mm0 \n\t"
570 "movq (%1, %0), %%mm1 \n\t"
571 "psubb %%mm0, %%mm1 \n\t"
572 "movq %%mm1, (%3, %0) \n\t"
573 "movq 8(%2, %0), %%mm0 \n\t"
574 "movq 8(%1, %0), %%mm1 \n\t"
575 "psubb %%mm0, %%mm1 \n\t"
576 "movq %%mm1, 8(%3, %0) \n\t"
577 "addl $16, %0 \n\t"
578 "cmpl %4, %0 \n\t"
579 " jb 1b \n\t"
580 : "+r" (i)
581 : "r"(src1), "r"(src2), "r"(dst), "r"(w-15)
582 );
583 for(; i<w; i++)
584 dst[i+0] = src1[i+0]-src2[i+0];
585}
1457ab52
MN
586#define LBUTTERFLY(a,b)\
587 "paddw " #b ", " #a " \n\t"\
588 "paddw " #b ", " #b " \n\t"\
589 "psubw " #a ", " #b " \n\t"
590
591#define HADAMARD48\
592 LBUTTERFLY(%%mm0, %%mm1)\
593 LBUTTERFLY(%%mm2, %%mm3)\
594 LBUTTERFLY(%%mm4, %%mm5)\
595 LBUTTERFLY(%%mm6, %%mm7)\
596 \
597 LBUTTERFLY(%%mm0, %%mm2)\
598 LBUTTERFLY(%%mm1, %%mm3)\
599 LBUTTERFLY(%%mm4, %%mm6)\
600 LBUTTERFLY(%%mm5, %%mm7)\
601 \
602 LBUTTERFLY(%%mm0, %%mm4)\
603 LBUTTERFLY(%%mm1, %%mm5)\
604 LBUTTERFLY(%%mm2, %%mm6)\
605 LBUTTERFLY(%%mm3, %%mm7)
606
607#define MMABS(a,z)\
608 "pxor " #z ", " #z " \n\t"\
609 "pcmpgtw " #a ", " #z " \n\t"\
610 "pxor " #z ", " #a " \n\t"\
611 "psubw " #z ", " #a " \n\t"
612
613#define MMABS_SUM(a,z, sum)\
614 "pxor " #z ", " #z " \n\t"\
615 "pcmpgtw " #a ", " #z " \n\t"\
616 "pxor " #z ", " #a " \n\t"\
617 "psubw " #z ", " #a " \n\t"\
618 "paddusw " #a ", " #sum " \n\t"
619
620
621#define SBUTTERFLY(a,b,t,n)\
622 "movq " #a ", " #t " \n\t" /* abcd */\
623 "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
624 "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
625
626#define TRANSPOSE4(a,b,c,d,t)\
627 SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
628 SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
629 SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
630 SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
631
632#define LOAD4(o, a, b, c, d)\
633 "movq "#o"(%1), " #a " \n\t"\
634 "movq "#o"+16(%1), " #b " \n\t"\
635 "movq "#o"+32(%1), " #c " \n\t"\
636 "movq "#o"+48(%1), " #d " \n\t"
637
638#define STORE4(o, a, b, c, d)\
639 "movq "#a", "#o"(%1) \n\t"\
640 "movq "#b", "#o"+16(%1) \n\t"\
641 "movq "#c", "#o"+32(%1) \n\t"\
642 "movq "#d", "#o"+48(%1) \n\t"\
643
644static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride){
645 uint64_t temp[16] __align8;
646 int sum=0;
647
648 diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
11f18faf 649
1457ab52
MN
650 asm volatile(
651 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
652 LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
653
654 HADAMARD48
655
656 "movq %%mm7, 112(%1) \n\t"
657
658 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
659 STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
660
661 "movq 112(%1), %%mm7 \n\t"
662 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
663 STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
664
665 LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
666 LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
667
668 HADAMARD48
669
670 "movq %%mm7, 120(%1) \n\t"
671
672 TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
673 STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
674
675 "movq 120(%1), %%mm7 \n\t"
676 TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
677 "movq %%mm7, %%mm5 \n\t"//FIXME remove
678 "movq %%mm6, %%mm7 \n\t"
679 "movq %%mm0, %%mm6 \n\t"
680// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
681
682 LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
683// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
684
685 HADAMARD48
686 "movq %%mm7, 64(%1) \n\t"
687 MMABS(%%mm0, %%mm7)
688 MMABS_SUM(%%mm1, %%mm7, %%mm0)
689 MMABS_SUM(%%mm2, %%mm7, %%mm0)
690 MMABS_SUM(%%mm3, %%mm7, %%mm0)
691 MMABS_SUM(%%mm4, %%mm7, %%mm0)
692 MMABS_SUM(%%mm5, %%mm7, %%mm0)
693 MMABS_SUM(%%mm6, %%mm7, %%mm0)
694 "movq 64(%1), %%mm1 \n\t"
695 MMABS_SUM(%%mm1, %%mm7, %%mm0)
696 "movq %%mm0, 64(%1) \n\t"
697
698 LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
699 LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
700
701 HADAMARD48
702 "movq %%mm7, (%1) \n\t"
703 MMABS(%%mm0, %%mm7)
704 MMABS_SUM(%%mm1, %%mm7, %%mm0)
705 MMABS_SUM(%%mm2, %%mm7, %%mm0)
706 MMABS_SUM(%%mm3, %%mm7, %%mm0)
707 MMABS_SUM(%%mm4, %%mm7, %%mm0)
708 MMABS_SUM(%%mm5, %%mm7, %%mm0)
709 MMABS_SUM(%%mm6, %%mm7, %%mm0)
710 "movq (%1), %%mm1 \n\t"
711 MMABS_SUM(%%mm1, %%mm7, %%mm0)
712 "movq 64(%1), %%mm1 \n\t"
713 MMABS_SUM(%%mm1, %%mm7, %%mm0)
714
715 "movq %%mm0, %%mm1 \n\t"
716 "psrlq $32, %%mm0 \n\t"
717 "paddusw %%mm1, %%mm0 \n\t"
718 "movq %%mm0, %%mm1 \n\t"
719 "psrlq $16, %%mm0 \n\t"
720 "paddusw %%mm1, %%mm0 \n\t"
721 "movd %%mm0, %0 \n\t"
722
723 : "=r" (sum)
724 : "r"(temp)
725 );
726 return sum&0xFFFF;
727}
728
729WARPER88_1616(hadamard8_diff_mmx, hadamard8_diff16_mmx)
11f18faf 730
3178ee4c
MN
731#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
732#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
733
826f429a
MN
734#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
735 "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
c296f66b 736 "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
826f429a
MN
737 "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
738 "movq "#in7", " #m3 " \n\t" /* d */\
739 "movq "#in0", %%mm5 \n\t" /* D */\
740 "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
741 "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
742 "movq "#in1", %%mm5 \n\t" /* C */\
743 "movq "#in2", %%mm6 \n\t" /* B */\
744 "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
745 "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
746 "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
747 "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
c296f66b 748 "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
826f429a
MN
749 "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
750 "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
751 "psraw $5, %%mm5 \n\t"\
752 "packuswb %%mm5, %%mm5 \n\t"\
753 OP(%%mm5, out, %%mm7, d)
754
3178ee4c 755#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
5c91a675 756static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
757 uint64_t temp;\
758\
759 asm volatile(\
760 "pxor %%mm7, %%mm7 \n\t"\
761 "1: \n\t"\
762 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
763 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
764 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
765 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
766 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
767 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
768 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
769 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
770 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
771 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
772 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
773 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
774 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
775 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
776 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
777 "paddw %%mm3, %%mm5 \n\t" /* b */\
778 "paddw %%mm2, %%mm6 \n\t" /* c */\
779 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
780 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
781 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
c296f66b 782 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
826f429a
MN
783 "paddw %%mm4, %%mm0 \n\t" /* a */\
784 "paddw %%mm1, %%mm5 \n\t" /* d */\
c296f66b 785 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
826f429a 786 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
c296f66b 787 "paddw %6, %%mm6 \n\t"\
826f429a
MN
788 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
789 "psraw $5, %%mm0 \n\t"\
c296f66b 790 "movq %%mm0, %5 \n\t"\
826f429a
MN
791 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
792 \
793 "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
794 "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
795 "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
796 "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
797 "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
798 "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
799 "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
800 "paddw %%mm0, %%mm2 \n\t" /* b */\
801 "paddw %%mm5, %%mm3 \n\t" /* c */\
802 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
803 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
804 "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
805 "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
806 "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
807 "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
c296f66b 808 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
826f429a
MN
809 "paddw %%mm2, %%mm1 \n\t" /* a */\
810 "paddw %%mm6, %%mm4 \n\t" /* d */\
c296f66b 811 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
826f429a 812 "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
c296f66b 813 "paddw %6, %%mm1 \n\t"\
826f429a
MN
814 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
815 "psraw $5, %%mm3 \n\t"\
c296f66b 816 "movq %5, %%mm1 \n\t"\
826f429a 817 "packuswb %%mm3, %%mm1 \n\t"\
3178ee4c 818 OP_MMX2(%%mm1, (%1),%%mm4, q)\
826f429a
MN
819 /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
820 \
821 "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
822 "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
823 "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
824 "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
825 "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
826 "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
827 "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
828 "paddw %%mm1, %%mm5 \n\t" /* b */\
829 "paddw %%mm4, %%mm0 \n\t" /* c */\
830 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
831 "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
832 "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
833 "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
c296f66b 834 "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
826f429a
MN
835 "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
836 "paddw %%mm3, %%mm2 \n\t" /* d */\
837 "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
838 "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
839 "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
840 "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
841 "paddw %%mm2, %%mm6 \n\t" /* a */\
c296f66b
MN
842 "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
843 "paddw %6, %%mm0 \n\t"\
826f429a
MN
844 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
845 "psraw $5, %%mm0 \n\t"\
846 /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
847 \
848 "paddw %%mm5, %%mm3 \n\t" /* a */\
849 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
850 "paddw %%mm4, %%mm6 \n\t" /* b */\
851 "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
852 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
853 "paddw %%mm1, %%mm4 \n\t" /* c */\
854 "paddw %%mm2, %%mm5 \n\t" /* d */\
855 "paddw %%mm6, %%mm6 \n\t" /* 2b */\
856 "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
c296f66b
MN
857 "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
858 "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
826f429a 859 "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
c296f66b 860 "paddw %6, %%mm4 \n\t"\
826f429a
MN
861 "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
862 "psraw $5, %%mm4 \n\t"\
863 "packuswb %%mm4, %%mm0 \n\t"\
3178ee4c 864 OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
826f429a
MN
865 \
866 "addl %3, %0 \n\t"\
867 "addl %4, %1 \n\t"\
868 "decl %2 \n\t"\
869 " jnz 1b \n\t"\
5a508a98 870 : "+a"(src), "+c"(dst), "+m"(h)\
0b093b6f
MN
871 : "d"(srcStride), "S"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
872 : "memory"\
826f429a
MN
873 );\
874}\
875\
876static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
877 int i;\
878 int16_t temp[16];\
879 /* quick HACK, XXX FIXME MUST be optimized */\
880 for(i=0; i<h; i++)\
881 {\
882 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
883 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
884 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
885 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
886 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
887 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
888 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
889 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
890 temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
891 temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
892 temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
893 temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
894 temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
895 temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
896 temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
897 temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
898 asm volatile(\
899 "movq (%0), %%mm0 \n\t"\
900 "movq 8(%0), %%mm1 \n\t"\
901 "paddw %2, %%mm0 \n\t"\
902 "paddw %2, %%mm1 \n\t"\
903 "psraw $5, %%mm0 \n\t"\
904 "psraw $5, %%mm1 \n\t"\
905 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 906 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a
MN
907 "movq 16(%0), %%mm0 \n\t"\
908 "movq 24(%0), %%mm1 \n\t"\
909 "paddw %2, %%mm0 \n\t"\
910 "paddw %2, %%mm1 \n\t"\
911 "psraw $5, %%mm0 \n\t"\
912 "psraw $5, %%mm1 \n\t"\
913 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 914 OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
826f429a 915 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 916 : "memory"\
826f429a
MN
917 );\
918 dst+=dstStride;\
919 src+=srcStride;\
920 }\
921}\
922\
5c91a675 923static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
826f429a
MN
924 uint64_t temp;\
925\
926 asm volatile(\
927 "pxor %%mm7, %%mm7 \n\t"\
928 "1: \n\t"\
929 "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
930 "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
931 "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
932 "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
933 "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
934 "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
935 "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
936 "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
937 "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
938 "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
939 "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
940 "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
941 "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
942 "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
943 "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
944 "paddw %%mm3, %%mm5 \n\t" /* b */\
945 "paddw %%mm2, %%mm6 \n\t" /* c */\
946 "paddw %%mm5, %%mm5 \n\t" /* 2b */\
947 "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
948 "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
c296f66b 949 "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
826f429a
MN
950 "paddw %%mm4, %%mm0 \n\t" /* a */\
951 "paddw %%mm1, %%mm5 \n\t" /* d */\
c296f66b 952 "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
826f429a 953 "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
c296f66b 954 "paddw %6, %%mm6 \n\t"\
826f429a
MN
955 "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
956 "psraw $5, %%mm0 \n\t"\
957 /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
958 \
959 "movd 5(%0), %%mm5 \n\t" /* FGHI */\
960 "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
961 "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
962 "paddw %%mm5, %%mm1 \n\t" /* a */\
963 "paddw %%mm6, %%mm2 \n\t" /* b */\
964 "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
965 "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
966 "paddw %%mm6, %%mm3 \n\t" /* c */\
967 "paddw %%mm5, %%mm4 \n\t" /* d */\
968 "paddw %%mm2, %%mm2 \n\t" /* 2b */\
969 "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
c296f66b
MN
970 "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
971 "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
826f429a 972 "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
c296f66b 973 "paddw %6, %%mm1 \n\t"\
826f429a
MN
974 "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
975 "psraw $5, %%mm3 \n\t"\
976 "packuswb %%mm3, %%mm0 \n\t"\
3178ee4c 977 OP_MMX2(%%mm0, (%1), %%mm4, q)\
826f429a
MN
978 \
979 "addl %3, %0 \n\t"\
980 "addl %4, %1 \n\t"\
981 "decl %2 \n\t"\
c296f66b 982 " jnz 1b \n\t"\
5a508a98 983 : "+a"(src), "+c"(dst), "+m"(h)\
0b093b6f
MN
984 : "S"(srcStride), "D"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
985 : "memory"\
826f429a
MN
986 );\
987}\
988\
989static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
990 int i;\
991 int16_t temp[8];\
992 /* quick HACK, XXX FIXME MUST be optimized */\
993 for(i=0; i<h; i++)\
994 {\
995 temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
996 temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
997 temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
998 temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
999 temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1000 temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1001 temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
1002 temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
1003 asm volatile(\
1004 "movq (%0), %%mm0 \n\t"\
1005 "movq 8(%0), %%mm1 \n\t"\
1006 "paddw %2, %%mm0 \n\t"\
1007 "paddw %2, %%mm1 \n\t"\
1008 "psraw $5, %%mm0 \n\t"\
1009 "psraw $5, %%mm1 \n\t"\
1010 "packuswb %%mm1, %%mm0 \n\t"\
3178ee4c 1011 OP_3DNOW(%%mm0, (%1), %%mm1, q)\
826f429a 1012 :: "r"(temp), "r"(dst), "m"(ROUNDER)\
0b093b6f 1013 :"memory"\
826f429a
MN
1014 );\
1015 dst+=dstStride;\
1016 src+=srcStride;\
1017 }\
3178ee4c
MN
1018}
1019
1020#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
1021\
1022static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1023 uint64_t temp[17*4];\
1024 uint64_t *temp_ptr= temp;\
1025 int count= 17;\
1026\
1027 /*FIXME unroll */\
1028 asm volatile(\
1029 "pxor %%mm7, %%mm7 \n\t"\
1030 "1: \n\t"\
1031 "movq (%0), %%mm0 \n\t"\
1032 "movq (%0), %%mm1 \n\t"\
1033 "movq 8(%0), %%mm2 \n\t"\
1034 "movq 8(%0), %%mm3 \n\t"\
1035 "punpcklbw %%mm7, %%mm0 \n\t"\
1036 "punpckhbw %%mm7, %%mm1 \n\t"\
1037 "punpcklbw %%mm7, %%mm2 \n\t"\
1038 "punpckhbw %%mm7, %%mm3 \n\t"\
1039 "movq %%mm0, (%1) \n\t"\
1040 "movq %%mm1, 17*8(%1) \n\t"\
5a508a98
MN
1041 "movq %%mm2, 2*17*8(%1) \n\t"\
1042 "movq %%mm3, 3*17*8(%1) \n\t"\
3178ee4c
MN
1043 "addl $8, %1 \n\t"\
1044 "addl %3, %0 \n\t"\
1045 "decl %2 \n\t"\
1046 " jnz 1b \n\t"\
1047 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
5a508a98 1048 : "r" (srcStride)\
0b093b6f 1049 : "memory"\
3178ee4c
MN
1050 );\
1051 \
1052 temp_ptr= temp;\
1053 count=4;\
1054 \
1055/*FIXME reorder for speed */\
3178ee4c
MN
1056 asm volatile(\
1057 /*"pxor %%mm7, %%mm7 \n\t"*/\
3178ee4c
MN
1058 "1: \n\t"\
1059 "movq (%0), %%mm0 \n\t"\
1060 "movq 8(%0), %%mm1 \n\t"\
1061 "movq 16(%0), %%mm2 \n\t"\
1062 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
1063 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
1064 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
3178ee4c 1065 "addl %4, %1 \n\t"\
c296f66b 1066 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
3178ee4c 1067 \
c296f66b 1068 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
3178ee4c 1069 "addl %4, %1 \n\t"\
c296f66b
MN
1070 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1071 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
3178ee4c 1072 "addl %4, %1 \n\t"\
c296f66b
MN
1073 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
1074 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
3178ee4c 1075 "addl %4, %1 \n\t"\
c296f66b
MN
1076 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
1077 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
3178ee4c 1078 "addl %4, %1 \n\t"\
c296f66b
MN
1079 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
1080 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
3178ee4c 1081 "addl %4, %1 \n\t"\
c296f66b 1082 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
3178ee4c 1083 \
c296f66b 1084 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
3178ee4c 1085 "addl %4, %1 \n\t" \
c296f66b
MN
1086 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
1087 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
3178ee4c
MN
1088 \
1089 "addl $136, %0 \n\t"\
c296f66b 1090 "addl %6, %1 \n\t"\
3178ee4c
MN
1091 "decl %2 \n\t"\
1092 " jnz 1b \n\t"\
3178ee4c 1093 \
5a508a98 1094 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
c296f66b 1095 : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*dstStride)\
0b093b6f 1096 :"memory"\
3178ee4c 1097 );\
826f429a
MN
1098}\
1099\
5c91a675 1100static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
826f429a
MN
1101 uint64_t temp[9*4];\
1102 uint64_t *temp_ptr= temp;\
1103 int count= 9;\
1104\
1105 /*FIXME unroll */\
1106 asm volatile(\
1107 "pxor %%mm7, %%mm7 \n\t"\
1108 "1: \n\t"\
1109 "movq (%0), %%mm0 \n\t"\
1110 "movq (%0), %%mm1 \n\t"\
1111 "punpcklbw %%mm7, %%mm0 \n\t"\
1112 "punpckhbw %%mm7, %%mm1 \n\t"\
1113 "movq %%mm0, (%1) \n\t"\
1114 "movq %%mm1, 9*8(%1) \n\t"\
1115 "addl $8, %1 \n\t"\
1116 "addl %3, %0 \n\t"\
1117 "decl %2 \n\t"\
1118 " jnz 1b \n\t"\
1119 : "+r" (src), "+r" (temp_ptr), "+r"(count)\
1120 : "r" (srcStride)\
0b093b6f 1121 : "memory"\
826f429a
MN
1122 );\
1123 \
1124 temp_ptr= temp;\
1125 count=2;\
1126 \
1127/*FIXME reorder for speed */\
1128 asm volatile(\
1129 /*"pxor %%mm7, %%mm7 \n\t"*/\
1130 "1: \n\t"\
1131 "movq (%0), %%mm0 \n\t"\
1132 "movq 8(%0), %%mm1 \n\t"\
1133 "movq 16(%0), %%mm2 \n\t"\
1134 "movq 24(%0), %%mm3 \n\t"\
c296f66b
MN
1135 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
1136 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
826f429a 1137 "addl %4, %1 \n\t"\
c296f66b 1138 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
826f429a 1139 \
c296f66b 1140 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
826f429a 1141 "addl %4, %1 \n\t"\
c296f66b 1142 QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
826f429a 1143 \
c296f66b 1144 QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
826f429a 1145 "addl %4, %1 \n\t"\
c296f66b
MN
1146 QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
1147 QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
826f429a
MN
1148 \
1149 "addl $72, %0 \n\t"\
c296f66b 1150 "addl %6, %1 \n\t"\
826f429a
MN
1151 "decl %2 \n\t"\
1152 " jnz 1b \n\t"\
1153 \
c296f66b
MN
1154 : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
1155 : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*dstStride)\
0b093b6f
MN
1156 : "memory"\
1157 );\
3178ee4c 1158}\
826f429a 1159\
0c1a9eda 1160static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 1161 OPNAME ## pixels8_mmx(dst, src, stride, 8);\
826f429a
MN
1162}\
1163\
0c1a9eda 1164static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1165 uint64_t temp[8];\
826f429a
MN
1166 uint8_t * const half= (uint8_t*)temp;\
1167 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1168 OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
1169}\
1170\
0c1a9eda 1171static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1172 OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
1173}\
1174\
0c1a9eda 1175static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1176 uint64_t temp[8];\
826f429a
MN
1177 uint8_t * const half= (uint8_t*)temp;\
1178 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1179 OPNAME ## pixels8_l2_mmx(dst, src+1, half, stride, stride, 8);\
1180}\
1181\
0c1a9eda 1182static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1183 uint64_t temp[8];\
826f429a 1184 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 1185 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
826f429a
MN
1186 OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
1187}\
1188\
0c1a9eda 1189static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 1190 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
1191}\
1192\
0c1a9eda 1193static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1194 uint64_t temp[8];\
826f429a 1195 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 1196 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
826f429a
MN
1197 OPNAME ## pixels8_l2_mmx(dst, src+stride, half, stride, stride, 8);\
1198}\
0c1a9eda 1199static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1200 uint64_t half[8 + 9];\
1201 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1202 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1203 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 1204 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
3178ee4c 1205 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 1206 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
826f429a 1207}\
0c1a9eda 1208static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1209 uint64_t half[8 + 9];\
1210 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1211 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1212 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 1213 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 1214 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 1215 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
826f429a 1216}\
0c1a9eda 1217static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1218 uint64_t half[8 + 9];\
1219 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1220 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1221 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953 1222 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
3178ee4c 1223 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 1224 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 1225}\
0c1a9eda 1226static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1227 uint64_t half[8 + 9];\
1228 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1229 uint8_t * const halfHV= ((uint8_t*)half);\
1230 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1231 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
3178ee4c 1232 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
db794953 1233 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
826f429a 1234}\
0c1a9eda 1235static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1236 uint64_t half[8 + 9];\
826f429a
MN
1237 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1238 uint8_t * const halfHV= ((uint8_t*)half);\
1239 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 1240 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
826f429a
MN
1241 OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
1242}\
0c1a9eda 1243static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1244 uint64_t half[8 + 9];\
826f429a
MN
1245 uint8_t * const halfH= ((uint8_t*)half) + 64;\
1246 uint8_t * const halfHV= ((uint8_t*)half);\
1247 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 1248 put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
826f429a
MN
1249 OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
1250}\
0c1a9eda 1251static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1252 uint64_t half[8 + 9];\
1253 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 1254 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953
MN
1255 put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
1256 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 1257}\
0c1a9eda 1258static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1259 uint64_t half[8 + 9];\
1260 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 1261 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
db794953
MN
1262 put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
1263 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 1264}\
0c1a9eda 1265static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953 1266 uint64_t half[9];\
826f429a
MN
1267 uint8_t * const halfH= ((uint8_t*)half);\
1268 put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
3178ee4c 1269 OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
826f429a 1270}\
0c1a9eda 1271static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 1272 OPNAME ## pixels16_mmx(dst, src, stride, 16);\
826f429a
MN
1273}\
1274\
0c1a9eda 1275static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1276 uint64_t temp[32];\
1277 uint8_t * const half= (uint8_t*)temp;\
1278 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1279 OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
1280}\
1281\
0c1a9eda 1282static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1283 OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
1284}\
1285\
0c1a9eda 1286static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1287 uint64_t temp[32];\
1288 uint8_t * const half= (uint8_t*)temp;\
1289 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1290 OPNAME ## pixels16_l2_mmx(dst, src+1, half, stride, stride, 16);\
1291}\
1292\
0c1a9eda 1293static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1294 uint64_t temp[32];\
1295 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 1296 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
826f429a
MN
1297 OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
1298}\
1299\
0c1a9eda 1300static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
3178ee4c 1301 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
826f429a
MN
1302}\
1303\
0c1a9eda 1304static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1305 uint64_t temp[32];\
1306 uint8_t * const half= (uint8_t*)temp;\
3178ee4c 1307 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
826f429a
MN
1308 OPNAME ## pixels16_l2_mmx(dst, src+stride, half, stride, stride, 16);\
1309}\
0c1a9eda 1310static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1311 uint64_t half[16*2 + 17*2];\
1312 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1313 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1314 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 1315 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
3178ee4c 1316 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 1317 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
826f429a 1318}\
0c1a9eda 1319static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1320 uint64_t half[16*2 + 17*2];\
1321 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1322 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1323 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 1324 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 1325 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 1326 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
826f429a 1327}\
0c1a9eda 1328static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1329 uint64_t half[16*2 + 17*2];\
1330 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1331 uint8_t * const halfHV= ((uint8_t*)half);\
826f429a 1332 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953 1333 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
3178ee4c 1334 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 1335 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 1336}\
0c1a9eda 1337static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1338 uint64_t half[16*2 + 17*2];\
1339 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1340 uint8_t * const halfHV= ((uint8_t*)half);\
1341 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1342 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
3178ee4c 1343 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
db794953 1344 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
826f429a 1345}\
0c1a9eda 1346static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1347 uint64_t half[16*2 + 17*2];\
1348 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1349 uint8_t * const halfHV= ((uint8_t*)half);\
1350 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 1351 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
826f429a
MN
1352 OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
1353}\
0c1a9eda 1354static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1355 uint64_t half[16*2 + 17*2];\
1356 uint8_t * const halfH= ((uint8_t*)half) + 256;\
1357 uint8_t * const halfHV= ((uint8_t*)half);\
1358 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 1359 put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
826f429a
MN
1360 OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
1361}\
0c1a9eda 1362static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1363 uint64_t half[17*2];\
1364 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 1365 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953
MN
1366 put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
1367 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 1368}\
0c1a9eda 1369static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
db794953
MN
1370 uint64_t half[17*2];\
1371 uint8_t * const halfH= ((uint8_t*)half);\
826f429a 1372 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
db794953
MN
1373 put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
1374 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a 1375}\
0c1a9eda 1376static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
826f429a
MN
1377 uint64_t half[17*2];\
1378 uint8_t * const halfH= ((uint8_t*)half);\
1379 put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
3178ee4c 1380 OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
826f429a
MN
1381}
1382
1383
1384#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
3178ee4c 1385#define AVG_3DNOW_OP(a,b,temp, size) \
826f429a
MN
1386"mov" #size " " #b ", " #temp " \n\t"\
1387"pavgusb " #temp ", " #a " \n\t"\
1388"mov" #size " " #a ", " #b " \n\t"
3178ee4c 1389#define AVG_MMX2_OP(a,b,temp, size) \
826f429a
MN
1390"mov" #size " " #b ", " #temp " \n\t"\
1391"pavgb " #temp ", " #a " \n\t"\
1392"mov" #size " " #a ", " #b " \n\t"
3178ee4c
MN
1393
1394QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
1395QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
1396QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
1397QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
1398QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
1399QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
826f429a 1400QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
3178ee4c 1401QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
826f429a
MN
1402QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
1403
61a4e8ae 1404#if 0
d6a4c0b1 1405static void just_return() { return; }
61a4e8ae 1406#endif
d6a4c0b1 1407
826f429a
MN
1408#define SET_QPEL_FUNC(postfix1, postfix2) \
1409 c->put_ ## postfix1 = put_ ## postfix2;\
1410 c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
1411 c->avg_ ## postfix1 = avg_ ## postfix2;
b0368839
MN
1412
1413/* external functions, from idct_mmx.c */
1414void ff_mmx_idct(DCTELEM *block);
1415void ff_mmxext_idct(DCTELEM *block);
1416
1417/* XXX: those functions should be suppressed ASAP when all IDCTs are
1418 converted */
1419static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1420{
1421 ff_mmx_idct (block);
1422 put_pixels_clamped_mmx(block, dest, line_size);
1423}
1424static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1425{
1426 ff_mmx_idct (block);
1427 add_pixels_clamped_mmx(block, dest, line_size);
1428}
1429static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1430{
1431 ff_mmxext_idct (block);
1432 put_pixels_clamped_mmx(block, dest, line_size);
1433}
1434static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1435{
1436 ff_mmxext_idct (block);
1437 add_pixels_clamped_mmx(block, dest, line_size);
1438}
826f429a 1439
b0368839 1440void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
de6d9b64
FB
1441{
1442 mm_flags = mm_support();
63f60826 1443
e5247b5f
ZK
1444 if (avctx->dsp_mask) {
1445 if (avctx->dsp_mask & FF_MM_FORCE)
1446 mm_flags |= (avctx->dsp_mask & 0xffff);
1447 else
1448 mm_flags &= ~(avctx->dsp_mask & 0xffff);
1449 }
63f60826 1450
1565dabc
LB
1451#if 0
1452 fprintf(stderr, "libavcodec: CPU flags:");
de6d9b64 1453 if (mm_flags & MM_MMX)
1565dabc 1454 fprintf(stderr, " mmx");
de6d9b64 1455 if (mm_flags & MM_MMXEXT)
1565dabc 1456 fprintf(stderr, " mmxext");
de6d9b64 1457 if (mm_flags & MM_3DNOW)
1565dabc 1458 fprintf(stderr, " 3dnow");
de6d9b64 1459 if (mm_flags & MM_SSE)
1565dabc 1460 fprintf(stderr, " sse");
de6d9b64 1461 if (mm_flags & MM_SSE2)
1565dabc
LB
1462 fprintf(stderr, " sse2");
1463 fprintf(stderr, "\n");
de6d9b64
FB
1464#endif
1465
1466 if (mm_flags & MM_MMX) {
b0368839
MN
1467 const int dct_algo = avctx->dct_algo;
1468 const int idct_algo= avctx->idct_algo;
1469
1470 if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX)
1471 c->fdct = ff_fdct_mmx;
1472
1473 if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
1474 c->idct_put= ff_simple_idct_put_mmx;
1475 c->idct_add= ff_simple_idct_add_mmx;
1476 c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
1477 }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
1478 if(mm_flags & MM_MMXEXT){
1479 c->idct_put= ff_libmpeg2mmx2_idct_put;
1480 c->idct_add= ff_libmpeg2mmx2_idct_add;
1481 }else{
1482 c->idct_put= ff_libmpeg2mmx_idct_put;
1483 c->idct_add= ff_libmpeg2mmx_idct_add;
1484 }
1485 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
1486 }
1487
eb4b3dd3
ZK
1488 c->get_pixels = get_pixels_mmx;
1489 c->diff_pixels = diff_pixels_mmx;
1490 c->put_pixels_clamped = put_pixels_clamped_mmx;
1491 c->add_pixels_clamped = add_pixels_clamped_mmx;
1492 c->clear_blocks = clear_blocks_mmx;
1493 c->pix_sum = pix_sum16_mmx;
1494
eb4b3dd3
ZK
1495 c->put_pixels_tab[0][0] = put_pixels16_mmx;
1496 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
1497 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
1498 c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
1499
1500 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
1501 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
1502 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
1503 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
1504
1505 c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
1506 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
1507 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
1508 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
1509
1510 c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
1511 c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
1512 c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
1513 c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
1514
1515 c->put_pixels_tab[1][0] = put_pixels8_mmx;
1516 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
1517 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
1518 c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
1519
1520 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
1521 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
1522 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
1523 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
1524
1525 c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
1526 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
1527 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
1528 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
1529
1530 c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
1531 c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
1532 c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
1533 c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
826f429a 1534
11f18faf
MN
1535 c->add_bytes= add_bytes_mmx;
1536 c->diff_bytes= diff_bytes_mmx;
1457ab52
MN
1537
1538 c->hadamard8_diff[0]= hadamard8_diff16_mmx;
1539 c->hadamard8_diff[1]= hadamard8_diff_mmx;
1540
2a006cd3
FL
1541 c->pix_norm1 = pix_norm1_mmx;
1542 c->sse[0] = sse16_mmx;
1457ab52 1543
de6d9b64 1544 if (mm_flags & MM_MMXEXT) {
eb4b3dd3
ZK
1545 c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
1546 c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
eb4b3dd3
ZK
1547
1548 c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
1549 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
1550 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
eb4b3dd3
ZK
1551
1552 c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
1553 c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
eb4b3dd3
ZK
1554
1555 c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
1556 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
1557 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
b0368839
MN
1558
1559 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
1560 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
1561 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
1562 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
1563 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
1564 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
1565 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
1566 }
3178ee4c 1567
c296f66b 1568#if 1
826f429a
MN
1569 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
1570 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
1571 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
1572 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
1573 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
1574 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
1575 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
1576 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
1577 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
1578 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
1579 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
1580 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
1581 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
1582 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
1583 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
1584 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
1585 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
1586 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
1587 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
1588 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
1589 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
1590 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
1591 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
1592 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
1593 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
1594 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
1595 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
1596 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
1597 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
1598 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
1599 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
1600 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
c296f66b 1601#endif
de6d9b64 1602 } else if (mm_flags & MM_3DNOW) {
eb4b3dd3
ZK
1603 c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
1604 c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
eb4b3dd3
ZK
1605
1606 c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
1607 c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
1608 c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
eb4b3dd3
ZK
1609
1610 c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
1611 c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
eb4b3dd3
ZK
1612
1613 c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
1614 c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
1615 c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
b0368839
MN
1616
1617 if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
1618 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
1619 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
1620 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
1621 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
1622 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
1623 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
1624 }
db794953 1625
826f429a
MN
1626 SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
1627 SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
1628 SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
1629 SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
1630 SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
1631 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
1632 SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
1633 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
1634 SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
1635 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
1636 SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
1637 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
1638 SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
1639 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
1640 SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
1641 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
1642 SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
1643 SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
1644 SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
1645 SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
1646 SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
1647 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
1648 SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
1649 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
1650 SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
1651 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
1652 SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
1653 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
1654 SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
1655 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
1656 SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
1657 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
de6d9b64
FB
1658 }
1659 }
b0368839
MN
1660
1661 dsputil_init_pix_mmx(c, avctx);
d6a4c0b1
ZK
1662#if 0
1663 // for speed testing
1664 get_pixels = just_return;
1665 put_pixels_clamped = just_return;
1666 add_pixels_clamped = just_return;
1667
1668 pix_abs16x16 = just_return;
1669 pix_abs16x16_x2 = just_return;
1670 pix_abs16x16_y2 = just_return;
1671 pix_abs16x16_xy2 = just_return;
1672
1673 put_pixels_tab[0] = just_return;
1674 put_pixels_tab[1] = just_return;
1675 put_pixels_tab[2] = just_return;
1676 put_pixels_tab[3] = just_return;
1677
1678 put_no_rnd_pixels_tab[0] = just_return;
1679 put_no_rnd_pixels_tab[1] = just_return;
1680 put_no_rnd_pixels_tab[2] = just_return;
1681 put_no_rnd_pixels_tab[3] = just_return;
1682
1683 avg_pixels_tab[0] = just_return;
1684 avg_pixels_tab[1] = just_return;
1685 avg_pixels_tab[2] = just_return;
1686 avg_pixels_tab[3] = just_return;
1687
1688 avg_no_rnd_pixels_tab[0] = just_return;
1689 avg_no_rnd_pixels_tab[1] = just_return;
1690 avg_no_rnd_pixels_tab[2] = just_return;
1691 avg_no_rnd_pixels_tab[3] = just_return;
1692
d6a4c0b1
ZK
1693 //av_fdct = just_return;
1694 //ff_idct = just_return;
1695#endif
de6d9b64 1696}