Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / dsputil_mmx.c @ 559738ef

History | View | Annotate | Download (123 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 file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 *
22
 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
23
 */
24

    
25
#include "libavutil/cpu.h"
26
#include "libavutil/x86_cpu.h"
27
#include "libavcodec/dsputil.h"
28
#include "libavcodec/h264dsp.h"
29
#include "libavcodec/mpegvideo.h"
30
#include "libavcodec/simple_idct.h"
31
#include "dsputil_mmx.h"
32
#include "idct_xvid.h"
33

    
34
//#undef NDEBUG
35
//#include <assert.h>
36

    
37
/* pixel operations */
38
DECLARE_ALIGNED(8,  const uint64_t, ff_bone) = 0x0101010101010101ULL;
39
DECLARE_ALIGNED(8,  const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
40

    
41
DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] =
42
{0x8000000080000000ULL, 0x8000000080000000ULL};
43

    
44
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_3  ) = 0x0003000300030003ULL;
45
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_4  ) = {0x0004000400040004ULL, 0x0004000400040004ULL};
46
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_5  ) = {0x0005000500050005ULL, 0x0005000500050005ULL};
47
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_8  ) = {0x0008000800080008ULL, 0x0008000800080008ULL};
48
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_9  ) = {0x0009000900090009ULL, 0x0009000900090009ULL};
49
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL;
50
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL};
51
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_17 ) = {0x0011001100110011ULL, 0x0011001100110011ULL};
52
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_18 ) = {0x0012001200120012ULL, 0x0012001200120012ULL};
53
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL;
54
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_27 ) = {0x001B001B001B001BULL, 0x001B001B001B001BULL};
55
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL};
56
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL};
57
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL;
58
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_53 ) = 0x0035003500350035ULL;
59
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_63 ) = {0x003F003F003F003FULL, 0x003F003F003F003FULL};
60
DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL};
61
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
62
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
63
DECLARE_ALIGNED(8,  const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
64

    
65
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_0  ) = {0x0000000000000000ULL, 0x0000000000000000ULL};
66
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_1  ) = {0x0101010101010101ULL, 0x0101010101010101ULL};
67
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_3  ) = {0x0303030303030303ULL, 0x0303030303030303ULL};
68
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_4  ) = {0x0404040404040404ULL, 0x0404040404040404ULL};
69
DECLARE_ALIGNED(8,  const uint64_t, ff_pb_7  ) = 0x0707070707070707ULL;
70
DECLARE_ALIGNED(8,  const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL;
71
DECLARE_ALIGNED(8,  const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL;
72
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_80 ) = {0x8080808080808080ULL, 0x8080808080808080ULL};
73
DECLARE_ALIGNED(8,  const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL;
74
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_A1 ) = {0xA1A1A1A1A1A1A1A1ULL, 0xA1A1A1A1A1A1A1A1ULL};
75
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_F8 ) = {0xF8F8F8F8F8F8F8F8ULL, 0xF8F8F8F8F8F8F8F8ULL};
76
DECLARE_ALIGNED(8,  const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL;
77
DECLARE_ALIGNED(16, const xmm_reg,  ff_pb_FE ) = {0xFEFEFEFEFEFEFEFEULL, 0xFEFEFEFEFEFEFEFEULL};
78

    
79
DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
80
DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
81

    
82
#define JUMPALIGN() __asm__ volatile (ASMALIGN(3)::)
83
#define MOVQ_ZERO(regd)  __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
84

    
85
#define MOVQ_BFE(regd) \
86
    __asm__ volatile ( \
87
    "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
88
    "paddb %%" #regd ", %%" #regd " \n\t" ::)
89

    
90
#ifndef PIC
91
#define MOVQ_BONE(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
92
#define MOVQ_WTWO(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
93
#else
94
// for shared library it's better to use this way for accessing constants
95
// pcmpeqd -> -1
96
#define MOVQ_BONE(regd) \
97
    __asm__ volatile ( \
98
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
99
    "psrlw $15, %%" #regd " \n\t" \
100
    "packuswb %%" #regd ", %%" #regd " \n\t" ::)
101

    
102
#define MOVQ_WTWO(regd) \
103
    __asm__ volatile ( \
104
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
105
    "psrlw $15, %%" #regd " \n\t" \
106
    "psllw $1, %%" #regd " \n\t"::)
107

    
108
#endif
109

    
110
// using regr as temporary and for the output result
111
// first argument is unmodifed and second is trashed
112
// regfe is supposed to contain 0xfefefefefefefefe
113
#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
114
    "movq " #rega ", " #regr "  \n\t"\
115
    "pand " #regb ", " #regr "  \n\t"\
116
    "pxor " #rega ", " #regb "  \n\t"\
117
    "pand " #regfe "," #regb "  \n\t"\
118
    "psrlq $1, " #regb "        \n\t"\
119
    "paddb " #regb ", " #regr " \n\t"
120

    
121
#define PAVGB_MMX(rega, regb, regr, regfe) \
122
    "movq " #rega ", " #regr "  \n\t"\
123
    "por  " #regb ", " #regr "  \n\t"\
124
    "pxor " #rega ", " #regb "  \n\t"\
125
    "pand " #regfe "," #regb "  \n\t"\
126
    "psrlq $1, " #regb "        \n\t"\
127
    "psubb " #regb ", " #regr " \n\t"
128

    
129
// mm6 is supposed to contain 0xfefefefefefefefe
130
#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp) \
131
    "movq " #rega ", " #regr "  \n\t"\
132
    "movq " #regc ", " #regp "  \n\t"\
133
    "pand " #regb ", " #regr "  \n\t"\
134
    "pand " #regd ", " #regp "  \n\t"\
135
    "pxor " #rega ", " #regb "  \n\t"\
136
    "pxor " #regc ", " #regd "  \n\t"\
137
    "pand %%mm6, " #regb "      \n\t"\
138
    "pand %%mm6, " #regd "      \n\t"\
139
    "psrlq $1, " #regb "        \n\t"\
140
    "psrlq $1, " #regd "        \n\t"\
141
    "paddb " #regb ", " #regr " \n\t"\
142
    "paddb " #regd ", " #regp " \n\t"
143

    
144
#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
145
    "movq " #rega ", " #regr "  \n\t"\
146
    "movq " #regc ", " #regp "  \n\t"\
147
    "por  " #regb ", " #regr "  \n\t"\
148
    "por  " #regd ", " #regp "  \n\t"\
149
    "pxor " #rega ", " #regb "  \n\t"\
150
    "pxor " #regc ", " #regd "  \n\t"\
151
    "pand %%mm6, " #regb "      \n\t"\
152
    "pand %%mm6, " #regd "      \n\t"\
153
    "psrlq $1, " #regd "        \n\t"\
154
    "psrlq $1, " #regb "        \n\t"\
155
    "psubb " #regb ", " #regr " \n\t"\
156
    "psubb " #regd ", " #regp " \n\t"
157

    
158
/***********************************/
159
/* MMX no rounding */
160
#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
161
#define SET_RND  MOVQ_WONE
162
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
163
#define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
164
#define OP_AVG(a, b, c, e)              PAVGB_MMX(a, b, c, e)
165

    
166
#include "dsputil_mmx_rnd_template.c"
167

    
168
#undef DEF
169
#undef SET_RND
170
#undef PAVGBP
171
#undef PAVGB
172
/***********************************/
173
/* MMX rounding */
174

    
175
#define DEF(x, y) x ## _ ## y ##_mmx
176
#define SET_RND  MOVQ_WTWO
177
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
178
#define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
179

    
180
#include "dsputil_mmx_rnd_template.c"
181

    
182
#undef DEF
183
#undef SET_RND
184
#undef PAVGBP
185
#undef PAVGB
186
#undef OP_AVG
187

    
188
/***********************************/
189
/* 3Dnow specific */
190

    
191
#define DEF(x) x ## _3dnow
192
#define PAVGB "pavgusb"
193
#define OP_AVG PAVGB
194

    
195
#include "dsputil_mmx_avg_template.c"
196

    
197
#undef DEF
198
#undef PAVGB
199
#undef OP_AVG
200

    
201
/***********************************/
202
/* MMX2 specific */
203

    
204
#define DEF(x) x ## _mmx2
205

    
206
/* Introduced only in MMX2 set */
207
#define PAVGB "pavgb"
208
#define OP_AVG PAVGB
209

    
210
#include "dsputil_mmx_avg_template.c"
211

    
212
#undef DEF
213
#undef PAVGB
214
#undef OP_AVG
215

    
216
#define put_no_rnd_pixels16_mmx put_pixels16_mmx
217
#define put_no_rnd_pixels8_mmx put_pixels8_mmx
218
#define put_pixels16_mmx2 put_pixels16_mmx
219
#define put_pixels8_mmx2 put_pixels8_mmx
220
#define put_pixels4_mmx2 put_pixels4_mmx
221
#define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
222
#define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
223
#define put_pixels16_3dnow put_pixels16_mmx
224
#define put_pixels8_3dnow put_pixels8_mmx
225
#define put_pixels4_3dnow put_pixels4_mmx
226
#define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
227
#define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
228

    
229
/***********************************/
230
/* standard MMX */
231

    
232
void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
233
{
234
    const DCTELEM *p;
235
    uint8_t *pix;
236

    
237
    /* read the pixels */
238
    p = block;
239
    pix = pixels;
240
    /* unrolled loop */
241
        __asm__ volatile(
242
                "movq   %3, %%mm0               \n\t"
243
                "movq   8%3, %%mm1              \n\t"
244
                "movq   16%3, %%mm2             \n\t"
245
                "movq   24%3, %%mm3             \n\t"
246
                "movq   32%3, %%mm4             \n\t"
247
                "movq   40%3, %%mm5             \n\t"
248
                "movq   48%3, %%mm6             \n\t"
249
                "movq   56%3, %%mm7             \n\t"
250
                "packuswb %%mm1, %%mm0          \n\t"
251
                "packuswb %%mm3, %%mm2          \n\t"
252
                "packuswb %%mm5, %%mm4          \n\t"
253
                "packuswb %%mm7, %%mm6          \n\t"
254
                "movq   %%mm0, (%0)             \n\t"
255
                "movq   %%mm2, (%0, %1)         \n\t"
256
                "movq   %%mm4, (%0, %1, 2)      \n\t"
257
                "movq   %%mm6, (%0, %2)         \n\t"
258
                ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
259
                :"memory");
260
        pix += line_size*4;
261
        p += 32;
262

    
263
    // if here would be an exact copy of the code above
264
    // compiler would generate some very strange code
265
    // thus using "r"
266
    __asm__ volatile(
267
            "movq       (%3), %%mm0             \n\t"
268
            "movq       8(%3), %%mm1            \n\t"
269
            "movq       16(%3), %%mm2           \n\t"
270
            "movq       24(%3), %%mm3           \n\t"
271
            "movq       32(%3), %%mm4           \n\t"
272
            "movq       40(%3), %%mm5           \n\t"
273
            "movq       48(%3), %%mm6           \n\t"
274
            "movq       56(%3), %%mm7           \n\t"
275
            "packuswb %%mm1, %%mm0              \n\t"
276
            "packuswb %%mm3, %%mm2              \n\t"
277
            "packuswb %%mm5, %%mm4              \n\t"
278
            "packuswb %%mm7, %%mm6              \n\t"
279
            "movq       %%mm0, (%0)             \n\t"
280
            "movq       %%mm2, (%0, %1)         \n\t"
281
            "movq       %%mm4, (%0, %1, 2)      \n\t"
282
            "movq       %%mm6, (%0, %2)         \n\t"
283
            ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
284
            :"memory");
285
}
286

    
287
DECLARE_ASM_CONST(8, uint8_t, ff_vector128)[8] =
288
  { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
289

    
290
#define put_signed_pixels_clamped_mmx_half(off) \
291
            "movq    "#off"(%2), %%mm1          \n\t"\
292
            "movq 16+"#off"(%2), %%mm2          \n\t"\
293
            "movq 32+"#off"(%2), %%mm3          \n\t"\
294
            "movq 48+"#off"(%2), %%mm4          \n\t"\
295
            "packsswb  8+"#off"(%2), %%mm1      \n\t"\
296
            "packsswb 24+"#off"(%2), %%mm2      \n\t"\
297
            "packsswb 40+"#off"(%2), %%mm3      \n\t"\
298
            "packsswb 56+"#off"(%2), %%mm4      \n\t"\
299
            "paddb %%mm0, %%mm1                 \n\t"\
300
            "paddb %%mm0, %%mm2                 \n\t"\
301
            "paddb %%mm0, %%mm3                 \n\t"\
302
            "paddb %%mm0, %%mm4                 \n\t"\
303
            "movq %%mm1, (%0)                   \n\t"\
304
            "movq %%mm2, (%0, %3)               \n\t"\
305
            "movq %%mm3, (%0, %3, 2)            \n\t"\
306
            "movq %%mm4, (%0, %1)               \n\t"
307

    
308
void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
309
{
310
    x86_reg line_skip = line_size;
311
    x86_reg line_skip3;
312

    
313
    __asm__ volatile (
314
            "movq "MANGLE(ff_vector128)", %%mm0 \n\t"
315
            "lea (%3, %3, 2), %1                \n\t"
316
            put_signed_pixels_clamped_mmx_half(0)
317
            "lea (%0, %3, 4), %0                \n\t"
318
            put_signed_pixels_clamped_mmx_half(64)
319
            :"+&r" (pixels), "=&r" (line_skip3)
320
            :"r" (block), "r"(line_skip)
321
            :"memory");
322
}
323

    
324
void ff_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
         ASMALIGN(3)
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"((x86_reg)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
         ASMALIGN(3)
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"((x86_reg)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
         ASMALIGN(3)
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"((x86_reg)line_size)
447
         : "%"REG_a, "memory"
448
        );
449
}
450

    
451
static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
452
{
453
    __asm__ volatile(
454
         "1:                            \n\t"
455
         "movdqu (%1), %%xmm0           \n\t"
456
         "movdqu (%1,%3), %%xmm1        \n\t"
457
         "movdqu (%1,%3,2), %%xmm2      \n\t"
458
         "movdqu (%1,%4), %%xmm3        \n\t"
459
         "movdqa %%xmm0, (%2)           \n\t"
460
         "movdqa %%xmm1, (%2,%3)        \n\t"
461
         "movdqa %%xmm2, (%2,%3,2)      \n\t"
462
         "movdqa %%xmm3, (%2,%4)        \n\t"
463
         "subl $4, %0                   \n\t"
464
         "lea (%1,%3,4), %1             \n\t"
465
         "lea (%2,%3,4), %2             \n\t"
466
         "jnz 1b                        \n\t"
467
         : "+g"(h), "+r" (pixels),  "+r" (block)
468
         : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
469
         : "memory"
470
        );
471
}
472

    
473
static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
474
{
475
    __asm__ volatile(
476
         "1:                            \n\t"
477
         "movdqu (%1), %%xmm0           \n\t"
478
         "movdqu (%1,%3), %%xmm1        \n\t"
479
         "movdqu (%1,%3,2), %%xmm2      \n\t"
480
         "movdqu (%1,%4), %%xmm3        \n\t"
481
         "pavgb  (%2), %%xmm0           \n\t"
482
         "pavgb  (%2,%3), %%xmm1        \n\t"
483
         "pavgb  (%2,%3,2), %%xmm2      \n\t"
484
         "pavgb  (%2,%4), %%xmm3        \n\t"
485
         "movdqa %%xmm0, (%2)           \n\t"
486
         "movdqa %%xmm1, (%2,%3)        \n\t"
487
         "movdqa %%xmm2, (%2,%3,2)      \n\t"
488
         "movdqa %%xmm3, (%2,%4)        \n\t"
489
         "subl $4, %0                   \n\t"
490
         "lea (%1,%3,4), %1             \n\t"
491
         "lea (%2,%3,4), %2             \n\t"
492
         "jnz 1b                        \n\t"
493
         : "+g"(h), "+r" (pixels),  "+r" (block)
494
         : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
495
         : "memory"
496
        );
497
}
498

    
499
#define CLEAR_BLOCKS(name,n) \
500
static void name(DCTELEM *blocks)\
501
{\
502
    __asm__ volatile(\
503
                "pxor %%mm7, %%mm7              \n\t"\
504
                "mov     %1, %%"REG_a"          \n\t"\
505
                "1:                             \n\t"\
506
                "movq %%mm7, (%0, %%"REG_a")    \n\t"\
507
                "movq %%mm7, 8(%0, %%"REG_a")   \n\t"\
508
                "movq %%mm7, 16(%0, %%"REG_a")  \n\t"\
509
                "movq %%mm7, 24(%0, %%"REG_a")  \n\t"\
510
                "add $32, %%"REG_a"             \n\t"\
511
                " js 1b                         \n\t"\
512
                : : "r" (((uint8_t *)blocks)+128*n),\
513
                    "i" (-128*n)\
514
                : "%"REG_a\
515
        );\
516
}
517
CLEAR_BLOCKS(clear_blocks_mmx, 6)
518
CLEAR_BLOCKS(clear_block_mmx, 1)
519

    
520
static void clear_block_sse(DCTELEM *block)
521
{
522
    __asm__ volatile(
523
        "xorps  %%xmm0, %%xmm0  \n"
524
        "movaps %%xmm0,    (%0) \n"
525
        "movaps %%xmm0,  16(%0) \n"
526
        "movaps %%xmm0,  32(%0) \n"
527
        "movaps %%xmm0,  48(%0) \n"
528
        "movaps %%xmm0,  64(%0) \n"
529
        "movaps %%xmm0,  80(%0) \n"
530
        "movaps %%xmm0,  96(%0) \n"
531
        "movaps %%xmm0, 112(%0) \n"
532
        :: "r"(block)
533
        : "memory"
534
    );
535
}
536

    
537
static void clear_blocks_sse(DCTELEM *blocks)
538
{\
539
    __asm__ volatile(
540
        "xorps  %%xmm0, %%xmm0  \n"
541
        "mov     %1, %%"REG_a"  \n"
542
        "1:                     \n"
543
        "movaps %%xmm0,    (%0, %%"REG_a") \n"
544
        "movaps %%xmm0,  16(%0, %%"REG_a") \n"
545
        "movaps %%xmm0,  32(%0, %%"REG_a") \n"
546
        "movaps %%xmm0,  48(%0, %%"REG_a") \n"
547
        "movaps %%xmm0,  64(%0, %%"REG_a") \n"
548
        "movaps %%xmm0,  80(%0, %%"REG_a") \n"
549
        "movaps %%xmm0,  96(%0, %%"REG_a") \n"
550
        "movaps %%xmm0, 112(%0, %%"REG_a") \n"
551
        "add $128, %%"REG_a"    \n"
552
        " js 1b                 \n"
553
        : : "r" (((uint8_t *)blocks)+128*6),
554
            "i" (-128*6)
555
        : "%"REG_a
556
    );
557
}
558

    
559
static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
560
    x86_reg i=0;
561
    __asm__ volatile(
562
        "jmp 2f                         \n\t"
563
        "1:                             \n\t"
564
        "movq  (%1, %0), %%mm0          \n\t"
565
        "movq  (%2, %0), %%mm1          \n\t"
566
        "paddb %%mm0, %%mm1             \n\t"
567
        "movq %%mm1, (%2, %0)           \n\t"
568
        "movq 8(%1, %0), %%mm0          \n\t"
569
        "movq 8(%2, %0), %%mm1          \n\t"
570
        "paddb %%mm0, %%mm1             \n\t"
571
        "movq %%mm1, 8(%2, %0)          \n\t"
572
        "add $16, %0                    \n\t"
573
        "2:                             \n\t"
574
        "cmp %3, %0                     \n\t"
575
        " js 1b                         \n\t"
576
        : "+r" (i)
577
        : "r"(src), "r"(dst), "r"((x86_reg)w-15)
578
    );
579
    for(; i<w; i++)
580
        dst[i+0] += src[i+0];
581
}
582

    
583
static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
584
    x86_reg i=0;
585
    __asm__ volatile(
586
        "jmp 2f                         \n\t"
587
        "1:                             \n\t"
588
        "movq   (%2, %0), %%mm0         \n\t"
589
        "movq  8(%2, %0), %%mm1         \n\t"
590
        "paddb  (%3, %0), %%mm0         \n\t"
591
        "paddb 8(%3, %0), %%mm1         \n\t"
592
        "movq %%mm0,  (%1, %0)          \n\t"
593
        "movq %%mm1, 8(%1, %0)          \n\t"
594
        "add $16, %0                    \n\t"
595
        "2:                             \n\t"
596
        "cmp %4, %0                     \n\t"
597
        " js 1b                         \n\t"
598
        : "+r" (i)
599
        : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
600
    );
601
    for(; i<w; i++)
602
        dst[i] = src1[i] + src2[i];
603
}
604

    
605
#if HAVE_7REGS && HAVE_TEN_OPERANDS
606
static void add_hfyu_median_prediction_cmov(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top) {
607
    x86_reg w2 = -w;
608
    x86_reg x;
609
    int l = *left & 0xff;
610
    int tl = *left_top & 0xff;
611
    int t;
612
    __asm__ volatile(
613
        "mov    %7, %3 \n"
614
        "1: \n"
615
        "movzx (%3,%4), %2 \n"
616
        "mov    %2, %k3 \n"
617
        "sub   %b1, %b3 \n"
618
        "add   %b0, %b3 \n"
619
        "mov    %2, %1 \n"
620
        "cmp    %0, %2 \n"
621
        "cmovg  %0, %2 \n"
622
        "cmovg  %1, %0 \n"
623
        "cmp   %k3, %0 \n"
624
        "cmovg %k3, %0 \n"
625
        "mov    %7, %3 \n"
626
        "cmp    %2, %0 \n"
627
        "cmovl  %2, %0 \n"
628
        "add (%6,%4), %b0 \n"
629
        "mov   %b0, (%5,%4) \n"
630
        "inc    %4 \n"
631
        "jl 1b \n"
632
        :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
633
        :"r"(dst+w), "r"(diff+w), "rm"(top+w)
634
    );
635
    *left = l;
636
    *left_top = tl;
637
}
638
#endif
639

    
640
#define H263_LOOP_FILTER \
641
        "pxor %%mm7, %%mm7              \n\t"\
642
        "movq  %0, %%mm0                \n\t"\
643
        "movq  %0, %%mm1                \n\t"\
644
        "movq  %3, %%mm2                \n\t"\
645
        "movq  %3, %%mm3                \n\t"\
646
        "punpcklbw %%mm7, %%mm0         \n\t"\
647
        "punpckhbw %%mm7, %%mm1         \n\t"\
648
        "punpcklbw %%mm7, %%mm2         \n\t"\
649
        "punpckhbw %%mm7, %%mm3         \n\t"\
650
        "psubw %%mm2, %%mm0             \n\t"\
651
        "psubw %%mm3, %%mm1             \n\t"\
652
        "movq  %1, %%mm2                \n\t"\
653
        "movq  %1, %%mm3                \n\t"\
654
        "movq  %2, %%mm4                \n\t"\
655
        "movq  %2, %%mm5                \n\t"\
656
        "punpcklbw %%mm7, %%mm2         \n\t"\
657
        "punpckhbw %%mm7, %%mm3         \n\t"\
658
        "punpcklbw %%mm7, %%mm4         \n\t"\
659
        "punpckhbw %%mm7, %%mm5         \n\t"\
660
        "psubw %%mm2, %%mm4             \n\t"\
661
        "psubw %%mm3, %%mm5             \n\t"\
662
        "psllw $2, %%mm4                \n\t"\
663
        "psllw $2, %%mm5                \n\t"\
664
        "paddw %%mm0, %%mm4             \n\t"\
665
        "paddw %%mm1, %%mm5             \n\t"\
666
        "pxor %%mm6, %%mm6              \n\t"\
667
        "pcmpgtw %%mm4, %%mm6           \n\t"\
668
        "pcmpgtw %%mm5, %%mm7           \n\t"\
669
        "pxor %%mm6, %%mm4              \n\t"\
670
        "pxor %%mm7, %%mm5              \n\t"\
671
        "psubw %%mm6, %%mm4             \n\t"\
672
        "psubw %%mm7, %%mm5             \n\t"\
673
        "psrlw $3, %%mm4                \n\t"\
674
        "psrlw $3, %%mm5                \n\t"\
675
        "packuswb %%mm5, %%mm4          \n\t"\
676
        "packsswb %%mm7, %%mm6          \n\t"\
677
        "pxor %%mm7, %%mm7              \n\t"\
678
        "movd %4, %%mm2                 \n\t"\
679
        "punpcklbw %%mm2, %%mm2         \n\t"\
680
        "punpcklbw %%mm2, %%mm2         \n\t"\
681
        "punpcklbw %%mm2, %%mm2         \n\t"\
682
        "psubusb %%mm4, %%mm2           \n\t"\
683
        "movq %%mm2, %%mm3              \n\t"\
684
        "psubusb %%mm4, %%mm3           \n\t"\
685
        "psubb %%mm3, %%mm2             \n\t"\
686
        "movq %1, %%mm3                 \n\t"\
687
        "movq %2, %%mm4                 \n\t"\
688
        "pxor %%mm6, %%mm3              \n\t"\
689
        "pxor %%mm6, %%mm4              \n\t"\
690
        "paddusb %%mm2, %%mm3           \n\t"\
691
        "psubusb %%mm2, %%mm4           \n\t"\
692
        "pxor %%mm6, %%mm3              \n\t"\
693
        "pxor %%mm6, %%mm4              \n\t"\
694
        "paddusb %%mm2, %%mm2           \n\t"\
695
        "packsswb %%mm1, %%mm0          \n\t"\
696
        "pcmpgtb %%mm0, %%mm7           \n\t"\
697
        "pxor %%mm7, %%mm0              \n\t"\
698
        "psubb %%mm7, %%mm0             \n\t"\
699
        "movq %%mm0, %%mm1              \n\t"\
700
        "psubusb %%mm2, %%mm0           \n\t"\
701
        "psubb %%mm0, %%mm1             \n\t"\
702
        "pand %5, %%mm1                 \n\t"\
703
        "psrlw $2, %%mm1                \n\t"\
704
        "pxor %%mm7, %%mm1              \n\t"\
705
        "psubb %%mm7, %%mm1             \n\t"\
706
        "movq %0, %%mm5                 \n\t"\
707
        "movq %3, %%mm6                 \n\t"\
708
        "psubb %%mm1, %%mm5             \n\t"\
709
        "paddb %%mm1, %%mm6             \n\t"
710

    
711
static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
712
    if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
713
    const int strength= ff_h263_loop_filter_strength[qscale];
714

    
715
    __asm__ volatile(
716

    
717
        H263_LOOP_FILTER
718

    
719
        "movq %%mm3, %1                 \n\t"
720
        "movq %%mm4, %2                 \n\t"
721
        "movq %%mm5, %0                 \n\t"
722
        "movq %%mm6, %3                 \n\t"
723
        : "+m" (*(uint64_t*)(src - 2*stride)),
724
          "+m" (*(uint64_t*)(src - 1*stride)),
725
          "+m" (*(uint64_t*)(src + 0*stride)),
726
          "+m" (*(uint64_t*)(src + 1*stride))
727
        : "g" (2*strength), "m"(ff_pb_FC)
728
    );
729
    }
730
}
731

    
732
static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
733
    if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
734
    const int strength= ff_h263_loop_filter_strength[qscale];
735
    DECLARE_ALIGNED(8, uint64_t, temp)[4];
736
    uint8_t *btemp= (uint8_t*)temp;
737

    
738
    src -= 2;
739

    
740
    transpose4x4(btemp  , src           , 8, stride);
741
    transpose4x4(btemp+4, src + 4*stride, 8, stride);
742
    __asm__ volatile(
743
        H263_LOOP_FILTER // 5 3 4 6
744

    
745
        : "+m" (temp[0]),
746
          "+m" (temp[1]),
747
          "+m" (temp[2]),
748
          "+m" (temp[3])
749
        : "g" (2*strength), "m"(ff_pb_FC)
750
    );
751

    
752
    __asm__ volatile(
753
        "movq %%mm5, %%mm1              \n\t"
754
        "movq %%mm4, %%mm0              \n\t"
755
        "punpcklbw %%mm3, %%mm5         \n\t"
756
        "punpcklbw %%mm6, %%mm4         \n\t"
757
        "punpckhbw %%mm3, %%mm1         \n\t"
758
        "punpckhbw %%mm6, %%mm0         \n\t"
759
        "movq %%mm5, %%mm3              \n\t"
760
        "movq %%mm1, %%mm6              \n\t"
761
        "punpcklwd %%mm4, %%mm5         \n\t"
762
        "punpcklwd %%mm0, %%mm1         \n\t"
763
        "punpckhwd %%mm4, %%mm3         \n\t"
764
        "punpckhwd %%mm0, %%mm6         \n\t"
765
        "movd %%mm5, (%0)               \n\t"
766
        "punpckhdq %%mm5, %%mm5         \n\t"
767
        "movd %%mm5, (%0,%2)            \n\t"
768
        "movd %%mm3, (%0,%2,2)          \n\t"
769
        "punpckhdq %%mm3, %%mm3         \n\t"
770
        "movd %%mm3, (%0,%3)            \n\t"
771
        "movd %%mm1, (%1)               \n\t"
772
        "punpckhdq %%mm1, %%mm1         \n\t"
773
        "movd %%mm1, (%1,%2)            \n\t"
774
        "movd %%mm6, (%1,%2,2)          \n\t"
775
        "punpckhdq %%mm6, %%mm6         \n\t"
776
        "movd %%mm6, (%1,%3)            \n\t"
777
        :: "r" (src),
778
           "r" (src + 4*stride),
779
           "r" ((x86_reg)   stride ),
780
           "r" ((x86_reg)(3*stride))
781
    );
782
    }
783
}
784

    
785
/* draw the edges of width 'w' of an image of size width, height
786
   this mmx version can only handle w==8 || w==16 */
787
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
788
{
789
    uint8_t *ptr, *last_line;
790
    int i;
791

    
792
    last_line = buf + (height - 1) * wrap;
793
    /* left and right */
794
    ptr = buf;
795
    if(w==8)
796
    {
797
        __asm__ volatile(
798
                "1:                             \n\t"
799
                "movd (%0), %%mm0               \n\t"
800
                "punpcklbw %%mm0, %%mm0         \n\t"
801
                "punpcklwd %%mm0, %%mm0         \n\t"
802
                "punpckldq %%mm0, %%mm0         \n\t"
803
                "movq %%mm0, -8(%0)             \n\t"
804
                "movq -8(%0, %2), %%mm1         \n\t"
805
                "punpckhbw %%mm1, %%mm1         \n\t"
806
                "punpckhwd %%mm1, %%mm1         \n\t"
807
                "punpckhdq %%mm1, %%mm1         \n\t"
808
                "movq %%mm1, (%0, %2)           \n\t"
809
                "add %1, %0                     \n\t"
810
                "cmp %3, %0                     \n\t"
811
                " jb 1b                         \n\t"
812
                : "+r" (ptr)
813
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
814
        );
815
    }
816
    else
817
    {
818
        __asm__ volatile(
819
                "1:                             \n\t"
820
                "movd (%0), %%mm0               \n\t"
821
                "punpcklbw %%mm0, %%mm0         \n\t"
822
                "punpcklwd %%mm0, %%mm0         \n\t"
823
                "punpckldq %%mm0, %%mm0         \n\t"
824
                "movq %%mm0, -8(%0)             \n\t"
825
                "movq %%mm0, -16(%0)            \n\t"
826
                "movq -8(%0, %2), %%mm1         \n\t"
827
                "punpckhbw %%mm1, %%mm1         \n\t"
828
                "punpckhwd %%mm1, %%mm1         \n\t"
829
                "punpckhdq %%mm1, %%mm1         \n\t"
830
                "movq %%mm1, (%0, %2)           \n\t"
831
                "movq %%mm1, 8(%0, %2)          \n\t"
832
                "add %1, %0                     \n\t"
833
                "cmp %3, %0                     \n\t"
834
                " jb 1b                         \n\t"
835
                : "+r" (ptr)
836
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
837
        );
838
    }
839

    
840
    for(i=0;i<w;i+=4) {
841
        /* top and bottom (and hopefully also the corners) */
842
        ptr= buf - (i + 1) * wrap - w;
843
        __asm__ volatile(
844
                "1:                             \n\t"
845
                "movq (%1, %0), %%mm0           \n\t"
846
                "movq %%mm0, (%0)               \n\t"
847
                "movq %%mm0, (%0, %2)           \n\t"
848
                "movq %%mm0, (%0, %2, 2)        \n\t"
849
                "movq %%mm0, (%0, %3)           \n\t"
850
                "add $8, %0                     \n\t"
851
                "cmp %4, %0                     \n\t"
852
                " jb 1b                         \n\t"
853
                : "+r" (ptr)
854
                : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
855
        );
856
        ptr= last_line + (i + 1) * wrap - w;
857
        __asm__ volatile(
858
                "1:                             \n\t"
859
                "movq (%1, %0), %%mm0           \n\t"
860
                "movq %%mm0, (%0)               \n\t"
861
                "movq %%mm0, (%0, %2)           \n\t"
862
                "movq %%mm0, (%0, %2, 2)        \n\t"
863
                "movq %%mm0, (%0, %3)           \n\t"
864
                "add $8, %0                     \n\t"
865
                "cmp %4, %0                     \n\t"
866
                " jb 1b                         \n\t"
867
                : "+r" (ptr)
868
                : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
869
        );
870
    }
871
}
872

    
873
#define PAETH(cpu, abs3)\
874
static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
875
{\
876
    x86_reg i = -bpp;\
877
    x86_reg end = w-3;\
878
    __asm__ volatile(\
879
        "pxor      %%mm7, %%mm7 \n"\
880
        "movd    (%1,%0), %%mm0 \n"\
881
        "movd    (%2,%0), %%mm1 \n"\
882
        "punpcklbw %%mm7, %%mm0 \n"\
883
        "punpcklbw %%mm7, %%mm1 \n"\
884
        "add       %4, %0 \n"\
885
        "1: \n"\
886
        "movq      %%mm1, %%mm2 \n"\
887
        "movd    (%2,%0), %%mm1 \n"\
888
        "movq      %%mm2, %%mm3 \n"\
889
        "punpcklbw %%mm7, %%mm1 \n"\
890
        "movq      %%mm2, %%mm4 \n"\
891
        "psubw     %%mm1, %%mm3 \n"\
892
        "psubw     %%mm0, %%mm4 \n"\
893
        "movq      %%mm3, %%mm5 \n"\
894
        "paddw     %%mm4, %%mm5 \n"\
895
        abs3\
896
        "movq      %%mm4, %%mm6 \n"\
897
        "pminsw    %%mm5, %%mm6 \n"\
898
        "pcmpgtw   %%mm6, %%mm3 \n"\
899
        "pcmpgtw   %%mm5, %%mm4 \n"\
900
        "movq      %%mm4, %%mm6 \n"\
901
        "pand      %%mm3, %%mm4 \n"\
902
        "pandn     %%mm3, %%mm6 \n"\
903
        "pandn     %%mm0, %%mm3 \n"\
904
        "movd    (%3,%0), %%mm0 \n"\
905
        "pand      %%mm1, %%mm6 \n"\
906
        "pand      %%mm4, %%mm2 \n"\
907
        "punpcklbw %%mm7, %%mm0 \n"\
908
        "movq      %6,    %%mm5 \n"\
909
        "paddw     %%mm6, %%mm0 \n"\
910
        "paddw     %%mm2, %%mm3 \n"\
911
        "paddw     %%mm3, %%mm0 \n"\
912
        "pand      %%mm5, %%mm0 \n"\
913
        "movq      %%mm0, %%mm3 \n"\
914
        "packuswb  %%mm3, %%mm3 \n"\
915
        "movd      %%mm3, (%1,%0) \n"\
916
        "add       %4, %0 \n"\
917
        "cmp       %5, %0 \n"\
918
        "jle 1b \n"\
919
        :"+r"(i)\
920
        :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
921
         "m"(ff_pw_255)\
922
        :"memory"\
923
    );\
924
}
925

    
926
#define ABS3_MMX2\
927
        "psubw     %%mm5, %%mm7 \n"\
928
        "pmaxsw    %%mm7, %%mm5 \n"\
929
        "pxor      %%mm6, %%mm6 \n"\
930
        "pxor      %%mm7, %%mm7 \n"\
931
        "psubw     %%mm3, %%mm6 \n"\
932
        "psubw     %%mm4, %%mm7 \n"\
933
        "pmaxsw    %%mm6, %%mm3 \n"\
934
        "pmaxsw    %%mm7, %%mm4 \n"\
935
        "pxor      %%mm7, %%mm7 \n"
936

    
937
#define ABS3_SSSE3\
938
        "pabsw     %%mm3, %%mm3 \n"\
939
        "pabsw     %%mm4, %%mm4 \n"\
940
        "pabsw     %%mm5, %%mm5 \n"
941

    
942
PAETH(mmx2, ABS3_MMX2)
943
#if HAVE_SSSE3
944
PAETH(ssse3, ABS3_SSSE3)
945
#endif
946

    
947
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
948
        "paddw " #m4 ", " #m3 "           \n\t" /* x1 */\
949
        "movq "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */\
950
        "pmullw " #m3 ", %%mm4            \n\t" /* 20x1 */\
951
        "movq "#in7", " #m3 "             \n\t" /* d */\
952
        "movq "#in0", %%mm5               \n\t" /* D */\
953
        "paddw " #m3 ", %%mm5             \n\t" /* x4 */\
954
        "psubw %%mm5, %%mm4               \n\t" /* 20x1 - x4 */\
955
        "movq "#in1", %%mm5               \n\t" /* C */\
956
        "movq "#in2", %%mm6               \n\t" /* B */\
957
        "paddw " #m6 ", %%mm5             \n\t" /* x3 */\
958
        "paddw " #m5 ", %%mm6             \n\t" /* x2 */\
959
        "paddw %%mm6, %%mm6               \n\t" /* 2x2 */\
960
        "psubw %%mm6, %%mm5               \n\t" /* -2x2 + x3 */\
961
        "pmullw "MANGLE(ff_pw_3)", %%mm5  \n\t" /* -6x2 + 3x3 */\
962
        "paddw " #rnd ", %%mm4            \n\t" /* x2 */\
963
        "paddw %%mm4, %%mm5               \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
964
        "psraw $5, %%mm5                  \n\t"\
965
        "packuswb %%mm5, %%mm5            \n\t"\
966
        OP(%%mm5, out, %%mm7, d)
967

    
968
#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
969
static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
970
    uint64_t temp;\
971
\
972
    __asm__ volatile(\
973
        "pxor %%mm7, %%mm7                \n\t"\
974
        "1:                               \n\t"\
975
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
976
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
977
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
978
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
979
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
980
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
981
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
982
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
983
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
984
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
985
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
986
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
987
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
988
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
989
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
990
        "paddw %%mm3, %%mm5               \n\t" /* b */\
991
        "paddw %%mm2, %%mm6               \n\t" /* c */\
992
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
993
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
994
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
995
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
996
        "paddw %%mm4, %%mm0               \n\t" /* a */\
997
        "paddw %%mm1, %%mm5               \n\t" /* d */\
998
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
999
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
1000
        "paddw %6, %%mm6                  \n\t"\
1001
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1002
        "psraw $5, %%mm0                  \n\t"\
1003
        "movq %%mm0, %5                   \n\t"\
1004
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1005
        \
1006
        "movq 5(%0), %%mm0                \n\t" /* FGHIJKLM */\
1007
        "movq %%mm0, %%mm5                \n\t" /* FGHIJKLM */\
1008
        "movq %%mm0, %%mm6                \n\t" /* FGHIJKLM */\
1009
        "psrlq $8, %%mm0                  \n\t" /* GHIJKLM0 */\
1010
        "psrlq $16, %%mm5                 \n\t" /* HIJKLM00 */\
1011
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0G0H0I0J */\
1012
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0H0I0J0K */\
1013
        "paddw %%mm0, %%mm2               \n\t" /* b */\
1014
        "paddw %%mm5, %%mm3               \n\t" /* c */\
1015
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
1016
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
1017
        "movq %%mm6, %%mm2                \n\t" /* FGHIJKLM */\
1018
        "psrlq $24, %%mm6                 \n\t" /* IJKLM000 */\
1019
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0F0G0H0I */\
1020
        "punpcklbw %%mm7, %%mm6           \n\t" /* 0I0J0K0L */\
1021
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
1022
        "paddw %%mm2, %%mm1               \n\t" /* a */\
1023
        "paddw %%mm6, %%mm4               \n\t" /* d */\
1024
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1025
        "psubw %%mm4, %%mm3               \n\t" /* - 6b +3c - d */\
1026
        "paddw %6, %%mm1                  \n\t"\
1027
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b +3c - d */\
1028
        "psraw $5, %%mm3                  \n\t"\
1029
        "movq %5, %%mm1                   \n\t"\
1030
        "packuswb %%mm3, %%mm1            \n\t"\
1031
        OP_MMX2(%%mm1, (%1),%%mm4, q)\
1032
        /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1033
        \
1034
        "movq 9(%0), %%mm1                \n\t" /* JKLMNOPQ */\
1035
        "movq %%mm1, %%mm4                \n\t" /* JKLMNOPQ */\
1036
        "movq %%mm1, %%mm3                \n\t" /* JKLMNOPQ */\
1037
        "psrlq $8, %%mm1                  \n\t" /* KLMNOPQ0 */\
1038
        "psrlq $16, %%mm4                 \n\t" /* LMNOPQ00 */\
1039
        "punpcklbw %%mm7, %%mm1           \n\t" /* 0K0L0M0N */\
1040
        "punpcklbw %%mm7, %%mm4           \n\t" /* 0L0M0N0O */\
1041
        "paddw %%mm1, %%mm5               \n\t" /* b */\
1042
        "paddw %%mm4, %%mm0               \n\t" /* c */\
1043
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1044
        "psubw %%mm5, %%mm0               \n\t" /* c - 2b */\
1045
        "movq %%mm3, %%mm5                \n\t" /* JKLMNOPQ */\
1046
        "psrlq $24, %%mm3                 \n\t" /* MNOPQ000 */\
1047
        "pmullw "MANGLE(ff_pw_3)", %%mm0  \n\t" /* 3c - 6b */\
1048
        "punpcklbw %%mm7, %%mm3           \n\t" /* 0M0N0O0P */\
1049
        "paddw %%mm3, %%mm2               \n\t" /* d */\
1050
        "psubw %%mm2, %%mm0               \n\t" /* -6b + 3c - d */\
1051
        "movq %%mm5, %%mm2                \n\t" /* JKLMNOPQ */\
1052
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0J0K0L0M */\
1053
        "punpckhbw %%mm7, %%mm5           \n\t" /* 0N0O0P0Q */\
1054
        "paddw %%mm2, %%mm6               \n\t" /* a */\
1055
        "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
1056
        "paddw %6, %%mm0                  \n\t"\
1057
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1058
        "psraw $5, %%mm0                  \n\t"\
1059
        /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1060
        \
1061
        "paddw %%mm5, %%mm3               \n\t" /* a */\
1062
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0O0P0Q0Q */\
1063
        "paddw %%mm4, %%mm6               \n\t" /* b */\
1064
        "pshufw $0xBE, %%mm5, %%mm4       \n\t" /* 0P0Q0Q0P */\
1065
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0Q0Q0P0O */\
1066
        "paddw %%mm1, %%mm4               \n\t" /* c */\
1067
        "paddw %%mm2, %%mm5               \n\t" /* d */\
1068
        "paddw %%mm6, %%mm6               \n\t" /* 2b */\
1069
        "psubw %%mm6, %%mm4               \n\t" /* c - 2b */\
1070
        "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1071
        "pmullw "MANGLE(ff_pw_3)", %%mm4  \n\t" /* 3c - 6b */\
1072
        "psubw %%mm5, %%mm3               \n\t" /* -6b + 3c - d */\
1073
        "paddw %6, %%mm4                  \n\t"\
1074
        "paddw %%mm3, %%mm4               \n\t" /* 20a - 6b + 3c - d */\
1075
        "psraw $5, %%mm4                  \n\t"\
1076
        "packuswb %%mm4, %%mm0            \n\t"\
1077
        OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
1078
        \
1079
        "add %3, %0                       \n\t"\
1080
        "add %4, %1                       \n\t"\
1081
        "decl %2                          \n\t"\
1082
        " jnz 1b                          \n\t"\
1083
        : "+a"(src), "+c"(dst), "+D"(h)\
1084
        : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1085
        : "memory"\
1086
    );\
1087
}\
1088
\
1089
static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1090
    int i;\
1091
    int16_t temp[16];\
1092
    /* quick HACK, XXX FIXME MUST be optimized */\
1093
    for(i=0; i<h; i++)\
1094
    {\
1095
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1096
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1097
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1098
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1099
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1100
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1101
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1102
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1103
        temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1104
        temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1105
        temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1106
        temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1107
        temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1108
        temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1109
        temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1110
        temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1111
        __asm__ volatile(\
1112
            "movq (%0), %%mm0               \n\t"\
1113
            "movq 8(%0), %%mm1              \n\t"\
1114
            "paddw %2, %%mm0                \n\t"\
1115
            "paddw %2, %%mm1                \n\t"\
1116
            "psraw $5, %%mm0                \n\t"\
1117
            "psraw $5, %%mm1                \n\t"\
1118
            "packuswb %%mm1, %%mm0          \n\t"\
1119
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1120
            "movq 16(%0), %%mm0             \n\t"\
1121
            "movq 24(%0), %%mm1             \n\t"\
1122
            "paddw %2, %%mm0                \n\t"\
1123
            "paddw %2, %%mm1                \n\t"\
1124
            "psraw $5, %%mm0                \n\t"\
1125
            "psraw $5, %%mm1                \n\t"\
1126
            "packuswb %%mm1, %%mm0          \n\t"\
1127
            OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
1128
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1129
            : "memory"\
1130
        );\
1131
        dst+=dstStride;\
1132
        src+=srcStride;\
1133
    }\
1134
}\
1135
\
1136
static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1137
    __asm__ volatile(\
1138
        "pxor %%mm7, %%mm7                \n\t"\
1139
        "1:                               \n\t"\
1140
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1141
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1142
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1143
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
1144
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
1145
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
1146
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
1147
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1148
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1149
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
1150
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
1151
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
1152
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
1153
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
1154
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
1155
        "paddw %%mm3, %%mm5               \n\t" /* b */\
1156
        "paddw %%mm2, %%mm6               \n\t" /* c */\
1157
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1158
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
1159
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
1160
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
1161
        "paddw %%mm4, %%mm0               \n\t" /* a */\
1162
        "paddw %%mm1, %%mm5               \n\t" /* d */\
1163
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1164
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
1165
        "paddw %5, %%mm6                  \n\t"\
1166
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1167
        "psraw $5, %%mm0                  \n\t"\
1168
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1169
        \
1170
        "movd 5(%0), %%mm5                \n\t" /* FGHI */\
1171
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0F0G0H0I */\
1172
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0G0H0I0I */\
1173
        "paddw %%mm5, %%mm1               \n\t" /* a */\
1174
        "paddw %%mm6, %%mm2               \n\t" /* b */\
1175
        "pshufw $0xBE, %%mm5, %%mm6       \n\t" /* 0H0I0I0H */\
1176
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0I0I0H0G */\
1177
        "paddw %%mm6, %%mm3               \n\t" /* c */\
1178
        "paddw %%mm5, %%mm4               \n\t" /* d */\
1179
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
1180
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
1181
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1182
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
1183
        "psubw %%mm4, %%mm3               \n\t" /* -6b + 3c - d */\
1184
        "paddw %5, %%mm1                  \n\t"\
1185
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b + 3c - d */\
1186
        "psraw $5, %%mm3                  \n\t"\
1187
        "packuswb %%mm3, %%mm0            \n\t"\
1188
        OP_MMX2(%%mm0, (%1), %%mm4, q)\
1189
        \
1190
        "add %3, %0                       \n\t"\
1191
        "add %4, %1                       \n\t"\
1192
        "decl %2                          \n\t"\
1193
        " jnz 1b                          \n\t"\
1194
        : "+a"(src), "+c"(dst), "+d"(h)\
1195
        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
1196
        : "memory"\
1197
    );\
1198
}\
1199
\
1200
static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1201
    int i;\
1202
    int16_t temp[8];\
1203
    /* quick HACK, XXX FIXME MUST be optimized */\
1204
    for(i=0; i<h; i++)\
1205
    {\
1206
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1207
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1208
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1209
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1210
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1211
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1212
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
1213
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
1214
        __asm__ volatile(\
1215
            "movq (%0), %%mm0           \n\t"\
1216
            "movq 8(%0), %%mm1          \n\t"\
1217
            "paddw %2, %%mm0            \n\t"\
1218
            "paddw %2, %%mm1            \n\t"\
1219
            "psraw $5, %%mm0            \n\t"\
1220
            "psraw $5, %%mm1            \n\t"\
1221
            "packuswb %%mm1, %%mm0      \n\t"\
1222
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1223
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1224
            :"memory"\
1225
        );\
1226
        dst+=dstStride;\
1227
        src+=srcStride;\
1228
    }\
1229
}
1230

    
1231
#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
1232
\
1233
static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1234
    uint64_t temp[17*4];\
1235
    uint64_t *temp_ptr= temp;\
1236
    int count= 17;\
1237
\
1238
    /*FIXME unroll */\
1239
    __asm__ volatile(\
1240
        "pxor %%mm7, %%mm7              \n\t"\
1241
        "1:                             \n\t"\
1242
        "movq (%0), %%mm0               \n\t"\
1243
        "movq (%0), %%mm1               \n\t"\
1244
        "movq 8(%0), %%mm2              \n\t"\
1245
        "movq 8(%0), %%mm3              \n\t"\
1246
        "punpcklbw %%mm7, %%mm0         \n\t"\
1247
        "punpckhbw %%mm7, %%mm1         \n\t"\
1248
        "punpcklbw %%mm7, %%mm2         \n\t"\
1249
        "punpckhbw %%mm7, %%mm3         \n\t"\
1250
        "movq %%mm0, (%1)               \n\t"\
1251
        "movq %%mm1, 17*8(%1)           \n\t"\
1252
        "movq %%mm2, 2*17*8(%1)         \n\t"\
1253
        "movq %%mm3, 3*17*8(%1)         \n\t"\
1254
        "add $8, %1                     \n\t"\
1255
        "add %3, %0                     \n\t"\
1256
        "decl %2                        \n\t"\
1257
        " jnz 1b                        \n\t"\
1258
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
1259
        : "r" ((x86_reg)srcStride)\
1260
        : "memory"\
1261
    );\
1262
    \
1263
    temp_ptr= temp;\
1264
    count=4;\
1265
    \
1266
/*FIXME reorder for speed */\
1267
    __asm__ volatile(\
1268
        /*"pxor %%mm7, %%mm7              \n\t"*/\
1269
        "1:                             \n\t"\
1270
        "movq (%0), %%mm0               \n\t"\
1271
        "movq 8(%0), %%mm1              \n\t"\
1272
        "movq 16(%0), %%mm2             \n\t"\
1273
        "movq 24(%0), %%mm3             \n\t"\
1274
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
1275
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
1276
        "add %4, %1                     \n\t"\
1277
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
1278
        \
1279
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
1280
        "add %4, %1                     \n\t"\
1281
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1282
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
1283
        "add %4, %1                     \n\t"\
1284
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
1285
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
1286
        "add %4, %1                     \n\t"\
1287
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
1288
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
1289
        "add %4, %1                     \n\t"\
1290
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
1291
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
1292
        "add %4, %1                     \n\t"\
1293
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
1294
        \
1295
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
1296
        "add %4, %1                     \n\t"  \
1297
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
1298
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
1299
        \
1300
        "add $136, %0                   \n\t"\
1301
        "add %6, %1                     \n\t"\
1302
        "decl %2                        \n\t"\
1303
        " jnz 1b                        \n\t"\
1304
        \
1305
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
1306
        : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(x86_reg)dstStride)\
1307
        :"memory"\
1308
    );\
1309
}\
1310
\
1311
static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1312
    uint64_t temp[9*2];\
1313
    uint64_t *temp_ptr= temp;\
1314
    int count= 9;\
1315
\
1316
    /*FIXME unroll */\
1317
    __asm__ volatile(\
1318
        "pxor %%mm7, %%mm7              \n\t"\
1319
        "1:                             \n\t"\
1320
        "movq (%0), %%mm0               \n\t"\
1321
        "movq (%0), %%mm1               \n\t"\
1322
        "punpcklbw %%mm7, %%mm0         \n\t"\
1323
        "punpckhbw %%mm7, %%mm1         \n\t"\
1324
        "movq %%mm0, (%1)               \n\t"\
1325
        "movq %%mm1, 9*8(%1)            \n\t"\
1326
        "add $8, %1                     \n\t"\
1327
        "add %3, %0                     \n\t"\
1328
        "decl %2                        \n\t"\
1329
        " jnz 1b                        \n\t"\
1330
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
1331
        : "r" ((x86_reg)srcStride)\
1332
        : "memory"\
1333
    );\
1334
    \
1335
    temp_ptr= temp;\
1336
    count=2;\
1337
    \
1338
/*FIXME reorder for speed */\
1339
    __asm__ volatile(\
1340
        /*"pxor %%mm7, %%mm7              \n\t"*/\
1341
        "1:                             \n\t"\
1342
        "movq (%0), %%mm0               \n\t"\
1343
        "movq 8(%0), %%mm1              \n\t"\
1344
        "movq 16(%0), %%mm2             \n\t"\
1345
        "movq 24(%0), %%mm3             \n\t"\
1346
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
1347
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
1348
        "add %4, %1                     \n\t"\
1349
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
1350
        \
1351
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
1352
        "add %4, %1                     \n\t"\
1353
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1354
        \
1355
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
1356
        "add %4, %1                     \n\t"\
1357
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
1358
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
1359
                \
1360
        "add $72, %0                    \n\t"\
1361
        "add %6, %1                     \n\t"\
1362
        "decl %2                        \n\t"\
1363
        " jnz 1b                        \n\t"\
1364
         \
1365
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
1366
        : "r"((x86_reg)dstStride), "r"(2*(x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*(x86_reg)dstStride)\
1367
        : "memory"\
1368
   );\
1369
}\
1370
\
1371
static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1372
    OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);\
1373
}\
1374
\
1375
static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1376
    uint64_t temp[8];\
1377
    uint8_t * const half= (uint8_t*)temp;\
1378
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1379
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
1380
}\
1381
\
1382
static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1383
    OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
1384
}\
1385
\
1386
static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1387
    uint64_t temp[8];\
1388
    uint8_t * const half= (uint8_t*)temp;\
1389
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1390
    OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
1391
}\
1392
\
1393
static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1394
    uint64_t temp[8];\
1395
    uint8_t * const half= (uint8_t*)temp;\
1396
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
1397
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
1398
}\
1399
\
1400
static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1401
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
1402
}\
1403
\
1404
static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1405
    uint64_t temp[8];\
1406
    uint8_t * const half= (uint8_t*)temp;\
1407
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
1408
    OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
1409
}\
1410
static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1411
    uint64_t half[8 + 9];\
1412
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1413
    uint8_t * const halfHV= ((uint8_t*)half);\
1414
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1415
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1416
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1417
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1418
}\
1419
static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1420
    uint64_t half[8 + 9];\
1421
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1422
    uint8_t * const halfHV= ((uint8_t*)half);\
1423
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1424
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1425
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1426
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1427
}\
1428
static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1429
    uint64_t half[8 + 9];\
1430
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1431
    uint8_t * const halfHV= ((uint8_t*)half);\
1432
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1433
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1434
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1435
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1436
}\
1437
static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1438
    uint64_t half[8 + 9];\
1439
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1440
    uint8_t * const halfHV= ((uint8_t*)half);\
1441
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1442
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1443
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1444
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1445
}\
1446
static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1447
    uint64_t half[8 + 9];\
1448
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1449
    uint8_t * const halfHV= ((uint8_t*)half);\
1450
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1451
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1452
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1453
}\
1454
static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1455
    uint64_t half[8 + 9];\
1456
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1457
    uint8_t * const halfHV= ((uint8_t*)half);\
1458
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1459
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1460
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1461
}\
1462
static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1463
    uint64_t half[8 + 9];\
1464
    uint8_t * const halfH= ((uint8_t*)half);\
1465
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1466
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1467
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1468
}\
1469
static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1470
    uint64_t half[8 + 9];\
1471
    uint8_t * const halfH= ((uint8_t*)half);\
1472
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1473
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1474
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1475
}\
1476
static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1477
    uint64_t half[9];\
1478
    uint8_t * const halfH= ((uint8_t*)half);\
1479
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1480
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1481
}\
1482
static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1483
    OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);\
1484
}\
1485
\
1486
static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1487
    uint64_t temp[32];\
1488
    uint8_t * const half= (uint8_t*)temp;\
1489
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1490
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
1491
}\
1492
\
1493
static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1494
    OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
1495
}\
1496
\
1497
static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1498
    uint64_t temp[32];\
1499
    uint8_t * const half= (uint8_t*)temp;\
1500
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1501
    OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
1502
}\
1503
\
1504
static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1505
    uint64_t temp[32];\
1506
    uint8_t * const half= (uint8_t*)temp;\
1507
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
1508
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
1509
}\
1510
\
1511
static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1512
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
1513
}\
1514
\
1515
static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1516
    uint64_t temp[32];\
1517
    uint8_t * const half= (uint8_t*)temp;\
1518
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
1519
    OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
1520
}\
1521
static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1522
    uint64_t half[16*2 + 17*2];\
1523
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1524
    uint8_t * const halfHV= ((uint8_t*)half);\
1525
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1526
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1527
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1528
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1529
}\
1530
static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1531
    uint64_t half[16*2 + 17*2];\
1532
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1533
    uint8_t * const halfHV= ((uint8_t*)half);\
1534
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1535
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1536
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1537
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1538
}\
1539
static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1540
    uint64_t half[16*2 + 17*2];\
1541
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1542
    uint8_t * const halfHV= ((uint8_t*)half);\
1543
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1544
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1545
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1546
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1547
}\
1548
static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1549
    uint64_t half[16*2 + 17*2];\
1550
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1551
    uint8_t * const halfHV= ((uint8_t*)half);\
1552
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1553
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1554
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1555
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1556
}\
1557
static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1558
    uint64_t half[16*2 + 17*2];\
1559
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1560
    uint8_t * const halfHV= ((uint8_t*)half);\
1561
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1562
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1563
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1564
}\
1565
static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1566
    uint64_t half[16*2 + 17*2];\
1567
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1568
    uint8_t * const halfHV= ((uint8_t*)half);\
1569
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1570
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1571
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1572
}\
1573
static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1574
    uint64_t half[17*2];\
1575
    uint8_t * const halfH= ((uint8_t*)half);\
1576
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1577
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1578
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1579
}\
1580
static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1581
    uint64_t half[17*2];\
1582
    uint8_t * const halfH= ((uint8_t*)half);\
1583
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1584
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1585
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1586
}\
1587
static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1588
    uint64_t half[17*2];\
1589
    uint8_t * const halfH= ((uint8_t*)half);\
1590
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1591
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1592
}
1593

    
1594
#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "        \n\t"
1595
#define AVG_3DNOW_OP(a,b,temp, size) \
1596
"mov" #size " " #b ", " #temp "   \n\t"\
1597
"pavgusb " #temp ", " #a "        \n\t"\
1598
"mov" #size " " #a ", " #b "      \n\t"
1599
#define AVG_MMX2_OP(a,b,temp, size) \
1600
"mov" #size " " #b ", " #temp "   \n\t"\
1601
"pavgb " #temp ", " #a "          \n\t"\
1602
"mov" #size " " #a ", " #b "      \n\t"
1603

    
1604
QPEL_BASE(put_       , ff_pw_16, _       , PUT_OP, PUT_OP)
1605
QPEL_BASE(avg_       , ff_pw_16, _       , AVG_MMX2_OP, AVG_3DNOW_OP)
1606
QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
1607
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, 3dnow)
1608
QPEL_OP(avg_       , ff_pw_16, _       , AVG_3DNOW_OP, 3dnow)
1609
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
1610
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, mmx2)
1611
QPEL_OP(avg_       , ff_pw_16, _       , AVG_MMX2_OP, mmx2)
1612
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
1613

    
1614
/***********************************/
1615
/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
1616

    
1617
#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
1618
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1619
    OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
1620
}
1621
#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
1622
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1623
    OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
1624
}
1625

    
1626
#define QPEL_2TAP(OPNAME, SIZE, MMX)\
1627
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
1628
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
1629
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
1630
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
1631
                          OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
1632
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
1633
                          OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
1634
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
1635
                          OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
1636
static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1637
    OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
1638
}\
1639
static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1640
    OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
1641
}\
1642
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0,         1,       0)\
1643
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1,        -1,       0)\
1644
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0,         stride,  0)\
1645
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride,   -stride,  0)\
1646
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0,         stride,  1)\
1647
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1,         stride, -1)\
1648
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride,   -stride,  1)\
1649
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
1650

    
1651
QPEL_2TAP(put_, 16, mmx2)
1652
QPEL_2TAP(avg_, 16, mmx2)
1653
QPEL_2TAP(put_,  8, mmx2)
1654
QPEL_2TAP(avg_,  8, mmx2)
1655
QPEL_2TAP(put_, 16, 3dnow)
1656
QPEL_2TAP(avg_, 16, 3dnow)
1657
QPEL_2TAP(put_,  8, 3dnow)
1658
QPEL_2TAP(avg_,  8, 3dnow)
1659

    
1660

    
1661
#if 0
1662
static void just_return(void) { return; }
1663
#endif
1664

    
1665
static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
1666
                    int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){
1667
    const int w = 8;
1668
    const int ix = ox>>(16+shift);
1669
    const int iy = oy>>(16+shift);
1670
    const int oxs = ox>>4;
1671
    const int oys = oy>>4;
1672
    const int dxxs = dxx>>4;
1673
    const int dxys = dxy>>4;
1674
    const int dyxs = dyx>>4;
1675
    const int dyys = dyy>>4;
1676
    const uint16_t r4[4] = {r,r,r,r};
1677
    const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
1678
    const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
1679
    const uint64_t shift2 = 2*shift;
1680
    uint8_t edge_buf[(h+1)*stride];
1681
    int x, y;
1682

    
1683
    const int dxw = (dxx-(1<<(16+shift)))*(w-1);
1684
    const int dyh = (dyy-(1<<(16+shift)))*(h-1);
1685
    const int dxh = dxy*(h-1);
1686
    const int dyw = dyx*(w-1);
1687
    if( // non-constant fullpel offset (3% of blocks)
1688
        ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
1689
         (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
1690
        // uses more than 16 bits of subpel mv (only at huge resolution)
1691
        || (dxx|dxy|dyx|dyy)&15 )
1692
    {
1693
        //FIXME could still use mmx for some of the rows
1694
        ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
1695
        return;
1696
    }
1697

    
1698
    src += ix + iy*stride;
1699
    if( (unsigned)ix >= width-w ||
1700
        (unsigned)iy >= height-h )
1701
    {
1702
        ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
1703
        src = edge_buf;
1704
    }
1705

    
1706
    __asm__ volatile(
1707
        "movd         %0, %%mm6 \n\t"
1708
        "pxor      %%mm7, %%mm7 \n\t"
1709
        "punpcklwd %%mm6, %%mm6 \n\t"
1710
        "punpcklwd %%mm6, %%mm6 \n\t"
1711
        :: "r"(1<<shift)
1712
    );
1713

    
1714
    for(x=0; x<w; x+=4){
1715
        uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
1716
                            oxs - dxys + dxxs*(x+1),
1717
                            oxs - dxys + dxxs*(x+2),
1718
                            oxs - dxys + dxxs*(x+3) };
1719
        uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
1720
                            oys - dyys + dyxs*(x+1),
1721
                            oys - dyys + dyxs*(x+2),
1722
                            oys - dyys + dyxs*(x+3) };
1723

    
1724
        for(y=0; y<h; y++){
1725
            __asm__ volatile(
1726
                "movq   %0,  %%mm4 \n\t"
1727
                "movq   %1,  %%mm5 \n\t"
1728
                "paddw  %2,  %%mm4 \n\t"
1729
                "paddw  %3,  %%mm5 \n\t"
1730
                "movq   %%mm4, %0  \n\t"
1731
                "movq   %%mm5, %1  \n\t"
1732
                "psrlw  $12, %%mm4 \n\t"
1733
                "psrlw  $12, %%mm5 \n\t"
1734
                : "+m"(*dx4), "+m"(*dy4)
1735
                : "m"(*dxy4), "m"(*dyy4)
1736
            );
1737

    
1738
            __asm__ volatile(
1739
                "movq   %%mm6, %%mm2 \n\t"
1740
                "movq   %%mm6, %%mm1 \n\t"
1741
                "psubw  %%mm4, %%mm2 \n\t"
1742
                "psubw  %%mm5, %%mm1 \n\t"
1743
                "movq   %%mm2, %%mm0 \n\t"
1744
                "movq   %%mm4, %%mm3 \n\t"
1745
                "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
1746
                "pmullw %%mm5, %%mm3 \n\t" // dx*dy
1747
                "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
1748
                "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
1749

    
1750
                "movd   %4,    %%mm5 \n\t"
1751
                "movd   %3,    %%mm4 \n\t"
1752
                "punpcklbw %%mm7, %%mm5 \n\t"
1753
                "punpcklbw %%mm7, %%mm4 \n\t"
1754
                "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
1755
                "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
1756

    
1757
                "movd   %2,    %%mm5 \n\t"
1758
                "movd   %1,    %%mm4 \n\t"
1759
                "punpcklbw %%mm7, %%mm5 \n\t"
1760
                "punpcklbw %%mm7, %%mm4 \n\t"
1761
                "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
1762
                "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
1763
                "paddw  %5,    %%mm1 \n\t"
1764
                "paddw  %%mm3, %%mm2 \n\t"
1765
                "paddw  %%mm1, %%mm0 \n\t"
1766
                "paddw  %%mm2, %%mm0 \n\t"
1767

    
1768
                "psrlw    %6,    %%mm0 \n\t"
1769
                "packuswb %%mm0, %%mm0 \n\t"
1770
                "movd     %%mm0, %0    \n\t"
1771

    
1772
                : "=m"(dst[x+y*stride])
1773
                : "m"(src[0]), "m"(src[1]),
1774
                  "m"(src[stride]), "m"(src[stride+1]),
1775
                  "m"(*r4), "m"(shift2)
1776
            );
1777
            src += stride;
1778
        }
1779
        src += 4-h*stride;
1780
    }
1781
}
1782

    
1783
#define PREFETCH(name, op) \
1784
static void name(void *mem, int stride, int h){\
1785
    const uint8_t *p= mem;\
1786
    do{\
1787
        __asm__ volatile(#op" %0" :: "m"(*p));\
1788
        p+= stride;\
1789
    }while(--h);\
1790
}
1791
PREFETCH(prefetch_mmx2,  prefetcht0)
1792
PREFETCH(prefetch_3dnow, prefetch)
1793
#undef PREFETCH
1794

    
1795
#include "h264_qpel_mmx.c"
1796

    
1797
void ff_put_h264_chroma_mc8_mmx_rnd   (uint8_t *dst, uint8_t *src,
1798
                                       int stride, int h, int x, int y);
1799
void ff_put_vc1_chroma_mc8_mmx_nornd  (uint8_t *dst, uint8_t *src,
1800
                                       int stride, int h, int x, int y);
1801
void ff_put_rv40_chroma_mc8_mmx       (uint8_t *dst, uint8_t *src,
1802
                                       int stride, int h, int x, int y);
1803
void ff_avg_h264_chroma_mc8_mmx2_rnd  (uint8_t *dst, uint8_t *src,
1804
                                       int stride, int h, int x, int y);
1805
void ff_avg_vc1_chroma_mc8_mmx2_nornd (uint8_t *dst, uint8_t *src,
1806
                                       int stride, int h, int x, int y);
1807
void ff_avg_rv40_chroma_mc8_mmx2      (uint8_t *dst, uint8_t *src,
1808
                                       int stride, int h, int x, int y);
1809
void ff_avg_h264_chroma_mc8_3dnow_rnd (uint8_t *dst, uint8_t *src,
1810
                                       int stride, int h, int x, int y);
1811
void ff_avg_vc1_chroma_mc8_3dnow_nornd(uint8_t *dst, uint8_t *src,
1812
                                       int stride, int h, int x, int y);
1813
void ff_avg_rv40_chroma_mc8_3dnow     (uint8_t *dst, uint8_t *src,
1814
                                       int stride, int h, int x, int y);
1815

    
1816
void ff_put_h264_chroma_mc4_mmx       (uint8_t *dst, uint8_t *src,
1817
                                       int stride, int h, int x, int y);
1818
void ff_put_rv40_chroma_mc4_mmx       (uint8_t *dst, uint8_t *src,
1819
                                       int stride, int h, int x, int y);
1820
void ff_avg_h264_chroma_mc4_mmx2      (uint8_t *dst, uint8_t *src,
1821
                                       int stride, int h, int x, int y);
1822
void ff_avg_rv40_chroma_mc4_mmx2      (uint8_t *dst, uint8_t *src,
1823
                                       int stride, int h, int x, int y);
1824
void ff_avg_h264_chroma_mc4_3dnow     (uint8_t *dst, uint8_t *src,
1825
                                       int stride, int h, int x, int y);
1826
void ff_avg_rv40_chroma_mc4_3dnow     (uint8_t *dst, uint8_t *src,
1827
                                       int stride, int h, int x, int y);
1828

    
1829
void ff_put_h264_chroma_mc2_mmx2      (uint8_t *dst, uint8_t *src,
1830
                                       int stride, int h, int x, int y);
1831
void ff_avg_h264_chroma_mc2_mmx2      (uint8_t *dst, uint8_t *src,
1832
                                       int stride, int h, int x, int y);
1833

    
1834
void ff_put_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
1835
                                       int stride, int h, int x, int y);
1836
void ff_put_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src,
1837
                                       int stride, int h, int x, int y);
1838
void ff_put_h264_chroma_mc4_ssse3     (uint8_t *dst, uint8_t *src,
1839
                                       int stride, int h, int x, int y);
1840

    
1841
void ff_avg_h264_chroma_mc8_ssse3_rnd (uint8_t *dst, uint8_t *src,
1842
                                       int stride, int h, int x, int y);
1843
void ff_avg_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src,
1844
                                       int stride, int h, int x, int y);
1845
void ff_avg_h264_chroma_mc4_ssse3     (uint8_t *dst, uint8_t *src,
1846
                                       int stride, int h, int x, int y);
1847

    
1848

    
1849
/* CAVS specific */
1850
void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1851
    put_pixels8_mmx(dst, src, stride, 8);
1852
}
1853
void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1854
    avg_pixels8_mmx(dst, src, stride, 8);
1855
}
1856
void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1857
    put_pixels16_mmx(dst, src, stride, 16);
1858
}
1859
void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1860
    avg_pixels16_mmx(dst, src, stride, 16);
1861
}
1862

    
1863
/* VC1 specific */
1864
void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
1865
    put_pixels8_mmx(dst, src, stride, 8);
1866
}
1867
void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
1868
    avg_pixels8_mmx2(dst, src, stride, 8);
1869
}
1870

    
1871
/* XXX: those functions should be suppressed ASAP when all IDCTs are
1872
   converted */
1873
#if CONFIG_GPL
1874
static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1875
{
1876
    ff_mmx_idct (block);
1877
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1878
}
1879
static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1880
{
1881
    ff_mmx_idct (block);
1882
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1883
}
1884
static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1885
{
1886
    ff_mmxext_idct (block);
1887
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1888
}
1889
static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1890
{
1891
    ff_mmxext_idct (block);
1892
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1893
}
1894
#endif
1895
static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
1896
{
1897
    ff_idct_xvid_mmx (block);
1898
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1899
}
1900
static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
1901
{
1902
    ff_idct_xvid_mmx (block);
1903
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1904
}
1905
static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
1906
{
1907
    ff_idct_xvid_mmx2 (block);
1908
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1909
}
1910
static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
1911
{
1912
    ff_idct_xvid_mmx2 (block);
1913
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1914
}
1915

    
1916
static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
1917
{
1918
    int i;
1919
    __asm__ volatile("pxor %%mm7, %%mm7":);
1920
    for(i=0; i<blocksize; i+=2) {
1921
        __asm__ volatile(
1922
            "movq    %0,    %%mm0 \n\t"
1923
            "movq    %1,    %%mm1 \n\t"
1924
            "movq    %%mm0, %%mm2 \n\t"
1925
            "movq    %%mm1, %%mm3 \n\t"
1926
            "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
1927
            "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
1928
            "pslld   $31,   %%mm2 \n\t" // keep only the sign bit
1929
            "pxor    %%mm2, %%mm1 \n\t"
1930
            "movq    %%mm3, %%mm4 \n\t"
1931
            "pand    %%mm1, %%mm3 \n\t"
1932
            "pandn   %%mm1, %%mm4 \n\t"
1933
            "pfadd   %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1934
            "pfsub   %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1935
            "movq    %%mm3, %1    \n\t"
1936
            "movq    %%mm0, %0    \n\t"
1937
            :"+m"(mag[i]), "+m"(ang[i])
1938
            ::"memory"
1939
        );
1940
    }
1941
    __asm__ volatile("femms");
1942
}
1943
static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
1944
{
1945
    int i;
1946

    
1947
    __asm__ volatile(
1948
            "movaps  %0,     %%xmm5 \n\t"
1949
        ::"m"(ff_pdw_80000000[0])
1950
    );
1951
    for(i=0; i<blocksize; i+=4) {
1952
        __asm__ volatile(
1953
            "movaps  %0,     %%xmm0 \n\t"
1954
            "movaps  %1,     %%xmm1 \n\t"
1955
            "xorps   %%xmm2, %%xmm2 \n\t"
1956
            "xorps   %%xmm3, %%xmm3 \n\t"
1957
            "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
1958
            "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
1959
            "andps   %%xmm5, %%xmm2 \n\t" // keep only the sign bit
1960
            "xorps   %%xmm2, %%xmm1 \n\t"
1961
            "movaps  %%xmm3, %%xmm4 \n\t"
1962
            "andps   %%xmm1, %%xmm3 \n\t"
1963
            "andnps  %%xmm1, %%xmm4 \n\t"
1964
            "addps   %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1965
            "subps   %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1966
            "movaps  %%xmm3, %1     \n\t"
1967
            "movaps  %%xmm0, %0     \n\t"
1968
            :"+m"(mag[i]), "+m"(ang[i])
1969
            ::"memory"
1970
        );
1971
    }
1972
}
1973

    
1974
#define IF1(x) x
1975
#define IF0(x)
1976

    
1977
#define MIX5(mono,stereo)\
1978
    __asm__ volatile(\
1979
        "movss          0(%2), %%xmm5 \n"\
1980
        "movss          8(%2), %%xmm6 \n"\
1981
        "movss         24(%2), %%xmm7 \n"\
1982
        "shufps    $0, %%xmm5, %%xmm5 \n"\
1983
        "shufps    $0, %%xmm6, %%xmm6 \n"\
1984
        "shufps    $0, %%xmm7, %%xmm7 \n"\
1985
        "1: \n"\
1986
        "movaps       (%0,%1), %%xmm0 \n"\
1987
        "movaps  0x400(%0,%1), %%xmm1 \n"\
1988
        "movaps  0x800(%0,%1), %%xmm2 \n"\
1989
        "movaps  0xc00(%0,%1), %%xmm3 \n"\
1990
        "movaps 0x1000(%0,%1), %%xmm4 \n"\
1991
        "mulps         %%xmm5, %%xmm0 \n"\
1992
        "mulps         %%xmm6, %%xmm1 \n"\
1993
        "mulps         %%xmm5, %%xmm2 \n"\
1994
        "mulps         %%xmm7, %%xmm3 \n"\
1995
        "mulps         %%xmm7, %%xmm4 \n"\
1996
 stereo("addps         %%xmm1, %%xmm0 \n")\
1997
        "addps         %%xmm1, %%xmm2 \n"\
1998
        "addps         %%xmm3, %%xmm0 \n"\
1999
        "addps         %%xmm4, %%xmm2 \n"\
2000
   mono("addps         %%xmm2, %%xmm0 \n")\
2001
        "movaps  %%xmm0,      (%0,%1) \n"\
2002
 stereo("movaps  %%xmm2, 0x400(%0,%1) \n")\
2003
        "add $16, %0 \n"\
2004
        "jl 1b \n"\
2005
        :"+&r"(i)\
2006
        :"r"(samples[0]+len), "r"(matrix)\
2007
        :"memory"\
2008
    );
2009

    
2010
#define MIX_MISC(stereo)\
2011
    __asm__ volatile(\
2012
        "1: \n"\
2013
        "movaps  (%3,%0), %%xmm0 \n"\
2014
 stereo("movaps   %%xmm0, %%xmm1 \n")\
2015
        "mulps    %%xmm4, %%xmm0 \n"\
2016
 stereo("mulps    %%xmm5, %%xmm1 \n")\
2017
        "lea 1024(%3,%0), %1 \n"\
2018
        "mov %5, %2 \n"\
2019
        "2: \n"\
2020
        "movaps   (%1),   %%xmm2 \n"\
2021
 stereo("movaps   %%xmm2, %%xmm3 \n")\
2022
        "mulps   (%4,%2), %%xmm2 \n"\
2023
 stereo("mulps 16(%4,%2), %%xmm3 \n")\
2024
        "addps    %%xmm2, %%xmm0 \n"\
2025
 stereo("addps    %%xmm3, %%xmm1 \n")\
2026
        "add $1024, %1 \n"\
2027
        "add $32, %2 \n"\
2028
        "jl 2b \n"\
2029
        "movaps   %%xmm0,     (%3,%0) \n"\
2030
 stereo("movaps   %%xmm1, 1024(%3,%0) \n")\
2031
        "add $16, %0 \n"\
2032
        "jl 1b \n"\
2033
        :"+&r"(i), "=&r"(j), "=&r"(k)\
2034
        :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
2035
        :"memory"\
2036
    );
2037

    
2038
static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
2039
{
2040
    int (*matrix_cmp)[2] = (int(*)[2])matrix;
2041
    intptr_t i,j,k;
2042

    
2043
    i = -len*sizeof(float);
2044
    if(in_ch == 5 && out_ch == 2 && !(matrix_cmp[0][1]|matrix_cmp[2][0]|matrix_cmp[3][1]|matrix_cmp[4][0]|(matrix_cmp[1][0]^matrix_cmp[1][1])|(matrix_cmp[0][0]^matrix_cmp[2][1]))) {
2045
        MIX5(IF0,IF1);
2046
    } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
2047
        MIX5(IF1,IF0);
2048
    } else {
2049
        DECLARE_ALIGNED(16, float, matrix_simd)[in_ch][2][4];
2050
        j = 2*in_ch*sizeof(float);
2051
        __asm__ volatile(
2052
            "1: \n"
2053
            "sub $8, %0 \n"
2054
            "movss     (%2,%0), %%xmm4 \n"
2055
            "movss    4(%2,%0), %%xmm5 \n"
2056
            "shufps $0, %%xmm4, %%xmm4 \n"
2057
            "shufps $0, %%xmm5, %%xmm5 \n"
2058
            "movaps %%xmm4,   (%1,%0,4) \n"
2059
            "movaps %%xmm5, 16(%1,%0,4) \n"
2060
            "jg 1b \n"
2061
            :"+&r"(j)
2062
            :"r"(matrix_simd), "r"(matrix)
2063
            :"memory"
2064
        );
2065
        if(out_ch == 2) {
2066
            MIX_MISC(IF1);
2067
        } else {
2068
            MIX_MISC(IF0);
2069
        }
2070
    }
2071
}
2072

    
2073
static void vector_fmul_3dnow(float *dst, const float *src, int len){
2074
    x86_reg i = (len-4)*4;
2075
    __asm__ volatile(
2076
        "1: \n\t"
2077
        "movq    (%1,%0), %%mm0 \n\t"
2078
        "movq   8(%1,%0), %%mm1 \n\t"
2079
        "pfmul   (%2,%0), %%mm0 \n\t"
2080
        "pfmul  8(%2,%0), %%mm1 \n\t"
2081
        "movq   %%mm0,  (%1,%0) \n\t"
2082
        "movq   %%mm1, 8(%1,%0) \n\t"
2083
        "sub  $16, %0 \n\t"
2084
        "jge 1b \n\t"
2085
        "femms  \n\t"
2086
        :"+r"(i)
2087
        :"r"(dst), "r"(src)
2088
        :"memory"
2089
    );
2090
}
2091
static void vector_fmul_sse(float *dst, const float *src, int len){
2092
    x86_reg i = (len-8)*4;
2093
    __asm__ volatile(
2094
        "1: \n\t"
2095
        "movaps    (%1,%0), %%xmm0 \n\t"
2096
        "movaps  16(%1,%0), %%xmm1 \n\t"
2097
        "mulps     (%2,%0), %%xmm0 \n\t"
2098
        "mulps   16(%2,%0), %%xmm1 \n\t"
2099
        "movaps  %%xmm0,   (%1,%0) \n\t"
2100
        "movaps  %%xmm1, 16(%1,%0) \n\t"
2101
        "sub  $32, %0 \n\t"
2102
        "jge 1b \n\t"
2103
        :"+r"(i)
2104
        :"r"(dst), "r"(src)
2105
        :"memory"
2106
    );
2107
}
2108

    
2109
static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
2110
    x86_reg i = len*4-16;
2111
    __asm__ volatile(
2112
        "1: \n\t"
2113
        "pswapd   8(%1), %%mm0 \n\t"
2114
        "pswapd    (%1), %%mm1 \n\t"
2115
        "pfmul  (%3,%0), %%mm0 \n\t"
2116
        "pfmul 8(%3,%0), %%mm1 \n\t"
2117
        "movq  %%mm0,  (%2,%0) \n\t"
2118
        "movq  %%mm1, 8(%2,%0) \n\t"
2119
        "add   $16, %1 \n\t"
2120
        "sub   $16, %0 \n\t"
2121
        "jge   1b \n\t"
2122
        :"+r"(i), "+r"(src1)
2123
        :"r"(dst), "r"(src0)
2124
    );
2125
    __asm__ volatile("femms");
2126
}
2127
static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
2128
    x86_reg i = len*4-32;
2129
    __asm__ volatile(
2130
        "1: \n\t"
2131
        "movaps        16(%1), %%xmm0 \n\t"
2132
        "movaps          (%1), %%xmm1 \n\t"
2133
        "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
2134
        "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
2135
        "mulps        (%3,%0), %%xmm0 \n\t"
2136
        "mulps      16(%3,%0), %%xmm1 \n\t"
2137
        "movaps     %%xmm0,   (%2,%0) \n\t"
2138
        "movaps     %%xmm1, 16(%2,%0) \n\t"
2139
        "add    $32, %1 \n\t"
2140
        "sub    $32, %0 \n\t"
2141
        "jge    1b \n\t"
2142
        :"+r"(i), "+r"(src1)
2143
        :"r"(dst), "r"(src0)
2144
    );
2145
}
2146

    
2147
static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1,
2148
                                  const float *src2, int len){
2149
    x86_reg i = (len-4)*4;
2150
    __asm__ volatile(
2151
        "1: \n\t"
2152
        "movq    (%2,%0), %%mm0 \n\t"
2153
        "movq   8(%2,%0), %%mm1 \n\t"
2154
        "pfmul   (%3,%0), %%mm0 \n\t"
2155
        "pfmul  8(%3,%0), %%mm1 \n\t"
2156
        "pfadd   (%4,%0), %%mm0 \n\t"
2157
        "pfadd  8(%4,%0), %%mm1 \n\t"
2158
        "movq  %%mm0,   (%1,%0) \n\t"
2159
        "movq  %%mm1,  8(%1,%0) \n\t"
2160
        "sub  $16, %0 \n\t"
2161
        "jge  1b \n\t"
2162
        :"+r"(i)
2163
        :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2164
        :"memory"
2165
    );
2166
    __asm__ volatile("femms");
2167
}
2168
static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
2169
                                const float *src2, int len){
2170
    x86_reg i = (len-8)*4;
2171
    __asm__ volatile(
2172
        "1: \n\t"
2173
        "movaps   (%2,%0), %%xmm0 \n\t"
2174
        "movaps 16(%2,%0), %%xmm1 \n\t"
2175
        "mulps    (%3,%0), %%xmm0 \n\t"
2176
        "mulps  16(%3,%0), %%xmm1 \n\t"
2177
        "addps    (%4,%0), %%xmm0 \n\t"
2178
        "addps  16(%4,%0), %%xmm1 \n\t"
2179
        "movaps %%xmm0,   (%1,%0) \n\t"
2180
        "movaps %%xmm1, 16(%1,%0) \n\t"
2181
        "sub  $32, %0 \n\t"
2182
        "jge  1b \n\t"
2183
        :"+r"(i)
2184
        :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2185
        :"memory"
2186
    );
2187
}
2188

    
2189
static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
2190
                                      const float *win, float add_bias, int len){
2191
#if HAVE_6REGS
2192
    if(add_bias == 0){
2193
        x86_reg i = -len*4;
2194
        x86_reg j = len*4-8;
2195
        __asm__ volatile(
2196
            "1: \n"
2197
            "pswapd  (%5,%1), %%mm1 \n"
2198
            "movq    (%5,%0), %%mm0 \n"
2199
            "pswapd  (%4,%1), %%mm5 \n"
2200
            "movq    (%3,%0), %%mm4 \n"
2201
            "movq      %%mm0, %%mm2 \n"
2202
            "movq      %%mm1, %%mm3 \n"
2203
            "pfmul     %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
2204
            "pfmul     %%mm5, %%mm3 \n" // src1[    j]*win[len+j]
2205
            "pfmul     %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
2206
            "pfmul     %%mm5, %%mm0 \n" // src1[    j]*win[len+i]
2207
            "pfadd     %%mm3, %%mm2 \n"
2208
            "pfsub     %%mm0, %%mm1 \n"
2209
            "pswapd    %%mm2, %%mm2 \n"
2210
            "movq      %%mm1, (%2,%0) \n"
2211
            "movq      %%mm2, (%2,%1) \n"
2212
            "sub $8, %1 \n"
2213
            "add $8, %0 \n"
2214
            "jl 1b \n"
2215
            "femms \n"
2216
            :"+r"(i), "+r"(j)
2217
            :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2218
        );
2219
    }else
2220
#endif
2221
        ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
2222
}
2223

    
2224
static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
2225
                                   const float *win, float add_bias, int len){
2226
#if HAVE_6REGS
2227
    if(add_bias == 0){
2228
        x86_reg i = -len*4;
2229
        x86_reg j = len*4-16;
2230
        __asm__ volatile(
2231
            "1: \n"
2232
            "movaps       (%5,%1), %%xmm1 \n"
2233
            "movaps       (%5,%0), %%xmm0 \n"
2234
            "movaps       (%4,%1), %%xmm5 \n"
2235
            "movaps       (%3,%0), %%xmm4 \n"
2236
            "shufps $0x1b, %%xmm1, %%xmm1 \n"
2237
            "shufps $0x1b, %%xmm5, %%xmm5 \n"
2238
            "movaps        %%xmm0, %%xmm2 \n"
2239
            "movaps        %%xmm1, %%xmm3 \n"
2240
            "mulps         %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
2241
            "mulps         %%xmm5, %%xmm3 \n" // src1[    j]*win[len+j]
2242
            "mulps         %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
2243
            "mulps         %%xmm5, %%xmm0 \n" // src1[    j]*win[len+i]
2244
            "addps         %%xmm3, %%xmm2 \n"
2245
            "subps         %%xmm0, %%xmm1 \n"
2246
            "shufps $0x1b, %%xmm2, %%xmm2 \n"
2247
            "movaps        %%xmm1, (%2,%0) \n"
2248
            "movaps        %%xmm2, (%2,%1) \n"
2249
            "sub $16, %1 \n"
2250
            "add $16, %0 \n"
2251
            "jl 1b \n"
2252
            :"+r"(i), "+r"(j)
2253
            :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2254
        );
2255
    }else
2256
#endif
2257
        ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
2258
}
2259

    
2260
static void int32_to_float_fmul_scalar_sse(float *dst, const int *src, float mul, int len)
2261
{
2262
    x86_reg i = -4*len;
2263
    __asm__ volatile(
2264
        "movss  %3, %%xmm4 \n"
2265
        "shufps $0, %%xmm4, %%xmm4 \n"
2266
        "1: \n"
2267
        "cvtpi2ps   (%2,%0), %%xmm0 \n"
2268
        "cvtpi2ps  8(%2,%0), %%xmm1 \n"
2269
        "cvtpi2ps 16(%2,%0), %%xmm2 \n"
2270
        "cvtpi2ps 24(%2,%0), %%xmm3 \n"
2271
        "movlhps  %%xmm1,    %%xmm0 \n"
2272
        "movlhps  %%xmm3,    %%xmm2 \n"
2273
        "mulps    %%xmm4,    %%xmm0 \n"
2274
        "mulps    %%xmm4,    %%xmm2 \n"
2275
        "movaps   %%xmm0,   (%1,%0) \n"
2276
        "movaps   %%xmm2, 16(%1,%0) \n"
2277
        "add $32, %0 \n"
2278
        "jl 1b \n"
2279
        :"+r"(i)
2280
        :"r"(dst+len), "r"(src+len), "m"(mul)
2281
    );
2282
}
2283

    
2284
static void int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len)
2285
{
2286
    x86_reg i = -4*len;
2287
    __asm__ volatile(
2288
        "movss  %3, %%xmm4 \n"
2289
        "shufps $0, %%xmm4, %%xmm4 \n"
2290
        "1: \n"
2291
        "cvtdq2ps   (%2,%0), %%xmm0 \n"
2292
        "cvtdq2ps 16(%2,%0), %%xmm1 \n"
2293
        "mulps    %%xmm4,    %%xmm0 \n"
2294
        "mulps    %%xmm4,    %%xmm1 \n"
2295
        "movaps   %%xmm0,   (%1,%0) \n"
2296
        "movaps   %%xmm1, 16(%1,%0) \n"
2297
        "add $32, %0 \n"
2298
        "jl 1b \n"
2299
        :"+r"(i)
2300
        :"r"(dst+len), "r"(src+len), "m"(mul)
2301
    );
2302
}
2303

    
2304
static void vector_clipf_sse(float *dst, const float *src, float min, float max,
2305
                             int len)
2306
{
2307
    x86_reg i = (len-16)*4;
2308
    __asm__ volatile(
2309
        "movss  %3, %%xmm4 \n"
2310
        "movss  %4, %%xmm5 \n"
2311
        "shufps $0, %%xmm4, %%xmm4 \n"
2312
        "shufps $0, %%xmm5, %%xmm5 \n"
2313
        "1: \n\t"
2314
        "movaps    (%2,%0), %%xmm0 \n\t" // 3/1 on intel
2315
        "movaps  16(%2,%0), %%xmm1 \n\t"
2316
        "movaps  32(%2,%0), %%xmm2 \n\t"
2317
        "movaps  48(%2,%0), %%xmm3 \n\t"
2318
        "maxps      %%xmm4, %%xmm0 \n\t"
2319
        "maxps      %%xmm4, %%xmm1 \n\t"
2320
        "maxps      %%xmm4, %%xmm2 \n\t"
2321
        "maxps      %%xmm4, %%xmm3 \n\t"
2322
        "minps      %%xmm5, %%xmm0 \n\t"
2323
        "minps      %%xmm5, %%xmm1 \n\t"
2324
        "minps      %%xmm5, %%xmm2 \n\t"
2325
        "minps      %%xmm5, %%xmm3 \n\t"
2326
        "movaps  %%xmm0,   (%1,%0) \n\t"
2327
        "movaps  %%xmm1, 16(%1,%0) \n\t"
2328
        "movaps  %%xmm2, 32(%1,%0) \n\t"
2329
        "movaps  %%xmm3, 48(%1,%0) \n\t"
2330
        "sub  $64, %0 \n\t"
2331
        "jge 1b \n\t"
2332
        :"+&r"(i)
2333
        :"r"(dst), "r"(src), "m"(min), "m"(max)
2334
        :"memory"
2335
    );
2336
}
2337

    
2338
static void float_to_int16_3dnow(int16_t *dst, const float *src, long len){
2339
    x86_reg reglen = len;
2340
    // not bit-exact: pf2id uses different rounding than C and SSE
2341
    __asm__ volatile(
2342
        "add        %0          , %0        \n\t"
2343
        "lea         (%2,%0,2)  , %2        \n\t"
2344
        "add        %0          , %1        \n\t"
2345
        "neg        %0                      \n\t"
2346
        "1:                                 \n\t"
2347
        "pf2id       (%2,%0,2)  , %%mm0     \n\t"
2348
        "pf2id      8(%2,%0,2)  , %%mm1     \n\t"
2349
        "pf2id     16(%2,%0,2)  , %%mm2     \n\t"
2350
        "pf2id     24(%2,%0,2)  , %%mm3     \n\t"
2351
        "packssdw   %%mm1       , %%mm0     \n\t"
2352
        "packssdw   %%mm3       , %%mm2     \n\t"
2353
        "movq       %%mm0       ,  (%1,%0)  \n\t"
2354
        "movq       %%mm2       , 8(%1,%0)  \n\t"
2355
        "add        $16         , %0        \n\t"
2356
        " js 1b                             \n\t"
2357
        "femms                              \n\t"
2358
        :"+r"(reglen), "+r"(dst), "+r"(src)
2359
    );
2360
}
2361
static void float_to_int16_sse(int16_t *dst, const float *src, long len){
2362
    x86_reg reglen = len;
2363
    __asm__ volatile(
2364
        "add        %0          , %0        \n\t"
2365
        "lea         (%2,%0,2)  , %2        \n\t"
2366
        "add        %0          , %1        \n\t"
2367
        "neg        %0                      \n\t"
2368
        "1:                                 \n\t"
2369
        "cvtps2pi    (%2,%0,2)  , %%mm0     \n\t"
2370
        "cvtps2pi   8(%2,%0,2)  , %%mm1     \n\t"
2371
        "cvtps2pi  16(%2,%0,2)  , %%mm2     \n\t"
2372
        "cvtps2pi  24(%2,%0,2)  , %%mm3     \n\t"
2373
        "packssdw   %%mm1       , %%mm0     \n\t"
2374
        "packssdw   %%mm3       , %%mm2     \n\t"
2375
        "movq       %%mm0       ,  (%1,%0)  \n\t"
2376
        "movq       %%mm2       , 8(%1,%0)  \n\t"
2377
        "add        $16         , %0        \n\t"
2378
        " js 1b                             \n\t"
2379
        "emms                               \n\t"
2380
        :"+r"(reglen), "+r"(dst), "+r"(src)
2381
    );
2382
}
2383

    
2384
static void float_to_int16_sse2(int16_t *dst, const float *src, long len){
2385
    x86_reg reglen = len;
2386
    __asm__ volatile(
2387
        "add        %0          , %0        \n\t"
2388
        "lea         (%2,%0,2)  , %2        \n\t"
2389
        "add        %0          , %1        \n\t"
2390
        "neg        %0                      \n\t"
2391
        "1:                                 \n\t"
2392
        "cvtps2dq    (%2,%0,2)  , %%xmm0    \n\t"
2393
        "cvtps2dq  16(%2,%0,2)  , %%xmm1    \n\t"
2394
        "packssdw   %%xmm1      , %%xmm0    \n\t"
2395
        "movdqa     %%xmm0      ,  (%1,%0)  \n\t"
2396
        "add        $16         , %0        \n\t"
2397
        " js 1b                             \n\t"
2398
        :"+r"(reglen), "+r"(dst), "+r"(src)
2399
    );
2400
}
2401

    
2402
void ff_vp3_idct_mmx(int16_t *input_data);
2403
void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2404
void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2405

    
2406
void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block);
2407

    
2408
void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2409
void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2410

    
2411
void ff_vp3_idct_sse2(int16_t *input_data);
2412
void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2413
void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2414

    
2415
void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len);
2416
void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len);
2417
void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len);
2418
int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2, int order, int shift);
2419
int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2, int order, int shift);
2420
int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2421
int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2422
int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2423
void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top);
2424
int  ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left);
2425
int  ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left);
2426

    
2427
#if !HAVE_YASM
2428
#define ff_float_to_int16_interleave6_sse(a,b,c)   float_to_int16_interleave_misc_sse(a,b,c,6)
2429
#define ff_float_to_int16_interleave6_3dnow(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
2430
#define ff_float_to_int16_interleave6_3dn2(a,b,c)  float_to_int16_interleave_misc_3dnow(a,b,c,6)
2431
#endif
2432
#define ff_float_to_int16_interleave6_sse2 ff_float_to_int16_interleave6_sse
2433

    
2434
#define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \
2435
/* gcc pessimizes register allocation if this is in the same function as float_to_int16_interleave_sse2*/\
2436
static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const float **src, long len, int channels){\
2437
    DECLARE_ALIGNED(16, int16_t, tmp)[len];\
2438
    int i,j,c;\
2439
    for(c=0; c<channels; c++){\
2440
        float_to_int16_##cpu(tmp, src[c], len);\
2441
        for(i=0, j=c; i<len; i++, j+=channels)\
2442
            dst[j] = tmp[i];\
2443
    }\
2444
}\
2445
\
2446
static void float_to_int16_interleave_##cpu(int16_t *dst, const float **src, long len, int channels){\
2447
    if(channels==1)\
2448
        float_to_int16_##cpu(dst, src[0], len);\
2449
    else if(channels==2){\
2450
        x86_reg reglen = len; \
2451
        const float *src0 = src[0];\
2452
        const float *src1 = src[1];\
2453
        __asm__ volatile(\
2454
            "shl $2, %0 \n"\
2455
            "add %0, %1 \n"\
2456
            "add %0, %2 \n"\
2457
            "add %0, %3 \n"\
2458
            "neg %0 \n"\
2459
            body\
2460
            :"+r"(reglen), "+r"(dst), "+r"(src0), "+r"(src1)\
2461
        );\
2462
    }else if(channels==6){\
2463
        ff_float_to_int16_interleave6_##cpu(dst, src, len);\
2464
    }else\
2465
        float_to_int16_interleave_misc_##cpu(dst, src, len, channels);\
2466
}
2467

    
2468
FLOAT_TO_INT16_INTERLEAVE(3dnow,
2469
    "1:                         \n"
2470
    "pf2id     (%2,%0), %%mm0   \n"
2471
    "pf2id    8(%2,%0), %%mm1   \n"
2472
    "pf2id     (%3,%0), %%mm2   \n"
2473
    "pf2id    8(%3,%0), %%mm3   \n"
2474
    "packssdw    %%mm1, %%mm0   \n"
2475
    "packssdw    %%mm3, %%mm2   \n"
2476
    "movq        %%mm0, %%mm1   \n"
2477
    "punpcklwd   %%mm2, %%mm0   \n"
2478
    "punpckhwd   %%mm2, %%mm1   \n"
2479
    "movq        %%mm0,  (%1,%0)\n"
2480
    "movq        %%mm1, 8(%1,%0)\n"
2481
    "add $16, %0                \n"
2482
    "js 1b                      \n"
2483
    "femms                      \n"
2484
)
2485

    
2486
FLOAT_TO_INT16_INTERLEAVE(sse,
2487
    "1:                         \n"
2488
    "cvtps2pi  (%2,%0), %%mm0   \n"
2489
    "cvtps2pi 8(%2,%0), %%mm1   \n"
2490
    "cvtps2pi  (%3,%0), %%mm2   \n"
2491
    "cvtps2pi 8(%3,%0), %%mm3   \n"
2492
    "packssdw    %%mm1, %%mm0   \n"
2493
    "packssdw    %%mm3, %%mm2   \n"
2494
    "movq        %%mm0, %%mm1   \n"
2495
    "punpcklwd   %%mm2, %%mm0   \n"
2496
    "punpckhwd   %%mm2, %%mm1   \n"
2497
    "movq        %%mm0,  (%1,%0)\n"
2498
    "movq        %%mm1, 8(%1,%0)\n"
2499
    "add $16, %0                \n"
2500
    "js 1b                      \n"
2501
    "emms                       \n"
2502
)
2503

    
2504
FLOAT_TO_INT16_INTERLEAVE(sse2,
2505
    "1:                         \n"
2506
    "cvtps2dq  (%2,%0), %%xmm0  \n"
2507
    "cvtps2dq  (%3,%0), %%xmm1  \n"
2508
    "packssdw   %%xmm1, %%xmm0  \n"
2509
    "movhlps    %%xmm0, %%xmm1  \n"
2510
    "punpcklwd  %%xmm1, %%xmm0  \n"
2511
    "movdqa     %%xmm0, (%1,%0) \n"
2512
    "add $16, %0                \n"
2513
    "js 1b                      \n"
2514
)
2515

    
2516
static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long len, int channels){
2517
    if(channels==6)
2518
        ff_float_to_int16_interleave6_3dn2(dst, src, len);
2519
    else
2520
        float_to_int16_interleave_3dnow(dst, src, len, channels);
2521
}
2522

    
2523
float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
2524

    
2525
void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2526
{
2527
    int mm_flags = av_get_cpu_flags();
2528

    
2529
    if (avctx->dsp_mask) {
2530
        if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
2531
            mm_flags |= (avctx->dsp_mask & 0xffff);
2532
        else
2533
            mm_flags &= ~(avctx->dsp_mask & 0xffff);
2534
    }
2535

    
2536
#if 0
2537
    av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
2538
    if (mm_flags & AV_CPU_FLAG_MMX)
2539
        av_log(avctx, AV_LOG_INFO, " mmx");
2540
    if (mm_flags & AV_CPU_FLAG_MMX2)
2541
        av_log(avctx, AV_LOG_INFO, " mmx2");
2542
    if (mm_flags & AV_CPU_FLAG_3DNOW)
2543
        av_log(avctx, AV_LOG_INFO, " 3dnow");
2544
    if (mm_flags & AV_CPU_FLAG_SSE)
2545
        av_log(avctx, AV_LOG_INFO, " sse");
2546
    if (mm_flags & AV_CPU_FLAG_SSE2)
2547
        av_log(avctx, AV_LOG_INFO, " sse2");
2548
    av_log(avctx, AV_LOG_INFO, "\n");
2549
#endif
2550

    
2551
    if (mm_flags & AV_CPU_FLAG_MMX) {
2552
        const int idct_algo= avctx->idct_algo;
2553

    
2554
        if(avctx->lowres==0){
2555
            if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
2556
                c->idct_put= ff_simple_idct_put_mmx;
2557
                c->idct_add= ff_simple_idct_add_mmx;
2558
                c->idct    = ff_simple_idct_mmx;
2559
                c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
2560
#if CONFIG_GPL
2561
            }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
2562
                if(mm_flags & AV_CPU_FLAG_MMX2){
2563
                    c->idct_put= ff_libmpeg2mmx2_idct_put;
2564
                    c->idct_add= ff_libmpeg2mmx2_idct_add;
2565
                    c->idct    = ff_mmxext_idct;
2566
                }else{
2567
                    c->idct_put= ff_libmpeg2mmx_idct_put;
2568
                    c->idct_add= ff_libmpeg2mmx_idct_add;
2569
                    c->idct    = ff_mmx_idct;
2570
                }
2571
                c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
2572
#endif
2573
            }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
2574
                     idct_algo==FF_IDCT_VP3 && HAVE_YASM){
2575
                if(mm_flags & AV_CPU_FLAG_SSE2){
2576
                    c->idct_put= ff_vp3_idct_put_sse2;
2577
                    c->idct_add= ff_vp3_idct_add_sse2;
2578
                    c->idct    = ff_vp3_idct_sse2;
2579
                    c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2580
                }else{
2581
                    c->idct_put= ff_vp3_idct_put_mmx;
2582
                    c->idct_add= ff_vp3_idct_add_mmx;
2583
                    c->idct    = ff_vp3_idct_mmx;
2584
                    c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
2585
                }
2586
            }else if(idct_algo==FF_IDCT_CAVS){
2587
                    c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2588
            }else if(idct_algo==FF_IDCT_XVIDMMX){
2589
                if(mm_flags & AV_CPU_FLAG_SSE2){
2590
                    c->idct_put= ff_idct_xvid_sse2_put;
2591
                    c->idct_add= ff_idct_xvid_sse2_add;
2592
                    c->idct    = ff_idct_xvid_sse2;
2593
                    c->idct_permutation_type= FF_SSE2_IDCT_PERM;
2594
                }else if(mm_flags & AV_CPU_FLAG_MMX2){
2595
                    c->idct_put= ff_idct_xvid_mmx2_put;
2596
                    c->idct_add= ff_idct_xvid_mmx2_add;
2597
                    c->idct    = ff_idct_xvid_mmx2;
2598
                }else{
2599
                    c->idct_put= ff_idct_xvid_mmx_put;
2600
                    c->idct_add= ff_idct_xvid_mmx_add;
2601
                    c->idct    = ff_idct_xvid_mmx;
2602
                }
2603
            }
2604
        }
2605

    
2606
        c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
2607
        c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
2608
        c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
2609
        c->clear_block  = clear_block_mmx;
2610
        c->clear_blocks = clear_blocks_mmx;
2611
        if ((mm_flags & AV_CPU_FLAG_SSE) &&
2612
            !(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){
2613
            /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
2614
            c->clear_block  = clear_block_sse;
2615
            c->clear_blocks = clear_blocks_sse;
2616
        }
2617

    
2618
#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
2619
        c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
2620
        c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
2621
        c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
2622
        c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
2623

    
2624
        SET_HPEL_FUNCS(put, 0, 16, mmx);
2625
        SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
2626
        SET_HPEL_FUNCS(avg, 0, 16, mmx);
2627
        SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
2628
        SET_HPEL_FUNCS(put, 1, 8, mmx);
2629
        SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
2630
        SET_HPEL_FUNCS(avg, 1, 8, mmx);
2631
        SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
2632

    
2633
        c->gmc= gmc_mmx;
2634

    
2635
        c->add_bytes= add_bytes_mmx;
2636
        c->add_bytes_l2= add_bytes_l2_mmx;
2637

    
2638
        c->draw_edges = draw_edges_mmx;
2639

    
2640
        if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2641
            c->h263_v_loop_filter= h263_v_loop_filter_mmx;
2642
            c->h263_h_loop_filter= h263_h_loop_filter_mmx;
2643
        }
2644

    
2645
#if HAVE_YASM
2646
        c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_mmx_rnd;
2647
        c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_mmx;
2648
        c->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_mmx_nornd;
2649

    
2650
        c->put_rv40_chroma_pixels_tab[0]= ff_put_rv40_chroma_mc8_mmx;
2651
        c->put_rv40_chroma_pixels_tab[1]= ff_put_rv40_chroma_mc4_mmx;
2652
#endif
2653

    
2654
        if (mm_flags & AV_CPU_FLAG_MMX2) {
2655
            c->prefetch = prefetch_mmx2;
2656

    
2657
            c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2658
            c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
2659

    
2660
            c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2661
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2662
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
2663

    
2664
            c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2665
            c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
2666

    
2667
            c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2668
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2669
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
2670

    
2671
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2672
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2673
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2674
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2675
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2676
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2677
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
2678

    
2679
                if (CONFIG_VP3_DECODER && HAVE_YASM) {
2680
                    c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
2681
                    c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
2682
                }
2683
            }
2684
            if (CONFIG_VP3_DECODER && HAVE_YASM) {
2685
                c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
2686
            }
2687

    
2688
            if (CONFIG_VP3_DECODER
2689
                && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
2690
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
2691
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
2692
            }
2693

    
2694
#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \
2695
            c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \
2696
            c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \
2697
            c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \
2698
            c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \
2699
            c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \
2700
            c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \
2701
            c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \
2702
            c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \
2703
            c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \
2704
            c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \
2705
            c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \
2706
            c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \
2707
            c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \
2708
            c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \
2709
            c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \
2710
            c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU
2711

    
2712
            SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2);
2713
            SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2);
2714
            SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2);
2715
            SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2);
2716
            SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2);
2717
            SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2);
2718

    
2719
            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2);
2720
            SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2);
2721
            SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2);
2722
            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2);
2723
            SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2);
2724
            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2);
2725

    
2726
            SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2);
2727
            SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2);
2728
            SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2);
2729
            SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2);
2730

    
2731
#if HAVE_YASM
2732
            c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_mmx2;
2733
            c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_mmx2;
2734

    
2735
            c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_mmx2_nornd;
2736

    
2737
            c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_mmx2_rnd;
2738
            c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_mmx2;
2739
            c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_mmx2;
2740
            c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_mmx2;
2741

    
2742
            c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
2743
#endif
2744
#if HAVE_7REGS && HAVE_TEN_OPERANDS
2745
            if( mm_flags&AV_CPU_FLAG_3DNOW )
2746
                c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
2747
#endif
2748

    
2749
            if (CONFIG_VC1_DECODER)
2750
                ff_vc1dsp_init_mmx(c, avctx);
2751

    
2752
            c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
2753
        } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
2754
            c->prefetch = prefetch_3dnow;
2755

    
2756
            c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
2757
            c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
2758

    
2759
            c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
2760
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
2761
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
2762

    
2763
            c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
2764
            c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
2765

    
2766
            c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
2767
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
2768
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
2769

    
2770
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2771
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
2772
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
2773
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
2774
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
2775
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
2776
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
2777
            }
2778

    
2779
            if (CONFIG_VP3_DECODER
2780
                && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
2781
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
2782
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
2783
            }
2784

    
2785
            SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow);
2786
            SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow);
2787
            SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow);
2788
            SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow);
2789
            SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow);
2790
            SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow);
2791

    
2792
            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow);
2793
            SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow);
2794
            SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow);
2795
            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow);
2796
            SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow);
2797
            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow);
2798

    
2799
            SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow);
2800
            SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow);
2801
            SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow);
2802
            SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow);
2803

    
2804
#if HAVE_YASM
2805
            c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_3dnow_rnd;
2806
            c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_3dnow;
2807

    
2808
            c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_3dnow_nornd;
2809

    
2810
            c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_3dnow;
2811
            c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_3dnow;
2812
#endif
2813
        }
2814

    
2815

    
2816
#define H264_QPEL_FUNCS(x, y, CPU)\
2817
            c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\
2818
            c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\
2819
            c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\
2820
            c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU;
2821
        if((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW)){
2822
            // these functions are slower than mmx on AMD, but faster on Intel
2823
            c->put_pixels_tab[0][0] = put_pixels16_sse2;
2824
            c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2;
2825
            c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
2826
            H264_QPEL_FUNCS(0, 0, sse2);
2827
        }
2828
        if(mm_flags & AV_CPU_FLAG_SSE2){
2829
            H264_QPEL_FUNCS(0, 1, sse2);
2830
            H264_QPEL_FUNCS(0, 2, sse2);
2831
            H264_QPEL_FUNCS(0, 3, sse2);
2832
            H264_QPEL_FUNCS(1, 1, sse2);
2833
            H264_QPEL_FUNCS(1, 2, sse2);
2834
            H264_QPEL_FUNCS(1, 3, sse2);
2835
            H264_QPEL_FUNCS(2, 1, sse2);
2836
            H264_QPEL_FUNCS(2, 2, sse2);
2837
            H264_QPEL_FUNCS(2, 3, sse2);
2838
            H264_QPEL_FUNCS(3, 1, sse2);
2839
            H264_QPEL_FUNCS(3, 2, sse2);
2840
            H264_QPEL_FUNCS(3, 3, sse2);
2841
        }
2842
#if HAVE_SSSE3
2843
        if(mm_flags & AV_CPU_FLAG_SSSE3){
2844
            H264_QPEL_FUNCS(1, 0, ssse3);
2845
            H264_QPEL_FUNCS(1, 1, ssse3);
2846
            H264_QPEL_FUNCS(1, 2, ssse3);
2847
            H264_QPEL_FUNCS(1, 3, ssse3);
2848
            H264_QPEL_FUNCS(2, 0, ssse3);
2849
            H264_QPEL_FUNCS(2, 1, ssse3);
2850
            H264_QPEL_FUNCS(2, 2, ssse3);
2851
            H264_QPEL_FUNCS(2, 3, ssse3);
2852
            H264_QPEL_FUNCS(3, 0, ssse3);
2853
            H264_QPEL_FUNCS(3, 1, ssse3);
2854
            H264_QPEL_FUNCS(3, 2, ssse3);
2855
            H264_QPEL_FUNCS(3, 3, ssse3);
2856
            c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3;
2857
#if HAVE_YASM
2858
            c->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_ssse3_nornd;
2859
            c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_ssse3_nornd;
2860
            c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_ssse3_rnd;
2861
            c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_ssse3_rnd;
2862
            c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_ssse3;
2863
            c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_ssse3;
2864
            c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
2865
            if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe
2866
                c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
2867
#endif
2868
        }
2869
#endif
2870

    
2871
        if(mm_flags & AV_CPU_FLAG_3DNOW){
2872
            c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
2873
            c->vector_fmul = vector_fmul_3dnow;
2874
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2875
                c->float_to_int16 = float_to_int16_3dnow;
2876
                c->float_to_int16_interleave = float_to_int16_interleave_3dnow;
2877
            }
2878
        }
2879
        if(mm_flags & AV_CPU_FLAG_3DNOWEXT){
2880
            c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
2881
            c->vector_fmul_window = vector_fmul_window_3dnow2;
2882
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2883
                c->float_to_int16_interleave = float_to_int16_interleave_3dn2;
2884
            }
2885
        }
2886
        if(mm_flags & AV_CPU_FLAG_MMX2){
2887
#if HAVE_YASM
2888
            c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
2889
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
2890
#endif
2891
        }
2892
        if(mm_flags & AV_CPU_FLAG_SSE){
2893
            c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
2894
            c->ac3_downmix = ac3_downmix_sse;
2895
            c->vector_fmul = vector_fmul_sse;
2896
            c->vector_fmul_reverse = vector_fmul_reverse_sse;
2897
            c->vector_fmul_add = vector_fmul_add_sse;
2898
            c->vector_fmul_window = vector_fmul_window_sse;
2899
            c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse;
2900
            c->vector_clipf = vector_clipf_sse;
2901
            c->float_to_int16 = float_to_int16_sse;
2902
            c->float_to_int16_interleave = float_to_int16_interleave_sse;
2903
#if HAVE_YASM
2904
            c->scalarproduct_float = ff_scalarproduct_float_sse;
2905
#endif
2906
        }
2907
        if(mm_flags & AV_CPU_FLAG_3DNOW)
2908
            c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse
2909
        if(mm_flags & AV_CPU_FLAG_SSE2){
2910
            c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2;
2911
            c->float_to_int16 = float_to_int16_sse2;
2912
            c->float_to_int16_interleave = float_to_int16_interleave_sse2;
2913
#if HAVE_YASM
2914
            c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
2915
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
2916
#endif
2917
        }
2918
        if((mm_flags & AV_CPU_FLAG_SSSE3) && !(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW)) && HAVE_YASM) // cachesplit
2919
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
2920
    }
2921

    
2922
    if (CONFIG_ENCODERS)
2923
        dsputilenc_init_mmx(c, avctx);
2924

    
2925
#if 0
2926
    // for speed testing
2927
    get_pixels = just_return;
2928
    put_pixels_clamped = just_return;
2929
    add_pixels_clamped = just_return;
2930

2931
    pix_abs16x16 = just_return;
2932
    pix_abs16x16_x2 = just_return;
2933
    pix_abs16x16_y2 = just_return;
2934
    pix_abs16x16_xy2 = just_return;
2935

2936
    put_pixels_tab[0] = just_return;
2937
    put_pixels_tab[1] = just_return;
2938
    put_pixels_tab[2] = just_return;
2939
    put_pixels_tab[3] = just_return;
2940

2941
    put_no_rnd_pixels_tab[0] = just_return;
2942
    put_no_rnd_pixels_tab[1] = just_return;
2943
    put_no_rnd_pixels_tab[2] = just_return;
2944
    put_no_rnd_pixels_tab[3] = just_return;
2945

2946
    avg_pixels_tab[0] = just_return;
2947
    avg_pixels_tab[1] = just_return;
2948
    avg_pixels_tab[2] = just_return;
2949
    avg_pixels_tab[3] = just_return;
2950

2951
    avg_no_rnd_pixels_tab[0] = just_return;
2952
    avg_no_rnd_pixels_tab[1] = just_return;
2953
    avg_no_rnd_pixels_tab[2] = just_return;
2954
    avg_no_rnd_pixels_tab[3] = just_return;
2955

2956
    //av_fdct = just_return;
2957
    //ff_idct = just_return;
2958
#endif
2959
}