Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / dsputil_mmx.c @ a6624e21

History | View | Annotate | Download (106 KB)

1
/*
2
 * MMX optimized DSP utils
3
 * Copyright (c) 2000, 2001 Fabrice Bellard.
4
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 *
20
 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
21
 */
22

    
23
#include "../dsputil.h"
24
#include "../simple_idct.h"
25
#include "../mpegvideo.h"
26
#include "mmx.h"
27

    
28
//#undef NDEBUG
29
//#include <assert.h>
30

    
31
extern const uint8_t ff_h263_loop_filter_strength[32];
32
extern void ff_idct_xvid_mmx(short *block);
33
extern void ff_idct_xvid_mmx2(short *block);
34

    
35
int mm_flags; /* multimedia extension flags */
36

    
37
/* pixel operations */
38
static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
39
static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
40
static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
41

    
42
static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
43
static const uint64_t ff_pw_3  attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
44
static const uint64_t ff_pw_4  attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL;
45
static const uint64_t ff_pw_5  attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL;
46
static const uint64_t ff_pw_8  attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL;
47
static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
48
static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL;
49
static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL;
50
static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
51

    
52
static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL;
53
static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
54

    
55
#define JUMPALIGN() __asm __volatile (".balign 8"::)
56
#define MOVQ_ZERO(regd)  __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
57

    
58
#define MOVQ_WONE(regd) \
59
    __asm __volatile ( \
60
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
61
    "psrlw $15, %%" #regd ::)
62

    
63
#define MOVQ_BFE(regd) \
64
    __asm __volatile ( \
65
    "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
66
    "paddb %%" #regd ", %%" #regd " \n\t" ::)
67

    
68
#ifndef PIC
69
#define MOVQ_BONE(regd)  __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
70
#define MOVQ_WTWO(regd)  __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
71
#else
72
// for shared library it's better to use this way for accessing constants
73
// pcmpeqd -> -1
74
#define MOVQ_BONE(regd) \
75
    __asm __volatile ( \
76
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
77
    "psrlw $15, %%" #regd " \n\t" \
78
    "packuswb %%" #regd ", %%" #regd " \n\t" ::)
79

    
80
#define MOVQ_WTWO(regd) \
81
    __asm __volatile ( \
82
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
83
    "psrlw $15, %%" #regd " \n\t" \
84
    "psllw $1, %%" #regd " \n\t"::)
85

    
86
#endif
87

    
88
// using regr as temporary and for the output result
89
// first argument is unmodifed and second is trashed
90
// regfe is supposed to contain 0xfefefefefefefefe
91
#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
92
    "movq " #rega ", " #regr "        \n\t"\
93
    "pand " #regb ", " #regr "        \n\t"\
94
    "pxor " #rega ", " #regb "        \n\t"\
95
    "pand " #regfe "," #regb "        \n\t"\
96
    "psrlq $1, " #regb "         \n\t"\
97
    "paddb " #regb ", " #regr "        \n\t"
98

    
99
#define PAVGB_MMX(rega, regb, regr, regfe) \
100
    "movq " #rega ", " #regr "        \n\t"\
101
    "por  " #regb ", " #regr "        \n\t"\
102
    "pxor " #rega ", " #regb "        \n\t"\
103
    "pand " #regfe "," #regb "        \n\t"\
104
    "psrlq $1, " #regb "        \n\t"\
105
    "psubb " #regb ", " #regr "        \n\t"
106

    
107
// mm6 is supposed to contain 0xfefefefefefefefe
108
#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp) \
109
    "movq " #rega ", " #regr "        \n\t"\
110
    "movq " #regc ", " #regp "        \n\t"\
111
    "pand " #regb ", " #regr "        \n\t"\
112
    "pand " #regd ", " #regp "        \n\t"\
113
    "pxor " #rega ", " #regb "        \n\t"\
114
    "pxor " #regc ", " #regd "        \n\t"\
115
    "pand %%mm6, " #regb "        \n\t"\
116
    "pand %%mm6, " #regd "        \n\t"\
117
    "psrlq $1, " #regb "         \n\t"\
118
    "psrlq $1, " #regd "         \n\t"\
119
    "paddb " #regb ", " #regr "        \n\t"\
120
    "paddb " #regd ", " #regp "        \n\t"
121

    
122
#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
123
    "movq " #rega ", " #regr "        \n\t"\
124
    "movq " #regc ", " #regp "        \n\t"\
125
    "por  " #regb ", " #regr "        \n\t"\
126
    "por  " #regd ", " #regp "        \n\t"\
127
    "pxor " #rega ", " #regb "        \n\t"\
128
    "pxor " #regc ", " #regd "        \n\t"\
129
    "pand %%mm6, " #regb "             \n\t"\
130
    "pand %%mm6, " #regd "             \n\t"\
131
    "psrlq $1, " #regd "        \n\t"\
132
    "psrlq $1, " #regb "        \n\t"\
133
    "psubb " #regb ", " #regr "        \n\t"\
134
    "psubb " #regd ", " #regp "        \n\t"
135

    
136
/***********************************/
137
/* MMX no rounding */
138
#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
139
#define SET_RND  MOVQ_WONE
140
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
141
#define PAVGB(a, b, c, e)                PAVGB_MMX_NO_RND(a, b, c, e)
142

    
143
#include "dsputil_mmx_rnd.h"
144

    
145
#undef DEF
146
#undef SET_RND
147
#undef PAVGBP
148
#undef PAVGB
149
/***********************************/
150
/* MMX rounding */
151

    
152
#define DEF(x, y) x ## _ ## y ##_mmx
153
#define SET_RND  MOVQ_WTWO
154
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
155
#define PAVGB(a, b, c, e)                PAVGB_MMX(a, b, c, e)
156

    
157
#include "dsputil_mmx_rnd.h"
158

    
159
#undef DEF
160
#undef SET_RND
161
#undef PAVGBP
162
#undef PAVGB
163

    
164
/***********************************/
165
/* 3Dnow specific */
166

    
167
#define DEF(x) x ## _3dnow
168
/* for Athlons PAVGUSB is prefered */
169
#define PAVGB "pavgusb"
170

    
171
#include "dsputil_mmx_avg.h"
172

    
173
#undef DEF
174
#undef PAVGB
175

    
176
/***********************************/
177
/* MMX2 specific */
178

    
179
#define DEF(x) x ## _mmx2
180

    
181
/* Introduced only in MMX2 set */
182
#define PAVGB "pavgb"
183

    
184
#include "dsputil_mmx_avg.h"
185

    
186
#undef DEF
187
#undef PAVGB
188

    
189
/***********************************/
190
/* standard MMX */
191

    
192
#ifdef CONFIG_ENCODERS
193
static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
194
{
195
    asm volatile(
196
        "mov $-128, %%"REG_a"        \n\t"
197
        "pxor %%mm7, %%mm7        \n\t"
198
        ".balign 16                \n\t"
199
        "1:                        \n\t"
200
        "movq (%0), %%mm0        \n\t"
201
        "movq (%0, %2), %%mm2        \n\t"
202
        "movq %%mm0, %%mm1        \n\t"
203
        "movq %%mm2, %%mm3        \n\t"
204
        "punpcklbw %%mm7, %%mm0        \n\t"
205
        "punpckhbw %%mm7, %%mm1        \n\t"
206
        "punpcklbw %%mm7, %%mm2        \n\t"
207
        "punpckhbw %%mm7, %%mm3        \n\t"
208
        "movq %%mm0, (%1, %%"REG_a")\n\t"
209
        "movq %%mm1, 8(%1, %%"REG_a")\n\t"
210
        "movq %%mm2, 16(%1, %%"REG_a")\n\t"
211
        "movq %%mm3, 24(%1, %%"REG_a")\n\t"
212
        "add %3, %0                \n\t"
213
        "add $32, %%"REG_a"        \n\t"
214
        "js 1b                        \n\t"
215
        : "+r" (pixels)
216
        : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2)
217
        : "%"REG_a
218
    );
219
}
220

    
221
static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
222
{
223
    asm volatile(
224
        "pxor %%mm7, %%mm7        \n\t"
225
        "mov $-128, %%"REG_a"        \n\t"
226
        ".balign 16                \n\t"
227
        "1:                        \n\t"
228
        "movq (%0), %%mm0        \n\t"
229
        "movq (%1), %%mm2        \n\t"
230
        "movq %%mm0, %%mm1        \n\t"
231
        "movq %%mm2, %%mm3        \n\t"
232
        "punpcklbw %%mm7, %%mm0        \n\t"
233
        "punpckhbw %%mm7, %%mm1        \n\t"
234
        "punpcklbw %%mm7, %%mm2        \n\t"
235
        "punpckhbw %%mm7, %%mm3        \n\t"
236
        "psubw %%mm2, %%mm0        \n\t"
237
        "psubw %%mm3, %%mm1        \n\t"
238
        "movq %%mm0, (%2, %%"REG_a")\n\t"
239
        "movq %%mm1, 8(%2, %%"REG_a")\n\t"
240
        "add %3, %0                \n\t"
241
        "add %3, %1                \n\t"
242
        "add $16, %%"REG_a"        \n\t"
243
        "jnz 1b                        \n\t"
244
        : "+r" (s1), "+r" (s2)
245
        : "r" (block+64), "r" ((long)stride)
246
        : "%"REG_a
247
    );
248
}
249
#endif //CONFIG_ENCODERS
250

    
251
void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
252
{
253
    const DCTELEM *p;
254
    uint8_t *pix;
255

    
256
    /* read the pixels */
257
    p = block;
258
    pix = pixels;
259
    /* unrolled loop */
260
        __asm __volatile(
261
                "movq        %3, %%mm0\n\t"
262
                "movq        8%3, %%mm1\n\t"
263
                "movq        16%3, %%mm2\n\t"
264
                "movq        24%3, %%mm3\n\t"
265
                "movq        32%3, %%mm4\n\t"
266
                "movq        40%3, %%mm5\n\t"
267
                "movq        48%3, %%mm6\n\t"
268
                "movq        56%3, %%mm7\n\t"
269
                "packuswb %%mm1, %%mm0\n\t"
270
                "packuswb %%mm3, %%mm2\n\t"
271
                "packuswb %%mm5, %%mm4\n\t"
272
                "packuswb %%mm7, %%mm6\n\t"
273
                "movq        %%mm0, (%0)\n\t"
274
                "movq        %%mm2, (%0, %1)\n\t"
275
                "movq        %%mm4, (%0, %1, 2)\n\t"
276
                "movq        %%mm6, (%0, %2)\n\t"
277
                ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "m"(*p)
278
                :"memory");
279
        pix += line_size*4;
280
        p += 32;
281

    
282
    // if here would be an exact copy of the code above
283
    // compiler would generate some very strange code
284
    // thus using "r"
285
    __asm __volatile(
286
            "movq        (%3), %%mm0\n\t"
287
            "movq        8(%3), %%mm1\n\t"
288
            "movq        16(%3), %%mm2\n\t"
289
            "movq        24(%3), %%mm3\n\t"
290
            "movq        32(%3), %%mm4\n\t"
291
            "movq        40(%3), %%mm5\n\t"
292
            "movq        48(%3), %%mm6\n\t"
293
            "movq        56(%3), %%mm7\n\t"
294
            "packuswb %%mm1, %%mm0\n\t"
295
            "packuswb %%mm3, %%mm2\n\t"
296
            "packuswb %%mm5, %%mm4\n\t"
297
            "packuswb %%mm7, %%mm6\n\t"
298
            "movq        %%mm0, (%0)\n\t"
299
            "movq        %%mm2, (%0, %1)\n\t"
300
            "movq        %%mm4, (%0, %1, 2)\n\t"
301
            "movq        %%mm6, (%0, %2)\n\t"
302
            ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "r"(p)
303
            :"memory");
304
}
305

    
306
static const unsigned char __align8 vector128[8] =
307
  { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
308

    
309
void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
310
{
311
    int i;
312

    
313
    movq_m2r(*vector128, mm1);
314
    for (i = 0; i < 8; i++) {
315
        movq_m2r(*(block), mm0);
316
        packsswb_m2r(*(block + 4), mm0);
317
        block += 8;
318
        paddb_r2r(mm1, mm0);
319
        movq_r2m(mm0, *pixels);
320
        pixels += line_size;
321
    }
322
}
323

    
324
void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
325
{
326
    const DCTELEM *p;
327
    uint8_t *pix;
328
    int i;
329

    
330
    /* read the pixels */
331
    p = block;
332
    pix = pixels;
333
    MOVQ_ZERO(mm7);
334
    i = 4;
335
    do {
336
        __asm __volatile(
337
                "movq        (%2), %%mm0\n\t"
338
                "movq        8(%2), %%mm1\n\t"
339
                "movq        16(%2), %%mm2\n\t"
340
                "movq        24(%2), %%mm3\n\t"
341
                "movq        %0, %%mm4\n\t"
342
                "movq        %1, %%mm6\n\t"
343
                "movq        %%mm4, %%mm5\n\t"
344
                "punpcklbw %%mm7, %%mm4\n\t"
345
                "punpckhbw %%mm7, %%mm5\n\t"
346
                "paddsw        %%mm4, %%mm0\n\t"
347
                "paddsw        %%mm5, %%mm1\n\t"
348
                "movq        %%mm6, %%mm5\n\t"
349
                "punpcklbw %%mm7, %%mm6\n\t"
350
                "punpckhbw %%mm7, %%mm5\n\t"
351
                "paddsw        %%mm6, %%mm2\n\t"
352
                "paddsw        %%mm5, %%mm3\n\t"
353
                "packuswb %%mm1, %%mm0\n\t"
354
                "packuswb %%mm3, %%mm2\n\t"
355
                "movq        %%mm0, %0\n\t"
356
                "movq        %%mm2, %1\n\t"
357
                :"+m"(*pix), "+m"(*(pix+line_size))
358
                :"r"(p)
359
                :"memory");
360
        pix += line_size*2;
361
        p += 16;
362
    } while (--i);
363
}
364

    
365
static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
366
{
367
    __asm __volatile(
368
         "lea (%3, %3), %%"REG_a"        \n\t"
369
         ".balign 8                        \n\t"
370
         "1:                                \n\t"
371
         "movd (%1), %%mm0                \n\t"
372
         "movd (%1, %3), %%mm1                \n\t"
373
         "movd %%mm0, (%2)                \n\t"
374
         "movd %%mm1, (%2, %3)                \n\t"
375
         "add %%"REG_a", %1                \n\t"
376
         "add %%"REG_a", %2                \n\t"
377
         "movd (%1), %%mm0                \n\t"
378
         "movd (%1, %3), %%mm1                \n\t"
379
         "movd %%mm0, (%2)                \n\t"
380
         "movd %%mm1, (%2, %3)                \n\t"
381
         "add %%"REG_a", %1                \n\t"
382
         "add %%"REG_a", %2                \n\t"
383
         "subl $4, %0                        \n\t"
384
         "jnz 1b                        \n\t"
385
         : "+g"(h), "+r" (pixels),  "+r" (block)
386
         : "r"((long)line_size)
387
         : "%"REG_a, "memory"
388
        );
389
}
390

    
391
static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
392
{
393
    __asm __volatile(
394
         "lea (%3, %3), %%"REG_a"        \n\t"
395
         ".balign 8                        \n\t"
396
         "1:                                \n\t"
397
         "movq (%1), %%mm0                \n\t"
398
         "movq (%1, %3), %%mm1                \n\t"
399
              "movq %%mm0, (%2)                \n\t"
400
         "movq %%mm1, (%2, %3)                \n\t"
401
         "add %%"REG_a", %1                \n\t"
402
         "add %%"REG_a", %2                \n\t"
403
         "movq (%1), %%mm0                \n\t"
404
         "movq (%1, %3), %%mm1                \n\t"
405
         "movq %%mm0, (%2)                \n\t"
406
         "movq %%mm1, (%2, %3)                \n\t"
407
         "add %%"REG_a", %1                \n\t"
408
         "add %%"REG_a", %2                \n\t"
409
         "subl $4, %0                        \n\t"
410
         "jnz 1b                        \n\t"
411
         : "+g"(h), "+r" (pixels),  "+r" (block)
412
         : "r"((long)line_size)
413
         : "%"REG_a, "memory"
414
        );
415
}
416

    
417
static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
418
{
419
    __asm __volatile(
420
         "lea (%3, %3), %%"REG_a"        \n\t"
421
         ".balign 8                        \n\t"
422
         "1:                                \n\t"
423
         "movq (%1), %%mm0                \n\t"
424
         "movq 8(%1), %%mm4                \n\t"
425
         "movq (%1, %3), %%mm1                \n\t"
426
         "movq 8(%1, %3), %%mm5                \n\t"
427
              "movq %%mm0, (%2)                \n\t"
428
              "movq %%mm4, 8(%2)                \n\t"
429
         "movq %%mm1, (%2, %3)                \n\t"
430
         "movq %%mm5, 8(%2, %3)                \n\t"
431
         "add %%"REG_a", %1                \n\t"
432
         "add %%"REG_a", %2               \n\t"
433
         "movq (%1), %%mm0                \n\t"
434
         "movq 8(%1), %%mm4                \n\t"
435
         "movq (%1, %3), %%mm1                \n\t"
436
         "movq 8(%1, %3), %%mm5                \n\t"
437
         "movq %%mm0, (%2)                \n\t"
438
         "movq %%mm4, 8(%2)                \n\t"
439
         "movq %%mm1, (%2, %3)                \n\t"
440
         "movq %%mm5, 8(%2, %3)                \n\t"
441
         "add %%"REG_a", %1                \n\t"
442
         "add %%"REG_a", %2               \n\t"
443
         "subl $4, %0                        \n\t"
444
         "jnz 1b                        \n\t"
445
         : "+g"(h), "+r" (pixels),  "+r" (block)
446
         : "r"((long)line_size)
447
         : "%"REG_a, "memory"
448
        );
449
}
450

    
451
static void clear_blocks_mmx(DCTELEM *blocks)
452
{
453
    __asm __volatile(
454
                "pxor %%mm7, %%mm7                \n\t"
455
                "mov $-128*6, %%"REG_a"        \n\t"
456
                "1:                                \n\t"
457
                "movq %%mm7, (%0, %%"REG_a")        \n\t"
458
                "movq %%mm7, 8(%0, %%"REG_a")        \n\t"
459
                "movq %%mm7, 16(%0, %%"REG_a")        \n\t"
460
                "movq %%mm7, 24(%0, %%"REG_a")        \n\t"
461
                "add $32, %%"REG_a"                \n\t"
462
                " js 1b                                \n\t"
463
                : : "r" (((uint8_t *)blocks)+128*6)
464
                : "%"REG_a
465
        );
466
}
467

    
468
#ifdef CONFIG_ENCODERS
469
static int pix_sum16_mmx(uint8_t * pix, int line_size){
470
    const int h=16;
471
    int sum;
472
    long index= -line_size*h;
473

    
474
    __asm __volatile(
475
                "pxor %%mm7, %%mm7                \n\t"
476
                "pxor %%mm6, %%mm6                \n\t"
477
                "1:                                \n\t"
478
                "movq (%2, %1), %%mm0                \n\t"
479
                "movq (%2, %1), %%mm1                \n\t"
480
                "movq 8(%2, %1), %%mm2                \n\t"
481
                "movq 8(%2, %1), %%mm3                \n\t"
482
                "punpcklbw %%mm7, %%mm0                \n\t"
483
                "punpckhbw %%mm7, %%mm1                \n\t"
484
                "punpcklbw %%mm7, %%mm2                \n\t"
485
                "punpckhbw %%mm7, %%mm3                \n\t"
486
                "paddw %%mm0, %%mm1                \n\t"
487
                "paddw %%mm2, %%mm3                \n\t"
488
                "paddw %%mm1, %%mm3                \n\t"
489
                "paddw %%mm3, %%mm6                \n\t"
490
                "add %3, %1                        \n\t"
491
                " js 1b                                \n\t"
492
                "movq %%mm6, %%mm5                \n\t"
493
                "psrlq $32, %%mm6                \n\t"
494
                "paddw %%mm5, %%mm6                \n\t"
495
                "movq %%mm6, %%mm5                \n\t"
496
                "psrlq $16, %%mm6                \n\t"
497
                "paddw %%mm5, %%mm6                \n\t"
498
                "movd %%mm6, %0                        \n\t"
499
                "andl $0xFFFF, %0                \n\t"
500
                : "=&r" (sum), "+r" (index)
501
                : "r" (pix - index), "r" ((long)line_size)
502
        );
503

    
504
        return sum;
505
}
506
#endif //CONFIG_ENCODERS
507

    
508
static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
509
    long i=0;
510
    asm volatile(
511
        "1:                                \n\t"
512
        "movq  (%1, %0), %%mm0                \n\t"
513
        "movq  (%2, %0), %%mm1                \n\t"
514
        "paddb %%mm0, %%mm1                \n\t"
515
        "movq %%mm1, (%2, %0)                \n\t"
516
        "movq 8(%1, %0), %%mm0                \n\t"
517
        "movq 8(%2, %0), %%mm1                \n\t"
518
        "paddb %%mm0, %%mm1                \n\t"
519
        "movq %%mm1, 8(%2, %0)                \n\t"
520
        "add $16, %0                        \n\t"
521
        "cmp %3, %0                        \n\t"
522
        " jb 1b                                \n\t"
523
        : "+r" (i)
524
        : "r"(src), "r"(dst), "r"((long)w-15)
525
    );
526
    for(; i<w; i++)
527
        dst[i+0] += src[i+0];
528
}
529

    
530
#define H263_LOOP_FILTER \
531
        "pxor %%mm7, %%mm7                \n\t"\
532
        "movq  %0, %%mm0                \n\t"\
533
        "movq  %0, %%mm1                \n\t"\
534
        "movq  %3, %%mm2                \n\t"\
535
        "movq  %3, %%mm3                \n\t"\
536
        "punpcklbw %%mm7, %%mm0                \n\t"\
537
        "punpckhbw %%mm7, %%mm1                \n\t"\
538
        "punpcklbw %%mm7, %%mm2                \n\t"\
539
        "punpckhbw %%mm7, %%mm3                \n\t"\
540
        "psubw %%mm2, %%mm0                \n\t"\
541
        "psubw %%mm3, %%mm1                \n\t"\
542
        "movq  %1, %%mm2                \n\t"\
543
        "movq  %1, %%mm3                \n\t"\
544
        "movq  %2, %%mm4                \n\t"\
545
        "movq  %2, %%mm5                \n\t"\
546
        "punpcklbw %%mm7, %%mm2                \n\t"\
547
        "punpckhbw %%mm7, %%mm3                \n\t"\
548
        "punpcklbw %%mm7, %%mm4                \n\t"\
549
        "punpckhbw %%mm7, %%mm5                \n\t"\
550
        "psubw %%mm2, %%mm4                \n\t"\
551
        "psubw %%mm3, %%mm5                \n\t"\
552
        "psllw $2, %%mm4                \n\t"\
553
        "psllw $2, %%mm5                \n\t"\
554
        "paddw %%mm0, %%mm4                \n\t"\
555
        "paddw %%mm1, %%mm5                \n\t"\
556
        "pxor %%mm6, %%mm6                \n\t"\
557
        "pcmpgtw %%mm4, %%mm6                \n\t"\
558
        "pcmpgtw %%mm5, %%mm7                \n\t"\
559
        "pxor %%mm6, %%mm4                \n\t"\
560
        "pxor %%mm7, %%mm5                \n\t"\
561
        "psubw %%mm6, %%mm4                \n\t"\
562
        "psubw %%mm7, %%mm5                \n\t"\
563
        "psrlw $3, %%mm4                \n\t"\
564
        "psrlw $3, %%mm5                \n\t"\
565
        "packuswb %%mm5, %%mm4                \n\t"\
566
        "packsswb %%mm7, %%mm6                \n\t"\
567
        "pxor %%mm7, %%mm7                \n\t"\
568
        "movd %4, %%mm2                        \n\t"\
569
        "punpcklbw %%mm2, %%mm2                \n\t"\
570
        "punpcklbw %%mm2, %%mm2                \n\t"\
571
        "punpcklbw %%mm2, %%mm2                \n\t"\
572
        "psubusb %%mm4, %%mm2                \n\t"\
573
        "movq %%mm2, %%mm3                \n\t"\
574
        "psubusb %%mm4, %%mm3                \n\t"\
575
        "psubb %%mm3, %%mm2                \n\t"\
576
        "movq %1, %%mm3                        \n\t"\
577
        "movq %2, %%mm4                        \n\t"\
578
        "pxor %%mm6, %%mm3                \n\t"\
579
        "pxor %%mm6, %%mm4                \n\t"\
580
        "paddusb %%mm2, %%mm3                \n\t"\
581
        "psubusb %%mm2, %%mm4                \n\t"\
582
        "pxor %%mm6, %%mm3                \n\t"\
583
        "pxor %%mm6, %%mm4                \n\t"\
584
        "paddusb %%mm2, %%mm2                \n\t"\
585
        "packsswb %%mm1, %%mm0                \n\t"\
586
        "pcmpgtb %%mm0, %%mm7                \n\t"\
587
        "pxor %%mm7, %%mm0                \n\t"\
588
        "psubb %%mm7, %%mm0                \n\t"\
589
        "movq %%mm0, %%mm1                \n\t"\
590
        "psubusb %%mm2, %%mm0                \n\t"\
591
        "psubb %%mm0, %%mm1                \n\t"\
592
        "pand %5, %%mm1                        \n\t"\
593
        "psrlw $2, %%mm1                \n\t"\
594
        "pxor %%mm7, %%mm1                \n\t"\
595
        "psubb %%mm7, %%mm1                \n\t"\
596
        "movq %0, %%mm5                        \n\t"\
597
        "movq %3, %%mm6                        \n\t"\
598
        "psubb %%mm1, %%mm5                \n\t"\
599
        "paddb %%mm1, %%mm6                \n\t"
600

    
601
static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
602
    const int strength= ff_h263_loop_filter_strength[qscale];
603

    
604
    asm volatile(
605
    
606
        H263_LOOP_FILTER
607
        
608
        "movq %%mm3, %1                        \n\t"
609
        "movq %%mm4, %2                        \n\t"
610
        "movq %%mm5, %0                        \n\t"
611
        "movq %%mm6, %3                        \n\t"
612
        : "+m" (*(uint64_t*)(src - 2*stride)),
613
          "+m" (*(uint64_t*)(src - 1*stride)),
614
          "+m" (*(uint64_t*)(src + 0*stride)),
615
          "+m" (*(uint64_t*)(src + 1*stride))
616
        : "g" (2*strength), "m"(ff_pb_FC)
617
    );
618
}
619

    
620
static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
621
    asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
622
        "movd  %4, %%mm0                \n\t"
623
        "movd  %5, %%mm1                \n\t"
624
        "movd  %6, %%mm2                \n\t"
625
        "movd  %7, %%mm3                \n\t"
626
        "punpcklbw %%mm1, %%mm0                \n\t"
627
        "punpcklbw %%mm3, %%mm2                \n\t"
628
        "movq %%mm0, %%mm1                \n\t"
629
        "punpcklwd %%mm2, %%mm0                \n\t"
630
        "punpckhwd %%mm2, %%mm1                \n\t"
631
        "movd  %%mm0, %0                \n\t"
632
        "punpckhdq %%mm0, %%mm0                \n\t"
633
        "movd  %%mm0, %1                \n\t"
634
        "movd  %%mm1, %2                \n\t"
635
        "punpckhdq %%mm1, %%mm1                \n\t"
636
        "movd  %%mm1, %3                \n\t"
637
        
638
        : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
639
          "=m" (*(uint32_t*)(dst + 1*dst_stride)),
640
          "=m" (*(uint32_t*)(dst + 2*dst_stride)),
641
          "=m" (*(uint32_t*)(dst + 3*dst_stride))
642
        :  "m" (*(uint32_t*)(src + 0*src_stride)),
643
           "m" (*(uint32_t*)(src + 1*src_stride)),
644
           "m" (*(uint32_t*)(src + 2*src_stride)),
645
           "m" (*(uint32_t*)(src + 3*src_stride))
646
    );
647
}
648

    
649
static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
650
    const int strength= ff_h263_loop_filter_strength[qscale];
651
    uint64_t temp[4] __attribute__ ((aligned(8)));
652
    uint8_t *btemp= (uint8_t*)temp;
653
    
654
    src -= 2;
655

    
656
    transpose4x4(btemp  , src           , 8, stride);
657
    transpose4x4(btemp+4, src + 4*stride, 8, stride);
658
    asm volatile(
659
        H263_LOOP_FILTER // 5 3 4 6
660
        
661
        : "+m" (temp[0]),
662
          "+m" (temp[1]),
663
          "+m" (temp[2]),
664
          "+m" (temp[3])
665
        : "g" (2*strength), "m"(ff_pb_FC)
666
    );
667

    
668
    asm volatile(
669
        "movq %%mm5, %%mm1                \n\t"
670
        "movq %%mm4, %%mm0                \n\t"
671
        "punpcklbw %%mm3, %%mm5                \n\t"
672
        "punpcklbw %%mm6, %%mm4                \n\t"
673
        "punpckhbw %%mm3, %%mm1                \n\t"
674
        "punpckhbw %%mm6, %%mm0                \n\t"
675
        "movq %%mm5, %%mm3                \n\t"
676
        "movq %%mm1, %%mm6                \n\t"
677
        "punpcklwd %%mm4, %%mm5                \n\t"
678
        "punpcklwd %%mm0, %%mm1                \n\t"
679
        "punpckhwd %%mm4, %%mm3                \n\t"
680
        "punpckhwd %%mm0, %%mm6                \n\t"
681
        "movd %%mm5, (%0)                \n\t"
682
        "punpckhdq %%mm5, %%mm5                \n\t"
683
        "movd %%mm5, (%0,%2)                \n\t"
684
        "movd %%mm3, (%0,%2,2)                \n\t"
685
        "punpckhdq %%mm3, %%mm3                \n\t"
686
        "movd %%mm3, (%0,%3)                \n\t"
687
        "movd %%mm1, (%1)                \n\t"
688
        "punpckhdq %%mm1, %%mm1                \n\t"
689
        "movd %%mm1, (%1,%2)                \n\t"
690
        "movd %%mm6, (%1,%2,2)                \n\t"
691
        "punpckhdq %%mm6, %%mm6                \n\t"
692
        "movd %%mm6, (%1,%3)                \n\t"
693
        :: "r" (src),
694
           "r" (src + 4*stride),
695
           "r" ((long)   stride ),
696
           "r" ((long)(3*stride))
697
    );
698
}
699

    
700
#ifdef CONFIG_ENCODERS
701
static int pix_norm1_mmx(uint8_t *pix, int line_size) {
702
    int tmp;
703
  asm volatile (
704
      "movl $16,%%ecx\n"
705
      "pxor %%mm0,%%mm0\n"
706
      "pxor %%mm7,%%mm7\n"
707
      "1:\n"
708
      "movq (%0),%%mm2\n"        /* mm2 = pix[0-7] */
709
      "movq 8(%0),%%mm3\n"        /* mm3 = pix[8-15] */
710

    
711
      "movq %%mm2,%%mm1\n"        /* mm1 = mm2 = pix[0-7] */
712

    
713
      "punpckhbw %%mm0,%%mm1\n"        /* mm1 = [pix4-7] */
714
      "punpcklbw %%mm0,%%mm2\n"        /* mm2 = [pix0-3] */
715

    
716
      "movq %%mm3,%%mm4\n"        /* mm4 = mm3 = pix[8-15] */
717
      "punpckhbw %%mm0,%%mm3\n"        /* mm3 = [pix12-15] */
718
      "punpcklbw %%mm0,%%mm4\n"        /* mm4 = [pix8-11] */
719

    
720
      "pmaddwd %%mm1,%%mm1\n"        /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
721
      "pmaddwd %%mm2,%%mm2\n"        /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
722

    
723
      "pmaddwd %%mm3,%%mm3\n"
724
      "pmaddwd %%mm4,%%mm4\n"
725

    
726
      "paddd %%mm1,%%mm2\n"        /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
727
                                          pix2^2+pix3^2+pix6^2+pix7^2) */
728
      "paddd %%mm3,%%mm4\n"
729
      "paddd %%mm2,%%mm7\n"
730

    
731
      "add %2, %0\n"
732
      "paddd %%mm4,%%mm7\n"
733
      "dec %%ecx\n"
734
      "jnz 1b\n"
735

    
736
      "movq %%mm7,%%mm1\n"
737
      "psrlq $32, %%mm7\n"        /* shift hi dword to lo */
738
      "paddd %%mm7,%%mm1\n"
739
      "movd %%mm1,%1\n"
740
      : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" );
741
    return tmp;
742
}
743

    
744
static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
745
    int tmp;
746
  asm volatile (
747
      "movl %4,%%ecx\n"
748
      "shr $1,%%ecx\n"
749
      "pxor %%mm0,%%mm0\n"        /* mm0 = 0 */
750
      "pxor %%mm7,%%mm7\n"        /* mm7 holds the sum */
751
      "1:\n"
752
      "movq (%0),%%mm1\n"        /* mm1 = pix1[0][0-7] */
753
      "movq (%1),%%mm2\n"        /* mm2 = pix2[0][0-7] */
754
      "movq (%0,%3),%%mm3\n"        /* mm3 = pix1[1][0-7] */
755
      "movq (%1,%3),%%mm4\n"        /* mm4 = pix2[1][0-7] */
756

    
757
      /* todo: mm1-mm2, mm3-mm4 */
758
      /* algo: substract mm1 from mm2 with saturation and vice versa */
759
      /*       OR the results to get absolute difference */
760
      "movq %%mm1,%%mm5\n"
761
      "movq %%mm3,%%mm6\n"
762
      "psubusb %%mm2,%%mm1\n"
763
      "psubusb %%mm4,%%mm3\n"
764
      "psubusb %%mm5,%%mm2\n"
765
      "psubusb %%mm6,%%mm4\n"
766

    
767
      "por %%mm1,%%mm2\n"
768
      "por %%mm3,%%mm4\n"
769

    
770
      /* now convert to 16-bit vectors so we can square them */
771
      "movq %%mm2,%%mm1\n"
772
      "movq %%mm4,%%mm3\n"
773

    
774
      "punpckhbw %%mm0,%%mm2\n"
775
      "punpckhbw %%mm0,%%mm4\n"
776
      "punpcklbw %%mm0,%%mm1\n"        /* mm1 now spread over (mm1,mm2) */
777
      "punpcklbw %%mm0,%%mm3\n"        /* mm4 now spread over (mm3,mm4) */
778

    
779
      "pmaddwd %%mm2,%%mm2\n"
780
      "pmaddwd %%mm4,%%mm4\n"
781
      "pmaddwd %%mm1,%%mm1\n"
782
      "pmaddwd %%mm3,%%mm3\n"
783

    
784
      "lea (%0,%3,2), %0\n"        /* pix1 += 2*line_size */
785
      "lea (%1,%3,2), %1\n"        /* pix2 += 2*line_size */
786

    
787
      "paddd %%mm2,%%mm1\n"
788
      "paddd %%mm4,%%mm3\n"
789
      "paddd %%mm1,%%mm7\n"
790
      "paddd %%mm3,%%mm7\n"
791

    
792
      "decl %%ecx\n"
793
      "jnz 1b\n"
794

    
795
      "movq %%mm7,%%mm1\n"
796
      "psrlq $32, %%mm7\n"        /* shift hi dword to lo */
797
      "paddd %%mm7,%%mm1\n"
798
      "movd %%mm1,%2\n"
799
      : "+r" (pix1), "+r" (pix2), "=r"(tmp) 
800
      : "r" ((long)line_size) , "m" (h)
801
      : "%ecx");
802
    return tmp;
803
}
804

    
805
static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
806
    int tmp;
807
  asm volatile (
808
      "movl %4,%%ecx\n"
809
      "pxor %%mm0,%%mm0\n"        /* mm0 = 0 */
810
      "pxor %%mm7,%%mm7\n"        /* mm7 holds the sum */
811
      "1:\n"
812
      "movq (%0),%%mm1\n"        /* mm1 = pix1[0-7] */
813
      "movq (%1),%%mm2\n"        /* mm2 = pix2[0-7] */
814
      "movq 8(%0),%%mm3\n"        /* mm3 = pix1[8-15] */
815
      "movq 8(%1),%%mm4\n"        /* mm4 = pix2[8-15] */
816

    
817
      /* todo: mm1-mm2, mm3-mm4 */
818
      /* algo: substract mm1 from mm2 with saturation and vice versa */
819
      /*       OR the results to get absolute difference */
820
      "movq %%mm1,%%mm5\n"
821
      "movq %%mm3,%%mm6\n"
822
      "psubusb %%mm2,%%mm1\n"
823
      "psubusb %%mm4,%%mm3\n"
824
      "psubusb %%mm5,%%mm2\n"
825
      "psubusb %%mm6,%%mm4\n"
826

    
827
      "por %%mm1,%%mm2\n"
828
      "por %%mm3,%%mm4\n"
829

    
830
      /* now convert to 16-bit vectors so we can square them */
831
      "movq %%mm2,%%mm1\n"
832
      "movq %%mm4,%%mm3\n"
833

    
834
      "punpckhbw %%mm0,%%mm2\n"
835
      "punpckhbw %%mm0,%%mm4\n"
836
      "punpcklbw %%mm0,%%mm1\n"        /* mm1 now spread over (mm1,mm2) */
837
      "punpcklbw %%mm0,%%mm3\n"        /* mm4 now spread over (mm3,mm4) */
838

    
839
      "pmaddwd %%mm2,%%mm2\n"
840
      "pmaddwd %%mm4,%%mm4\n"
841
      "pmaddwd %%mm1,%%mm1\n"
842
      "pmaddwd %%mm3,%%mm3\n"
843

    
844
      "add %3,%0\n"
845
      "add %3,%1\n"
846

    
847
      "paddd %%mm2,%%mm1\n"
848
      "paddd %%mm4,%%mm3\n"
849
      "paddd %%mm1,%%mm7\n"
850
      "paddd %%mm3,%%mm7\n"
851

    
852
      "decl %%ecx\n"
853
      "jnz 1b\n"
854

    
855
      "movq %%mm7,%%mm1\n"
856
      "psrlq $32, %%mm7\n"        /* shift hi dword to lo */
857
      "paddd %%mm7,%%mm1\n"
858
      "movd %%mm1,%2\n"
859
      : "+r" (pix1), "+r" (pix2), "=r"(tmp) 
860
      : "r" ((long)line_size) , "m" (h)
861
      : "%ecx");
862
    return tmp;
863
}
864

    
865
static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
866
    int tmp;
867
  asm volatile (
868
      "shr $1,%2\n"
869
      "pxor %%xmm0,%%xmm0\n"        /* mm0 = 0 */
870
      "pxor %%xmm7,%%xmm7\n"        /* mm7 holds the sum */
871
      "1:\n"
872
      "movdqu (%0),%%xmm1\n"        /* mm1 = pix1[0][0-15] */
873
      "movdqu (%1),%%xmm2\n"        /* mm2 = pix2[0][0-15] */
874
      "movdqu (%0,%4),%%xmm3\n"        /* mm3 = pix1[1][0-15] */
875
      "movdqu (%1,%4),%%xmm4\n"        /* mm4 = pix2[1][0-15] */
876

    
877
      /* todo: mm1-mm2, mm3-mm4 */
878
      /* algo: substract mm1 from mm2 with saturation and vice versa */
879
      /*       OR the results to get absolute difference */
880
      "movdqa %%xmm1,%%xmm5\n"
881
      "movdqa %%xmm3,%%xmm6\n"
882
      "psubusb %%xmm2,%%xmm1\n"
883
      "psubusb %%xmm4,%%xmm3\n"
884
      "psubusb %%xmm5,%%xmm2\n"
885
      "psubusb %%xmm6,%%xmm4\n"
886

    
887
      "por %%xmm1,%%xmm2\n"
888
      "por %%xmm3,%%xmm4\n"
889

    
890
      /* now convert to 16-bit vectors so we can square them */
891
      "movdqa %%xmm2,%%xmm1\n"
892
      "movdqa %%xmm4,%%xmm3\n"
893

    
894
      "punpckhbw %%xmm0,%%xmm2\n"
895
      "punpckhbw %%xmm0,%%xmm4\n"
896
      "punpcklbw %%xmm0,%%xmm1\n"        /* mm1 now spread over (mm1,mm2) */
897
      "punpcklbw %%xmm0,%%xmm3\n"        /* mm4 now spread over (mm3,mm4) */
898

    
899
      "pmaddwd %%xmm2,%%xmm2\n"
900
      "pmaddwd %%xmm4,%%xmm4\n"
901
      "pmaddwd %%xmm1,%%xmm1\n"
902
      "pmaddwd %%xmm3,%%xmm3\n"
903

    
904
      "lea (%0,%4,2), %0\n"        /* pix1 += 2*line_size */
905
      "lea (%1,%4,2), %1\n"        /* pix2 += 2*line_size */
906

    
907
      "paddd %%xmm2,%%xmm1\n"
908
      "paddd %%xmm4,%%xmm3\n"
909
      "paddd %%xmm1,%%xmm7\n"
910
      "paddd %%xmm3,%%xmm7\n"
911

    
912
      "decl %2\n"
913
      "jnz 1b\n"
914

    
915
      "movdqa %%xmm7,%%xmm1\n"
916
      "psrldq $8, %%xmm7\n"        /* shift hi qword to lo */
917
      "paddd %%xmm1,%%xmm7\n"
918
      "movdqa %%xmm7,%%xmm1\n"
919
      "psrldq $4, %%xmm7\n"        /* shift hi dword to lo */
920
      "paddd %%xmm1,%%xmm7\n"
921
      "movd %%xmm7,%3\n"
922
      : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp) 
923
      : "r" ((long)line_size));
924
    return tmp;
925
}
926

    
927
static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
928
    int tmp;
929
  asm volatile (
930
      "movl %3,%%ecx\n"
931
      "pxor %%mm7,%%mm7\n"
932
      "pxor %%mm6,%%mm6\n"
933
      
934
      "movq (%0),%%mm0\n"
935
      "movq %%mm0, %%mm1\n"
936
      "psllq $8, %%mm0\n"
937
      "psrlq $8, %%mm1\n"
938
      "psrlq $8, %%mm0\n"
939
      "movq %%mm0, %%mm2\n"
940
      "movq %%mm1, %%mm3\n"
941
      "punpcklbw %%mm7,%%mm0\n"
942
      "punpcklbw %%mm7,%%mm1\n"
943
      "punpckhbw %%mm7,%%mm2\n"
944
      "punpckhbw %%mm7,%%mm3\n"
945
      "psubw %%mm1, %%mm0\n"
946
      "psubw %%mm3, %%mm2\n"
947
      
948
      "add %2,%0\n"
949
      
950
      "movq (%0),%%mm4\n"
951
      "movq %%mm4, %%mm1\n"
952
      "psllq $8, %%mm4\n"
953
      "psrlq $8, %%mm1\n"
954
      "psrlq $8, %%mm4\n"
955
      "movq %%mm4, %%mm5\n"
956
      "movq %%mm1, %%mm3\n"
957
      "punpcklbw %%mm7,%%mm4\n"
958
      "punpcklbw %%mm7,%%mm1\n"
959
      "punpckhbw %%mm7,%%mm5\n"
960
      "punpckhbw %%mm7,%%mm3\n"
961
      "psubw %%mm1, %%mm4\n"
962
      "psubw %%mm3, %%mm5\n"
963
      "psubw %%mm4, %%mm0\n"
964
      "psubw %%mm5, %%mm2\n"
965
      "pxor %%mm3, %%mm3\n"
966
      "pxor %%mm1, %%mm1\n"
967
      "pcmpgtw %%mm0, %%mm3\n\t"
968
      "pcmpgtw %%mm2, %%mm1\n\t"
969
      "pxor %%mm3, %%mm0\n"
970
      "pxor %%mm1, %%mm2\n"
971
      "psubw %%mm3, %%mm0\n" 
972
      "psubw %%mm1, %%mm2\n"
973
      "paddw %%mm0, %%mm2\n"
974
      "paddw %%mm2, %%mm6\n"
975

    
976
      "add %2,%0\n"
977
      "1:\n"
978
  
979
      "movq (%0),%%mm0\n"
980
      "movq %%mm0, %%mm1\n"
981
      "psllq $8, %%mm0\n"
982
      "psrlq $8, %%mm1\n"
983
      "psrlq $8, %%mm0\n"
984
      "movq %%mm0, %%mm2\n"
985
      "movq %%mm1, %%mm3\n"
986
      "punpcklbw %%mm7,%%mm0\n"
987
      "punpcklbw %%mm7,%%mm1\n"
988
      "punpckhbw %%mm7,%%mm2\n"
989
      "punpckhbw %%mm7,%%mm3\n"
990
      "psubw %%mm1, %%mm0\n"
991
      "psubw %%mm3, %%mm2\n"
992
      "psubw %%mm0, %%mm4\n"
993
      "psubw %%mm2, %%mm5\n"
994
      "pxor %%mm3, %%mm3\n"
995
      "pxor %%mm1, %%mm1\n"
996
      "pcmpgtw %%mm4, %%mm3\n\t"
997
      "pcmpgtw %%mm5, %%mm1\n\t"
998
      "pxor %%mm3, %%mm4\n"
999
      "pxor %%mm1, %%mm5\n"
1000
      "psubw %%mm3, %%mm4\n" 
1001
      "psubw %%mm1, %%mm5\n"
1002
      "paddw %%mm4, %%mm5\n"
1003
      "paddw %%mm5, %%mm6\n"
1004
      
1005
      "add %2,%0\n"
1006
      
1007
      "movq (%0),%%mm4\n"
1008
      "movq %%mm4, %%mm1\n"
1009
      "psllq $8, %%mm4\n"
1010
      "psrlq $8, %%mm1\n"
1011
      "psrlq $8, %%mm4\n"
1012
      "movq %%mm4, %%mm5\n"
1013
      "movq %%mm1, %%mm3\n"
1014
      "punpcklbw %%mm7,%%mm4\n"
1015
      "punpcklbw %%mm7,%%mm1\n"
1016
      "punpckhbw %%mm7,%%mm5\n"
1017
      "punpckhbw %%mm7,%%mm3\n"
1018
      "psubw %%mm1, %%mm4\n"
1019
      "psubw %%mm3, %%mm5\n"
1020
      "psubw %%mm4, %%mm0\n"
1021
      "psubw %%mm5, %%mm2\n"
1022
      "pxor %%mm3, %%mm3\n"
1023
      "pxor %%mm1, %%mm1\n"
1024
      "pcmpgtw %%mm0, %%mm3\n\t"
1025
      "pcmpgtw %%mm2, %%mm1\n\t"
1026
      "pxor %%mm3, %%mm0\n"
1027
      "pxor %%mm1, %%mm2\n"
1028
      "psubw %%mm3, %%mm0\n" 
1029
      "psubw %%mm1, %%mm2\n"
1030
      "paddw %%mm0, %%mm2\n"
1031
      "paddw %%mm2, %%mm6\n"
1032

    
1033
      "add %2,%0\n"
1034
      "subl $2, %%ecx\n"
1035
      " jnz 1b\n"
1036

    
1037
      "movq %%mm6, %%mm0\n"
1038
      "punpcklwd %%mm7,%%mm0\n"
1039
      "punpckhwd %%mm7,%%mm6\n"
1040
      "paddd %%mm0, %%mm6\n"
1041
      
1042
      "movq %%mm6,%%mm0\n"
1043
      "psrlq $32, %%mm6\n"
1044
      "paddd %%mm6,%%mm0\n"
1045
      "movd %%mm0,%1\n"
1046
      : "+r" (pix1), "=r"(tmp) 
1047
      : "r" ((long)line_size) , "g" (h-2)
1048
      : "%ecx");
1049
      return tmp;
1050
}
1051

    
1052
static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
1053
    int tmp;
1054
    uint8_t * pix= pix1;
1055
  asm volatile (
1056
      "movl %3,%%ecx\n"
1057
      "pxor %%mm7,%%mm7\n"
1058
      "pxor %%mm6,%%mm6\n"
1059
      
1060
      "movq (%0),%%mm0\n"
1061
      "movq 1(%0),%%mm1\n"
1062
      "movq %%mm0, %%mm2\n"
1063
      "movq %%mm1, %%mm3\n"
1064
      "punpcklbw %%mm7,%%mm0\n"
1065
      "punpcklbw %%mm7,%%mm1\n"
1066
      "punpckhbw %%mm7,%%mm2\n"
1067
      "punpckhbw %%mm7,%%mm3\n"
1068
      "psubw %%mm1, %%mm0\n"
1069
      "psubw %%mm3, %%mm2\n"
1070
      
1071
      "add %2,%0\n"
1072
      
1073
      "movq (%0),%%mm4\n"
1074
      "movq 1(%0),%%mm1\n"
1075
      "movq %%mm4, %%mm5\n"
1076
      "movq %%mm1, %%mm3\n"
1077
      "punpcklbw %%mm7,%%mm4\n"
1078
      "punpcklbw %%mm7,%%mm1\n"
1079
      "punpckhbw %%mm7,%%mm5\n"
1080
      "punpckhbw %%mm7,%%mm3\n"
1081
      "psubw %%mm1, %%mm4\n"
1082
      "psubw %%mm3, %%mm5\n"
1083
      "psubw %%mm4, %%mm0\n"
1084
      "psubw %%mm5, %%mm2\n"
1085
      "pxor %%mm3, %%mm3\n"
1086
      "pxor %%mm1, %%mm1\n"
1087
      "pcmpgtw %%mm0, %%mm3\n\t"
1088
      "pcmpgtw %%mm2, %%mm1\n\t"
1089
      "pxor %%mm3, %%mm0\n"
1090
      "pxor %%mm1, %%mm2\n"
1091
      "psubw %%mm3, %%mm0\n" 
1092
      "psubw %%mm1, %%mm2\n"
1093
      "paddw %%mm0, %%mm2\n"
1094
      "paddw %%mm2, %%mm6\n"
1095

    
1096
      "add %2,%0\n"
1097
      "1:\n"
1098
  
1099
      "movq (%0),%%mm0\n"
1100
      "movq 1(%0),%%mm1\n"
1101
      "movq %%mm0, %%mm2\n"
1102
      "movq %%mm1, %%mm3\n"
1103
      "punpcklbw %%mm7,%%mm0\n"
1104
      "punpcklbw %%mm7,%%mm1\n"
1105
      "punpckhbw %%mm7,%%mm2\n"
1106
      "punpckhbw %%mm7,%%mm3\n"
1107
      "psubw %%mm1, %%mm0\n"
1108
      "psubw %%mm3, %%mm2\n"
1109
      "psubw %%mm0, %%mm4\n"
1110
      "psubw %%mm2, %%mm5\n"
1111
      "pxor %%mm3, %%mm3\n"
1112
      "pxor %%mm1, %%mm1\n"
1113
      "pcmpgtw %%mm4, %%mm3\n\t"
1114
      "pcmpgtw %%mm5, %%mm1\n\t"
1115
      "pxor %%mm3, %%mm4\n"
1116
      "pxor %%mm1, %%mm5\n"
1117
      "psubw %%mm3, %%mm4\n"
1118
      "psubw %%mm1, %%mm5\n"
1119
      "paddw %%mm4, %%mm5\n"
1120
      "paddw %%mm5, %%mm6\n"
1121
      
1122
      "add %2,%0\n"
1123
      
1124
      "movq (%0),%%mm4\n"
1125
      "movq 1(%0),%%mm1\n"
1126
      "movq %%mm4, %%mm5\n"
1127
      "movq %%mm1, %%mm3\n"
1128
      "punpcklbw %%mm7,%%mm4\n"
1129
      "punpcklbw %%mm7,%%mm1\n"
1130
      "punpckhbw %%mm7,%%mm5\n"
1131
      "punpckhbw %%mm7,%%mm3\n"
1132
      "psubw %%mm1, %%mm4\n"
1133
      "psubw %%mm3, %%mm5\n"
1134
      "psubw %%mm4, %%mm0\n"
1135
      "psubw %%mm5, %%mm2\n"
1136
      "pxor %%mm3, %%mm3\n"
1137
      "pxor %%mm1, %%mm1\n"
1138
      "pcmpgtw %%mm0, %%mm3\n\t"
1139
      "pcmpgtw %%mm2, %%mm1\n\t"
1140
      "pxor %%mm3, %%mm0\n"
1141
      "pxor %%mm1, %%mm2\n"
1142
      "psubw %%mm3, %%mm0\n" 
1143
      "psubw %%mm1, %%mm2\n"
1144
      "paddw %%mm0, %%mm2\n"
1145
      "paddw %%mm2, %%mm6\n"
1146

    
1147
      "add %2,%0\n"
1148
      "subl $2, %%ecx\n"
1149
      " jnz 1b\n"
1150

    
1151
      "movq %%mm6, %%mm0\n"
1152
      "punpcklwd %%mm7,%%mm0\n"
1153
      "punpckhwd %%mm7,%%mm6\n"
1154
      "paddd %%mm0, %%mm6\n"
1155
      
1156
      "movq %%mm6,%%mm0\n"
1157
      "psrlq $32, %%mm6\n"
1158
      "paddd %%mm6,%%mm0\n"
1159
      "movd %%mm0,%1\n"
1160
      : "+r" (pix1), "=r"(tmp) 
1161
      : "r" ((long)line_size) , "g" (h-2)
1162
      : "%ecx");
1163
      return tmp + hf_noise8_mmx(pix+8, line_size, h);
1164
}
1165

    
1166
static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1167
    MpegEncContext *c = p;
1168
    int score1= sse16_mmx(c, pix1, pix2, line_size, h);
1169
    int score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
1170

    
1171
    if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1172
    else  return score1 + ABS(score2)*8;
1173
}
1174

    
1175
static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1176
    MpegEncContext *c = p;
1177
    int score1= sse8_mmx(c, pix1, pix2, line_size, h);
1178
    int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
1179

    
1180
    if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
1181
    else  return score1 + ABS(score2)*8;
1182
}
1183

    
1184
static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1185
    int tmp;
1186
    
1187
    assert( (((int)pix) & 7) == 0);
1188
    assert((line_size &7) ==0);
1189
    
1190
#define SUM(in0, in1, out0, out1) \
1191
      "movq (%0), %%mm2\n"\
1192
      "movq 8(%0), %%mm3\n"\
1193
      "add %2,%0\n"\
1194
      "movq %%mm2, " #out0 "\n"\
1195
      "movq %%mm3, " #out1 "\n"\
1196
      "psubusb " #in0 ", %%mm2\n"\
1197
      "psubusb " #in1 ", %%mm3\n"\
1198
      "psubusb " #out0 ", " #in0 "\n"\
1199
      "psubusb " #out1 ", " #in1 "\n"\
1200
      "por %%mm2, " #in0 "\n"\
1201
      "por %%mm3, " #in1 "\n"\
1202
      "movq " #in0 ", %%mm2\n"\
1203
      "movq " #in1 ", %%mm3\n"\
1204
      "punpcklbw %%mm7, " #in0 "\n"\
1205
      "punpcklbw %%mm7, " #in1 "\n"\
1206
      "punpckhbw %%mm7, %%mm2\n"\
1207
      "punpckhbw %%mm7, %%mm3\n"\
1208
      "paddw " #in1 ", " #in0 "\n"\
1209
      "paddw %%mm3, %%mm2\n"\
1210
      "paddw %%mm2, " #in0 "\n"\
1211
      "paddw " #in0 ", %%mm6\n"
1212

    
1213
    
1214
  asm volatile (
1215
      "movl %3,%%ecx\n"
1216
      "pxor %%mm6,%%mm6\n"
1217
      "pxor %%mm7,%%mm7\n"
1218
      "movq (%0),%%mm0\n"
1219
      "movq 8(%0),%%mm1\n"
1220
      "add %2,%0\n"
1221
      "subl $2, %%ecx\n"
1222
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1223
      "1:\n"
1224
      
1225
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1226
      
1227
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1228
      
1229
      "subl $2, %%ecx\n"
1230
      "jnz 1b\n"
1231

    
1232
      "movq %%mm6,%%mm0\n"
1233
      "psrlq $32, %%mm6\n"
1234
      "paddw %%mm6,%%mm0\n"
1235
      "movq %%mm0,%%mm6\n"
1236
      "psrlq $16, %%mm0\n"
1237
      "paddw %%mm6,%%mm0\n"
1238
      "movd %%mm0,%1\n"
1239
      : "+r" (pix), "=r"(tmp) 
1240
      : "r" ((long)line_size) , "m" (h)
1241
      : "%ecx");
1242
    return tmp & 0xFFFF;
1243
}
1244
#undef SUM
1245

    
1246
static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1247
    int tmp;
1248
    
1249
    assert( (((int)pix) & 7) == 0);
1250
    assert((line_size &7) ==0);
1251
    
1252
#define SUM(in0, in1, out0, out1) \
1253
      "movq (%0), " #out0 "\n"\
1254
      "movq 8(%0), " #out1 "\n"\
1255
      "add %2,%0\n"\
1256
      "psadbw " #out0 ", " #in0 "\n"\
1257
      "psadbw " #out1 ", " #in1 "\n"\
1258
      "paddw " #in1 ", " #in0 "\n"\
1259
      "paddw " #in0 ", %%mm6\n"
1260

    
1261
  asm volatile (
1262
      "movl %3,%%ecx\n"
1263
      "pxor %%mm6,%%mm6\n"
1264
      "pxor %%mm7,%%mm7\n"
1265
      "movq (%0),%%mm0\n"
1266
      "movq 8(%0),%%mm1\n"
1267
      "add %2,%0\n"
1268
      "subl $2, %%ecx\n"
1269
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1270
      "1:\n"
1271
      
1272
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1273
      
1274
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1275
      
1276
      "subl $2, %%ecx\n"
1277
      "jnz 1b\n"
1278

    
1279
      "movd %%mm6,%1\n"
1280
      : "+r" (pix), "=r"(tmp) 
1281
      : "r" ((long)line_size) , "m" (h)
1282
      : "%ecx");
1283
    return tmp;
1284
}
1285
#undef SUM
1286

    
1287
static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1288
    int tmp;
1289
    
1290
    assert( (((int)pix1) & 7) == 0);
1291
    assert( (((int)pix2) & 7) == 0);
1292
    assert((line_size &7) ==0);
1293
    
1294
#define SUM(in0, in1, out0, out1) \
1295
      "movq (%0),%%mm2\n"\
1296
      "movq (%1)," #out0 "\n"\
1297
      "movq 8(%0),%%mm3\n"\
1298
      "movq 8(%1)," #out1 "\n"\
1299
      "add %3,%0\n"\
1300
      "add %3,%1\n"\
1301
      "psubb " #out0 ", %%mm2\n"\
1302
      "psubb " #out1 ", %%mm3\n"\
1303
      "pxor %%mm7, %%mm2\n"\
1304
      "pxor %%mm7, %%mm3\n"\
1305
      "movq %%mm2, " #out0 "\n"\
1306
      "movq %%mm3, " #out1 "\n"\
1307
      "psubusb " #in0 ", %%mm2\n"\
1308
      "psubusb " #in1 ", %%mm3\n"\
1309
      "psubusb " #out0 ", " #in0 "\n"\
1310
      "psubusb " #out1 ", " #in1 "\n"\
1311
      "por %%mm2, " #in0 "\n"\
1312
      "por %%mm3, " #in1 "\n"\
1313
      "movq " #in0 ", %%mm2\n"\
1314
      "movq " #in1 ", %%mm3\n"\
1315
      "punpcklbw %%mm7, " #in0 "\n"\
1316
      "punpcklbw %%mm7, " #in1 "\n"\
1317
      "punpckhbw %%mm7, %%mm2\n"\
1318
      "punpckhbw %%mm7, %%mm3\n"\
1319
      "paddw " #in1 ", " #in0 "\n"\
1320
      "paddw %%mm3, %%mm2\n"\
1321
      "paddw %%mm2, " #in0 "\n"\
1322
      "paddw " #in0 ", %%mm6\n"
1323

    
1324
    
1325
  asm volatile (
1326
      "movl %4,%%ecx\n"
1327
      "pxor %%mm6,%%mm6\n"
1328
      "pcmpeqw %%mm7,%%mm7\n"
1329
      "psllw $15, %%mm7\n"
1330
      "packsswb %%mm7, %%mm7\n"
1331
      "movq (%0),%%mm0\n"
1332
      "movq (%1),%%mm2\n"
1333
      "movq 8(%0),%%mm1\n"
1334
      "movq 8(%1),%%mm3\n"
1335
      "add %3,%0\n"
1336
      "add %3,%1\n"
1337
      "subl $2, %%ecx\n"
1338
      "psubb %%mm2, %%mm0\n"
1339
      "psubb %%mm3, %%mm1\n"
1340
      "pxor %%mm7, %%mm0\n"
1341
      "pxor %%mm7, %%mm1\n"
1342
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1343
      "1:\n"
1344
      
1345
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1346
      
1347
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1348
      
1349
      "subl $2, %%ecx\n"
1350
      "jnz 1b\n"
1351

    
1352
      "movq %%mm6,%%mm0\n"
1353
      "psrlq $32, %%mm6\n"
1354
      "paddw %%mm6,%%mm0\n"
1355
      "movq %%mm0,%%mm6\n"
1356
      "psrlq $16, %%mm0\n"
1357
      "paddw %%mm6,%%mm0\n"
1358
      "movd %%mm0,%2\n"
1359
      : "+r" (pix1), "+r" (pix2), "=r"(tmp) 
1360
      : "r" ((long)line_size) , "m" (h)
1361
      : "%ecx");
1362
    return tmp & 0x7FFF;
1363
}
1364
#undef SUM
1365

    
1366
static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1367
    int tmp;
1368
    
1369
    assert( (((int)pix1) & 7) == 0);
1370
    assert( (((int)pix2) & 7) == 0);
1371
    assert((line_size &7) ==0);
1372
    
1373
#define SUM(in0, in1, out0, out1) \
1374
      "movq (%0)," #out0 "\n"\
1375
      "movq (%1),%%mm2\n"\
1376
      "movq 8(%0)," #out1 "\n"\
1377
      "movq 8(%1),%%mm3\n"\
1378
      "add %3,%0\n"\
1379
      "add %3,%1\n"\
1380
      "psubb %%mm2, " #out0 "\n"\
1381
      "psubb %%mm3, " #out1 "\n"\
1382
      "pxor %%mm7, " #out0 "\n"\
1383
      "pxor %%mm7, " #out1 "\n"\
1384
      "psadbw " #out0 ", " #in0 "\n"\
1385
      "psadbw " #out1 ", " #in1 "\n"\
1386
      "paddw " #in1 ", " #in0 "\n"\
1387
      "paddw " #in0 ", %%mm6\n"
1388

    
1389
  asm volatile (
1390
      "movl %4,%%ecx\n"
1391
      "pxor %%mm6,%%mm6\n"
1392
      "pcmpeqw %%mm7,%%mm7\n"
1393
      "psllw $15, %%mm7\n"
1394
      "packsswb %%mm7, %%mm7\n"
1395
      "movq (%0),%%mm0\n"
1396
      "movq (%1),%%mm2\n"
1397
      "movq 8(%0),%%mm1\n"
1398
      "movq 8(%1),%%mm3\n"
1399
      "add %3,%0\n"
1400
      "add %3,%1\n"
1401
      "subl $2, %%ecx\n"
1402
      "psubb %%mm2, %%mm0\n"
1403
      "psubb %%mm3, %%mm1\n"
1404
      "pxor %%mm7, %%mm0\n"
1405
      "pxor %%mm7, %%mm1\n"
1406
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1407
      "1:\n"
1408
      
1409
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1410
      
1411
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1412
      
1413
      "subl $2, %%ecx\n"
1414
      "jnz 1b\n"
1415

    
1416
      "movd %%mm6,%2\n"
1417
      : "+r" (pix1), "+r" (pix2), "=r"(tmp) 
1418
      : "r" ((long)line_size) , "m" (h)
1419
      : "%ecx");
1420
    return tmp;
1421
}
1422
#undef SUM
1423

    
1424
static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
1425
    long i=0;
1426
    asm volatile(
1427
        "1:                                \n\t"
1428
        "movq  (%2, %0), %%mm0                \n\t"
1429
        "movq  (%1, %0), %%mm1                \n\t"
1430
        "psubb %%mm0, %%mm1                \n\t"
1431
        "movq %%mm1, (%3, %0)                \n\t"
1432
        "movq 8(%2, %0), %%mm0                \n\t"
1433
        "movq 8(%1, %0), %%mm1                \n\t"
1434
        "psubb %%mm0, %%mm1                \n\t"
1435
        "movq %%mm1, 8(%3, %0)                \n\t"
1436
        "add $16, %0                        \n\t"
1437
        "cmp %4, %0                        \n\t"
1438
        " jb 1b                                \n\t"
1439
        : "+r" (i)
1440
        : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15)
1441
    );
1442
    for(; i<w; i++)
1443
        dst[i+0] = src1[i+0]-src2[i+0];
1444
}
1445

    
1446
static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
1447
    long i=0;
1448
    uint8_t l, lt;
1449
    
1450
    asm volatile(
1451
        "1:                                \n\t"
1452
        "movq  -1(%1, %0), %%mm0        \n\t" // LT
1453
        "movq  (%1, %0), %%mm1                \n\t" // T
1454
        "movq  -1(%2, %0), %%mm2        \n\t" // L
1455
        "movq  (%2, %0), %%mm3                \n\t" // X
1456
        "movq %%mm2, %%mm4                \n\t" // L
1457
        "psubb %%mm0, %%mm2                \n\t"
1458
        "paddb %%mm1, %%mm2                \n\t" // L + T - LT
1459
        "movq %%mm4, %%mm5                \n\t" // L
1460
        "pmaxub %%mm1, %%mm4                \n\t" // max(T, L)
1461
        "pminub %%mm5, %%mm1                \n\t" // min(T, L)
1462
        "pminub %%mm2, %%mm4                \n\t" 
1463
        "pmaxub %%mm1, %%mm4                \n\t"
1464
        "psubb %%mm4, %%mm3                \n\t" // dst - pred
1465
        "movq %%mm3, (%3, %0)                \n\t"
1466
        "add $8, %0                        \n\t"
1467
        "cmp %4, %0                        \n\t"
1468
        " jb 1b                                \n\t"
1469
        : "+r" (i)
1470
        : "r"(src1), "r"(src2), "r"(dst), "r"((long)w)
1471
    );
1472

    
1473
    l= *left;
1474
    lt= *left_top;
1475
    
1476
    dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
1477
    
1478
    *left_top= src1[w-1];
1479
    *left    = src2[w-1];
1480
}
1481

    
1482
#define LBUTTERFLY2(a1,b1,a2,b2)\
1483
    "paddw " #b1 ", " #a1 "                \n\t"\
1484
    "paddw " #b2 ", " #a2 "                \n\t"\
1485
    "paddw " #b1 ", " #b1 "                \n\t"\
1486
    "paddw " #b2 ", " #b2 "                \n\t"\
1487
    "psubw " #a1 ", " #b1 "                \n\t"\
1488
    "psubw " #a2 ", " #b2 "                \n\t"
1489

    
1490
#define HADAMARD48\
1491
        LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
1492
        LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
1493
        LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
1494
        LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
1495
        LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
1496
        LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
1497

    
1498
#define MMABS(a,z)\
1499
    "pxor " #z ", " #z "                \n\t"\
1500
    "pcmpgtw " #a ", " #z "                \n\t"\
1501
    "pxor " #z ", " #a "                \n\t"\
1502
    "psubw " #z ", " #a "                \n\t"
1503

    
1504
#define MMABS_SUM(a,z, sum)\
1505
    "pxor " #z ", " #z "                \n\t"\
1506
    "pcmpgtw " #a ", " #z "                \n\t"\
1507
    "pxor " #z ", " #a "                \n\t"\
1508
    "psubw " #z ", " #a "                \n\t"\
1509
    "paddusw " #a ", " #sum "                \n\t"
1510

    
1511
#define MMABS_MMX2(a,z)\
1512
    "pxor " #z ", " #z "                \n\t"\
1513
    "psubw " #a ", " #z "                \n\t"\
1514
    "pmaxsw " #z ", " #a "                \n\t"
1515

    
1516
#define MMABS_SUM_MMX2(a,z, sum)\
1517
    "pxor " #z ", " #z "                \n\t"\
1518
    "psubw " #a ", " #z "                \n\t"\
1519
    "pmaxsw " #z ", " #a "                \n\t"\
1520
    "paddusw " #a ", " #sum "                \n\t"
1521
        
1522
#define SBUTTERFLY(a,b,t,n)\
1523
    "movq " #a ", " #t "                \n\t" /* abcd */\
1524
    "punpckl" #n " " #b ", " #a "        \n\t" /* aebf */\
1525
    "punpckh" #n " " #b ", " #t "        \n\t" /* cgdh */\
1526

    
1527
#define TRANSPOSE4(a,b,c,d,t)\
1528
    SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
1529
    SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
1530
    SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
1531
    SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
1532

    
1533
#define LOAD4(o, a, b, c, d)\
1534
        "movq "#o"(%1), " #a "                \n\t"\
1535
        "movq "#o"+16(%1), " #b "        \n\t"\
1536
        "movq "#o"+32(%1), " #c "        \n\t"\
1537
        "movq "#o"+48(%1), " #d "        \n\t"
1538

    
1539
#define STORE4(o, a, b, c, d)\
1540
        "movq "#a", "#o"(%1)                \n\t"\
1541
        "movq "#b", "#o"+16(%1)                \n\t"\
1542
        "movq "#c", "#o"+32(%1)                \n\t"\
1543
        "movq "#d", "#o"+48(%1)                \n\t"\
1544

    
1545
static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
1546
    uint64_t temp[16] __align8;
1547
    int sum=0;
1548
    
1549
    assert(h==8);
1550

    
1551
    diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1552

    
1553
    asm volatile(
1554
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1555
        LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1556
        
1557
        HADAMARD48
1558
        
1559
        "movq %%mm7, 112(%1)                \n\t"
1560
        
1561
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1562
        STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1563
        
1564
        "movq 112(%1), %%mm7                 \n\t"
1565
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1566
        STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1567

    
1568
        LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1569
        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1570
        
1571
        HADAMARD48
1572
        
1573
        "movq %%mm7, 120(%1)                \n\t"
1574
        
1575
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1576
        STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1577
        
1578
        "movq 120(%1), %%mm7                 \n\t"
1579
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1580
        "movq %%mm7, %%mm5                \n\t"//FIXME remove
1581
        "movq %%mm6, %%mm7                \n\t"
1582
        "movq %%mm0, %%mm6                \n\t"
1583
//        STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1584
        
1585
        LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1586
//        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1587
        
1588
        HADAMARD48
1589
        "movq %%mm7, 64(%1)                \n\t"
1590
        MMABS(%%mm0, %%mm7)
1591
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1592
        MMABS_SUM(%%mm2, %%mm7, %%mm0)
1593
        MMABS_SUM(%%mm3, %%mm7, %%mm0)
1594
        MMABS_SUM(%%mm4, %%mm7, %%mm0)
1595
        MMABS_SUM(%%mm5, %%mm7, %%mm0)
1596
        MMABS_SUM(%%mm6, %%mm7, %%mm0)
1597
        "movq 64(%1), %%mm1                \n\t"
1598
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1599
        "movq %%mm0, 64(%1)                \n\t"
1600
        
1601
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1602
        LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1603
        
1604
        HADAMARD48
1605
        "movq %%mm7, (%1)                \n\t"
1606
        MMABS(%%mm0, %%mm7)
1607
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1608
        MMABS_SUM(%%mm2, %%mm7, %%mm0)
1609
        MMABS_SUM(%%mm3, %%mm7, %%mm0)
1610
        MMABS_SUM(%%mm4, %%mm7, %%mm0)
1611
        MMABS_SUM(%%mm5, %%mm7, %%mm0)
1612
        MMABS_SUM(%%mm6, %%mm7, %%mm0)
1613
        "movq (%1), %%mm1                \n\t"
1614
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1615
        "movq 64(%1), %%mm1                \n\t"
1616
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1617
        
1618
        "movq %%mm0, %%mm1                \n\t"
1619
        "psrlq $32, %%mm0                \n\t"
1620
        "paddusw %%mm1, %%mm0                \n\t"
1621
        "movq %%mm0, %%mm1                \n\t"
1622
        "psrlq $16, %%mm0                \n\t"
1623
        "paddusw %%mm1, %%mm0                \n\t"
1624
        "movd %%mm0, %0                        \n\t"
1625
                
1626
        : "=r" (sum)
1627
        : "r"(temp)
1628
    );
1629
    return sum&0xFFFF;
1630
}
1631

    
1632
static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
1633
    uint64_t temp[16] __align8;
1634
    int sum=0;
1635
    
1636
    assert(h==8);
1637

    
1638
    diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1639

    
1640
    asm volatile(
1641
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1642
        LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1643
        
1644
        HADAMARD48
1645
        
1646
        "movq %%mm7, 112(%1)                \n\t"
1647
        
1648
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1649
        STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1650
        
1651
        "movq 112(%1), %%mm7                 \n\t"
1652
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1653
        STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1654

    
1655
        LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1656
        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1657
        
1658
        HADAMARD48
1659
        
1660
        "movq %%mm7, 120(%1)                \n\t"
1661
        
1662
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1663
        STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1664
        
1665
        "movq 120(%1), %%mm7                 \n\t"
1666
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1667
        "movq %%mm7, %%mm5                \n\t"//FIXME remove
1668
        "movq %%mm6, %%mm7                \n\t"
1669
        "movq %%mm0, %%mm6                \n\t"
1670
//        STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1671
        
1672
        LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1673
//        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1674
        
1675
        HADAMARD48
1676
        "movq %%mm7, 64(%1)                \n\t"
1677
        MMABS_MMX2(%%mm0, %%mm7)
1678
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1679
        MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1680
        MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1681
        MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1682
        MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1683
        MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1684
        "movq 64(%1), %%mm1                \n\t"
1685
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1686
        "movq %%mm0, 64(%1)                \n\t"
1687
        
1688
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1689
        LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1690
        
1691
        HADAMARD48
1692
        "movq %%mm7, (%1)                \n\t"
1693
        MMABS_MMX2(%%mm0, %%mm7)
1694
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1695
        MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1696
        MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1697
        MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1698
        MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1699
        MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1700
        "movq (%1), %%mm1                \n\t"
1701
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1702
        "movq 64(%1), %%mm1                \n\t"
1703
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1704
        
1705
        "pshufw $0x0E, %%mm0, %%mm1     \n\t"
1706
        "paddusw %%mm1, %%mm0                \n\t"
1707
        "pshufw $0x01, %%mm0, %%mm1     \n\t"
1708
        "paddusw %%mm1, %%mm0                \n\t"
1709
        "movd %%mm0, %0                        \n\t"
1710
                
1711
        : "=r" (sum)
1712
        : "r"(temp)
1713
    );
1714
    return sum&0xFFFF;
1715
}
1716

    
1717

    
1718
WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
1719
WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
1720
#endif //CONFIG_ENCODERS
1721

    
1722
#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
1723
#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
1724

    
1725
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
1726
        "paddw " #m4 ", " #m3 "                \n\t" /* x1 */\
1727
        "movq "MANGLE(ff_pw_20)", %%mm4                \n\t" /* 20 */\
1728
        "pmullw " #m3 ", %%mm4                \n\t" /* 20x1 */\
1729
        "movq "#in7", " #m3 "                \n\t" /* d */\
1730
        "movq "#in0", %%mm5                \n\t" /* D */\
1731
        "paddw " #m3 ", %%mm5                \n\t" /* x4 */\
1732
        "psubw %%mm5, %%mm4                \n\t" /* 20x1 - x4 */\
1733
        "movq "#in1", %%mm5                \n\t" /* C */\
1734
        "movq "#in2", %%mm6                \n\t" /* B */\
1735
        "paddw " #m6 ", %%mm5                \n\t" /* x3 */\
1736
        "paddw " #m5 ", %%mm6                \n\t" /* x2 */\
1737
        "paddw %%mm6, %%mm6                \n\t" /* 2x2 */\
1738
        "psubw %%mm6, %%mm5                \n\t" /* -2x2 + x3 */\
1739
        "pmullw "MANGLE(ff_pw_3)", %%mm5        \n\t" /* -6x2 + 3x3 */\
1740
        "paddw " #rnd ", %%mm4                \n\t" /* x2 */\
1741
        "paddw %%mm4, %%mm5                \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
1742
        "psraw $5, %%mm5                \n\t"\
1743
        "packuswb %%mm5, %%mm5                \n\t"\
1744
        OP(%%mm5, out, %%mm7, d)
1745

    
1746
#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
1747
static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1748
    uint64_t temp;\
1749
\
1750
    asm volatile(\
1751
        "pxor %%mm7, %%mm7                \n\t"\
1752
        "1:                                \n\t"\
1753
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1754
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1755
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1756
        "punpcklbw %%mm7, %%mm0                \n\t" /* 0A0B0C0D */\
1757
        "punpckhbw %%mm7, %%mm1                \n\t" /* 0E0F0G0H */\
1758
        "pshufw $0x90, %%mm0, %%mm5        \n\t" /* 0A0A0B0C */\
1759
        "pshufw $0x41, %%mm0, %%mm6        \n\t" /* 0B0A0A0B */\
1760
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1761
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1762
        "psllq $8, %%mm2                \n\t" /* 0ABCDEFG */\
1763
        "psllq $16, %%mm3                \n\t" /* 00ABCDEF */\
1764
        "psllq $24, %%mm4                \n\t" /* 000ABCDE */\
1765
        "punpckhbw %%mm7, %%mm2                \n\t" /* 0D0E0F0G */\
1766
        "punpckhbw %%mm7, %%mm3                \n\t" /* 0C0D0E0F */\
1767
        "punpckhbw %%mm7, %%mm4                \n\t" /* 0B0C0D0E */\
1768
        "paddw %%mm3, %%mm5                \n\t" /* b */\
1769
        "paddw %%mm2, %%mm6                \n\t" /* c */\
1770
        "paddw %%mm5, %%mm5                \n\t" /* 2b */\
1771
        "psubw %%mm5, %%mm6                \n\t" /* c - 2b */\
1772
        "pshufw $0x06, %%mm0, %%mm5        \n\t" /* 0C0B0A0A */\
1773
        "pmullw "MANGLE(ff_pw_3)", %%mm6                \n\t" /* 3c - 6b */\
1774
        "paddw %%mm4, %%mm0                \n\t" /* a */\
1775
        "paddw %%mm1, %%mm5                \n\t" /* d */\
1776
        "pmullw "MANGLE(ff_pw_20)", %%mm0                \n\t" /* 20a */\
1777
        "psubw %%mm5, %%mm0                \n\t" /* 20a - d */\
1778
        "paddw %6, %%mm6                \n\t"\
1779
        "paddw %%mm6, %%mm0                \n\t" /* 20a - 6b + 3c - d */\
1780
        "psraw $5, %%mm0                \n\t"\
1781
        "movq %%mm0, %5                        \n\t"\
1782
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1783
        \
1784
        "movq 5(%0), %%mm0                \n\t" /* FGHIJKLM */\
1785
        "movq %%mm0, %%mm5                \n\t" /* FGHIJKLM */\
1786
        "movq %%mm0, %%mm6                \n\t" /* FGHIJKLM */\
1787
        "psrlq $8, %%mm0                \n\t" /* GHIJKLM0 */\
1788
        "psrlq $16, %%mm5                \n\t" /* HIJKLM00 */\
1789
        "punpcklbw %%mm7, %%mm0                \n\t" /* 0G0H0I0J */\
1790
        "punpcklbw %%mm7, %%mm5                \n\t" /* 0H0I0J0K */\
1791
        "paddw %%mm0, %%mm2                \n\t" /* b */\
1792
        "paddw %%mm5, %%mm3                \n\t" /* c */\
1793
        "paddw %%mm2, %%mm2                \n\t" /* 2b */\
1794
        "psubw %%mm2, %%mm3                \n\t" /* c - 2b */\
1795
        "movq %%mm6, %%mm2                \n\t" /* FGHIJKLM */\
1796
        "psrlq $24, %%mm6                \n\t" /* IJKLM000 */\
1797
        "punpcklbw %%mm7, %%mm2                \n\t" /* 0F0G0H0I */\
1798
        "punpcklbw %%mm7, %%mm6                \n\t" /* 0I0J0K0L */\
1799
        "pmullw "MANGLE(ff_pw_3)", %%mm3                \n\t" /* 3c - 6b */\
1800
        "paddw %%mm2, %%mm1                \n\t" /* a */\
1801
        "paddw %%mm6, %%mm4                \n\t" /* d */\
1802
        "pmullw "MANGLE(ff_pw_20)", %%mm1                \n\t" /* 20a */\
1803
        "psubw %%mm4, %%mm3                \n\t" /* - 6b +3c - d */\
1804
        "paddw %6, %%mm1                \n\t"\
1805
        "paddw %%mm1, %%mm3                \n\t" /* 20a - 6b +3c - d */\
1806
        "psraw $5, %%mm3                \n\t"\
1807
        "movq %5, %%mm1                        \n\t"\
1808
        "packuswb %%mm3, %%mm1                \n\t"\
1809
        OP_MMX2(%%mm1, (%1),%%mm4, q)\
1810
        /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1811
        \
1812
        "movq 9(%0), %%mm1                \n\t" /* JKLMNOPQ */\
1813
        "movq %%mm1, %%mm4                \n\t" /* JKLMNOPQ */\
1814
        "movq %%mm1, %%mm3                \n\t" /* JKLMNOPQ */\
1815
        "psrlq $8, %%mm1                \n\t" /* KLMNOPQ0 */\
1816
        "psrlq $16, %%mm4                \n\t" /* LMNOPQ00 */\
1817
        "punpcklbw %%mm7, %%mm1                \n\t" /* 0K0L0M0N */\
1818
        "punpcklbw %%mm7, %%mm4                \n\t" /* 0L0M0N0O */\
1819
        "paddw %%mm1, %%mm5                \n\t" /* b */\
1820
        "paddw %%mm4, %%mm0                \n\t" /* c */\
1821
        "paddw %%mm5, %%mm5                \n\t" /* 2b */\
1822
        "psubw %%mm5, %%mm0                \n\t" /* c - 2b */\
1823
        "movq %%mm3, %%mm5                \n\t" /* JKLMNOPQ */\
1824
        "psrlq $24, %%mm3                \n\t" /* MNOPQ000 */\
1825
        "pmullw "MANGLE(ff_pw_3)", %%mm0                \n\t" /* 3c - 6b */\
1826
        "punpcklbw %%mm7, %%mm3                \n\t" /* 0M0N0O0P */\
1827
        "paddw %%mm3, %%mm2                \n\t" /* d */\
1828
        "psubw %%mm2, %%mm0                \n\t" /* -6b + 3c - d */\
1829
        "movq %%mm5, %%mm2                \n\t" /* JKLMNOPQ */\
1830
        "punpcklbw %%mm7, %%mm2                \n\t" /* 0J0K0L0M */\
1831
        "punpckhbw %%mm7, %%mm5                \n\t" /* 0N0O0P0Q */\
1832
        "paddw %%mm2, %%mm6                \n\t" /* a */\
1833
        "pmullw "MANGLE(ff_pw_20)", %%mm6                \n\t" /* 20a */\
1834
        "paddw %6, %%mm0                \n\t"\
1835
        "paddw %%mm6, %%mm0                \n\t" /* 20a - 6b + 3c - d */\
1836
        "psraw $5, %%mm0                \n\t"\
1837
        /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1838
        \
1839
        "paddw %%mm5, %%mm3                \n\t" /* a */\
1840
        "pshufw $0xF9, %%mm5, %%mm6        \n\t" /* 0O0P0Q0Q */\
1841
        "paddw %%mm4, %%mm6                \n\t" /* b */\
1842
        "pshufw $0xBE, %%mm5, %%mm4        \n\t" /* 0P0Q0Q0P */\
1843
        "pshufw $0x6F, %%mm5, %%mm5        \n\t" /* 0Q0Q0P0O */\
1844
        "paddw %%mm1, %%mm4                \n\t" /* c */\
1845
        "paddw %%mm2, %%mm5                \n\t" /* d */\
1846
        "paddw %%mm6, %%mm6                \n\t" /* 2b */\
1847
        "psubw %%mm6, %%mm4                \n\t" /* c - 2b */\
1848
        "pmullw "MANGLE(ff_pw_20)", %%mm3                \n\t" /* 20a */\
1849
        "pmullw "MANGLE(ff_pw_3)", %%mm4                \n\t" /* 3c - 6b */\
1850
        "psubw %%mm5, %%mm3                \n\t" /* -6b + 3c - d */\
1851
        "paddw %6, %%mm4                \n\t"\
1852
        "paddw %%mm3, %%mm4                \n\t" /* 20a - 6b + 3c - d */\
1853
        "psraw $5, %%mm4                \n\t"\
1854
        "packuswb %%mm4, %%mm0                \n\t"\
1855
        OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
1856
        \
1857
        "add %3, %0                        \n\t"\
1858
        "add %4, %1                        \n\t"\
1859
        "decl %2                        \n\t"\
1860
        " jnz 1b                                \n\t"\
1861
        : "+a"(src), "+c"(dst), "+m"(h)\
1862
        : "d"((long)srcStride), "S"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1863
        : "memory"\
1864
    );\
1865
}\
1866
\
1867
static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1868
    int i;\
1869
    int16_t temp[16];\
1870
    /* quick HACK, XXX FIXME MUST be optimized */\
1871
    for(i=0; i<h; i++)\
1872
    {\
1873
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1874
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1875
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1876
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1877
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1878
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1879
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1880
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1881
        temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1882
        temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1883
        temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1884
        temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1885
        temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1886
        temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1887
        temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1888
        temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1889
        asm volatile(\
1890
            "movq (%0), %%mm0                \n\t"\
1891
            "movq 8(%0), %%mm1                \n\t"\
1892
            "paddw %2, %%mm0                \n\t"\
1893
            "paddw %2, %%mm1                \n\t"\
1894
            "psraw $5, %%mm0                \n\t"\
1895
            "psraw $5, %%mm1                \n\t"\
1896
            "packuswb %%mm1, %%mm0        \n\t"\
1897
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1898
            "movq 16(%0), %%mm0                \n\t"\
1899
            "movq 24(%0), %%mm1                \n\t"\
1900
            "paddw %2, %%mm0                \n\t"\
1901
            "paddw %2, %%mm1                \n\t"\
1902
            "psraw $5, %%mm0                \n\t"\
1903
            "psraw $5, %%mm1                \n\t"\
1904
            "packuswb %%mm1, %%mm0        \n\t"\
1905
            OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
1906
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1907
            : "memory"\
1908
        );\
1909
        dst+=dstStride;\
1910
        src+=srcStride;\
1911
    }\
1912
}\
1913
\
1914
static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1915
    uint64_t temp;\
1916
\
1917
    asm volatile(\
1918
        "pxor %%mm7, %%mm7                \n\t"\
1919
        "1:                                \n\t"\
1920
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1921
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1922
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1923
        "punpcklbw %%mm7, %%mm0                \n\t" /* 0A0B0C0D */\
1924
        "punpckhbw %%mm7, %%mm1                \n\t" /* 0E0F0G0H */\
1925
        "pshufw $0x90, %%mm0, %%mm5        \n\t" /* 0A0A0B0C */\
1926
        "pshufw $0x41, %%mm0, %%mm6        \n\t" /* 0B0A0A0B */\
1927
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1928
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1929
        "psllq $8, %%mm2                \n\t" /* 0ABCDEFG */\
1930
        "psllq $16, %%mm3                \n\t" /* 00ABCDEF */\
1931
        "psllq $24, %%mm4                \n\t" /* 000ABCDE */\
1932
        "punpckhbw %%mm7, %%mm2                \n\t" /* 0D0E0F0G */\
1933
        "punpckhbw %%mm7, %%mm3                \n\t" /* 0C0D0E0F */\
1934
        "punpckhbw %%mm7, %%mm4                \n\t" /* 0B0C0D0E */\
1935
        "paddw %%mm3, %%mm5                \n\t" /* b */\
1936
        "paddw %%mm2, %%mm6                \n\t" /* c */\
1937
        "paddw %%mm5, %%mm5                \n\t" /* 2b */\
1938
        "psubw %%mm5, %%mm6                \n\t" /* c - 2b */\
1939
        "pshufw $0x06, %%mm0, %%mm5        \n\t" /* 0C0B0A0A */\
1940
        "pmullw "MANGLE(ff_pw_3)", %%mm6                \n\t" /* 3c - 6b */\
1941
        "paddw %%mm4, %%mm0                \n\t" /* a */\
1942
        "paddw %%mm1, %%mm5                \n\t" /* d */\
1943
        "pmullw "MANGLE(ff_pw_20)", %%mm0                \n\t" /* 20a */\
1944
        "psubw %%mm5, %%mm0                \n\t" /* 20a - d */\
1945
        "paddw %6, %%mm6                \n\t"\
1946
        "paddw %%mm6, %%mm0                \n\t" /* 20a - 6b + 3c - d */\
1947
        "psraw $5, %%mm0                \n\t"\
1948
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1949
        \
1950
        "movd 5(%0), %%mm5                \n\t" /* FGHI */\
1951
        "punpcklbw %%mm7, %%mm5                \n\t" /* 0F0G0H0I */\
1952
        "pshufw $0xF9, %%mm5, %%mm6        \n\t" /* 0G0H0I0I */\
1953
        "paddw %%mm5, %%mm1                \n\t" /* a */\
1954
        "paddw %%mm6, %%mm2                \n\t" /* b */\
1955
        "pshufw $0xBE, %%mm5, %%mm6        \n\t" /* 0H0I0I0H */\
1956
        "pshufw $0x6F, %%mm5, %%mm5        \n\t" /* 0I0I0H0G */\
1957
        "paddw %%mm6, %%mm3                \n\t" /* c */\
1958
        "paddw %%mm5, %%mm4                \n\t" /* d */\
1959
        "paddw %%mm2, %%mm2                \n\t" /* 2b */\
1960
        "psubw %%mm2, %%mm3                \n\t" /* c - 2b */\
1961
        "pmullw "MANGLE(ff_pw_20)", %%mm1                \n\t" /* 20a */\
1962
        "pmullw "MANGLE(ff_pw_3)", %%mm3                \n\t" /* 3c - 6b */\
1963
        "psubw %%mm4, %%mm3                \n\t" /* -6b + 3c - d */\
1964
        "paddw %6, %%mm1                \n\t"\
1965
        "paddw %%mm1, %%mm3                \n\t" /* 20a - 6b + 3c - d */\
1966
        "psraw $5, %%mm3                \n\t"\
1967
        "packuswb %%mm3, %%mm0                \n\t"\
1968
        OP_MMX2(%%mm0, (%1), %%mm4, q)\
1969
        \
1970
        "add %3, %0                        \n\t"\
1971
        "add %4, %1                        \n\t"\
1972
        "decl %2                        \n\t"\
1973
        " jnz 1b                        \n\t"\
1974
        : "+a"(src), "+c"(dst), "+m"(h)\
1975
        : "S"((long)srcStride), "D"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1976
        : "memory"\
1977
    );\
1978
}\
1979
\
1980
static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1981
    int i;\
1982
    int16_t temp[8];\
1983
    /* quick HACK, XXX FIXME MUST be optimized */\
1984
    for(i=0; i<h; i++)\
1985
    {\
1986
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1987
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1988
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1989
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1990
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1991
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1992
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
1993
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
1994
        asm volatile(\
1995
            "movq (%0), %%mm0                \n\t"\
1996
            "movq 8(%0), %%mm1                \n\t"\
1997
            "paddw %2, %%mm0                \n\t"\
1998
            "paddw %2, %%mm1                \n\t"\
1999
            "psraw $5, %%mm0                \n\t"\
2000
            "psraw $5, %%mm1                \n\t"\
2001
            "packuswb %%mm1, %%mm0        \n\t"\
2002
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
2003
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
2004
            :"memory"\
2005
        );\
2006
        dst+=dstStride;\
2007
        src+=srcStride;\
2008
    }\
2009
}
2010

    
2011
#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
2012
\
2013
static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2014
    uint64_t temp[17*4];\
2015
    uint64_t *temp_ptr= temp;\
2016
    int count= 17;\
2017
\
2018
    /*FIXME unroll */\
2019
    asm volatile(\
2020
        "pxor %%mm7, %%mm7                \n\t"\
2021
        "1:                                \n\t"\
2022
        "movq (%0), %%mm0                \n\t"\
2023
        "movq (%0), %%mm1                \n\t"\
2024
        "movq 8(%0), %%mm2                \n\t"\
2025
        "movq 8(%0), %%mm3                \n\t"\
2026
        "punpcklbw %%mm7, %%mm0                \n\t"\
2027
        "punpckhbw %%mm7, %%mm1                \n\t"\
2028
        "punpcklbw %%mm7, %%mm2                \n\t"\
2029
        "punpckhbw %%mm7, %%mm3                \n\t"\
2030
        "movq %%mm0, (%1)                \n\t"\
2031
        "movq %%mm1, 17*8(%1)                \n\t"\
2032
        "movq %%mm2, 2*17*8(%1)                \n\t"\
2033
        "movq %%mm3, 3*17*8(%1)                \n\t"\
2034
        "add $8, %1                        \n\t"\
2035
        "add %3, %0                        \n\t"\
2036
        "decl %2                        \n\t"\
2037
        " jnz 1b                        \n\t"\
2038
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
2039
        : "r" ((long)srcStride)\
2040
        : "memory"\
2041
    );\
2042
    \
2043
    temp_ptr= temp;\
2044
    count=4;\
2045
    \
2046
/*FIXME reorder for speed */\
2047
    asm volatile(\
2048
        /*"pxor %%mm7, %%mm7                \n\t"*/\
2049
        "1:                                \n\t"\
2050
        "movq (%0), %%mm0                \n\t"\
2051
        "movq 8(%0), %%mm1                \n\t"\
2052
        "movq 16(%0), %%mm2                \n\t"\
2053
        "movq 24(%0), %%mm3                \n\t"\
2054
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
2055
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
2056
        "add %4, %1                        \n\t"\
2057
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
2058
        \
2059
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
2060
        "add %4, %1                        \n\t"\
2061
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
2062
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
2063
        "add %4, %1                        \n\t"\
2064
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
2065
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
2066
        "add %4, %1                        \n\t"\
2067
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
2068
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
2069
        "add %4, %1                        \n\t"\
2070
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
2071
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
2072
        "add %4, %1                        \n\t"\
2073
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
2074
        \
2075
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
2076
        "add %4, %1                        \n\t"  \
2077
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
2078
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
2079
        \
2080
        "add $136, %0                        \n\t"\
2081
        "add %6, %1                        \n\t"\
2082
        "decl %2                        \n\t"\
2083
        " jnz 1b                        \n\t"\
2084
        \
2085
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
2086
        : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(long)dstStride)\
2087
        :"memory"\
2088
    );\
2089
}\
2090
\
2091
static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2092
    uint64_t temp[9*2];\
2093
    uint64_t *temp_ptr= temp;\
2094
    int count= 9;\
2095
\
2096
    /*FIXME unroll */\
2097
    asm volatile(\
2098
        "pxor %%mm7, %%mm7                \n\t"\
2099
        "1:                                \n\t"\
2100
        "movq (%0), %%mm0                \n\t"\
2101
        "movq (%0), %%mm1                \n\t"\
2102
        "punpcklbw %%mm7, %%mm0                \n\t"\
2103
        "punpckhbw %%mm7, %%mm1                \n\t"\
2104
        "movq %%mm0, (%1)                \n\t"\
2105
        "movq %%mm1, 9*8(%1)                \n\t"\
2106
        "add $8, %1                        \n\t"\
2107
        "add %3, %0                        \n\t"\
2108
        "decl %2                        \n\t"\
2109
        " jnz 1b                        \n\t"\
2110
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
2111
        : "r" ((long)srcStride)\
2112
        : "memory"\
2113
    );\
2114
    \
2115
    temp_ptr= temp;\
2116
    count=2;\
2117
    \
2118
/*FIXME reorder for speed */\
2119
    asm volatile(\
2120
        /*"pxor %%mm7, %%mm7                \n\t"*/\
2121
        "1:                                \n\t"\
2122
        "movq (%0), %%mm0                \n\t"\
2123
        "movq 8(%0), %%mm1                \n\t"\
2124
        "movq 16(%0), %%mm2                \n\t"\
2125
        "movq 24(%0), %%mm3                \n\t"\
2126
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
2127
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
2128
        "add %4, %1                        \n\t"\
2129
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
2130
        \
2131
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
2132
        "add %4, %1                        \n\t"\
2133
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
2134
        \
2135
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
2136
        "add %4, %1                        \n\t"\
2137
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
2138
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
2139
                \
2140
        "add $72, %0                        \n\t"\
2141
        "add %6, %1                        \n\t"\
2142
        "decl %2                        \n\t"\
2143
        " jnz 1b                        \n\t"\
2144
         \
2145
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
2146
        : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(long)dstStride)\
2147
        : "memory"\
2148
   );\
2149
}\
2150
\
2151
static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
2152
    OPNAME ## pixels8_mmx(dst, src, stride, 8);\
2153
}\
2154
\
2155
static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2156
    uint64_t temp[8];\
2157
    uint8_t * const half= (uint8_t*)temp;\
2158
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
2159
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
2160
}\
2161
\
2162
static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2163
    OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
2164
}\
2165
\
2166
static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2167
    uint64_t temp[8];\
2168
    uint8_t * const half= (uint8_t*)temp;\
2169
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
2170
    OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
2171
}\
2172
\
2173
static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2174
    uint64_t temp[8];\
2175
    uint8_t * const half= (uint8_t*)temp;\
2176
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
2177
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
2178
}\
2179
\
2180
static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2181
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
2182
}\
2183
\
2184
static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2185
    uint64_t temp[8];\
2186
    uint8_t * const half= (uint8_t*)temp;\
2187
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
2188
    OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
2189
}\
2190
static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2191
    uint64_t half[8 + 9];\
2192
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2193
    uint8_t * const halfHV= ((uint8_t*)half);\
2194
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2195
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
2196
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2197
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
2198
}\
2199
static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2200
    uint64_t half[8 + 9];\
2201
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2202
    uint8_t * const halfHV= ((uint8_t*)half);\
2203
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2204
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
2205
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2206
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
2207
}\
2208
static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2209
    uint64_t half[8 + 9];\
2210
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2211
    uint8_t * const halfHV= ((uint8_t*)half);\
2212
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2213
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
2214
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2215
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
2216
}\
2217
static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2218
    uint64_t half[8 + 9];\
2219
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2220
    uint8_t * const halfHV= ((uint8_t*)half);\
2221
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2222
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
2223
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2224
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
2225
}\
2226
static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2227
    uint64_t half[8 + 9];\
2228
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2229
    uint8_t * const halfHV= ((uint8_t*)half);\
2230
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2231
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2232
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
2233
}\
2234
static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2235
    uint64_t half[8 + 9];\
2236
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
2237
    uint8_t * const halfHV= ((uint8_t*)half);\
2238
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2239
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
2240
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
2241
}\
2242
static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2243
    uint64_t half[8 + 9];\
2244
    uint8_t * const halfH= ((uint8_t*)half);\
2245
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2246
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
2247
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
2248
}\
2249
static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2250
    uint64_t half[8 + 9];\
2251
    uint8_t * const halfH= ((uint8_t*)half);\
2252
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2253
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
2254
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
2255
}\
2256
static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2257
    uint64_t half[9];\
2258
    uint8_t * const halfH= ((uint8_t*)half);\
2259
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
2260
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
2261
}\
2262
static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
2263
    OPNAME ## pixels16_mmx(dst, src, stride, 16);\
2264
}\
2265
\
2266
static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2267
    uint64_t temp[32];\
2268
    uint8_t * const half= (uint8_t*)temp;\
2269
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
2270
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
2271
}\
2272
\
2273
static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2274
    OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
2275
}\
2276
\
2277
static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2278
    uint64_t temp[32];\
2279
    uint8_t * const half= (uint8_t*)temp;\
2280
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
2281
    OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
2282
}\
2283
\
2284
static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2285
    uint64_t temp[32];\
2286
    uint8_t * const half= (uint8_t*)temp;\
2287
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
2288
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
2289
}\
2290
\
2291
static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2292
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
2293
}\
2294
\
2295
static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2296
    uint64_t temp[32];\
2297
    uint8_t * const half= (uint8_t*)temp;\
2298
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
2299
    OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
2300
}\
2301
static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2302
    uint64_t half[16*2 + 17*2];\
2303
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2304
    uint8_t * const halfHV= ((uint8_t*)half);\
2305
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2306
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
2307
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2308
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
2309
}\
2310
static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2311
    uint64_t half[16*2 + 17*2];\
2312
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2313
    uint8_t * const halfHV= ((uint8_t*)half);\
2314
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2315
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
2316
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2317
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
2318
}\
2319
static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2320
    uint64_t half[16*2 + 17*2];\
2321
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2322
    uint8_t * const halfHV= ((uint8_t*)half);\
2323
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2324
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
2325
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2326
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
2327
}\
2328
static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2329
    uint64_t half[16*2 + 17*2];\
2330
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2331
    uint8_t * const halfHV= ((uint8_t*)half);\
2332
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2333
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
2334
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2335
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
2336
}\
2337
static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2338
    uint64_t half[16*2 + 17*2];\
2339
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2340
    uint8_t * const halfHV= ((uint8_t*)half);\
2341
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2342
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2343
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
2344
}\
2345
static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2346
    uint64_t half[16*2 + 17*2];\
2347
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
2348
    uint8_t * const halfHV= ((uint8_t*)half);\
2349
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2350
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
2351
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
2352
}\
2353
static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2354
    uint64_t half[17*2];\
2355
    uint8_t * const halfH= ((uint8_t*)half);\
2356
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2357
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
2358
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
2359
}\
2360
static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2361
    uint64_t half[17*2];\
2362
    uint8_t * const halfH= ((uint8_t*)half);\
2363
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2364
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
2365
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
2366
}\
2367
static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
2368
    uint64_t half[17*2];\
2369
    uint8_t * const halfH= ((uint8_t*)half);\
2370
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
2371
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
2372
}
2373

    
2374
#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "        \n\t"
2375
#define AVG_3DNOW_OP(a,b,temp, size) \
2376
"mov" #size " " #b ", " #temp "        \n\t"\
2377
"pavgusb " #temp ", " #a "        \n\t"\
2378
"mov" #size " " #a ", " #b "        \n\t"
2379
#define AVG_MMX2_OP(a,b,temp, size) \
2380
"mov" #size " " #b ", " #temp "        \n\t"\
2381
"pavgb " #temp ", " #a "        \n\t"\
2382
"mov" #size " " #a ", " #b "        \n\t"
2383

    
2384
QPEL_BASE(put_       , ff_pw_16, _       , PUT_OP, PUT_OP)
2385
QPEL_BASE(avg_       , ff_pw_16, _       , AVG_MMX2_OP, AVG_3DNOW_OP)
2386
QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
2387
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, 3dnow)
2388
QPEL_OP(avg_       , ff_pw_16, _       , AVG_3DNOW_OP, 3dnow)
2389
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
2390
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, mmx2)
2391
QPEL_OP(avg_       , ff_pw_16, _       , AVG_MMX2_OP, mmx2)
2392
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
2393

    
2394
#if 0
2395
static void just_return() { return; }
2396
#endif
2397

    
2398
#define SET_QPEL_FUNC(postfix1, postfix2) \
2399
    c->put_ ## postfix1 = put_ ## postfix2;\
2400
    c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
2401
    c->avg_ ## postfix1 = avg_ ## postfix2;
2402

    
2403
static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
2404
    long i=0;
2405
    
2406
    assert(ABS(scale) < 256);
2407
    scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2408

    
2409
    asm volatile(
2410
        "pcmpeqw %%mm6, %%mm6                \n\t" // -1w
2411
        "psrlw $15, %%mm6                \n\t" //  1w
2412
        "pxor %%mm7, %%mm7                \n\t"
2413
        "movd  %4, %%mm5                \n\t" 
2414
        "punpcklwd %%mm5, %%mm5                \n\t" 
2415
        "punpcklwd %%mm5, %%mm5                \n\t" 
2416
        "1:                                \n\t"
2417
        "movq  (%1, %0), %%mm0                \n\t" 
2418
        "movq  8(%1, %0), %%mm1                \n\t"
2419
        "pmulhw %%mm5, %%mm0                \n\t"
2420
        "pmulhw %%mm5, %%mm1                \n\t"
2421
        "paddw %%mm6, %%mm0                \n\t"
2422
        "paddw %%mm6, %%mm1                \n\t"
2423
        "psraw $1, %%mm0                \n\t"
2424
        "psraw $1, %%mm1                \n\t"
2425
        "paddw (%2, %0), %%mm0                \n\t"
2426
        "paddw 8(%2, %0), %%mm1                \n\t"
2427
        "psraw $6, %%mm0                \n\t"
2428
        "psraw $6, %%mm1                \n\t"
2429
        "pmullw (%3, %0), %%mm0                \n\t"
2430
        "pmullw 8(%3, %0), %%mm1        \n\t"
2431
        "pmaddwd %%mm0, %%mm0                \n\t"
2432
        "pmaddwd %%mm1, %%mm1                \n\t"
2433
        "paddd %%mm1, %%mm0                \n\t"
2434
        "psrld $4, %%mm0                \n\t"
2435
        "paddd %%mm0, %%mm7                \n\t"
2436
        "add $16, %0                        \n\t"
2437
        "cmp $128, %0                        \n\t" //FIXME optimize & bench
2438
        " jb 1b                                \n\t"
2439
        "movq %%mm7, %%mm6                \n\t"
2440
        "psrlq $32, %%mm7                \n\t"
2441
        "paddd %%mm6, %%mm7                \n\t"
2442
        "psrld $2, %%mm7                \n\t"
2443
        "movd %%mm7, %0                        \n\t"
2444
        
2445
        : "+r" (i)
2446
        : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
2447
    );
2448
    return i;
2449
}
2450

    
2451
static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){
2452
    long i=0;
2453
    
2454
    if(ABS(scale) < 256){
2455
        scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT;
2456
        asm volatile(
2457
                "pcmpeqw %%mm6, %%mm6                \n\t" // -1w
2458
                "psrlw $15, %%mm6                \n\t" //  1w
2459
                "movd  %3, %%mm5                \n\t" 
2460
                "punpcklwd %%mm5, %%mm5                \n\t" 
2461
                "punpcklwd %%mm5, %%mm5                \n\t" 
2462
                "1:                                \n\t"
2463
                "movq  (%1, %0), %%mm0                \n\t" 
2464
                "movq  8(%1, %0), %%mm1                \n\t"
2465
                "pmulhw %%mm5, %%mm0                \n\t"
2466
                "pmulhw %%mm5, %%mm1                \n\t"
2467
                "paddw %%mm6, %%mm0                \n\t" 
2468
                "paddw %%mm6, %%mm1                \n\t"
2469
                "psraw $1, %%mm0                \n\t"
2470
                "psraw $1, %%mm1                \n\t"
2471
                "paddw (%2, %0), %%mm0                \n\t"
2472
                "paddw 8(%2, %0), %%mm1                \n\t"
2473
                "movq %%mm0, (%2, %0)                \n\t"
2474
                "movq %%mm1, 8(%2, %0)                \n\t"
2475
                "add $16, %0                        \n\t"
2476
                "cmp $128, %0                        \n\t" //FIXME optimize & bench
2477
                " jb 1b                                \n\t"
2478
                
2479
                : "+r" (i)
2480
                : "r"(basis), "r"(rem), "g"(scale)
2481
        );
2482
    }else{
2483
        for(i=0; i<8*8; i++){
2484
            rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
2485
        }    
2486
    }
2487
}
2488

    
2489
#include "h264dsp_mmx.c"
2490
    
2491
/* external functions, from idct_mmx.c */
2492
void ff_mmx_idct(DCTELEM *block);
2493
void ff_mmxext_idct(DCTELEM *block);
2494

    
2495
void ff_vp3_idct_sse2(int16_t *input_data);
2496
void ff_vp3_idct_mmx(int16_t *data);
2497
void ff_vp3_dsp_init_mmx(void);
2498

    
2499
/* XXX: those functions should be suppressed ASAP when all IDCTs are
2500
   converted */
2501
static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2502
{
2503
    ff_mmx_idct (block);
2504
    put_pixels_clamped_mmx(block, dest, line_size);
2505
}
2506
static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2507
{
2508
    ff_mmx_idct (block);
2509
    add_pixels_clamped_mmx(block, dest, line_size);
2510
}
2511
static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
2512
{
2513
    ff_mmxext_idct (block);
2514
    put_pixels_clamped_mmx(block, dest, line_size);
2515
}
2516
static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
2517
{
2518
    ff_mmxext_idct (block);
2519
    add_pixels_clamped_mmx(block, dest, line_size);
2520
}
2521
static void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
2522
{
2523
    ff_vp3_idct_sse2(block);
2524
    put_signed_pixels_clamped_mmx(block, dest, line_size);
2525
}
2526
static void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
2527
{
2528
    ff_vp3_idct_sse2(block);
2529
    add_pixels_clamped_mmx(block, dest, line_size);
2530
}
2531
static void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
2532
{
2533
    ff_vp3_idct_mmx(block);
2534
    put_signed_pixels_clamped_mmx(block, dest, line_size);
2535
}
2536
static void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block)
2537
{
2538
    ff_vp3_idct_mmx(block);
2539
    add_pixels_clamped_mmx(block, dest, line_size);
2540
}
2541
#ifdef CONFIG_GPL
2542
static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
2543
{
2544
    ff_idct_xvid_mmx (block);
2545
    put_pixels_clamped_mmx(block, dest, line_size);
2546
}
2547
static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
2548
{
2549
    ff_idct_xvid_mmx (block);
2550
    add_pixels_clamped_mmx(block, dest, line_size);
2551
}
2552
static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
2553
{
2554
    ff_idct_xvid_mmx2 (block);
2555
    put_pixels_clamped_mmx(block, dest, line_size);
2556
}
2557
static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
2558
{
2559
    ff_idct_xvid_mmx2 (block);
2560
    add_pixels_clamped_mmx(block, dest, line_size);
2561
}
2562
#endif
2563
    
2564
void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2565
{
2566
    mm_flags = mm_support();
2567

    
2568
    if (avctx->dsp_mask) {
2569
        if (avctx->dsp_mask & FF_MM_FORCE)
2570
            mm_flags |= (avctx->dsp_mask & 0xffff);
2571
        else
2572
            mm_flags &= ~(avctx->dsp_mask & 0xffff);
2573
    }
2574

    
2575
#if 0
2576
    av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
2577
    if (mm_flags & MM_MMX)
2578
        av_log(avctx, AV_LOG_INFO, " mmx");
2579
    if (mm_flags & MM_MMXEXT)
2580
        av_log(avctx, AV_LOG_INFO, " mmxext");
2581
    if (mm_flags & MM_3DNOW)
2582
        av_log(avctx, AV_LOG_INFO, " 3dnow");
2583
    if (mm_flags & MM_SSE)
2584
        av_log(avctx, AV_LOG_INFO, " sse");
2585
    if (mm_flags & MM_SSE2)
2586
        av_log(avctx, AV_LOG_INFO, " sse2");
2587
    av_log(avctx, AV_LOG_INFO, "\n");
2588
#endif
2589

    
2590
    if (mm_flags & MM_MMX) {
2591
        const int idct_algo= avctx->idct_algo;
2592

    
2593
#ifdef CONFIG_ENCODERS
2594
        const int dct_algo = avctx->dct_algo;
2595
        if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
2596
            if(mm_flags & MM_SSE2){
2597
                c->fdct = ff_fdct_sse2;
2598
            }else if(mm_flags & MM_MMXEXT){
2599
                c->fdct = ff_fdct_mmx2;
2600
            }else{
2601
                c->fdct = ff_fdct_mmx;
2602
            }
2603
        }
2604
#endif //CONFIG_ENCODERS
2605
        if(avctx->lowres==0){
2606
            if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
2607
                c->idct_put= ff_simple_idct_put_mmx;
2608
                c->idct_add= ff_simple_idct_add_mmx;
2609
                c->idct    = ff_simple_idct_mmx;
2610
                c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
2611
            }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
2612
                if(mm_flags & MM_MMXEXT){
2613
                    c->idct_put= ff_libmpeg2mmx2_idct_put;
2614
                    c->idct_add= ff_libmpeg2mmx2_idct_add;
2615
                    c->idct    = ff_mmxext_idct;
2616
                }else{
2617
                    c->idct_put= ff_libmpeg2mmx_idct_put;
2618
                    c->idct_add= ff_libmpeg2mmx_idct_add;
2619
                    c->idct    = ff_mmx_idct;
2620
                }
2621
                c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
2622
            }else if(idct_algo==FF_IDCT_VP3){
2623
                if(mm_flags & MM_SSE2){
2624
                    c->idct_put= ff_vp3_idct_put_sse2;
2625
                    c->idct_add= ff_vp3_idct_add_sse2;
2626
                    c->idct    = ff_vp3_idct_sse2;
2627
                    c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2628
                }else{
2629
                    ff_vp3_dsp_init_mmx();
2630
                    c->idct_put= ff_vp3_idct_put_mmx;
2631
                    c->idct_add= ff_vp3_idct_add_mmx;
2632
                    c->idct    = ff_vp3_idct_mmx;
2633
                    c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
2634
                }
2635
#ifdef CONFIG_GPL
2636
            }else if(idct_algo==FF_IDCT_XVIDMMX){
2637
                if(mm_flags & MM_MMXEXT){
2638
                    c->idct_put= ff_idct_xvid_mmx2_put;
2639
                    c->idct_add= ff_idct_xvid_mmx2_add;
2640
                    c->idct    = ff_idct_xvid_mmx2;
2641
                }else{
2642
                    c->idct_put= ff_idct_xvid_mmx_put;
2643
                    c->idct_add= ff_idct_xvid_mmx_add;
2644
                    c->idct    = ff_idct_xvid_mmx;
2645
                }
2646
#endif
2647
            }
2648
        }
2649

    
2650
#ifdef CONFIG_ENCODERS
2651
        c->get_pixels = get_pixels_mmx;
2652
        c->diff_pixels = diff_pixels_mmx;
2653
#endif //CONFIG_ENCODERS
2654
        c->put_pixels_clamped = put_pixels_clamped_mmx;
2655
        c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx;
2656
        c->add_pixels_clamped = add_pixels_clamped_mmx;
2657
        c->clear_blocks = clear_blocks_mmx;
2658
#ifdef CONFIG_ENCODERS
2659
        c->pix_sum = pix_sum16_mmx;
2660
#endif //CONFIG_ENCODERS
2661

    
2662
        c->put_pixels_tab[0][0] = put_pixels16_mmx;
2663
        c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
2664
        c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
2665
        c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
2666

    
2667
        c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
2668
        c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
2669
        c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
2670
        c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
2671

    
2672
        c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
2673
        c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
2674
        c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
2675
        c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
2676

    
2677
        c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
2678
        c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
2679
        c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
2680
        c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
2681

    
2682
        c->put_pixels_tab[1][0] = put_pixels8_mmx;
2683
        c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
2684
        c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
2685
        c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
2686

    
2687
        c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
2688
        c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
2689
        c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
2690
        c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
2691

    
2692
        c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
2693
        c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
2694
        c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
2695
        c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
2696

    
2697
        c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
2698
        c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
2699
        c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
2700
        c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
2701
                
2702
        c->add_bytes= add_bytes_mmx;
2703
#ifdef CONFIG_ENCODERS
2704
        c->diff_bytes= diff_bytes_mmx;
2705
        
2706
        c->hadamard8_diff[0]= hadamard8_diff16_mmx;
2707
        c->hadamard8_diff[1]= hadamard8_diff_mmx;
2708
        
2709
        c->pix_norm1 = pix_norm1_mmx;
2710
        c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx;
2711
          c->sse[1] = sse8_mmx;
2712
        c->vsad[4]= vsad_intra16_mmx;
2713

    
2714
        c->nsse[0] = nsse16_mmx;
2715
        c->nsse[1] = nsse8_mmx;
2716
        if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2717
            c->vsad[0] = vsad16_mmx;
2718
        }
2719
        
2720
        if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2721
            c->try_8x8basis= try_8x8basis_mmx;
2722
        }
2723
        c->add_8x8basis= add_8x8basis_mmx;
2724
        
2725
#endif //CONFIG_ENCODERS
2726

    
2727
        c->h263_v_loop_filter= h263_v_loop_filter_mmx;
2728
        c->h263_h_loop_filter= h263_h_loop_filter_mmx;        
2729
        c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx;
2730
        c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx;
2731
        
2732
        if (mm_flags & MM_MMXEXT) {
2733
            c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2734
            c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
2735

    
2736
            c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2737
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2738
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
2739

    
2740
            c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2741
            c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
2742

    
2743
            c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2744
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2745
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
2746

    
2747
#ifdef CONFIG_ENCODERS
2748
            c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
2749
            c->hadamard8_diff[1]= hadamard8_diff_mmx2;
2750
            c->vsad[4]= vsad_intra16_mmx2;
2751
#endif //CONFIG_ENCODERS
2752

    
2753
            c->h264_idct_add= ff_h264_idct_add_mmx2;
2754

    
2755
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2756
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2757
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2758
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2759
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2760
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2761
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
2762
#ifdef CONFIG_ENCODERS
2763
                c->vsad[0] = vsad16_mmx2;
2764
#endif //CONFIG_ENCODERS
2765
            }
2766

    
2767
#if 1
2768
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
2769
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
2770
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
2771
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
2772
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
2773
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
2774
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
2775
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
2776
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
2777
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
2778
            SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
2779
            SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
2780
            SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
2781
            SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
2782
            SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
2783
            SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
2784
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
2785
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
2786
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
2787
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
2788
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
2789
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
2790
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
2791
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
2792
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
2793
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
2794
            SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
2795
            SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
2796
            SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
2797
            SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
2798
            SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
2799
            SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
2800
#endif
2801

    
2802
//FIXME 3dnow too
2803
#define dspfunc(PFX, IDX, NUM) \
2804
    c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_mmx2; \
2805
    c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_mmx2; \
2806
    c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_mmx2; \
2807
    c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_mmx2; \
2808
    c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_mmx2; \
2809
    c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_mmx2; \
2810
    c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_mmx2; \
2811
    c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_mmx2; \
2812
    c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_mmx2; \
2813
    c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_mmx2; \
2814
    c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_mmx2; \
2815
    c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_mmx2; \
2816
    c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_mmx2; \
2817
    c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_mmx2; \
2818
    c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_mmx2; \
2819
    c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_mmx2
2820

    
2821
            dspfunc(put_h264_qpel, 0, 16);
2822
            dspfunc(put_h264_qpel, 1, 8);
2823
            dspfunc(put_h264_qpel, 2, 4);
2824
            dspfunc(avg_h264_qpel, 0, 16);
2825
            dspfunc(avg_h264_qpel, 1, 8);
2826
            dspfunc(avg_h264_qpel, 2, 4);
2827
#undef dspfunc
2828

    
2829
            c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2;
2830
            c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2;
2831
            c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2;
2832
            c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2;
2833
            c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2;
2834
            c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2;
2835
            c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2;
2836
            c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2;
2837

    
2838
            c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2;
2839
            c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2;
2840
            c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2;
2841
            c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2;
2842
            c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2;
2843
            c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2;
2844
            c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2;
2845
            c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2;
2846

    
2847
            c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2;
2848
            c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2;
2849
            c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2;
2850
            c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2;
2851
            c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2;
2852
            c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2;
2853
            c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
2854
            c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
2855

    
2856
#ifdef CONFIG_ENCODERS
2857
            c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2;
2858
#endif //CONFIG_ENCODERS
2859
        } else if (mm_flags & MM_3DNOW) {
2860
            c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
2861
            c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
2862

    
2863
            c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
2864
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
2865
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
2866

    
2867
            c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
2868
            c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
2869

    
2870
            c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
2871
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
2872
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
2873

    
2874
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2875
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
2876
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
2877
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
2878
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
2879
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
2880
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
2881
            }
2882

    
2883
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
2884
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
2885
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
2886
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
2887
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
2888
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
2889
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
2890
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
2891
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
2892
            SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
2893
            SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
2894
            SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
2895
            SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
2896
            SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
2897
            SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
2898
            SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
2899
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
2900
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
2901
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
2902
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
2903
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
2904
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
2905
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
2906
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
2907
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
2908
            SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
2909
            SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
2910
            SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
2911
            SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
2912
            SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
2913
            SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
2914
            SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
2915

    
2916
#define dspfunc(PFX, IDX, NUM) \
2917
    c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_3dnow; \
2918
    c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_3dnow; \
2919
    c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_3dnow; \
2920
    c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_3dnow; \
2921
    c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_3dnow; \
2922
    c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_3dnow; \
2923
    c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_3dnow; \
2924
    c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_3dnow; \
2925
    c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_3dnow; \
2926
    c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_3dnow; \
2927
    c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_3dnow; \
2928
    c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_3dnow; \
2929
    c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_3dnow; \
2930
    c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_3dnow; \
2931
    c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_3dnow; \
2932
    c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_3dnow
2933

    
2934
            dspfunc(put_h264_qpel, 0, 16);
2935
            dspfunc(put_h264_qpel, 1, 8);
2936
            dspfunc(put_h264_qpel, 2, 4);
2937
            dspfunc(avg_h264_qpel, 0, 16);
2938
            dspfunc(avg_h264_qpel, 1, 8);
2939
            dspfunc(avg_h264_qpel, 2, 4);
2940

    
2941
            c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow;
2942
            c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
2943
        }
2944
    }
2945
        
2946
#ifdef CONFIG_ENCODERS
2947
    dsputil_init_pix_mmx(c, avctx);
2948
#endif //CONFIG_ENCODERS
2949
#if 0
2950
    // for speed testing
2951
    get_pixels = just_return;
2952
    put_pixels_clamped = just_return;
2953
    add_pixels_clamped = just_return;
2954

2955
    pix_abs16x16 = just_return;
2956
    pix_abs16x16_x2 = just_return;
2957
    pix_abs16x16_y2 = just_return;
2958
    pix_abs16x16_xy2 = just_return;
2959

2960
    put_pixels_tab[0] = just_return;
2961
    put_pixels_tab[1] = just_return;
2962
    put_pixels_tab[2] = just_return;
2963
    put_pixels_tab[3] = just_return;
2964

2965
    put_no_rnd_pixels_tab[0] = just_return;
2966
    put_no_rnd_pixels_tab[1] = just_return;
2967
    put_no_rnd_pixels_tab[2] = just_return;
2968
    put_no_rnd_pixels_tab[3] = just_return;
2969

2970
    avg_pixels_tab[0] = just_return;
2971
    avg_pixels_tab[1] = just_return;
2972
    avg_pixels_tab[2] = just_return;
2973
    avg_pixels_tab[3] = just_return;
2974

2975
    avg_no_rnd_pixels_tab[0] = just_return;
2976
    avg_no_rnd_pixels_tab[1] = just_return;
2977
    avg_no_rnd_pixels_tab[2] = just_return;
2978
    avg_no_rnd_pixels_tab[3] = just_return;
2979

2980
    //av_fdct = just_return;
2981
    //ff_idct = just_return;
2982
#endif
2983
}