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