Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / dsputil_mmx.c @ e9f5f020

History | View | Annotate | Download (125 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/x86_cpu.h"
26
#include "libavcodec/dsputil.h"
27
#include "libavcodec/h264dsp.h"
28
#include "libavcodec/mpegvideo.h"
29
#include "libavcodec/simple_idct.h"
30
#include "dsputil_mmx.h"
31
#include "idct_xvid.h"
32

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

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

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

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

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

    
76
DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 };
77
DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 };
78

    
79
#define JUMPALIGN() __asm__ volatile (ASMALIGN(3)::)
80
#define MOVQ_ZERO(regd)  __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
81

    
82
#define MOVQ_BFE(regd) \
83
    __asm__ volatile ( \
84
    "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
85
    "paddb %%" #regd ", %%" #regd " \n\t" ::)
86

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

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

    
105
#endif
106

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

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

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

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

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

    
163
#include "dsputil_mmx_rnd_template.c"
164

    
165
#undef DEF
166
#undef SET_RND
167
#undef PAVGBP
168
#undef PAVGB
169
/***********************************/
170
/* MMX rounding */
171

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

    
177
#include "dsputil_mmx_rnd_template.c"
178

    
179
#undef DEF
180
#undef SET_RND
181
#undef PAVGBP
182
#undef PAVGB
183
#undef OP_AVG
184

    
185
/***********************************/
186
/* 3Dnow specific */
187

    
188
#define DEF(x) x ## _3dnow
189
#define PAVGB "pavgusb"
190
#define OP_AVG PAVGB
191

    
192
#include "dsputil_mmx_avg_template.c"
193

    
194
#undef DEF
195
#undef PAVGB
196
#undef OP_AVG
197

    
198
/***********************************/
199
/* MMX2 specific */
200

    
201
#define DEF(x) x ## _mmx2
202

    
203
/* Introduced only in MMX2 set */
204
#define PAVGB "pavgb"
205
#define OP_AVG PAVGB
206

    
207
#include "dsputil_mmx_avg_template.c"
208

    
209
#undef DEF
210
#undef PAVGB
211
#undef OP_AVG
212

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

    
226
/***********************************/
227
/* standard MMX */
228

    
229
void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
230
{
231
    const DCTELEM *p;
232
    uint8_t *pix;
233

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

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

    
284
DECLARE_ASM_CONST(8, uint8_t, ff_vector128)[8] =
285
  { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
286

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

    
305
void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
306
{
307
    x86_reg line_skip = line_size;
308
    x86_reg line_skip3;
309

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

    
321
void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
322
{
323
    const DCTELEM *p;
324
    uint8_t *pix;
325
    int i;
326

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
712
    __asm__ volatile(
713

    
714
        H263_LOOP_FILTER
715

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

    
729
static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
730
    __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
731
        "movd  %4, %%mm0                \n\t"
732
        "movd  %5, %%mm1                \n\t"
733
        "movd  %6, %%mm2                \n\t"
734
        "movd  %7, %%mm3                \n\t"
735
        "punpcklbw %%mm1, %%mm0         \n\t"
736
        "punpcklbw %%mm3, %%mm2         \n\t"
737
        "movq %%mm0, %%mm1              \n\t"
738
        "punpcklwd %%mm2, %%mm0         \n\t"
739
        "punpckhwd %%mm2, %%mm1         \n\t"
740
        "movd  %%mm0, %0                \n\t"
741
        "punpckhdq %%mm0, %%mm0         \n\t"
742
        "movd  %%mm0, %1                \n\t"
743
        "movd  %%mm1, %2                \n\t"
744
        "punpckhdq %%mm1, %%mm1         \n\t"
745
        "movd  %%mm1, %3                \n\t"
746

    
747
        : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
748
          "=m" (*(uint32_t*)(dst + 1*dst_stride)),
749
          "=m" (*(uint32_t*)(dst + 2*dst_stride)),
750
          "=m" (*(uint32_t*)(dst + 3*dst_stride))
751
        :  "m" (*(uint32_t*)(src + 0*src_stride)),
752
           "m" (*(uint32_t*)(src + 1*src_stride)),
753
           "m" (*(uint32_t*)(src + 2*src_stride)),
754
           "m" (*(uint32_t*)(src + 3*src_stride))
755
    );
756
}
757

    
758
static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
759
    if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
760
    const int strength= ff_h263_loop_filter_strength[qscale];
761
    DECLARE_ALIGNED(8, uint64_t, temp)[4];
762
    uint8_t *btemp= (uint8_t*)temp;
763

    
764
    src -= 2;
765

    
766
    transpose4x4(btemp  , src           , 8, stride);
767
    transpose4x4(btemp+4, src + 4*stride, 8, stride);
768
    __asm__ volatile(
769
        H263_LOOP_FILTER // 5 3 4 6
770

    
771
        : "+m" (temp[0]),
772
          "+m" (temp[1]),
773
          "+m" (temp[2]),
774
          "+m" (temp[3])
775
        : "g" (2*strength), "m"(ff_pb_FC)
776
    );
777

    
778
    __asm__ volatile(
779
        "movq %%mm5, %%mm1              \n\t"
780
        "movq %%mm4, %%mm0              \n\t"
781
        "punpcklbw %%mm3, %%mm5         \n\t"
782
        "punpcklbw %%mm6, %%mm4         \n\t"
783
        "punpckhbw %%mm3, %%mm1         \n\t"
784
        "punpckhbw %%mm6, %%mm0         \n\t"
785
        "movq %%mm5, %%mm3              \n\t"
786
        "movq %%mm1, %%mm6              \n\t"
787
        "punpcklwd %%mm4, %%mm5         \n\t"
788
        "punpcklwd %%mm0, %%mm1         \n\t"
789
        "punpckhwd %%mm4, %%mm3         \n\t"
790
        "punpckhwd %%mm0, %%mm6         \n\t"
791
        "movd %%mm5, (%0)               \n\t"
792
        "punpckhdq %%mm5, %%mm5         \n\t"
793
        "movd %%mm5, (%0,%2)            \n\t"
794
        "movd %%mm3, (%0,%2,2)          \n\t"
795
        "punpckhdq %%mm3, %%mm3         \n\t"
796
        "movd %%mm3, (%0,%3)            \n\t"
797
        "movd %%mm1, (%1)               \n\t"
798
        "punpckhdq %%mm1, %%mm1         \n\t"
799
        "movd %%mm1, (%1,%2)            \n\t"
800
        "movd %%mm6, (%1,%2,2)          \n\t"
801
        "punpckhdq %%mm6, %%mm6         \n\t"
802
        "movd %%mm6, (%1,%3)            \n\t"
803
        :: "r" (src),
804
           "r" (src + 4*stride),
805
           "r" ((x86_reg)   stride ),
806
           "r" ((x86_reg)(3*stride))
807
    );
808
    }
809
}
810

    
811
/* draw the edges of width 'w' of an image of size width, height
812
   this mmx version can only handle w==8 || w==16 */
813
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
814
{
815
    uint8_t *ptr, *last_line;
816
    int i;
817

    
818
    last_line = buf + (height - 1) * wrap;
819
    /* left and right */
820
    ptr = buf;
821
    if(w==8)
822
    {
823
        __asm__ volatile(
824
                "1:                             \n\t"
825
                "movd (%0), %%mm0               \n\t"
826
                "punpcklbw %%mm0, %%mm0         \n\t"
827
                "punpcklwd %%mm0, %%mm0         \n\t"
828
                "punpckldq %%mm0, %%mm0         \n\t"
829
                "movq %%mm0, -8(%0)             \n\t"
830
                "movq -8(%0, %2), %%mm1         \n\t"
831
                "punpckhbw %%mm1, %%mm1         \n\t"
832
                "punpckhwd %%mm1, %%mm1         \n\t"
833
                "punpckhdq %%mm1, %%mm1         \n\t"
834
                "movq %%mm1, (%0, %2)           \n\t"
835
                "add %1, %0                     \n\t"
836
                "cmp %3, %0                     \n\t"
837
                " jb 1b                         \n\t"
838
                : "+r" (ptr)
839
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
840
        );
841
    }
842
    else
843
    {
844
        __asm__ volatile(
845
                "1:                             \n\t"
846
                "movd (%0), %%mm0               \n\t"
847
                "punpcklbw %%mm0, %%mm0         \n\t"
848
                "punpcklwd %%mm0, %%mm0         \n\t"
849
                "punpckldq %%mm0, %%mm0         \n\t"
850
                "movq %%mm0, -8(%0)             \n\t"
851
                "movq %%mm0, -16(%0)            \n\t"
852
                "movq -8(%0, %2), %%mm1         \n\t"
853
                "punpckhbw %%mm1, %%mm1         \n\t"
854
                "punpckhwd %%mm1, %%mm1         \n\t"
855
                "punpckhdq %%mm1, %%mm1         \n\t"
856
                "movq %%mm1, (%0, %2)           \n\t"
857
                "movq %%mm1, 8(%0, %2)          \n\t"
858
                "add %1, %0                     \n\t"
859
                "cmp %3, %0                     \n\t"
860
                " jb 1b                         \n\t"
861
                : "+r" (ptr)
862
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
863
        );
864
    }
865

    
866
    for(i=0;i<w;i+=4) {
867
        /* top and bottom (and hopefully also the corners) */
868
        ptr= buf - (i + 1) * wrap - w;
869
        __asm__ volatile(
870
                "1:                             \n\t"
871
                "movq (%1, %0), %%mm0           \n\t"
872
                "movq %%mm0, (%0)               \n\t"
873
                "movq %%mm0, (%0, %2)           \n\t"
874
                "movq %%mm0, (%0, %2, 2)        \n\t"
875
                "movq %%mm0, (%0, %3)           \n\t"
876
                "add $8, %0                     \n\t"
877
                "cmp %4, %0                     \n\t"
878
                " jb 1b                         \n\t"
879
                : "+r" (ptr)
880
                : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
881
        );
882
        ptr= last_line + (i + 1) * wrap - w;
883
        __asm__ volatile(
884
                "1:                             \n\t"
885
                "movq (%1, %0), %%mm0           \n\t"
886
                "movq %%mm0, (%0)               \n\t"
887
                "movq %%mm0, (%0, %2)           \n\t"
888
                "movq %%mm0, (%0, %2, 2)        \n\t"
889
                "movq %%mm0, (%0, %3)           \n\t"
890
                "add $8, %0                     \n\t"
891
                "cmp %4, %0                     \n\t"
892
                " jb 1b                         \n\t"
893
                : "+r" (ptr)
894
                : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
895
        );
896
    }
897
}
898

    
899
#define PAETH(cpu, abs3)\
900
static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
901
{\
902
    x86_reg i = -bpp;\
903
    x86_reg end = w-3;\
904
    __asm__ volatile(\
905
        "pxor      %%mm7, %%mm7 \n"\
906
        "movd    (%1,%0), %%mm0 \n"\
907
        "movd    (%2,%0), %%mm1 \n"\
908
        "punpcklbw %%mm7, %%mm0 \n"\
909
        "punpcklbw %%mm7, %%mm1 \n"\
910
        "add       %4, %0 \n"\
911
        "1: \n"\
912
        "movq      %%mm1, %%mm2 \n"\
913
        "movd    (%2,%0), %%mm1 \n"\
914
        "movq      %%mm2, %%mm3 \n"\
915
        "punpcklbw %%mm7, %%mm1 \n"\
916
        "movq      %%mm2, %%mm4 \n"\
917
        "psubw     %%mm1, %%mm3 \n"\
918
        "psubw     %%mm0, %%mm4 \n"\
919
        "movq      %%mm3, %%mm5 \n"\
920
        "paddw     %%mm4, %%mm5 \n"\
921
        abs3\
922
        "movq      %%mm4, %%mm6 \n"\
923
        "pminsw    %%mm5, %%mm6 \n"\
924
        "pcmpgtw   %%mm6, %%mm3 \n"\
925
        "pcmpgtw   %%mm5, %%mm4 \n"\
926
        "movq      %%mm4, %%mm6 \n"\
927
        "pand      %%mm3, %%mm4 \n"\
928
        "pandn     %%mm3, %%mm6 \n"\
929
        "pandn     %%mm0, %%mm3 \n"\
930
        "movd    (%3,%0), %%mm0 \n"\
931
        "pand      %%mm1, %%mm6 \n"\
932
        "pand      %%mm4, %%mm2 \n"\
933
        "punpcklbw %%mm7, %%mm0 \n"\
934
        "movq      %6,    %%mm5 \n"\
935
        "paddw     %%mm6, %%mm0 \n"\
936
        "paddw     %%mm2, %%mm3 \n"\
937
        "paddw     %%mm3, %%mm0 \n"\
938
        "pand      %%mm5, %%mm0 \n"\
939
        "movq      %%mm0, %%mm3 \n"\
940
        "packuswb  %%mm3, %%mm3 \n"\
941
        "movd      %%mm3, (%1,%0) \n"\
942
        "add       %4, %0 \n"\
943
        "cmp       %5, %0 \n"\
944
        "jle 1b \n"\
945
        :"+r"(i)\
946
        :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
947
         "m"(ff_pw_255)\
948
        :"memory"\
949
    );\
950
}
951

    
952
#define ABS3_MMX2\
953
        "psubw     %%mm5, %%mm7 \n"\
954
        "pmaxsw    %%mm7, %%mm5 \n"\
955
        "pxor      %%mm6, %%mm6 \n"\
956
        "pxor      %%mm7, %%mm7 \n"\
957
        "psubw     %%mm3, %%mm6 \n"\
958
        "psubw     %%mm4, %%mm7 \n"\
959
        "pmaxsw    %%mm6, %%mm3 \n"\
960
        "pmaxsw    %%mm7, %%mm4 \n"\
961
        "pxor      %%mm7, %%mm7 \n"
962

    
963
#define ABS3_SSSE3\
964
        "pabsw     %%mm3, %%mm3 \n"\
965
        "pabsw     %%mm4, %%mm4 \n"\
966
        "pabsw     %%mm5, %%mm5 \n"
967

    
968
PAETH(mmx2, ABS3_MMX2)
969
#if HAVE_SSSE3
970
PAETH(ssse3, ABS3_SSSE3)
971
#endif
972

    
973
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
974
        "paddw " #m4 ", " #m3 "           \n\t" /* x1 */\
975
        "movq "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */\
976
        "pmullw " #m3 ", %%mm4            \n\t" /* 20x1 */\
977
        "movq "#in7", " #m3 "             \n\t" /* d */\
978
        "movq "#in0", %%mm5               \n\t" /* D */\
979
        "paddw " #m3 ", %%mm5             \n\t" /* x4 */\
980
        "psubw %%mm5, %%mm4               \n\t" /* 20x1 - x4 */\
981
        "movq "#in1", %%mm5               \n\t" /* C */\
982
        "movq "#in2", %%mm6               \n\t" /* B */\
983
        "paddw " #m6 ", %%mm5             \n\t" /* x3 */\
984
        "paddw " #m5 ", %%mm6             \n\t" /* x2 */\
985
        "paddw %%mm6, %%mm6               \n\t" /* 2x2 */\
986
        "psubw %%mm6, %%mm5               \n\t" /* -2x2 + x3 */\
987
        "pmullw "MANGLE(ff_pw_3)", %%mm5  \n\t" /* -6x2 + 3x3 */\
988
        "paddw " #rnd ", %%mm4            \n\t" /* x2 */\
989
        "paddw %%mm4, %%mm5               \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
990
        "psraw $5, %%mm5                  \n\t"\
991
        "packuswb %%mm5, %%mm5            \n\t"\
992
        OP(%%mm5, out, %%mm7, d)
993

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

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

    
1620
#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "        \n\t"
1621
#define AVG_3DNOW_OP(a,b,temp, size) \
1622
"mov" #size " " #b ", " #temp "   \n\t"\
1623
"pavgusb " #temp ", " #a "        \n\t"\
1624
"mov" #size " " #a ", " #b "      \n\t"
1625
#define AVG_MMX2_OP(a,b,temp, size) \
1626
"mov" #size " " #b ", " #temp "   \n\t"\
1627
"pavgb " #temp ", " #a "          \n\t"\
1628
"mov" #size " " #a ", " #b "      \n\t"
1629

    
1630
QPEL_BASE(put_       , ff_pw_16, _       , PUT_OP, PUT_OP)
1631
QPEL_BASE(avg_       , ff_pw_16, _       , AVG_MMX2_OP, AVG_3DNOW_OP)
1632
QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
1633
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, 3dnow)
1634
QPEL_OP(avg_       , ff_pw_16, _       , AVG_3DNOW_OP, 3dnow)
1635
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
1636
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, mmx2)
1637
QPEL_OP(avg_       , ff_pw_16, _       , AVG_MMX2_OP, mmx2)
1638
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
1639

    
1640
/***********************************/
1641
/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
1642

    
1643
#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
1644
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1645
    OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
1646
}
1647
#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
1648
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1649
    OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
1650
}
1651

    
1652
#define QPEL_2TAP(OPNAME, SIZE, MMX)\
1653
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
1654
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
1655
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
1656
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
1657
                          OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
1658
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
1659
                          OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
1660
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
1661
                          OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
1662
static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1663
    OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
1664
}\
1665
static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1666
    OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
1667
}\
1668
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0,         1,       0)\
1669
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1,        -1,       0)\
1670
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0,         stride,  0)\
1671
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride,   -stride,  0)\
1672
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0,         stride,  1)\
1673
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1,         stride, -1)\
1674
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride,   -stride,  1)\
1675
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
1676

    
1677
QPEL_2TAP(put_, 16, mmx2)
1678
QPEL_2TAP(avg_, 16, mmx2)
1679
QPEL_2TAP(put_,  8, mmx2)
1680
QPEL_2TAP(avg_,  8, mmx2)
1681
QPEL_2TAP(put_, 16, 3dnow)
1682
QPEL_2TAP(avg_, 16, 3dnow)
1683
QPEL_2TAP(put_,  8, 3dnow)
1684
QPEL_2TAP(avg_,  8, 3dnow)
1685

    
1686

    
1687
#if 0
1688
static void just_return(void) { return; }
1689
#endif
1690

    
1691
static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
1692
                    int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){
1693
    const int w = 8;
1694
    const int ix = ox>>(16+shift);
1695
    const int iy = oy>>(16+shift);
1696
    const int oxs = ox>>4;
1697
    const int oys = oy>>4;
1698
    const int dxxs = dxx>>4;
1699
    const int dxys = dxy>>4;
1700
    const int dyxs = dyx>>4;
1701
    const int dyys = dyy>>4;
1702
    const uint16_t r4[4] = {r,r,r,r};
1703
    const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
1704
    const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
1705
    const uint64_t shift2 = 2*shift;
1706
    uint8_t edge_buf[(h+1)*stride];
1707
    int x, y;
1708

    
1709
    const int dxw = (dxx-(1<<(16+shift)))*(w-1);
1710
    const int dyh = (dyy-(1<<(16+shift)))*(h-1);
1711
    const int dxh = dxy*(h-1);
1712
    const int dyw = dyx*(w-1);
1713
    if( // non-constant fullpel offset (3% of blocks)
1714
        ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
1715
         (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
1716
        // uses more than 16 bits of subpel mv (only at huge resolution)
1717
        || (dxx|dxy|dyx|dyy)&15 )
1718
    {
1719
        //FIXME could still use mmx for some of the rows
1720
        ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
1721
        return;
1722
    }
1723

    
1724
    src += ix + iy*stride;
1725
    if( (unsigned)ix >= width-w ||
1726
        (unsigned)iy >= height-h )
1727
    {
1728
        ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
1729
        src = edge_buf;
1730
    }
1731

    
1732
    __asm__ volatile(
1733
        "movd         %0, %%mm6 \n\t"
1734
        "pxor      %%mm7, %%mm7 \n\t"
1735
        "punpcklwd %%mm6, %%mm6 \n\t"
1736
        "punpcklwd %%mm6, %%mm6 \n\t"
1737
        :: "r"(1<<shift)
1738
    );
1739

    
1740
    for(x=0; x<w; x+=4){
1741
        uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
1742
                            oxs - dxys + dxxs*(x+1),
1743
                            oxs - dxys + dxxs*(x+2),
1744
                            oxs - dxys + dxxs*(x+3) };
1745
        uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
1746
                            oys - dyys + dyxs*(x+1),
1747
                            oys - dyys + dyxs*(x+2),
1748
                            oys - dyys + dyxs*(x+3) };
1749

    
1750
        for(y=0; y<h; y++){
1751
            __asm__ volatile(
1752
                "movq   %0,  %%mm4 \n\t"
1753
                "movq   %1,  %%mm5 \n\t"
1754
                "paddw  %2,  %%mm4 \n\t"
1755
                "paddw  %3,  %%mm5 \n\t"
1756
                "movq   %%mm4, %0  \n\t"
1757
                "movq   %%mm5, %1  \n\t"
1758
                "psrlw  $12, %%mm4 \n\t"
1759
                "psrlw  $12, %%mm5 \n\t"
1760
                : "+m"(*dx4), "+m"(*dy4)
1761
                : "m"(*dxy4), "m"(*dyy4)
1762
            );
1763

    
1764
            __asm__ volatile(
1765
                "movq   %%mm6, %%mm2 \n\t"
1766
                "movq   %%mm6, %%mm1 \n\t"
1767
                "psubw  %%mm4, %%mm2 \n\t"
1768
                "psubw  %%mm5, %%mm1 \n\t"
1769
                "movq   %%mm2, %%mm0 \n\t"
1770
                "movq   %%mm4, %%mm3 \n\t"
1771
                "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
1772
                "pmullw %%mm5, %%mm3 \n\t" // dx*dy
1773
                "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
1774
                "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
1775

    
1776
                "movd   %4,    %%mm5 \n\t"
1777
                "movd   %3,    %%mm4 \n\t"
1778
                "punpcklbw %%mm7, %%mm5 \n\t"
1779
                "punpcklbw %%mm7, %%mm4 \n\t"
1780
                "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
1781
                "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
1782

    
1783
                "movd   %2,    %%mm5 \n\t"
1784
                "movd   %1,    %%mm4 \n\t"
1785
                "punpcklbw %%mm7, %%mm5 \n\t"
1786
                "punpcklbw %%mm7, %%mm4 \n\t"
1787
                "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
1788
                "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
1789
                "paddw  %5,    %%mm1 \n\t"
1790
                "paddw  %%mm3, %%mm2 \n\t"
1791
                "paddw  %%mm1, %%mm0 \n\t"
1792
                "paddw  %%mm2, %%mm0 \n\t"
1793

    
1794
                "psrlw    %6,    %%mm0 \n\t"
1795
                "packuswb %%mm0, %%mm0 \n\t"
1796
                "movd     %%mm0, %0    \n\t"
1797

    
1798
                : "=m"(dst[x+y*stride])
1799
                : "m"(src[0]), "m"(src[1]),
1800
                  "m"(src[stride]), "m"(src[stride+1]),
1801
                  "m"(*r4), "m"(shift2)
1802
            );
1803
            src += stride;
1804
        }
1805
        src += 4-h*stride;
1806
    }
1807
}
1808

    
1809
#define PREFETCH(name, op) \
1810
static void name(void *mem, int stride, int h){\
1811
    const uint8_t *p= mem;\
1812
    do{\
1813
        __asm__ volatile(#op" %0" :: "m"(*p));\
1814
        p+= stride;\
1815
    }while(--h);\
1816
}
1817
PREFETCH(prefetch_mmx2,  prefetcht0)
1818
PREFETCH(prefetch_3dnow, prefetch)
1819
#undef PREFETCH
1820

    
1821
#include "h264dsp_mmx.c"
1822
#include "rv40dsp_mmx.c"
1823

    
1824
/* CAVS specific */
1825
void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1826
    put_pixels8_mmx(dst, src, stride, 8);
1827
}
1828
void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1829
    avg_pixels8_mmx(dst, src, stride, 8);
1830
}
1831
void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1832
    put_pixels16_mmx(dst, src, stride, 16);
1833
}
1834
void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1835
    avg_pixels16_mmx(dst, src, stride, 16);
1836
}
1837

    
1838
/* VC1 specific */
1839
void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
1840
    put_pixels8_mmx(dst, src, stride, 8);
1841
}
1842
void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
1843
    avg_pixels8_mmx2(dst, src, stride, 8);
1844
}
1845

    
1846
/* XXX: those functions should be suppressed ASAP when all IDCTs are
1847
   converted */
1848
#if CONFIG_GPL
1849
static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1850
{
1851
    ff_mmx_idct (block);
1852
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1853
}
1854
static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1855
{
1856
    ff_mmx_idct (block);
1857
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1858
}
1859
static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1860
{
1861
    ff_mmxext_idct (block);
1862
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1863
}
1864
static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1865
{
1866
    ff_mmxext_idct (block);
1867
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1868
}
1869
#endif
1870
static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
1871
{
1872
    ff_idct_xvid_mmx (block);
1873
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1874
}
1875
static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
1876
{
1877
    ff_idct_xvid_mmx (block);
1878
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1879
}
1880
static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
1881
{
1882
    ff_idct_xvid_mmx2 (block);
1883
    ff_put_pixels_clamped_mmx(block, dest, line_size);
1884
}
1885
static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
1886
{
1887
    ff_idct_xvid_mmx2 (block);
1888
    ff_add_pixels_clamped_mmx(block, dest, line_size);
1889
}
1890

    
1891
static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
1892
{
1893
    int i;
1894
    __asm__ volatile("pxor %%mm7, %%mm7":);
1895
    for(i=0; i<blocksize; i+=2) {
1896
        __asm__ volatile(
1897
            "movq    %0,    %%mm0 \n\t"
1898
            "movq    %1,    %%mm1 \n\t"
1899
            "movq    %%mm0, %%mm2 \n\t"
1900
            "movq    %%mm1, %%mm3 \n\t"
1901
            "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
1902
            "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
1903
            "pslld   $31,   %%mm2 \n\t" // keep only the sign bit
1904
            "pxor    %%mm2, %%mm1 \n\t"
1905
            "movq    %%mm3, %%mm4 \n\t"
1906
            "pand    %%mm1, %%mm3 \n\t"
1907
            "pandn   %%mm1, %%mm4 \n\t"
1908
            "pfadd   %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1909
            "pfsub   %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1910
            "movq    %%mm3, %1    \n\t"
1911
            "movq    %%mm0, %0    \n\t"
1912
            :"+m"(mag[i]), "+m"(ang[i])
1913
            ::"memory"
1914
        );
1915
    }
1916
    __asm__ volatile("femms");
1917
}
1918
static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
1919
{
1920
    int i;
1921

    
1922
    __asm__ volatile(
1923
            "movaps  %0,     %%xmm5 \n\t"
1924
        ::"m"(ff_pdw_80000000[0])
1925
    );
1926
    for(i=0; i<blocksize; i+=4) {
1927
        __asm__ volatile(
1928
            "movaps  %0,     %%xmm0 \n\t"
1929
            "movaps  %1,     %%xmm1 \n\t"
1930
            "xorps   %%xmm2, %%xmm2 \n\t"
1931
            "xorps   %%xmm3, %%xmm3 \n\t"
1932
            "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
1933
            "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
1934
            "andps   %%xmm5, %%xmm2 \n\t" // keep only the sign bit
1935
            "xorps   %%xmm2, %%xmm1 \n\t"
1936
            "movaps  %%xmm3, %%xmm4 \n\t"
1937
            "andps   %%xmm1, %%xmm3 \n\t"
1938
            "andnps  %%xmm1, %%xmm4 \n\t"
1939
            "addps   %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1940
            "subps   %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1941
            "movaps  %%xmm3, %1     \n\t"
1942
            "movaps  %%xmm0, %0     \n\t"
1943
            :"+m"(mag[i]), "+m"(ang[i])
1944
            ::"memory"
1945
        );
1946
    }
1947
}
1948

    
1949
#define IF1(x) x
1950
#define IF0(x)
1951

    
1952
#define MIX5(mono,stereo)\
1953
    __asm__ volatile(\
1954
        "movss          0(%2), %%xmm5 \n"\
1955
        "movss          8(%2), %%xmm6 \n"\
1956
        "movss         24(%2), %%xmm7 \n"\
1957
        "shufps    $0, %%xmm5, %%xmm5 \n"\
1958
        "shufps    $0, %%xmm6, %%xmm6 \n"\
1959
        "shufps    $0, %%xmm7, %%xmm7 \n"\
1960
        "1: \n"\
1961
        "movaps       (%0,%1), %%xmm0 \n"\
1962
        "movaps  0x400(%0,%1), %%xmm1 \n"\
1963
        "movaps  0x800(%0,%1), %%xmm2 \n"\
1964
        "movaps  0xc00(%0,%1), %%xmm3 \n"\
1965
        "movaps 0x1000(%0,%1), %%xmm4 \n"\
1966
        "mulps         %%xmm5, %%xmm0 \n"\
1967
        "mulps         %%xmm6, %%xmm1 \n"\
1968
        "mulps         %%xmm5, %%xmm2 \n"\
1969
        "mulps         %%xmm7, %%xmm3 \n"\
1970
        "mulps         %%xmm7, %%xmm4 \n"\
1971
 stereo("addps         %%xmm1, %%xmm0 \n")\
1972
        "addps         %%xmm1, %%xmm2 \n"\
1973
        "addps         %%xmm3, %%xmm0 \n"\
1974
        "addps         %%xmm4, %%xmm2 \n"\
1975
   mono("addps         %%xmm2, %%xmm0 \n")\
1976
        "movaps  %%xmm0,      (%0,%1) \n"\
1977
 stereo("movaps  %%xmm2, 0x400(%0,%1) \n")\
1978
        "add $16, %0 \n"\
1979
        "jl 1b \n"\
1980
        :"+&r"(i)\
1981
        :"r"(samples[0]+len), "r"(matrix)\
1982
        :"memory"\
1983
    );
1984

    
1985
#define MIX_MISC(stereo)\
1986
    __asm__ volatile(\
1987
        "1: \n"\
1988
        "movaps  (%3,%0), %%xmm0 \n"\
1989
 stereo("movaps   %%xmm0, %%xmm1 \n")\
1990
        "mulps    %%xmm6, %%xmm0 \n"\
1991
 stereo("mulps    %%xmm7, %%xmm1 \n")\
1992
        "lea 1024(%3,%0), %1 \n"\
1993
        "mov %5, %2 \n"\
1994
        "2: \n"\
1995
        "movaps   (%1),   %%xmm2 \n"\
1996
 stereo("movaps   %%xmm2, %%xmm3 \n")\
1997
        "mulps   (%4,%2), %%xmm2 \n"\
1998
 stereo("mulps 16(%4,%2), %%xmm3 \n")\
1999
        "addps    %%xmm2, %%xmm0 \n"\
2000
 stereo("addps    %%xmm3, %%xmm1 \n")\
2001
        "add $1024, %1 \n"\
2002
        "add $32, %2 \n"\
2003
        "jl 2b \n"\
2004
        "movaps   %%xmm0,     (%3,%0) \n"\
2005
 stereo("movaps   %%xmm1, 1024(%3,%0) \n")\
2006
        "add $16, %0 \n"\
2007
        "jl 1b \n"\
2008
        :"+&r"(i), "=&r"(j), "=&r"(k)\
2009
        :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
2010
        :"memory"\
2011
    );
2012

    
2013
static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
2014
{
2015
    int (*matrix_cmp)[2] = (int(*)[2])matrix;
2016
    intptr_t i,j,k;
2017

    
2018
    i = -len*sizeof(float);
2019
    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]))) {
2020
        MIX5(IF0,IF1);
2021
    } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
2022
        MIX5(IF1,IF0);
2023
    } else {
2024
        DECLARE_ALIGNED(16, float, matrix_simd)[in_ch][2][4];
2025
        j = 2*in_ch*sizeof(float);
2026
        __asm__ volatile(
2027
            "1: \n"
2028
            "sub $8, %0 \n"
2029
            "movss     (%2,%0), %%xmm6 \n"
2030
            "movss    4(%2,%0), %%xmm7 \n"
2031
            "shufps $0, %%xmm6, %%xmm6 \n"
2032
            "shufps $0, %%xmm7, %%xmm7 \n"
2033
            "movaps %%xmm6,   (%1,%0,4) \n"
2034
            "movaps %%xmm7, 16(%1,%0,4) \n"
2035
            "jg 1b \n"
2036
            :"+&r"(j)
2037
            :"r"(matrix_simd), "r"(matrix)
2038
            :"memory"
2039
        );
2040
        if(out_ch == 2) {
2041
            MIX_MISC(IF1);
2042
        } else {
2043
            MIX_MISC(IF0);
2044
        }
2045
    }
2046
}
2047

    
2048
static void vector_fmul_3dnow(float *dst, const float *src, int len){
2049
    x86_reg i = (len-4)*4;
2050
    __asm__ volatile(
2051
        "1: \n\t"
2052
        "movq    (%1,%0), %%mm0 \n\t"
2053
        "movq   8(%1,%0), %%mm1 \n\t"
2054
        "pfmul   (%2,%0), %%mm0 \n\t"
2055
        "pfmul  8(%2,%0), %%mm1 \n\t"
2056
        "movq   %%mm0,  (%1,%0) \n\t"
2057
        "movq   %%mm1, 8(%1,%0) \n\t"
2058
        "sub  $16, %0 \n\t"
2059
        "jge 1b \n\t"
2060
        "femms  \n\t"
2061
        :"+r"(i)
2062
        :"r"(dst), "r"(src)
2063
        :"memory"
2064
    );
2065
}
2066
static void vector_fmul_sse(float *dst, const float *src, int len){
2067
    x86_reg i = (len-8)*4;
2068
    __asm__ volatile(
2069
        "1: \n\t"
2070
        "movaps    (%1,%0), %%xmm0 \n\t"
2071
        "movaps  16(%1,%0), %%xmm1 \n\t"
2072
        "mulps     (%2,%0), %%xmm0 \n\t"
2073
        "mulps   16(%2,%0), %%xmm1 \n\t"
2074
        "movaps  %%xmm0,   (%1,%0) \n\t"
2075
        "movaps  %%xmm1, 16(%1,%0) \n\t"
2076
        "sub  $32, %0 \n\t"
2077
        "jge 1b \n\t"
2078
        :"+r"(i)
2079
        :"r"(dst), "r"(src)
2080
        :"memory"
2081
    );
2082
}
2083

    
2084
static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
2085
    x86_reg i = len*4-16;
2086
    __asm__ volatile(
2087
        "1: \n\t"
2088
        "pswapd   8(%1), %%mm0 \n\t"
2089
        "pswapd    (%1), %%mm1 \n\t"
2090
        "pfmul  (%3,%0), %%mm0 \n\t"
2091
        "pfmul 8(%3,%0), %%mm1 \n\t"
2092
        "movq  %%mm0,  (%2,%0) \n\t"
2093
        "movq  %%mm1, 8(%2,%0) \n\t"
2094
        "add   $16, %1 \n\t"
2095
        "sub   $16, %0 \n\t"
2096
        "jge   1b \n\t"
2097
        :"+r"(i), "+r"(src1)
2098
        :"r"(dst), "r"(src0)
2099
    );
2100
    __asm__ volatile("femms");
2101
}
2102
static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
2103
    x86_reg i = len*4-32;
2104
    __asm__ volatile(
2105
        "1: \n\t"
2106
        "movaps        16(%1), %%xmm0 \n\t"
2107
        "movaps          (%1), %%xmm1 \n\t"
2108
        "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
2109
        "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
2110
        "mulps        (%3,%0), %%xmm0 \n\t"
2111
        "mulps      16(%3,%0), %%xmm1 \n\t"
2112
        "movaps     %%xmm0,   (%2,%0) \n\t"
2113
        "movaps     %%xmm1, 16(%2,%0) \n\t"
2114
        "add    $32, %1 \n\t"
2115
        "sub    $32, %0 \n\t"
2116
        "jge    1b \n\t"
2117
        :"+r"(i), "+r"(src1)
2118
        :"r"(dst), "r"(src0)
2119
    );
2120
}
2121

    
2122
static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1,
2123
                                  const float *src2, int len){
2124
    x86_reg i = (len-4)*4;
2125
    __asm__ volatile(
2126
        "1: \n\t"
2127
        "movq    (%2,%0), %%mm0 \n\t"
2128
        "movq   8(%2,%0), %%mm1 \n\t"
2129
        "pfmul   (%3,%0), %%mm0 \n\t"
2130
        "pfmul  8(%3,%0), %%mm1 \n\t"
2131
        "pfadd   (%4,%0), %%mm0 \n\t"
2132
        "pfadd  8(%4,%0), %%mm1 \n\t"
2133
        "movq  %%mm0,   (%1,%0) \n\t"
2134
        "movq  %%mm1,  8(%1,%0) \n\t"
2135
        "sub  $16, %0 \n\t"
2136
        "jge  1b \n\t"
2137
        :"+r"(i)
2138
        :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2139
        :"memory"
2140
    );
2141
    __asm__ volatile("femms");
2142
}
2143
static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
2144
                                const float *src2, int len){
2145
    x86_reg i = (len-8)*4;
2146
    __asm__ volatile(
2147
        "1: \n\t"
2148
        "movaps   (%2,%0), %%xmm0 \n\t"
2149
        "movaps 16(%2,%0), %%xmm1 \n\t"
2150
        "mulps    (%3,%0), %%xmm0 \n\t"
2151
        "mulps  16(%3,%0), %%xmm1 \n\t"
2152
        "addps    (%4,%0), %%xmm0 \n\t"
2153
        "addps  16(%4,%0), %%xmm1 \n\t"
2154
        "movaps %%xmm0,   (%1,%0) \n\t"
2155
        "movaps %%xmm1, 16(%1,%0) \n\t"
2156
        "sub  $32, %0 \n\t"
2157
        "jge  1b \n\t"
2158
        :"+r"(i)
2159
        :"r"(dst), "r"(src0), "r"(src1), "r"(src2)
2160
        :"memory"
2161
    );
2162
}
2163

    
2164
static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1,
2165
                                      const float *win, float add_bias, int len){
2166
#if HAVE_6REGS
2167
    if(add_bias == 0){
2168
        x86_reg i = -len*4;
2169
        x86_reg j = len*4-8;
2170
        __asm__ volatile(
2171
            "1: \n"
2172
            "pswapd  (%5,%1), %%mm1 \n"
2173
            "movq    (%5,%0), %%mm0 \n"
2174
            "pswapd  (%4,%1), %%mm5 \n"
2175
            "movq    (%3,%0), %%mm4 \n"
2176
            "movq      %%mm0, %%mm2 \n"
2177
            "movq      %%mm1, %%mm3 \n"
2178
            "pfmul     %%mm4, %%mm2 \n" // src0[len+i]*win[len+i]
2179
            "pfmul     %%mm5, %%mm3 \n" // src1[    j]*win[len+j]
2180
            "pfmul     %%mm4, %%mm1 \n" // src0[len+i]*win[len+j]
2181
            "pfmul     %%mm5, %%mm0 \n" // src1[    j]*win[len+i]
2182
            "pfadd     %%mm3, %%mm2 \n"
2183
            "pfsub     %%mm0, %%mm1 \n"
2184
            "pswapd    %%mm2, %%mm2 \n"
2185
            "movq      %%mm1, (%2,%0) \n"
2186
            "movq      %%mm2, (%2,%1) \n"
2187
            "sub $8, %1 \n"
2188
            "add $8, %0 \n"
2189
            "jl 1b \n"
2190
            "femms \n"
2191
            :"+r"(i), "+r"(j)
2192
            :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2193
        );
2194
    }else
2195
#endif
2196
        ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
2197
}
2198

    
2199
static void vector_fmul_window_sse(float *dst, const float *src0, const float *src1,
2200
                                   const float *win, float add_bias, int len){
2201
#if HAVE_6REGS
2202
    if(add_bias == 0){
2203
        x86_reg i = -len*4;
2204
        x86_reg j = len*4-16;
2205
        __asm__ volatile(
2206
            "1: \n"
2207
            "movaps       (%5,%1), %%xmm1 \n"
2208
            "movaps       (%5,%0), %%xmm0 \n"
2209
            "movaps       (%4,%1), %%xmm5 \n"
2210
            "movaps       (%3,%0), %%xmm4 \n"
2211
            "shufps $0x1b, %%xmm1, %%xmm1 \n"
2212
            "shufps $0x1b, %%xmm5, %%xmm5 \n"
2213
            "movaps        %%xmm0, %%xmm2 \n"
2214
            "movaps        %%xmm1, %%xmm3 \n"
2215
            "mulps         %%xmm4, %%xmm2 \n" // src0[len+i]*win[len+i]
2216
            "mulps         %%xmm5, %%xmm3 \n" // src1[    j]*win[len+j]
2217
            "mulps         %%xmm4, %%xmm1 \n" // src0[len+i]*win[len+j]
2218
            "mulps         %%xmm5, %%xmm0 \n" // src1[    j]*win[len+i]
2219
            "addps         %%xmm3, %%xmm2 \n"
2220
            "subps         %%xmm0, %%xmm1 \n"
2221
            "shufps $0x1b, %%xmm2, %%xmm2 \n"
2222
            "movaps        %%xmm1, (%2,%0) \n"
2223
            "movaps        %%xmm2, (%2,%1) \n"
2224
            "sub $16, %1 \n"
2225
            "add $16, %0 \n"
2226
            "jl 1b \n"
2227
            :"+r"(i), "+r"(j)
2228
            :"r"(dst+len), "r"(src0+len), "r"(src1), "r"(win+len)
2229
        );
2230
    }else
2231
#endif
2232
        ff_vector_fmul_window_c(dst, src0, src1, win, add_bias, len);
2233
}
2234

    
2235
static void int32_to_float_fmul_scalar_sse(float *dst, const int *src, float mul, int len)
2236
{
2237
    x86_reg i = -4*len;
2238
    __asm__ volatile(
2239
        "movss  %3, %%xmm4 \n"
2240
        "shufps $0, %%xmm4, %%xmm4 \n"
2241
        "1: \n"
2242
        "cvtpi2ps   (%2,%0), %%xmm0 \n"
2243
        "cvtpi2ps  8(%2,%0), %%xmm1 \n"
2244
        "cvtpi2ps 16(%2,%0), %%xmm2 \n"
2245
        "cvtpi2ps 24(%2,%0), %%xmm3 \n"
2246
        "movlhps  %%xmm1,    %%xmm0 \n"
2247
        "movlhps  %%xmm3,    %%xmm2 \n"
2248
        "mulps    %%xmm4,    %%xmm0 \n"
2249
        "mulps    %%xmm4,    %%xmm2 \n"
2250
        "movaps   %%xmm0,   (%1,%0) \n"
2251
        "movaps   %%xmm2, 16(%1,%0) \n"
2252
        "add $32, %0 \n"
2253
        "jl 1b \n"
2254
        :"+r"(i)
2255
        :"r"(dst+len), "r"(src+len), "m"(mul)
2256
    );
2257
}
2258

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

    
2279
static void vector_clipf_sse(float *dst, const float *src, float min, float max,
2280
                             int len)
2281
{
2282
    x86_reg i = (len-16)*4;
2283
    __asm__ volatile(
2284
        "movss  %3, %%xmm4 \n"
2285
        "movss  %4, %%xmm5 \n"
2286
        "shufps $0, %%xmm4, %%xmm4 \n"
2287
        "shufps $0, %%xmm5, %%xmm5 \n"
2288
        "1: \n\t"
2289
        "movaps    (%2,%0), %%xmm0 \n\t" // 3/1 on intel
2290
        "movaps  16(%2,%0), %%xmm1 \n\t"
2291
        "movaps  32(%2,%0), %%xmm2 \n\t"
2292
        "movaps  48(%2,%0), %%xmm3 \n\t"
2293
        "maxps      %%xmm4, %%xmm0 \n\t"
2294
        "maxps      %%xmm4, %%xmm1 \n\t"
2295
        "maxps      %%xmm4, %%xmm2 \n\t"
2296
        "maxps      %%xmm4, %%xmm3 \n\t"
2297
        "minps      %%xmm5, %%xmm0 \n\t"
2298
        "minps      %%xmm5, %%xmm1 \n\t"
2299
        "minps      %%xmm5, %%xmm2 \n\t"
2300
        "minps      %%xmm5, %%xmm3 \n\t"
2301
        "movaps  %%xmm0,   (%1,%0) \n\t"
2302
        "movaps  %%xmm1, 16(%1,%0) \n\t"
2303
        "movaps  %%xmm2, 32(%1,%0) \n\t"
2304
        "movaps  %%xmm3, 48(%1,%0) \n\t"
2305
        "sub  $64, %0 \n\t"
2306
        "jge 1b \n\t"
2307
        :"+&r"(i)
2308
        :"r"(dst), "r"(src), "m"(min), "m"(max)
2309
        :"memory"
2310
    );
2311
}
2312

    
2313
static void float_to_int16_3dnow(int16_t *dst, const float *src, long len){
2314
    x86_reg reglen = len;
2315
    // not bit-exact: pf2id uses different rounding than C and SSE
2316
    __asm__ volatile(
2317
        "add        %0          , %0        \n\t"
2318
        "lea         (%2,%0,2)  , %2        \n\t"
2319
        "add        %0          , %1        \n\t"
2320
        "neg        %0                      \n\t"
2321
        "1:                                 \n\t"
2322
        "pf2id       (%2,%0,2)  , %%mm0     \n\t"
2323
        "pf2id      8(%2,%0,2)  , %%mm1     \n\t"
2324
        "pf2id     16(%2,%0,2)  , %%mm2     \n\t"
2325
        "pf2id     24(%2,%0,2)  , %%mm3     \n\t"
2326
        "packssdw   %%mm1       , %%mm0     \n\t"
2327
        "packssdw   %%mm3       , %%mm2     \n\t"
2328
        "movq       %%mm0       ,  (%1,%0)  \n\t"
2329
        "movq       %%mm2       , 8(%1,%0)  \n\t"
2330
        "add        $16         , %0        \n\t"
2331
        " js 1b                             \n\t"
2332
        "femms                              \n\t"
2333
        :"+r"(reglen), "+r"(dst), "+r"(src)
2334
    );
2335
}
2336
static void float_to_int16_sse(int16_t *dst, const float *src, long len){
2337
    x86_reg reglen = len;
2338
    __asm__ volatile(
2339
        "add        %0          , %0        \n\t"
2340
        "lea         (%2,%0,2)  , %2        \n\t"
2341
        "add        %0          , %1        \n\t"
2342
        "neg        %0                      \n\t"
2343
        "1:                                 \n\t"
2344
        "cvtps2pi    (%2,%0,2)  , %%mm0     \n\t"
2345
        "cvtps2pi   8(%2,%0,2)  , %%mm1     \n\t"
2346
        "cvtps2pi  16(%2,%0,2)  , %%mm2     \n\t"
2347
        "cvtps2pi  24(%2,%0,2)  , %%mm3     \n\t"
2348
        "packssdw   %%mm1       , %%mm0     \n\t"
2349
        "packssdw   %%mm3       , %%mm2     \n\t"
2350
        "movq       %%mm0       ,  (%1,%0)  \n\t"
2351
        "movq       %%mm2       , 8(%1,%0)  \n\t"
2352
        "add        $16         , %0        \n\t"
2353
        " js 1b                             \n\t"
2354
        "emms                               \n\t"
2355
        :"+r"(reglen), "+r"(dst), "+r"(src)
2356
    );
2357
}
2358

    
2359
static void float_to_int16_sse2(int16_t *dst, const float *src, long len){
2360
    x86_reg reglen = len;
2361
    __asm__ volatile(
2362
        "add        %0          , %0        \n\t"
2363
        "lea         (%2,%0,2)  , %2        \n\t"
2364
        "add        %0          , %1        \n\t"
2365
        "neg        %0                      \n\t"
2366
        "1:                                 \n\t"
2367
        "cvtps2dq    (%2,%0,2)  , %%xmm0    \n\t"
2368
        "cvtps2dq  16(%2,%0,2)  , %%xmm1    \n\t"
2369
        "packssdw   %%xmm1      , %%xmm0    \n\t"
2370
        "movdqa     %%xmm0      ,  (%1,%0)  \n\t"
2371
        "add        $16         , %0        \n\t"
2372
        " js 1b                             \n\t"
2373
        :"+r"(reglen), "+r"(dst), "+r"(src)
2374
    );
2375
}
2376

    
2377
void ff_vp3_idct_mmx(int16_t *input_data);
2378
void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2379
void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block);
2380

    
2381
void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block);
2382

    
2383
void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2384
void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
2385

    
2386
void ff_vp3_idct_sse2(int16_t *input_data);
2387
void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2388
void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block);
2389

    
2390
void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len);
2391
void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len);
2392
void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len);
2393
int32_t ff_scalarproduct_int16_mmx2(const int16_t *v1, const int16_t *v2, int order, int shift);
2394
int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2, int order, int shift);
2395
int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2396
int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2397
int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul);
2398
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);
2399
int  ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left);
2400
int  ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left);
2401
void ff_x264_deblock_v_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
2402
void ff_x264_deblock_h_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0);
2403
void ff_x264_deblock_h_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
2404
void ff_x264_deblock_v_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta);
2405
void ff_x264_deblock_h_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta);
2406

    
2407
#if HAVE_YASM && ARCH_X86_32
2408
void ff_x264_deblock_v8_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta);
2409
static void ff_x264_deblock_v_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta)
2410
{
2411
    ff_x264_deblock_v8_luma_intra_mmxext(pix+0, stride, alpha, beta);
2412
    ff_x264_deblock_v8_luma_intra_mmxext(pix+8, stride, alpha, beta);
2413
}
2414
#elif !HAVE_YASM
2415
#define ff_float_to_int16_interleave6_sse(a,b,c)   float_to_int16_interleave_misc_sse(a,b,c,6)
2416
#define ff_float_to_int16_interleave6_3dnow(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6)
2417
#define ff_float_to_int16_interleave6_3dn2(a,b,c)  float_to_int16_interleave_misc_3dnow(a,b,c,6)
2418
#endif
2419
#define ff_float_to_int16_interleave6_sse2 ff_float_to_int16_interleave6_sse
2420

    
2421
#define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \
2422
/* gcc pessimizes register allocation if this is in the same function as float_to_int16_interleave_sse2*/\
2423
static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const float **src, long len, int channels){\
2424
    DECLARE_ALIGNED(16, int16_t, tmp)[len];\
2425
    int i,j,c;\
2426
    for(c=0; c<channels; c++){\
2427
        float_to_int16_##cpu(tmp, src[c], len);\
2428
        for(i=0, j=c; i<len; i++, j+=channels)\
2429
            dst[j] = tmp[i];\
2430
    }\
2431
}\
2432
\
2433
static void float_to_int16_interleave_##cpu(int16_t *dst, const float **src, long len, int channels){\
2434
    if(channels==1)\
2435
        float_to_int16_##cpu(dst, src[0], len);\
2436
    else if(channels==2){\
2437
        x86_reg reglen = len; \
2438
        const float *src0 = src[0];\
2439
        const float *src1 = src[1];\
2440
        __asm__ volatile(\
2441
            "shl $2, %0 \n"\
2442
            "add %0, %1 \n"\
2443
            "add %0, %2 \n"\
2444
            "add %0, %3 \n"\
2445
            "neg %0 \n"\
2446
            body\
2447
            :"+r"(reglen), "+r"(dst), "+r"(src0), "+r"(src1)\
2448
        );\
2449
    }else if(channels==6){\
2450
        ff_float_to_int16_interleave6_##cpu(dst, src, len);\
2451
    }else\
2452
        float_to_int16_interleave_misc_##cpu(dst, src, len, channels);\
2453
}
2454

    
2455
FLOAT_TO_INT16_INTERLEAVE(3dnow,
2456
    "1:                         \n"
2457
    "pf2id     (%2,%0), %%mm0   \n"
2458
    "pf2id    8(%2,%0), %%mm1   \n"
2459
    "pf2id     (%3,%0), %%mm2   \n"
2460
    "pf2id    8(%3,%0), %%mm3   \n"
2461
    "packssdw    %%mm1, %%mm0   \n"
2462
    "packssdw    %%mm3, %%mm2   \n"
2463
    "movq        %%mm0, %%mm1   \n"
2464
    "punpcklwd   %%mm2, %%mm0   \n"
2465
    "punpckhwd   %%mm2, %%mm1   \n"
2466
    "movq        %%mm0,  (%1,%0)\n"
2467
    "movq        %%mm1, 8(%1,%0)\n"
2468
    "add $16, %0                \n"
2469
    "js 1b                      \n"
2470
    "femms                      \n"
2471
)
2472

    
2473
FLOAT_TO_INT16_INTERLEAVE(sse,
2474
    "1:                         \n"
2475
    "cvtps2pi  (%2,%0), %%mm0   \n"
2476
    "cvtps2pi 8(%2,%0), %%mm1   \n"
2477
    "cvtps2pi  (%3,%0), %%mm2   \n"
2478
    "cvtps2pi 8(%3,%0), %%mm3   \n"
2479
    "packssdw    %%mm1, %%mm0   \n"
2480
    "packssdw    %%mm3, %%mm2   \n"
2481
    "movq        %%mm0, %%mm1   \n"
2482
    "punpcklwd   %%mm2, %%mm0   \n"
2483
    "punpckhwd   %%mm2, %%mm1   \n"
2484
    "movq        %%mm0,  (%1,%0)\n"
2485
    "movq        %%mm1, 8(%1,%0)\n"
2486
    "add $16, %0                \n"
2487
    "js 1b                      \n"
2488
    "emms                       \n"
2489
)
2490

    
2491
FLOAT_TO_INT16_INTERLEAVE(sse2,
2492
    "1:                         \n"
2493
    "cvtps2dq  (%2,%0), %%xmm0  \n"
2494
    "cvtps2dq  (%3,%0), %%xmm1  \n"
2495
    "packssdw   %%xmm1, %%xmm0  \n"
2496
    "movhlps    %%xmm0, %%xmm1  \n"
2497
    "punpcklwd  %%xmm1, %%xmm0  \n"
2498
    "movdqa     %%xmm0, (%1,%0) \n"
2499
    "add $16, %0                \n"
2500
    "js 1b                      \n"
2501
)
2502

    
2503
static void float_to_int16_interleave_3dn2(int16_t *dst, const float **src, long len, int channels){
2504
    if(channels==6)
2505
        ff_float_to_int16_interleave6_3dn2(dst, src, len);
2506
    else
2507
        float_to_int16_interleave_3dnow(dst, src, len, channels);
2508
}
2509

    
2510
float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
2511

    
2512
void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2513
{
2514
    int mm_flags = mm_support();
2515

    
2516
    if (avctx->dsp_mask) {
2517
        if (avctx->dsp_mask & FF_MM_FORCE)
2518
            mm_flags |= (avctx->dsp_mask & 0xffff);
2519
        else
2520
            mm_flags &= ~(avctx->dsp_mask & 0xffff);
2521
    }
2522

    
2523
#if 0
2524
    av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:");
2525
    if (mm_flags & FF_MM_MMX)
2526
        av_log(avctx, AV_LOG_INFO, " mmx");
2527
    if (mm_flags & FF_MM_MMX2)
2528
        av_log(avctx, AV_LOG_INFO, " mmx2");
2529
    if (mm_flags & FF_MM_3DNOW)
2530
        av_log(avctx, AV_LOG_INFO, " 3dnow");
2531
    if (mm_flags & FF_MM_SSE)
2532
        av_log(avctx, AV_LOG_INFO, " sse");
2533
    if (mm_flags & FF_MM_SSE2)
2534
        av_log(avctx, AV_LOG_INFO, " sse2");
2535
    av_log(avctx, AV_LOG_INFO, "\n");
2536
#endif
2537

    
2538
    if (mm_flags & FF_MM_MMX) {
2539
        const int idct_algo= avctx->idct_algo;
2540

    
2541
        if(avctx->lowres==0){
2542
            if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
2543
                c->idct_put= ff_simple_idct_put_mmx;
2544
                c->idct_add= ff_simple_idct_add_mmx;
2545
                c->idct    = ff_simple_idct_mmx;
2546
                c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
2547
#if CONFIG_GPL
2548
            }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
2549
                if(mm_flags & FF_MM_MMX2){
2550
                    c->idct_put= ff_libmpeg2mmx2_idct_put;
2551
                    c->idct_add= ff_libmpeg2mmx2_idct_add;
2552
                    c->idct    = ff_mmxext_idct;
2553
                }else{
2554
                    c->idct_put= ff_libmpeg2mmx_idct_put;
2555
                    c->idct_add= ff_libmpeg2mmx_idct_add;
2556
                    c->idct    = ff_mmx_idct;
2557
                }
2558
                c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
2559
#endif
2560
            }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER) &&
2561
                     idct_algo==FF_IDCT_VP3){
2562
                if(mm_flags & FF_MM_SSE2){
2563
                    c->idct_put= ff_vp3_idct_put_sse2;
2564
                    c->idct_add= ff_vp3_idct_add_sse2;
2565
                    c->idct    = ff_vp3_idct_sse2;
2566
                    c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2567
                }else{
2568
                    c->idct_put= ff_vp3_idct_put_mmx;
2569
                    c->idct_add= ff_vp3_idct_add_mmx;
2570
                    c->idct    = ff_vp3_idct_mmx;
2571
                    c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM;
2572
                }
2573
            }else if(idct_algo==FF_IDCT_CAVS){
2574
                    c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM;
2575
            }else if(idct_algo==FF_IDCT_XVIDMMX){
2576
                if(mm_flags & FF_MM_SSE2){
2577
                    c->idct_put= ff_idct_xvid_sse2_put;
2578
                    c->idct_add= ff_idct_xvid_sse2_add;
2579
                    c->idct    = ff_idct_xvid_sse2;
2580
                    c->idct_permutation_type= FF_SSE2_IDCT_PERM;
2581
                }else if(mm_flags & FF_MM_MMX2){
2582
                    c->idct_put= ff_idct_xvid_mmx2_put;
2583
                    c->idct_add= ff_idct_xvid_mmx2_add;
2584
                    c->idct    = ff_idct_xvid_mmx2;
2585
                }else{
2586
                    c->idct_put= ff_idct_xvid_mmx_put;
2587
                    c->idct_add= ff_idct_xvid_mmx_add;
2588
                    c->idct    = ff_idct_xvid_mmx;
2589
                }
2590
            }
2591
        }
2592

    
2593
        c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
2594
        c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
2595
        c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
2596
        c->clear_block  = clear_block_mmx;
2597
        c->clear_blocks = clear_blocks_mmx;
2598
        if ((mm_flags & FF_MM_SSE) &&
2599
            !(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){
2600
            /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
2601
            c->clear_block  = clear_block_sse;
2602
            c->clear_blocks = clear_blocks_sse;
2603
        }
2604

    
2605
#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
2606
        c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
2607
        c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
2608
        c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
2609
        c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU
2610

    
2611
        SET_HPEL_FUNCS(put, 0, 16, mmx);
2612
        SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx);
2613
        SET_HPEL_FUNCS(avg, 0, 16, mmx);
2614
        SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx);
2615
        SET_HPEL_FUNCS(put, 1, 8, mmx);
2616
        SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx);
2617
        SET_HPEL_FUNCS(avg, 1, 8, mmx);
2618
        SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx);
2619

    
2620
        c->gmc= gmc_mmx;
2621

    
2622
        c->add_bytes= add_bytes_mmx;
2623
        c->add_bytes_l2= add_bytes_l2_mmx;
2624

    
2625
        c->draw_edges = draw_edges_mmx;
2626

    
2627
        if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
2628
            c->h263_v_loop_filter= h263_v_loop_filter_mmx;
2629
            c->h263_h_loop_filter= h263_h_loop_filter_mmx;
2630
        }
2631
        c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_rnd;
2632
        c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx;
2633
        c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_vc1_chroma_mc8_mmx_nornd;
2634

    
2635
        c->put_rv40_chroma_pixels_tab[0]= put_rv40_chroma_mc8_mmx;
2636
        c->put_rv40_chroma_pixels_tab[1]= put_rv40_chroma_mc4_mmx;
2637

    
2638
        if (mm_flags & FF_MM_MMX2) {
2639
            c->prefetch = prefetch_mmx2;
2640

    
2641
            c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
2642
            c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
2643

    
2644
            c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
2645
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
2646
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
2647

    
2648
            c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
2649
            c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
2650

    
2651
            c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
2652
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
2653
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
2654

    
2655
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2656
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
2657
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
2658
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
2659
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
2660
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
2661
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
2662

    
2663
                if (CONFIG_VP3_DECODER) {
2664
                    c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2;
2665
                    c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2;
2666
                }
2667
            }
2668
            if (CONFIG_VP3_DECODER) {
2669
                c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2;
2670
            }
2671

    
2672
            if (CONFIG_VP3_DECODER
2673
                && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
2674
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_mmx2;
2675
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2;
2676
            }
2677

    
2678
#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \
2679
            c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \
2680
            c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \
2681
            c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \
2682
            c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \
2683
            c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \
2684
            c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \
2685
            c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \
2686
            c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \
2687
            c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \
2688
            c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \
2689
            c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \
2690
            c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \
2691
            c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \
2692
            c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \
2693
            c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \
2694
            c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU
2695

    
2696
            SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2);
2697
            SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2);
2698
            SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2);
2699
            SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2);
2700
            SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2);
2701
            SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2);
2702

    
2703
            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2);
2704
            SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2);
2705
            SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2);
2706
            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2);
2707
            SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2);
2708
            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2);
2709

    
2710
            SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2);
2711
            SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2);
2712
            SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2);
2713
            SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2);
2714

    
2715
            c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_mmx2;
2716
            c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_mmx2;
2717

    
2718
            c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_vc1_chroma_mc8_mmx2_nornd;
2719

    
2720
            c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2_rnd;
2721
            c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2;
2722
            c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2;
2723
            c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2;
2724

    
2725
#if HAVE_YASM
2726
            c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2;
2727
#endif
2728
#if HAVE_7REGS && HAVE_TEN_OPERANDS
2729
            if( mm_flags&FF_MM_3DNOW )
2730
                c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov;
2731
#endif
2732

    
2733
            if (CONFIG_VC1_DECODER)
2734
                ff_vc1dsp_init_mmx(c, avctx);
2735

    
2736
            c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2;
2737
        } else if (mm_flags & FF_MM_3DNOW) {
2738
            c->prefetch = prefetch_3dnow;
2739

    
2740
            c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
2741
            c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
2742

    
2743
            c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
2744
            c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
2745
            c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
2746

    
2747
            c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
2748
            c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
2749

    
2750
            c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
2751
            c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
2752
            c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
2753

    
2754
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2755
                c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
2756
                c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
2757
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
2758
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
2759
                c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
2760
                c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
2761
            }
2762

    
2763
            if (CONFIG_VP3_DECODER
2764
                && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) {
2765
                c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_exact_3dnow;
2766
                c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow;
2767
            }
2768

    
2769
            SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow);
2770
            SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow);
2771
            SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow);
2772
            SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow);
2773
            SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow);
2774
            SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow);
2775

    
2776
            SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow);
2777
            SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow);
2778
            SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow);
2779
            SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow);
2780
            SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow);
2781
            SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow);
2782

    
2783
            SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow);
2784
            SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow);
2785
            SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow);
2786
            SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow);
2787

    
2788
            c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow_rnd;
2789
            c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow;
2790

    
2791
            c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_3dnow;
2792
            c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_3dnow;
2793
        }
2794

    
2795

    
2796
#define H264_QPEL_FUNCS(x, y, CPU)\
2797
            c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\
2798
            c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\
2799
            c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\
2800
            c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU;
2801
        if((mm_flags & FF_MM_SSE2) && !(mm_flags & FF_MM_3DNOW)){
2802
            // these functions are slower than mmx on AMD, but faster on Intel
2803
            c->put_pixels_tab[0][0] = put_pixels16_sse2;
2804
            c->avg_pixels_tab[0][0] = avg_pixels16_sse2;
2805
            H264_QPEL_FUNCS(0, 0, sse2);
2806
        }
2807
        if(mm_flags & FF_MM_SSE2){
2808
            H264_QPEL_FUNCS(0, 1, sse2);
2809
            H264_QPEL_FUNCS(0, 2, sse2);
2810
            H264_QPEL_FUNCS(0, 3, sse2);
2811
            H264_QPEL_FUNCS(1, 1, sse2);
2812
            H264_QPEL_FUNCS(1, 2, sse2);
2813
            H264_QPEL_FUNCS(1, 3, sse2);
2814
            H264_QPEL_FUNCS(2, 1, sse2);
2815
            H264_QPEL_FUNCS(2, 2, sse2);
2816
            H264_QPEL_FUNCS(2, 3, sse2);
2817
            H264_QPEL_FUNCS(3, 1, sse2);
2818
            H264_QPEL_FUNCS(3, 2, sse2);
2819
            H264_QPEL_FUNCS(3, 3, sse2);
2820
        }
2821
#if HAVE_SSSE3
2822
        if(mm_flags & FF_MM_SSSE3){
2823
            H264_QPEL_FUNCS(1, 0, ssse3);
2824
            H264_QPEL_FUNCS(1, 1, ssse3);
2825
            H264_QPEL_FUNCS(1, 2, ssse3);
2826
            H264_QPEL_FUNCS(1, 3, ssse3);
2827
            H264_QPEL_FUNCS(2, 0, ssse3);
2828
            H264_QPEL_FUNCS(2, 1, ssse3);
2829
            H264_QPEL_FUNCS(2, 2, ssse3);
2830
            H264_QPEL_FUNCS(2, 3, ssse3);
2831
            H264_QPEL_FUNCS(3, 0, ssse3);
2832
            H264_QPEL_FUNCS(3, 1, ssse3);
2833
            H264_QPEL_FUNCS(3, 2, ssse3);
2834
            H264_QPEL_FUNCS(3, 3, ssse3);
2835
            c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_vc1_chroma_mc8_ssse3_nornd;
2836
            c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_vc1_chroma_mc8_ssse3_nornd;
2837
            c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_ssse3_rnd;
2838
            c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_ssse3_rnd;
2839
            c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_ssse3;
2840
            c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_ssse3;
2841
            c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3;
2842
#if HAVE_YASM
2843
            c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3;
2844
            if (mm_flags & FF_MM_SSE4) // not really sse4, just slow on Conroe
2845
                c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4;
2846
#endif
2847
        }
2848
#endif
2849

    
2850
        if(mm_flags & FF_MM_3DNOW){
2851
            c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow;
2852
            c->vector_fmul = vector_fmul_3dnow;
2853
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2854
                c->float_to_int16 = float_to_int16_3dnow;
2855
                c->float_to_int16_interleave = float_to_int16_interleave_3dnow;
2856
            }
2857
        }
2858
        if(mm_flags & FF_MM_3DNOWEXT){
2859
            c->vector_fmul_reverse = vector_fmul_reverse_3dnow2;
2860
            c->vector_fmul_window = vector_fmul_window_3dnow2;
2861
            if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
2862
                c->float_to_int16_interleave = float_to_int16_interleave_3dn2;
2863
            }
2864
        }
2865
        if(mm_flags & FF_MM_MMX2){
2866
#if HAVE_YASM
2867
            c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2;
2868
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2;
2869
#endif
2870
        }
2871
        if(mm_flags & FF_MM_SSE){
2872
            c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse;
2873
            c->ac3_downmix = ac3_downmix_sse;
2874
            c->vector_fmul = vector_fmul_sse;
2875
            c->vector_fmul_reverse = vector_fmul_reverse_sse;
2876
            c->vector_fmul_add = vector_fmul_add_sse;
2877
            c->vector_fmul_window = vector_fmul_window_sse;
2878
            c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse;
2879
            c->vector_clipf = vector_clipf_sse;
2880
            c->float_to_int16 = float_to_int16_sse;
2881
            c->float_to_int16_interleave = float_to_int16_interleave_sse;
2882
#if HAVE_YASM
2883
            c->scalarproduct_float = ff_scalarproduct_float_sse;
2884
#endif
2885
        }
2886
        if(mm_flags & FF_MM_3DNOW)
2887
            c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse
2888
        if(mm_flags & FF_MM_SSE2){
2889
            c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2;
2890
            c->float_to_int16 = float_to_int16_sse2;
2891
            c->float_to_int16_interleave = float_to_int16_interleave_sse2;
2892
#if HAVE_YASM
2893
            c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
2894
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2;
2895
#endif
2896
        }
2897
        if((mm_flags & FF_MM_SSSE3) && !(mm_flags & (FF_MM_SSE42|FF_MM_3DNOW)) && HAVE_YASM) // cachesplit
2898
            c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3;
2899
    }
2900

    
2901
    if (CONFIG_ENCODERS)
2902
        dsputilenc_init_mmx(c, avctx);
2903

    
2904
#if 0
2905
    // for speed testing
2906
    get_pixels = just_return;
2907
    put_pixels_clamped = just_return;
2908
    add_pixels_clamped = just_return;
2909

2910
    pix_abs16x16 = just_return;
2911
    pix_abs16x16_x2 = just_return;
2912
    pix_abs16x16_y2 = just_return;
2913
    pix_abs16x16_xy2 = just_return;
2914

2915
    put_pixels_tab[0] = just_return;
2916
    put_pixels_tab[1] = just_return;
2917
    put_pixels_tab[2] = just_return;
2918
    put_pixels_tab[3] = just_return;
2919

2920
    put_no_rnd_pixels_tab[0] = just_return;
2921
    put_no_rnd_pixels_tab[1] = just_return;
2922
    put_no_rnd_pixels_tab[2] = just_return;
2923
    put_no_rnd_pixels_tab[3] = just_return;
2924

2925
    avg_pixels_tab[0] = just_return;
2926
    avg_pixels_tab[1] = just_return;
2927
    avg_pixels_tab[2] = just_return;
2928
    avg_pixels_tab[3] = just_return;
2929

2930
    avg_no_rnd_pixels_tab[0] = just_return;
2931
    avg_no_rnd_pixels_tab[1] = just_return;
2932
    avg_no_rnd_pixels_tab[2] = just_return;
2933
    avg_no_rnd_pixels_tab[3] = just_return;
2934

2935
    //av_fdct = just_return;
2936
    //ff_idct = just_return;
2937
#endif
2938
}
2939

    
2940
#if CONFIG_H264DSP
2941
void ff_h264dsp_init_x86(H264DSPContext *c)
2942
{
2943
    int mm_flags = mm_support();
2944

    
2945
    if (mm_flags & FF_MM_MMX) {
2946
        c->h264_idct_dc_add=
2947
        c->h264_idct_add= ff_h264_idct_add_mmx;
2948
        c->h264_idct8_dc_add=
2949
        c->h264_idct8_add= ff_h264_idct8_add_mmx;
2950

    
2951
        c->h264_idct_add16     = ff_h264_idct_add16_mmx;
2952
        c->h264_idct8_add4     = ff_h264_idct8_add4_mmx;
2953
        c->h264_idct_add8      = ff_h264_idct_add8_mmx;
2954
        c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx;
2955

    
2956
        if (mm_flags & FF_MM_MMX2) {
2957
            c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2;
2958
            c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2;
2959
            c->h264_idct_add16     = ff_h264_idct_add16_mmx2;
2960
            c->h264_idct8_add4     = ff_h264_idct8_add4_mmx2;
2961
            c->h264_idct_add8      = ff_h264_idct_add8_mmx2;
2962
            c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx2;
2963

    
2964
            c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2;
2965
            c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2;
2966
            c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2;
2967
            c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2;
2968
            c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2;
2969
            c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2;
2970
            c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2;
2971

    
2972
            c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2;
2973
            c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2;
2974
            c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2;
2975
            c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2;
2976
            c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2;
2977
            c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2;
2978
            c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2;
2979
            c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2;
2980

    
2981
            c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2;
2982
            c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2;
2983
            c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2;
2984
            c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2;
2985
            c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2;
2986
            c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2;
2987
            c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2;
2988
            c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2;
2989
        }
2990
        if(mm_flags & FF_MM_SSE2){
2991
            c->h264_idct8_add = ff_h264_idct8_add_sse2;
2992
            c->h264_idct8_add4= ff_h264_idct8_add4_sse2;
2993
        }
2994

    
2995
#if HAVE_YASM
2996
        if (mm_flags & FF_MM_MMX2){
2997
#if ARCH_X86_32
2998
            c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext;
2999
            c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext;
3000
#endif
3001
            if( mm_flags&FF_MM_SSE2 ){
3002
                c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_sse2;
3003
                c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_sse2;
3004
#if ARCH_X86_64 || !defined(__ICC) || __ICC > 1110
3005
                c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2;
3006
                c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2;
3007
                c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2;
3008
                c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_sse2;
3009
#endif
3010
#if CONFIG_GPL
3011
                c->h264_idct_add16 = ff_h264_idct_add16_sse2;
3012
                c->h264_idct_add8  = ff_h264_idct_add8_sse2;
3013
                c->h264_idct_add16intra = ff_h264_idct_add16intra_sse2;
3014
#endif
3015
            }
3016
            if ( mm_flags&FF_MM_SSSE3 ){
3017
                c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_ssse3;
3018
                c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_ssse3;
3019
            }
3020
        }
3021
#endif
3022
    }
3023
}
3024
#endif /* CONFIG_H264DSP */