Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / dsputil_mmx.c @ 531a3d27

History | View | Annotate | Download (125 KB)

1 de6d9b64 Fabrice Bellard
/*
2
 * MMX optimized DSP utils
3 406792e7 Diego Biurrun
 * Copyright (c) 2000, 2001 Fabrice Bellard
4 8f2ab833 Michael Niedermayer
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 de6d9b64 Fabrice Bellard
 *
6 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9 ff4ec49e Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
12 de6d9b64 Fabrice Bellard
 *
13 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
14 de6d9b64 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ff4ec49e Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17 de6d9b64 Fabrice Bellard
 *
18 ff4ec49e Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
19 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
20 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 de6d9b64 Fabrice Bellard
 *
22
 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
23
 */
24
25 245976da Diego Biurrun
#include "libavutil/x86_cpu.h"
26
#include "libavcodec/dsputil.h"
27
#include "libavcodec/h263.h"
28
#include "libavcodec/mpegvideo.h"
29
#include "libavcodec/simple_idct.h"
30 182f56cb Aurelien Jacobs
#include "dsputil_mmx.h"
31 5b0b7054 Aurelien Jacobs
#include "vp3dsp_mmx.h"
32
#include "vp3dsp_sse2.h"
33 6af3c226 Sebastien Lucas
#include "vp6dsp_mmx.h"
34 ecb24904 Zuxy Meng
#include "vp6dsp_sse2.h"
35 54a0b6e5 Alexander Strange
#include "idct_xvid.h"
36 de6d9b64 Fabrice Bellard
37 622348f9 Michael Niedermayer
//#undef NDEBUG
38
//#include <assert.h>
39
40 486497e0 Måns Rullgård
int mm_flags; /* multimedia extension flags */
41 1457ab52 Michael Niedermayer
42 de6d9b64 Fabrice Bellard
/* pixel operations */
43 43de5065 Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_bone) = 0x0101010101010101ULL;
44
DECLARE_ALIGNED_8 (const uint64_t, ff_wtwo) = 0x0002000200020002ULL;
45 de6d9b64 Fabrice Bellard
46 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_16(const uint64_t, ff_pdw_80000000[2]) =
47 21bb884f Michael Niedermayer
{0x8000000080000000ULL, 0x8000000080000000ULL};
48
49 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_3  ) = 0x0003000300030003ULL;
50
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_4  ) = 0x0004000400040004ULL;
51 5e660449 Aurelien Jacobs
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_5  ) = {0x0005000500050005ULL, 0x0005000500050005ULL};
52
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_8  ) = {0x0008000800080008ULL, 0x0008000800080008ULL};
53 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL;
54 5e660449 Aurelien Jacobs
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL};
55 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL;
56 5e660449 Aurelien Jacobs
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL};
57
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL};
58 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL;
59 5110b25e Aurelien Jacobs
DECLARE_ALIGNED_16(const xmm_reg,  ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL};
60 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL;
61 a2b7bc8e Loren Merritt
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_128) = 0x0080008000800080ULL;
62 4a9ca0a2 Loren Merritt
DECLARE_ALIGNED_8 (const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL;
63 826f429a Michael Niedermayer
64 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1  ) = 0x0101010101010101ULL;
65
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3  ) = 0x0303030303030303ULL;
66
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_7  ) = 0x0707070707070707ULL;
67 357f45d9 David Conrad
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL;
68 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL;
69 357f45d9 David Conrad
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL;
70 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_A1 ) = 0xA1A1A1A1A1A1A1A1ULL;
71
DECLARE_ALIGNED_8 (const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL;
72 359f98de Michael Niedermayer
73 182f56cb Aurelien Jacobs
DECLARE_ALIGNED_16(const double, ff_pd_1[2]) = { 1.0, 1.0 };
74
DECLARE_ALIGNED_16(const double, ff_pd_2[2]) = { 2.0, 2.0 };
75 6810b93a Loren Merritt
76 be449fca Diego Pettenò
#define JUMPALIGN() __asm__ volatile (ASMALIGN(3)::)
77
#define MOVQ_ZERO(regd)  __asm__ volatile ("pxor %%" #regd ", %%" #regd ::)
78 d6a4c0b1 Zdenek Kabelac
79 fca0f0e5 Zdenek Kabelac
#define MOVQ_BFE(regd) \
80 be449fca Diego Pettenò
    __asm__ volatile ( \
81 fca0f0e5 Zdenek Kabelac
    "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
82
    "paddb %%" #regd ", %%" #regd " \n\t" ::)
83
84 d6a4c0b1 Zdenek Kabelac
#ifndef PIC
85 be449fca Diego Pettenò
#define MOVQ_BONE(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone))
86
#define MOVQ_WTWO(regd)  __asm__ volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo))
87 d6a4c0b1 Zdenek Kabelac
#else
88
// for shared library it's better to use this way for accessing constants
89
// pcmpeqd -> -1
90 fca0f0e5 Zdenek Kabelac
#define MOVQ_BONE(regd) \
91 be449fca Diego Pettenò
    __asm__ volatile ( \
92 fca0f0e5 Zdenek Kabelac
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
93
    "psrlw $15, %%" #regd " \n\t" \
94
    "packuswb %%" #regd ", %%" #regd " \n\t" ::)
95 d6a4c0b1 Zdenek Kabelac
96
#define MOVQ_WTWO(regd) \
97 be449fca Diego Pettenò
    __asm__ volatile ( \
98 fca0f0e5 Zdenek Kabelac
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
99
    "psrlw $15, %%" #regd " \n\t" \
100
    "psllw $1, %%" #regd " \n\t"::)
101 a7bd8797 Michael Niedermayer
102 d6a4c0b1 Zdenek Kabelac
#endif
103
104 fca0f0e5 Zdenek Kabelac
// using regr as temporary and for the output result
105 def60345 Zdenek Kabelac
// first argument is unmodifed and second is trashed
106 39825f31 Zdenek Kabelac
// regfe is supposed to contain 0xfefefefefefefefe
107
#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
108 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
109
    "pand " #regb ", " #regr "  \n\t"\
110
    "pxor " #rega ", " #regb "  \n\t"\
111
    "pand " #regfe "," #regb "  \n\t"\
112
    "psrlq $1, " #regb "        \n\t"\
113
    "paddb " #regb ", " #regr " \n\t"
114 def60345 Zdenek Kabelac
115 39825f31 Zdenek Kabelac
#define PAVGB_MMX(rega, regb, regr, regfe) \
116 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
117
    "por  " #regb ", " #regr "  \n\t"\
118
    "pxor " #rega ", " #regb "  \n\t"\
119
    "pand " #regfe "," #regb "  \n\t"\
120
    "psrlq $1, " #regb "        \n\t"\
121
    "psubb " #regb ", " #regr " \n\t"
122 def60345 Zdenek Kabelac
123 39825f31 Zdenek Kabelac
// mm6 is supposed to contain 0xfefefefefefefefe
124 6aa6ea8e Zdenek Kabelac
#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp) \
125 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
126
    "movq " #regc ", " #regp "  \n\t"\
127
    "pand " #regb ", " #regr "  \n\t"\
128
    "pand " #regd ", " #regp "  \n\t"\
129
    "pxor " #rega ", " #regb "  \n\t"\
130
    "pxor " #regc ", " #regd "  \n\t"\
131
    "pand %%mm6, " #regb "      \n\t"\
132
    "pand %%mm6, " #regd "      \n\t"\
133
    "psrlq $1, " #regb "        \n\t"\
134
    "psrlq $1, " #regd "        \n\t"\
135
    "paddb " #regb ", " #regr " \n\t"\
136
    "paddb " #regd ", " #regp " \n\t"
137 6aa6ea8e Zdenek Kabelac
138
#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
139 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
140
    "movq " #regc ", " #regp "  \n\t"\
141
    "por  " #regb ", " #regr "  \n\t"\
142
    "por  " #regd ", " #regp "  \n\t"\
143
    "pxor " #rega ", " #regb "  \n\t"\
144
    "pxor " #regc ", " #regd "  \n\t"\
145
    "pand %%mm6, " #regb "      \n\t"\
146
    "pand %%mm6, " #regd "      \n\t"\
147
    "psrlq $1, " #regd "        \n\t"\
148
    "psrlq $1, " #regb "        \n\t"\
149
    "psubb " #regb ", " #regr " \n\t"\
150
    "psubb " #regd ", " #regp " \n\t"
151 6aa6ea8e Zdenek Kabelac
152 91abb473 Zdenek Kabelac
/***********************************/
153
/* MMX no rounding */
154
#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
155 fca0f0e5 Zdenek Kabelac
#define SET_RND  MOVQ_WONE
156 bb270c08 Diego Biurrun
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
157
#define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
158 fca0f0e5 Zdenek Kabelac
159 782fc0c3 Diego Pettenò
#include "dsputil_mmx_rnd_template.c"
160 91abb473 Zdenek Kabelac
161
#undef DEF
162 fca0f0e5 Zdenek Kabelac
#undef SET_RND
163 6aa6ea8e Zdenek Kabelac
#undef PAVGBP
164 39825f31 Zdenek Kabelac
#undef PAVGB
165 91abb473 Zdenek Kabelac
/***********************************/
166
/* MMX rounding */
167
168
#define DEF(x, y) x ## _ ## y ##_mmx
169 fca0f0e5 Zdenek Kabelac
#define SET_RND  MOVQ_WTWO
170 bb270c08 Diego Biurrun
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
171
#define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
172 fca0f0e5 Zdenek Kabelac
173 782fc0c3 Diego Pettenò
#include "dsputil_mmx_rnd_template.c"
174 91abb473 Zdenek Kabelac
175
#undef DEF
176 fca0f0e5 Zdenek Kabelac
#undef SET_RND
177 6aa6ea8e Zdenek Kabelac
#undef PAVGBP
178 39825f31 Zdenek Kabelac
#undef PAVGB
179 a7bd8797 Michael Niedermayer
180 de6d9b64 Fabrice Bellard
/***********************************/
181
/* 3Dnow specific */
182
183
#define DEF(x) x ## _3dnow
184
#define PAVGB "pavgusb"
185
186 782fc0c3 Diego Pettenò
#include "dsputil_mmx_avg_template.c"
187 de6d9b64 Fabrice Bellard
188
#undef DEF
189
#undef PAVGB
190
191
/***********************************/
192
/* MMX2 specific */
193
194 607dce96 Michael Niedermayer
#define DEF(x) x ## _mmx2
195 de6d9b64 Fabrice Bellard
196
/* Introduced only in MMX2 set */
197
#define PAVGB "pavgb"
198
199 782fc0c3 Diego Pettenò
#include "dsputil_mmx_avg_template.c"
200 de6d9b64 Fabrice Bellard
201
#undef DEF
202
#undef PAVGB
203
204 b2f77586 Loren Merritt
#define put_no_rnd_pixels16_mmx put_pixels16_mmx
205
#define put_no_rnd_pixels8_mmx put_pixels8_mmx
206 6c01d006 Loren Merritt
#define put_pixels16_mmx2 put_pixels16_mmx
207
#define put_pixels8_mmx2 put_pixels8_mmx
208
#define put_pixels4_mmx2 put_pixels4_mmx
209
#define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx
210
#define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx
211
#define put_pixels16_3dnow put_pixels16_mmx
212
#define put_pixels8_3dnow put_pixels8_mmx
213
#define put_pixels4_3dnow put_pixels4_mmx
214
#define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx
215
#define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx
216
217 de6d9b64 Fabrice Bellard
/***********************************/
218
/* standard MMX */
219
220 0c1a9eda Zdenek Kabelac
void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
221 de6d9b64 Fabrice Bellard
{
222
    const DCTELEM *p;
223 0c1a9eda Zdenek Kabelac
    uint8_t *pix;
224 de6d9b64 Fabrice Bellard
225
    /* read the pixels */
226
    p = block;
227
    pix = pixels;
228 d6a4c0b1 Zdenek Kabelac
    /* unrolled loop */
229 be449fca Diego Pettenò
        __asm__ volatile(
230 bb270c08 Diego Biurrun
                "movq   %3, %%mm0               \n\t"
231
                "movq   8%3, %%mm1              \n\t"
232
                "movq   16%3, %%mm2             \n\t"
233
                "movq   24%3, %%mm3             \n\t"
234
                "movq   32%3, %%mm4             \n\t"
235
                "movq   40%3, %%mm5             \n\t"
236
                "movq   48%3, %%mm6             \n\t"
237
                "movq   56%3, %%mm7             \n\t"
238
                "packuswb %%mm1, %%mm0          \n\t"
239
                "packuswb %%mm3, %%mm2          \n\t"
240
                "packuswb %%mm5, %%mm4          \n\t"
241
                "packuswb %%mm7, %%mm6          \n\t"
242
                "movq   %%mm0, (%0)             \n\t"
243
                "movq   %%mm2, (%0, %1)         \n\t"
244
                "movq   %%mm4, (%0, %1, 2)      \n\t"
245
                "movq   %%mm6, (%0, %2)         \n\t"
246 40d0e665 Ramiro Polla
                ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "m"(*p)
247 bb270c08 Diego Biurrun
                :"memory");
248 de6d9b64 Fabrice Bellard
        pix += line_size*4;
249
        p += 32;
250 d6a4c0b1 Zdenek Kabelac
251
    // if here would be an exact copy of the code above
252
    // compiler would generate some very strange code
253
    // thus using "r"
254 be449fca Diego Pettenò
    __asm__ volatile(
255 bb270c08 Diego Biurrun
            "movq       (%3), %%mm0             \n\t"
256
            "movq       8(%3), %%mm1            \n\t"
257
            "movq       16(%3), %%mm2           \n\t"
258
            "movq       24(%3), %%mm3           \n\t"
259
            "movq       32(%3), %%mm4           \n\t"
260
            "movq       40(%3), %%mm5           \n\t"
261
            "movq       48(%3), %%mm6           \n\t"
262
            "movq       56(%3), %%mm7           \n\t"
263
            "packuswb %%mm1, %%mm0              \n\t"
264
            "packuswb %%mm3, %%mm2              \n\t"
265
            "packuswb %%mm5, %%mm4              \n\t"
266
            "packuswb %%mm7, %%mm6              \n\t"
267
            "movq       %%mm0, (%0)             \n\t"
268
            "movq       %%mm2, (%0, %1)         \n\t"
269
            "movq       %%mm4, (%0, %1, 2)      \n\t"
270
            "movq       %%mm6, (%0, %2)         \n\t"
271 40d0e665 Ramiro Polla
            ::"r" (pix), "r" ((x86_reg)line_size), "r" ((x86_reg)line_size*3), "r"(p)
272 bb270c08 Diego Biurrun
            :"memory");
273 de6d9b64 Fabrice Bellard
}
274
275 531a3d27 Reimar Döffinger
DECLARE_ASM_CONST(8, uint8_t, ff_vector128[8]) =
276 7daabccb Mike Melanson
  { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
277
278 3dd65312 Alex Converse
#define put_signed_pixels_clamped_mmx_half(off) \
279
            "movq    "#off"(%2), %%mm1          \n\t"\
280
            "movq 16+"#off"(%2), %%mm2          \n\t"\
281
            "movq 32+"#off"(%2), %%mm3          \n\t"\
282
            "movq 48+"#off"(%2), %%mm4          \n\t"\
283
            "packsswb  8+"#off"(%2), %%mm1      \n\t"\
284
            "packsswb 24+"#off"(%2), %%mm2      \n\t"\
285
            "packsswb 40+"#off"(%2), %%mm3      \n\t"\
286
            "packsswb 56+"#off"(%2), %%mm4      \n\t"\
287
            "paddb %%mm0, %%mm1                 \n\t"\
288
            "paddb %%mm0, %%mm2                 \n\t"\
289
            "paddb %%mm0, %%mm3                 \n\t"\
290
            "paddb %%mm0, %%mm4                 \n\t"\
291
            "movq %%mm1, (%0)                   \n\t"\
292
            "movq %%mm2, (%0, %3)               \n\t"\
293
            "movq %%mm3, (%0, %3, 2)            \n\t"\
294
            "movq %%mm4, (%0, %1)               \n\t"
295
296 f9ed9d85 Mike Melanson
void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
297
{
298 3dd65312 Alex Converse
    x86_reg line_skip = line_size;
299
    x86_reg av_uninit(line_skip3);
300
301
    __asm__ volatile (
302
            "movq "MANGLE(ff_vector128)", %%mm0 \n\t"
303
            "lea (%3, %3, 2), %1                \n\t"
304
            put_signed_pixels_clamped_mmx_half(0)
305
            "lea (%0, %3, 4), %0                \n\t"
306
            put_signed_pixels_clamped_mmx_half(64)
307
            :"+r" (pixels), "+r" (line_skip3)
308
            :"r" (block), "r"(line_skip)
309
            :"memory");
310 f9ed9d85 Mike Melanson
}
311
312 0c1a9eda Zdenek Kabelac
void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
313 de6d9b64 Fabrice Bellard
{
314
    const DCTELEM *p;
315 0c1a9eda Zdenek Kabelac
    uint8_t *pix;
316 de6d9b64 Fabrice Bellard
    int i;
317
318
    /* read the pixels */
319
    p = block;
320
    pix = pixels;
321 d6a4c0b1 Zdenek Kabelac
    MOVQ_ZERO(mm7);
322
    i = 4;
323 cd8e5f96 Zdenek Kabelac
    do {
324 be449fca Diego Pettenò
        __asm__ volatile(
325 bb270c08 Diego Biurrun
                "movq   (%2), %%mm0     \n\t"
326
                "movq   8(%2), %%mm1    \n\t"
327
                "movq   16(%2), %%mm2   \n\t"
328
                "movq   24(%2), %%mm3   \n\t"
329
                "movq   %0, %%mm4       \n\t"
330
                "movq   %1, %%mm6       \n\t"
331
                "movq   %%mm4, %%mm5    \n\t"
332
                "punpcklbw %%mm7, %%mm4 \n\t"
333
                "punpckhbw %%mm7, %%mm5 \n\t"
334
                "paddsw %%mm4, %%mm0    \n\t"
335
                "paddsw %%mm5, %%mm1    \n\t"
336
                "movq   %%mm6, %%mm5    \n\t"
337
                "punpcklbw %%mm7, %%mm6 \n\t"
338
                "punpckhbw %%mm7, %%mm5 \n\t"
339
                "paddsw %%mm6, %%mm2    \n\t"
340
                "paddsw %%mm5, %%mm3    \n\t"
341
                "packuswb %%mm1, %%mm0  \n\t"
342
                "packuswb %%mm3, %%mm2  \n\t"
343
                "movq   %%mm0, %0       \n\t"
344
                "movq   %%mm2, %1       \n\t"
345
                :"+m"(*pix), "+m"(*(pix+line_size))
346
                :"r"(p)
347
                :"memory");
348 de6d9b64 Fabrice Bellard
        pix += line_size*2;
349
        p += 16;
350 cd8e5f96 Zdenek Kabelac
    } while (--i);
351 de6d9b64 Fabrice Bellard
}
352
353 437525c4 Michael Niedermayer
static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
354
{
355 be449fca Diego Pettenò
    __asm__ volatile(
356 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
357 4454dc1b John Dalgliesh
         ASMALIGN(3)
358 bb270c08 Diego Biurrun
         "1:                            \n\t"
359
         "movd (%1), %%mm0              \n\t"
360
         "movd (%1, %3), %%mm1          \n\t"
361
         "movd %%mm0, (%2)              \n\t"
362
         "movd %%mm1, (%2, %3)          \n\t"
363
         "add %%"REG_a", %1             \n\t"
364
         "add %%"REG_a", %2             \n\t"
365
         "movd (%1), %%mm0              \n\t"
366
         "movd (%1, %3), %%mm1          \n\t"
367
         "movd %%mm0, (%2)              \n\t"
368
         "movd %%mm1, (%2, %3)          \n\t"
369
         "add %%"REG_a", %1             \n\t"
370
         "add %%"REG_a", %2             \n\t"
371
         "subl $4, %0                   \n\t"
372
         "jnz 1b                        \n\t"
373
         : "+g"(h), "+r" (pixels),  "+r" (block)
374 40d0e665 Ramiro Polla
         : "r"((x86_reg)line_size)
375 bb270c08 Diego Biurrun
         : "%"REG_a, "memory"
376
        );
377 437525c4 Michael Niedermayer
}
378
379 0c1a9eda Zdenek Kabelac
static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
380 de6d9b64 Fabrice Bellard
{
381 be449fca Diego Pettenò
    __asm__ volatile(
382 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
383 4454dc1b John Dalgliesh
         ASMALIGN(3)
384 bb270c08 Diego Biurrun
         "1:                            \n\t"
385
         "movq (%1), %%mm0              \n\t"
386
         "movq (%1, %3), %%mm1          \n\t"
387
         "movq %%mm0, (%2)              \n\t"
388
         "movq %%mm1, (%2, %3)          \n\t"
389
         "add %%"REG_a", %1             \n\t"
390
         "add %%"REG_a", %2             \n\t"
391
         "movq (%1), %%mm0              \n\t"
392
         "movq (%1, %3), %%mm1          \n\t"
393
         "movq %%mm0, (%2)              \n\t"
394
         "movq %%mm1, (%2, %3)          \n\t"
395
         "add %%"REG_a", %1             \n\t"
396
         "add %%"REG_a", %2             \n\t"
397
         "subl $4, %0                   \n\t"
398
         "jnz 1b                        \n\t"
399
         : "+g"(h), "+r" (pixels),  "+r" (block)
400 40d0e665 Ramiro Polla
         : "r"((x86_reg)line_size)
401 bb270c08 Diego Biurrun
         : "%"REG_a, "memory"
402
        );
403 de6d9b64 Fabrice Bellard
}
404
405 0c1a9eda Zdenek Kabelac
static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
406 b3184779 Michael Niedermayer
{
407 be449fca Diego Pettenò
    __asm__ volatile(
408 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
409 4454dc1b John Dalgliesh
         ASMALIGN(3)
410 bb270c08 Diego Biurrun
         "1:                            \n\t"
411
         "movq (%1), %%mm0              \n\t"
412
         "movq 8(%1), %%mm4             \n\t"
413
         "movq (%1, %3), %%mm1          \n\t"
414
         "movq 8(%1, %3), %%mm5         \n\t"
415
         "movq %%mm0, (%2)              \n\t"
416
         "movq %%mm4, 8(%2)             \n\t"
417
         "movq %%mm1, (%2, %3)          \n\t"
418
         "movq %%mm5, 8(%2, %3)         \n\t"
419
         "add %%"REG_a", %1             \n\t"
420
         "add %%"REG_a", %2             \n\t"
421
         "movq (%1), %%mm0              \n\t"
422
         "movq 8(%1), %%mm4             \n\t"
423
         "movq (%1, %3), %%mm1          \n\t"
424
         "movq 8(%1, %3), %%mm5         \n\t"
425
         "movq %%mm0, (%2)              \n\t"
426
         "movq %%mm4, 8(%2)             \n\t"
427
         "movq %%mm1, (%2, %3)          \n\t"
428
         "movq %%mm5, 8(%2, %3)         \n\t"
429
         "add %%"REG_a", %1             \n\t"
430
         "add %%"REG_a", %2             \n\t"
431
         "subl $4, %0                   \n\t"
432
         "jnz 1b                        \n\t"
433
         : "+g"(h), "+r" (pixels),  "+r" (block)
434 40d0e665 Ramiro Polla
         : "r"((x86_reg)line_size)
435 bb270c08 Diego Biurrun
         : "%"REG_a, "memory"
436
        );
437 b3184779 Michael Niedermayer
}
438
439 ddf96970 Loren Merritt
static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
440
{
441 be449fca Diego Pettenò
    __asm__ volatile(
442 ddf96970 Loren Merritt
         "1:                            \n\t"
443
         "movdqu (%1), %%xmm0           \n\t"
444
         "movdqu (%1,%3), %%xmm1        \n\t"
445
         "movdqu (%1,%3,2), %%xmm2      \n\t"
446
         "movdqu (%1,%4), %%xmm3        \n\t"
447
         "movdqa %%xmm0, (%2)           \n\t"
448
         "movdqa %%xmm1, (%2,%3)        \n\t"
449
         "movdqa %%xmm2, (%2,%3,2)      \n\t"
450
         "movdqa %%xmm3, (%2,%4)        \n\t"
451
         "subl $4, %0                   \n\t"
452
         "lea (%1,%3,4), %1             \n\t"
453
         "lea (%2,%3,4), %2             \n\t"
454
         "jnz 1b                        \n\t"
455
         : "+g"(h), "+r" (pixels),  "+r" (block)
456 40d0e665 Ramiro Polla
         : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
457 ddf96970 Loren Merritt
         : "memory"
458
        );
459
}
460
461
static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
462
{
463 be449fca Diego Pettenò
    __asm__ volatile(
464 ddf96970 Loren Merritt
         "1:                            \n\t"
465
         "movdqu (%1), %%xmm0           \n\t"
466
         "movdqu (%1,%3), %%xmm1        \n\t"
467
         "movdqu (%1,%3,2), %%xmm2      \n\t"
468
         "movdqu (%1,%4), %%xmm3        \n\t"
469
         "pavgb  (%2), %%xmm0           \n\t"
470
         "pavgb  (%2,%3), %%xmm1        \n\t"
471
         "pavgb  (%2,%3,2), %%xmm2      \n\t"
472
         "pavgb  (%2,%4), %%xmm3        \n\t"
473
         "movdqa %%xmm0, (%2)           \n\t"
474
         "movdqa %%xmm1, (%2,%3)        \n\t"
475
         "movdqa %%xmm2, (%2,%3,2)      \n\t"
476
         "movdqa %%xmm3, (%2,%4)        \n\t"
477
         "subl $4, %0                   \n\t"
478
         "lea (%1,%3,4), %1             \n\t"
479
         "lea (%2,%3,4), %2             \n\t"
480
         "jnz 1b                        \n\t"
481
         : "+g"(h), "+r" (pixels),  "+r" (block)
482 40d0e665 Ramiro Polla
         : "r"((x86_reg)line_size), "r"((x86_reg)3L*line_size)
483 ddf96970 Loren Merritt
         : "memory"
484
        );
485
}
486
487 5fecfb7d Loren Merritt
#define CLEAR_BLOCKS(name,n) \
488
static void name(DCTELEM *blocks)\
489
{\
490
    __asm__ volatile(\
491
                "pxor %%mm7, %%mm7              \n\t"\
492
                "mov     %1, %%"REG_a"          \n\t"\
493
                "1:                             \n\t"\
494
                "movq %%mm7, (%0, %%"REG_a")    \n\t"\
495
                "movq %%mm7, 8(%0, %%"REG_a")   \n\t"\
496
                "movq %%mm7, 16(%0, %%"REG_a")  \n\t"\
497
                "movq %%mm7, 24(%0, %%"REG_a")  \n\t"\
498
                "add $32, %%"REG_a"             \n\t"\
499
                " js 1b                         \n\t"\
500
                : : "r" (((uint8_t *)blocks)+128*n),\
501
                    "i" (-128*n)\
502
                : "%"REG_a\
503
        );\
504
}
505
CLEAR_BLOCKS(clear_blocks_mmx, 6)
506
CLEAR_BLOCKS(clear_block_mmx, 1)
507
508
static void clear_block_sse(DCTELEM *block)
509 649c00c9 Michael Niedermayer
{
510 be449fca Diego Pettenò
    __asm__ volatile(
511 5fecfb7d Loren Merritt
        "xorps  %%xmm0, %%xmm0  \n"
512
        "movaps %%xmm0,    (%0) \n"
513
        "movaps %%xmm0,  16(%0) \n"
514
        "movaps %%xmm0,  32(%0) \n"
515
        "movaps %%xmm0,  48(%0) \n"
516
        "movaps %%xmm0,  64(%0) \n"
517
        "movaps %%xmm0,  80(%0) \n"
518
        "movaps %%xmm0,  96(%0) \n"
519
        "movaps %%xmm0, 112(%0) \n"
520
        :: "r"(block)
521
        : "memory"
522
    );
523 649c00c9 Michael Niedermayer
}
524
525 11f18faf Michael Niedermayer
static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
526 40d0e665 Ramiro Polla
    x86_reg i=0;
527 be449fca Diego Pettenò
    __asm__ volatile(
528 00eebe3d Reimar Döffinger
        "jmp 2f                         \n\t"
529 bb270c08 Diego Biurrun
        "1:                             \n\t"
530
        "movq  (%1, %0), %%mm0          \n\t"
531
        "movq  (%2, %0), %%mm1          \n\t"
532
        "paddb %%mm0, %%mm1             \n\t"
533
        "movq %%mm1, (%2, %0)           \n\t"
534
        "movq 8(%1, %0), %%mm0          \n\t"
535
        "movq 8(%2, %0), %%mm1          \n\t"
536
        "paddb %%mm0, %%mm1             \n\t"
537
        "movq %%mm1, 8(%2, %0)          \n\t"
538
        "add $16, %0                    \n\t"
539 00eebe3d Reimar Döffinger
        "2:                             \n\t"
540 bb270c08 Diego Biurrun
        "cmp %3, %0                     \n\t"
541 00eebe3d Reimar Döffinger
        " js 1b                         \n\t"
542 11f18faf Michael Niedermayer
        : "+r" (i)
543 40d0e665 Ramiro Polla
        : "r"(src), "r"(dst), "r"((x86_reg)w-15)
544 11f18faf Michael Niedermayer
    );
545
    for(; i<w; i++)
546
        dst[i+0] += src[i+0];
547
}
548
549 4a9ca0a2 Loren Merritt
static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
550 40d0e665 Ramiro Polla
    x86_reg i=0;
551 be449fca Diego Pettenò
    __asm__ volatile(
552 00eebe3d Reimar Döffinger
        "jmp 2f                         \n\t"
553 4a9ca0a2 Loren Merritt
        "1:                             \n\t"
554
        "movq   (%2, %0), %%mm0         \n\t"
555
        "movq  8(%2, %0), %%mm1         \n\t"
556
        "paddb  (%3, %0), %%mm0         \n\t"
557
        "paddb 8(%3, %0), %%mm1         \n\t"
558
        "movq %%mm0,  (%1, %0)          \n\t"
559
        "movq %%mm1, 8(%1, %0)          \n\t"
560
        "add $16, %0                    \n\t"
561 00eebe3d Reimar Döffinger
        "2:                             \n\t"
562 4a9ca0a2 Loren Merritt
        "cmp %4, %0                     \n\t"
563 00eebe3d Reimar Döffinger
        " js 1b                         \n\t"
564 4a9ca0a2 Loren Merritt
        : "+r" (i)
565 40d0e665 Ramiro Polla
        : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15)
566 4a9ca0a2 Loren Merritt
    );
567
    for(; i<w; i++)
568
        dst[i] = src1[i] + src2[i];
569
}
570
571 d3a4b4e0 Diego Biurrun
#if HAVE_7REGS && HAVE_TEN_OPERANDS
572 3daa434a Loren Merritt
static void add_hfyu_median_prediction_cmov(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top) {
573
    x86_reg w2 = -w;
574
    x86_reg x;
575
    int l = *left & 0xff;
576
    int tl = *left_top & 0xff;
577
    int t;
578
    __asm__ volatile(
579
        "mov    %7, %3 \n"
580
        "1: \n"
581
        "movzx (%3,%4), %2 \n"
582
        "mov    %2, %k3 \n"
583
        "sub   %b1, %b3 \n"
584
        "add   %b0, %b3 \n"
585
        "mov    %2, %1 \n"
586
        "cmp    %0, %2 \n"
587
        "cmovg  %0, %2 \n"
588
        "cmovg  %1, %0 \n"
589
        "cmp   %k3, %0 \n"
590
        "cmovg %k3, %0 \n"
591
        "mov    %7, %3 \n"
592
        "cmp    %2, %0 \n"
593
        "cmovl  %2, %0 \n"
594
        "add (%6,%4), %b0 \n"
595
        "mov   %b0, (%5,%4) \n"
596
        "inc    %4 \n"
597
        "jl 1b \n"
598
        :"+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
599
        :"r"(dst+w), "r"(diff+w), "rm"(top+w)
600
    );
601
    *left = l;
602
    *left_top = tl;
603
}
604
#endif
605
606 3615e2be Michael Niedermayer
#define H263_LOOP_FILTER \
607 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
608
        "movq  %0, %%mm0                \n\t"\
609
        "movq  %0, %%mm1                \n\t"\
610
        "movq  %3, %%mm2                \n\t"\
611
        "movq  %3, %%mm3                \n\t"\
612
        "punpcklbw %%mm7, %%mm0         \n\t"\
613
        "punpckhbw %%mm7, %%mm1         \n\t"\
614
        "punpcklbw %%mm7, %%mm2         \n\t"\
615
        "punpckhbw %%mm7, %%mm3         \n\t"\
616
        "psubw %%mm2, %%mm0             \n\t"\
617
        "psubw %%mm3, %%mm1             \n\t"\
618
        "movq  %1, %%mm2                \n\t"\
619
        "movq  %1, %%mm3                \n\t"\
620
        "movq  %2, %%mm4                \n\t"\
621
        "movq  %2, %%mm5                \n\t"\
622
        "punpcklbw %%mm7, %%mm2         \n\t"\
623
        "punpckhbw %%mm7, %%mm3         \n\t"\
624
        "punpcklbw %%mm7, %%mm4         \n\t"\
625
        "punpckhbw %%mm7, %%mm5         \n\t"\
626
        "psubw %%mm2, %%mm4             \n\t"\
627
        "psubw %%mm3, %%mm5             \n\t"\
628
        "psllw $2, %%mm4                \n\t"\
629
        "psllw $2, %%mm5                \n\t"\
630
        "paddw %%mm0, %%mm4             \n\t"\
631
        "paddw %%mm1, %%mm5             \n\t"\
632
        "pxor %%mm6, %%mm6              \n\t"\
633
        "pcmpgtw %%mm4, %%mm6           \n\t"\
634
        "pcmpgtw %%mm5, %%mm7           \n\t"\
635
        "pxor %%mm6, %%mm4              \n\t"\
636
        "pxor %%mm7, %%mm5              \n\t"\
637
        "psubw %%mm6, %%mm4             \n\t"\
638
        "psubw %%mm7, %%mm5             \n\t"\
639
        "psrlw $3, %%mm4                \n\t"\
640
        "psrlw $3, %%mm5                \n\t"\
641
        "packuswb %%mm5, %%mm4          \n\t"\
642
        "packsswb %%mm7, %%mm6          \n\t"\
643
        "pxor %%mm7, %%mm7              \n\t"\
644
        "movd %4, %%mm2                 \n\t"\
645
        "punpcklbw %%mm2, %%mm2         \n\t"\
646
        "punpcklbw %%mm2, %%mm2         \n\t"\
647
        "punpcklbw %%mm2, %%mm2         \n\t"\
648
        "psubusb %%mm4, %%mm2           \n\t"\
649
        "movq %%mm2, %%mm3              \n\t"\
650
        "psubusb %%mm4, %%mm3           \n\t"\
651
        "psubb %%mm3, %%mm2             \n\t"\
652
        "movq %1, %%mm3                 \n\t"\
653
        "movq %2, %%mm4                 \n\t"\
654
        "pxor %%mm6, %%mm3              \n\t"\
655
        "pxor %%mm6, %%mm4              \n\t"\
656
        "paddusb %%mm2, %%mm3           \n\t"\
657
        "psubusb %%mm2, %%mm4           \n\t"\
658
        "pxor %%mm6, %%mm3              \n\t"\
659
        "pxor %%mm6, %%mm4              \n\t"\
660
        "paddusb %%mm2, %%mm2           \n\t"\
661
        "packsswb %%mm1, %%mm0          \n\t"\
662
        "pcmpgtb %%mm0, %%mm7           \n\t"\
663
        "pxor %%mm7, %%mm0              \n\t"\
664
        "psubb %%mm7, %%mm0             \n\t"\
665
        "movq %%mm0, %%mm1              \n\t"\
666
        "psubusb %%mm2, %%mm0           \n\t"\
667
        "psubb %%mm0, %%mm1             \n\t"\
668
        "pand %5, %%mm1                 \n\t"\
669
        "psrlw $2, %%mm1                \n\t"\
670
        "pxor %%mm7, %%mm1              \n\t"\
671
        "psubb %%mm7, %%mm1             \n\t"\
672
        "movq %0, %%mm5                 \n\t"\
673
        "movq %3, %%mm6                 \n\t"\
674
        "psubb %%mm1, %%mm5             \n\t"\
675
        "paddb %%mm1, %%mm6             \n\t"
676 3615e2be Michael Niedermayer
677 359f98de Michael Niedermayer
static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
678 49fb20cb Aurelien Jacobs
    if(CONFIG_ANY_H263) {
679 359f98de Michael Niedermayer
    const int strength= ff_h263_loop_filter_strength[qscale];
680
681 be449fca Diego Pettenò
    __asm__ volatile(
682 115329f1 Diego Biurrun
683 3615e2be Michael Niedermayer
        H263_LOOP_FILTER
684 115329f1 Diego Biurrun
685 bb270c08 Diego Biurrun
        "movq %%mm3, %1                 \n\t"
686
        "movq %%mm4, %2                 \n\t"
687
        "movq %%mm5, %0                 \n\t"
688
        "movq %%mm6, %3                 \n\t"
689 359f98de Michael Niedermayer
        : "+m" (*(uint64_t*)(src - 2*stride)),
690
          "+m" (*(uint64_t*)(src - 1*stride)),
691
          "+m" (*(uint64_t*)(src + 0*stride)),
692
          "+m" (*(uint64_t*)(src + 1*stride))
693
        : "g" (2*strength), "m"(ff_pb_FC)
694
    );
695 73f51a4d Aurelien Jacobs
    }
696 359f98de Michael Niedermayer
}
697
698 3615e2be Michael Niedermayer
static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
699 be449fca Diego Pettenò
    __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
700 bb270c08 Diego Biurrun
        "movd  %4, %%mm0                \n\t"
701
        "movd  %5, %%mm1                \n\t"
702
        "movd  %6, %%mm2                \n\t"
703
        "movd  %7, %%mm3                \n\t"
704
        "punpcklbw %%mm1, %%mm0         \n\t"
705
        "punpcklbw %%mm3, %%mm2         \n\t"
706
        "movq %%mm0, %%mm1              \n\t"
707
        "punpcklwd %%mm2, %%mm0         \n\t"
708
        "punpckhwd %%mm2, %%mm1         \n\t"
709
        "movd  %%mm0, %0                \n\t"
710
        "punpckhdq %%mm0, %%mm0         \n\t"
711
        "movd  %%mm0, %1                \n\t"
712
        "movd  %%mm1, %2                \n\t"
713
        "punpckhdq %%mm1, %%mm1         \n\t"
714
        "movd  %%mm1, %3                \n\t"
715 115329f1 Diego Biurrun
716 3615e2be Michael Niedermayer
        : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
717
          "=m" (*(uint32_t*)(dst + 1*dst_stride)),
718
          "=m" (*(uint32_t*)(dst + 2*dst_stride)),
719
          "=m" (*(uint32_t*)(dst + 3*dst_stride))
720
        :  "m" (*(uint32_t*)(src + 0*src_stride)),
721
           "m" (*(uint32_t*)(src + 1*src_stride)),
722
           "m" (*(uint32_t*)(src + 2*src_stride)),
723
           "m" (*(uint32_t*)(src + 3*src_stride))
724
    );
725
}
726
727
static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
728 49fb20cb Aurelien Jacobs
    if(CONFIG_ANY_H263) {
729 3615e2be Michael Niedermayer
    const int strength= ff_h263_loop_filter_strength[qscale];
730 27215c6b Reimar Döffinger
    DECLARE_ALIGNED(8, uint64_t, temp[4]);
731 3615e2be Michael Niedermayer
    uint8_t *btemp= (uint8_t*)temp;
732 115329f1 Diego Biurrun
733 3615e2be Michael Niedermayer
    src -= 2;
734
735
    transpose4x4(btemp  , src           , 8, stride);
736
    transpose4x4(btemp+4, src + 4*stride, 8, stride);
737 be449fca Diego Pettenò
    __asm__ volatile(
738 3615e2be Michael Niedermayer
        H263_LOOP_FILTER // 5 3 4 6
739 115329f1 Diego Biurrun
740 3615e2be Michael Niedermayer
        : "+m" (temp[0]),
741
          "+m" (temp[1]),
742
          "+m" (temp[2]),
743
          "+m" (temp[3])
744
        : "g" (2*strength), "m"(ff_pb_FC)
745
    );
746
747 be449fca Diego Pettenò
    __asm__ volatile(
748 bb270c08 Diego Biurrun
        "movq %%mm5, %%mm1              \n\t"
749
        "movq %%mm4, %%mm0              \n\t"
750
        "punpcklbw %%mm3, %%mm5         \n\t"
751
        "punpcklbw %%mm6, %%mm4         \n\t"
752
        "punpckhbw %%mm3, %%mm1         \n\t"
753
        "punpckhbw %%mm6, %%mm0         \n\t"
754
        "movq %%mm5, %%mm3              \n\t"
755
        "movq %%mm1, %%mm6              \n\t"
756
        "punpcklwd %%mm4, %%mm5         \n\t"
757
        "punpcklwd %%mm0, %%mm1         \n\t"
758
        "punpckhwd %%mm4, %%mm3         \n\t"
759
        "punpckhwd %%mm0, %%mm6         \n\t"
760
        "movd %%mm5, (%0)               \n\t"
761
        "punpckhdq %%mm5, %%mm5         \n\t"
762
        "movd %%mm5, (%0,%2)            \n\t"
763
        "movd %%mm3, (%0,%2,2)          \n\t"
764
        "punpckhdq %%mm3, %%mm3         \n\t"
765
        "movd %%mm3, (%0,%3)            \n\t"
766
        "movd %%mm1, (%1)               \n\t"
767
        "punpckhdq %%mm1, %%mm1         \n\t"
768
        "movd %%mm1, (%1,%2)            \n\t"
769
        "movd %%mm6, (%1,%2,2)          \n\t"
770
        "punpckhdq %%mm6, %%mm6         \n\t"
771
        "movd %%mm6, (%1,%3)            \n\t"
772 4d9ae03b Martin Drab
        :: "r" (src),
773
           "r" (src + 4*stride),
774 40d0e665 Ramiro Polla
           "r" ((x86_reg)   stride ),
775
           "r" ((x86_reg)(3*stride))
776 3615e2be Michael Niedermayer
    );
777 73f51a4d Aurelien Jacobs
    }
778 3615e2be Michael Niedermayer
}
779
780 5a6a9e78 Aurelien Jacobs
/* draw the edges of width 'w' of an image of size width, height
781
   this mmx version can only handle w==8 || w==16 */
782
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
783
{
784
    uint8_t *ptr, *last_line;
785
    int i;
786
787
    last_line = buf + (height - 1) * wrap;
788
    /* left and right */
789
    ptr = buf;
790
    if(w==8)
791
    {
792 be449fca Diego Pettenò
        __asm__ volatile(
793 5a6a9e78 Aurelien Jacobs
                "1:                             \n\t"
794
                "movd (%0), %%mm0               \n\t"
795
                "punpcklbw %%mm0, %%mm0         \n\t"
796
                "punpcklwd %%mm0, %%mm0         \n\t"
797
                "punpckldq %%mm0, %%mm0         \n\t"
798
                "movq %%mm0, -8(%0)             \n\t"
799
                "movq -8(%0, %2), %%mm1         \n\t"
800
                "punpckhbw %%mm1, %%mm1         \n\t"
801
                "punpckhwd %%mm1, %%mm1         \n\t"
802
                "punpckhdq %%mm1, %%mm1         \n\t"
803
                "movq %%mm1, (%0, %2)           \n\t"
804
                "add %1, %0                     \n\t"
805
                "cmp %3, %0                     \n\t"
806
                " jb 1b                         \n\t"
807
                : "+r" (ptr)
808 40d0e665 Ramiro Polla
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
809 5a6a9e78 Aurelien Jacobs
        );
810
    }
811
    else
812
    {
813 be449fca Diego Pettenò
        __asm__ volatile(
814 5a6a9e78 Aurelien Jacobs
                "1:                             \n\t"
815
                "movd (%0), %%mm0               \n\t"
816
                "punpcklbw %%mm0, %%mm0         \n\t"
817
                "punpcklwd %%mm0, %%mm0         \n\t"
818
                "punpckldq %%mm0, %%mm0         \n\t"
819
                "movq %%mm0, -8(%0)             \n\t"
820
                "movq %%mm0, -16(%0)            \n\t"
821
                "movq -8(%0, %2), %%mm1         \n\t"
822
                "punpckhbw %%mm1, %%mm1         \n\t"
823
                "punpckhwd %%mm1, %%mm1         \n\t"
824
                "punpckhdq %%mm1, %%mm1         \n\t"
825
                "movq %%mm1, (%0, %2)           \n\t"
826
                "movq %%mm1, 8(%0, %2)          \n\t"
827
                "add %1, %0                     \n\t"
828
                "cmp %3, %0                     \n\t"
829
                " jb 1b                         \n\t"
830
                : "+r" (ptr)
831 40d0e665 Ramiro Polla
                : "r" ((x86_reg)wrap), "r" ((x86_reg)width), "r" (ptr + wrap*height)
832 5a6a9e78 Aurelien Jacobs
        );
833
    }
834
835
    for(i=0;i<w;i+=4) {
836
        /* top and bottom (and hopefully also the corners) */
837
        ptr= buf - (i + 1) * wrap - w;
838 be449fca Diego Pettenò
        __asm__ volatile(
839 5a6a9e78 Aurelien Jacobs
                "1:                             \n\t"
840
                "movq (%1, %0), %%mm0           \n\t"
841
                "movq %%mm0, (%0)               \n\t"
842
                "movq %%mm0, (%0, %2)           \n\t"
843
                "movq %%mm0, (%0, %2, 2)        \n\t"
844
                "movq %%mm0, (%0, %3)           \n\t"
845
                "add $8, %0                     \n\t"
846
                "cmp %4, %0                     \n\t"
847
                " jb 1b                         \n\t"
848
                : "+r" (ptr)
849 40d0e665 Ramiro Polla
                : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
850 5a6a9e78 Aurelien Jacobs
        );
851
        ptr= last_line + (i + 1) * wrap - w;
852 be449fca Diego Pettenò
        __asm__ volatile(
853 5a6a9e78 Aurelien Jacobs
                "1:                             \n\t"
854
                "movq (%1, %0), %%mm0           \n\t"
855
                "movq %%mm0, (%0)               \n\t"
856
                "movq %%mm0, (%0, %2)           \n\t"
857
                "movq %%mm0, (%0, %2, 2)        \n\t"
858
                "movq %%mm0, (%0, %3)           \n\t"
859
                "add $8, %0                     \n\t"
860
                "cmp %4, %0                     \n\t"
861
                " jb 1b                         \n\t"
862
                : "+r" (ptr)
863 40d0e665 Ramiro Polla
                : "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
864 5a6a9e78 Aurelien Jacobs
        );
865
    }
866
}
867
868 4a9ca0a2 Loren Merritt
#define PAETH(cpu, abs3)\
869 f769b746 Uoti Urpala
static void add_png_paeth_prediction_##cpu(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp)\
870 4a9ca0a2 Loren Merritt
{\
871 40d0e665 Ramiro Polla
    x86_reg i = -bpp;\
872
    x86_reg end = w-3;\
873 be449fca Diego Pettenò
    __asm__ volatile(\
874 4a9ca0a2 Loren Merritt
        "pxor      %%mm7, %%mm7 \n"\
875
        "movd    (%1,%0), %%mm0 \n"\
876
        "movd    (%2,%0), %%mm1 \n"\
877
        "punpcklbw %%mm7, %%mm0 \n"\
878
        "punpcklbw %%mm7, %%mm1 \n"\
879
        "add       %4, %0 \n"\
880
        "1: \n"\
881
        "movq      %%mm1, %%mm2 \n"\
882
        "movd    (%2,%0), %%mm1 \n"\
883
        "movq      %%mm2, %%mm3 \n"\
884
        "punpcklbw %%mm7, %%mm1 \n"\
885
        "movq      %%mm2, %%mm4 \n"\
886
        "psubw     %%mm1, %%mm3 \n"\
887
        "psubw     %%mm0, %%mm4 \n"\
888
        "movq      %%mm3, %%mm5 \n"\
889
        "paddw     %%mm4, %%mm5 \n"\
890
        abs3\
891
        "movq      %%mm4, %%mm6 \n"\
892
        "pminsw    %%mm5, %%mm6 \n"\
893
        "pcmpgtw   %%mm6, %%mm3 \n"\
894
        "pcmpgtw   %%mm5, %%mm4 \n"\
895
        "movq      %%mm4, %%mm6 \n"\
896
        "pand      %%mm3, %%mm4 \n"\
897
        "pandn     %%mm3, %%mm6 \n"\
898
        "pandn     %%mm0, %%mm3 \n"\
899
        "movd    (%3,%0), %%mm0 \n"\
900
        "pand      %%mm1, %%mm6 \n"\
901
        "pand      %%mm4, %%mm2 \n"\
902
        "punpcklbw %%mm7, %%mm0 \n"\
903
        "movq      %6,    %%mm5 \n"\
904
        "paddw     %%mm6, %%mm0 \n"\
905
        "paddw     %%mm2, %%mm3 \n"\
906
        "paddw     %%mm3, %%mm0 \n"\
907
        "pand      %%mm5, %%mm0 \n"\
908
        "movq      %%mm0, %%mm3 \n"\
909
        "packuswb  %%mm3, %%mm3 \n"\
910
        "movd      %%mm3, (%1,%0) \n"\
911
        "add       %4, %0 \n"\
912
        "cmp       %5, %0 \n"\
913
        "jle 1b \n"\
914
        :"+r"(i)\
915 40d0e665 Ramiro Polla
        :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\
916 4a9ca0a2 Loren Merritt
         "m"(ff_pw_255)\
917
        :"memory"\
918
    );\
919
}
920
921
#define ABS3_MMX2\
922
        "psubw     %%mm5, %%mm7 \n"\
923
        "pmaxsw    %%mm7, %%mm5 \n"\
924
        "pxor      %%mm6, %%mm6 \n"\
925
        "pxor      %%mm7, %%mm7 \n"\
926
        "psubw     %%mm3, %%mm6 \n"\
927
        "psubw     %%mm4, %%mm7 \n"\
928
        "pmaxsw    %%mm6, %%mm3 \n"\
929
        "pmaxsw    %%mm7, %%mm4 \n"\
930
        "pxor      %%mm7, %%mm7 \n"
931
932
#define ABS3_SSSE3\
933
        "pabsw     %%mm3, %%mm3 \n"\
934
        "pabsw     %%mm4, %%mm4 \n"\
935
        "pabsw     %%mm5, %%mm5 \n"
936
937
PAETH(mmx2, ABS3_MMX2)
938 b250f9c6 Aurelien Jacobs
#if HAVE_SSSE3
939 4a9ca0a2 Loren Merritt
PAETH(ssse3, ABS3_SSSE3)
940
#endif
941
942 826f429a Michael Niedermayer
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
943 bb270c08 Diego Biurrun
        "paddw " #m4 ", " #m3 "           \n\t" /* x1 */\
944
        "movq "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */\
945
        "pmullw " #m3 ", %%mm4            \n\t" /* 20x1 */\
946
        "movq "#in7", " #m3 "             \n\t" /* d */\
947
        "movq "#in0", %%mm5               \n\t" /* D */\
948
        "paddw " #m3 ", %%mm5             \n\t" /* x4 */\
949
        "psubw %%mm5, %%mm4               \n\t" /* 20x1 - x4 */\
950
        "movq "#in1", %%mm5               \n\t" /* C */\
951
        "movq "#in2", %%mm6               \n\t" /* B */\
952
        "paddw " #m6 ", %%mm5             \n\t" /* x3 */\
953
        "paddw " #m5 ", %%mm6             \n\t" /* x2 */\
954
        "paddw %%mm6, %%mm6               \n\t" /* 2x2 */\
955
        "psubw %%mm6, %%mm5               \n\t" /* -2x2 + x3 */\
956
        "pmullw "MANGLE(ff_pw_3)", %%mm5  \n\t" /* -6x2 + 3x3 */\
957
        "paddw " #rnd ", %%mm4            \n\t" /* x2 */\
958
        "paddw %%mm4, %%mm5               \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
959
        "psraw $5, %%mm5                  \n\t"\
960
        "packuswb %%mm5, %%mm5            \n\t"\
961 826f429a Michael Niedermayer
        OP(%%mm5, out, %%mm7, d)
962
963 3178ee4c Michael Niedermayer
#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
964 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
965 826f429a Michael Niedermayer
    uint64_t temp;\
966
\
967 be449fca Diego Pettenò
    __asm__ volatile(\
968 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7                \n\t"\
969
        "1:                               \n\t"\
970
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
971
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
972
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
973
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
974
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
975
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
976
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
977
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
978
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
979
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
980
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
981
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
982
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
983
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
984
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
985
        "paddw %%mm3, %%mm5               \n\t" /* b */\
986
        "paddw %%mm2, %%mm6               \n\t" /* c */\
987
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
988
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
989
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
990
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
991
        "paddw %%mm4, %%mm0               \n\t" /* a */\
992
        "paddw %%mm1, %%mm5               \n\t" /* d */\
993
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
994
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
995
        "paddw %6, %%mm6                  \n\t"\
996
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
997
        "psraw $5, %%mm0                  \n\t"\
998
        "movq %%mm0, %5                   \n\t"\
999 826f429a Michael Niedermayer
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1000
        \
1001 bb270c08 Diego Biurrun
        "movq 5(%0), %%mm0                \n\t" /* FGHIJKLM */\
1002
        "movq %%mm0, %%mm5                \n\t" /* FGHIJKLM */\
1003
        "movq %%mm0, %%mm6                \n\t" /* FGHIJKLM */\
1004
        "psrlq $8, %%mm0                  \n\t" /* GHIJKLM0 */\
1005
        "psrlq $16, %%mm5                 \n\t" /* HIJKLM00 */\
1006
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0G0H0I0J */\
1007
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0H0I0J0K */\
1008
        "paddw %%mm0, %%mm2               \n\t" /* b */\
1009
        "paddw %%mm5, %%mm3               \n\t" /* c */\
1010
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
1011
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
1012
        "movq %%mm6, %%mm2                \n\t" /* FGHIJKLM */\
1013
        "psrlq $24, %%mm6                 \n\t" /* IJKLM000 */\
1014
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0F0G0H0I */\
1015
        "punpcklbw %%mm7, %%mm6           \n\t" /* 0I0J0K0L */\
1016
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
1017
        "paddw %%mm2, %%mm1               \n\t" /* a */\
1018
        "paddw %%mm6, %%mm4               \n\t" /* d */\
1019
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1020
        "psubw %%mm4, %%mm3               \n\t" /* - 6b +3c - d */\
1021
        "paddw %6, %%mm1                  \n\t"\
1022
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b +3c - d */\
1023
        "psraw $5, %%mm3                  \n\t"\
1024
        "movq %5, %%mm1                   \n\t"\
1025
        "packuswb %%mm3, %%mm1            \n\t"\
1026 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm1, (%1),%%mm4, q)\
1027 826f429a Michael Niedermayer
        /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1028
        \
1029 bb270c08 Diego Biurrun
        "movq 9(%0), %%mm1                \n\t" /* JKLMNOPQ */\
1030
        "movq %%mm1, %%mm4                \n\t" /* JKLMNOPQ */\
1031
        "movq %%mm1, %%mm3                \n\t" /* JKLMNOPQ */\
1032
        "psrlq $8, %%mm1                  \n\t" /* KLMNOPQ0 */\
1033
        "psrlq $16, %%mm4                 \n\t" /* LMNOPQ00 */\
1034
        "punpcklbw %%mm7, %%mm1           \n\t" /* 0K0L0M0N */\
1035
        "punpcklbw %%mm7, %%mm4           \n\t" /* 0L0M0N0O */\
1036
        "paddw %%mm1, %%mm5               \n\t" /* b */\
1037
        "paddw %%mm4, %%mm0               \n\t" /* c */\
1038
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1039
        "psubw %%mm5, %%mm0               \n\t" /* c - 2b */\
1040
        "movq %%mm3, %%mm5                \n\t" /* JKLMNOPQ */\
1041
        "psrlq $24, %%mm3                 \n\t" /* MNOPQ000 */\
1042
        "pmullw "MANGLE(ff_pw_3)", %%mm0  \n\t" /* 3c - 6b */\
1043
        "punpcklbw %%mm7, %%mm3           \n\t" /* 0M0N0O0P */\
1044
        "paddw %%mm3, %%mm2               \n\t" /* d */\
1045
        "psubw %%mm2, %%mm0               \n\t" /* -6b + 3c - d */\
1046
        "movq %%mm5, %%mm2                \n\t" /* JKLMNOPQ */\
1047
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0J0K0L0M */\
1048
        "punpckhbw %%mm7, %%mm5           \n\t" /* 0N0O0P0Q */\
1049
        "paddw %%mm2, %%mm6               \n\t" /* a */\
1050
        "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
1051
        "paddw %6, %%mm0                  \n\t"\
1052
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1053
        "psraw $5, %%mm0                  \n\t"\
1054 826f429a Michael Niedermayer
        /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1055
        \
1056 bb270c08 Diego Biurrun
        "paddw %%mm5, %%mm3               \n\t" /* a */\
1057
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0O0P0Q0Q */\
1058
        "paddw %%mm4, %%mm6               \n\t" /* b */\
1059
        "pshufw $0xBE, %%mm5, %%mm4       \n\t" /* 0P0Q0Q0P */\
1060
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0Q0Q0P0O */\
1061
        "paddw %%mm1, %%mm4               \n\t" /* c */\
1062
        "paddw %%mm2, %%mm5               \n\t" /* d */\
1063
        "paddw %%mm6, %%mm6               \n\t" /* 2b */\
1064
        "psubw %%mm6, %%mm4               \n\t" /* c - 2b */\
1065
        "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1066
        "pmullw "MANGLE(ff_pw_3)", %%mm4  \n\t" /* 3c - 6b */\
1067
        "psubw %%mm5, %%mm3               \n\t" /* -6b + 3c - d */\
1068
        "paddw %6, %%mm4                  \n\t"\
1069
        "paddw %%mm3, %%mm4               \n\t" /* 20a - 6b + 3c - d */\
1070
        "psraw $5, %%mm4                  \n\t"\
1071
        "packuswb %%mm4, %%mm0            \n\t"\
1072 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
1073 826f429a Michael Niedermayer
        \
1074 bb270c08 Diego Biurrun
        "add %3, %0                       \n\t"\
1075
        "add %4, %1                       \n\t"\
1076
        "decl %2                          \n\t"\
1077
        " jnz 1b                          \n\t"\
1078 943032b1 Michael Niedermayer
        : "+a"(src), "+c"(dst), "+D"(h)\
1079 40d0e665 Ramiro Polla
        : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1080 0b093b6f Michael Niedermayer
        : "memory"\
1081 826f429a Michael Niedermayer
    );\
1082
}\
1083
\
1084
static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1085
    int i;\
1086
    int16_t temp[16];\
1087
    /* quick HACK, XXX FIXME MUST be optimized */\
1088
    for(i=0; i<h; i++)\
1089
    {\
1090
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1091
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1092
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1093
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1094
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1095
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1096
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1097
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1098
        temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1099
        temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1100
        temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1101
        temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1102
        temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1103
        temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1104
        temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1105
        temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1106 be449fca Diego Pettenò
        __asm__ volatile(\
1107 bb270c08 Diego Biurrun
            "movq (%0), %%mm0               \n\t"\
1108
            "movq 8(%0), %%mm1              \n\t"\
1109
            "paddw %2, %%mm0                \n\t"\
1110
            "paddw %2, %%mm1                \n\t"\
1111
            "psraw $5, %%mm0                \n\t"\
1112
            "psraw $5, %%mm1                \n\t"\
1113
            "packuswb %%mm1, %%mm0          \n\t"\
1114 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1115 bb270c08 Diego Biurrun
            "movq 16(%0), %%mm0             \n\t"\
1116
            "movq 24(%0), %%mm1             \n\t"\
1117
            "paddw %2, %%mm0                \n\t"\
1118
            "paddw %2, %%mm1                \n\t"\
1119
            "psraw $5, %%mm0                \n\t"\
1120
            "psraw $5, %%mm1                \n\t"\
1121
            "packuswb %%mm1, %%mm0          \n\t"\
1122 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
1123 826f429a Michael Niedermayer
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1124 0b093b6f Michael Niedermayer
            : "memory"\
1125 826f429a Michael Niedermayer
        );\
1126
        dst+=dstStride;\
1127
        src+=srcStride;\
1128
    }\
1129
}\
1130
\
1131 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1132 be449fca Diego Pettenò
    __asm__ volatile(\
1133 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7                \n\t"\
1134
        "1:                               \n\t"\
1135
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1136
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1137
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1138
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
1139
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
1140
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
1141
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
1142
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1143
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1144
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
1145
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
1146
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
1147
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
1148
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
1149
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
1150
        "paddw %%mm3, %%mm5               \n\t" /* b */\
1151
        "paddw %%mm2, %%mm6               \n\t" /* c */\
1152
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1153
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
1154
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
1155
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
1156
        "paddw %%mm4, %%mm0               \n\t" /* a */\
1157
        "paddw %%mm1, %%mm5               \n\t" /* d */\
1158
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1159
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
1160 dea00a46 Michael Niedermayer
        "paddw %5, %%mm6                  \n\t"\
1161 bb270c08 Diego Biurrun
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1162
        "psraw $5, %%mm0                  \n\t"\
1163 826f429a Michael Niedermayer
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1164
        \
1165 bb270c08 Diego Biurrun
        "movd 5(%0), %%mm5                \n\t" /* FGHI */\
1166
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0F0G0H0I */\
1167
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0G0H0I0I */\
1168
        "paddw %%mm5, %%mm1               \n\t" /* a */\
1169
        "paddw %%mm6, %%mm2               \n\t" /* b */\
1170
        "pshufw $0xBE, %%mm5, %%mm6       \n\t" /* 0H0I0I0H */\
1171
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0I0I0H0G */\
1172
        "paddw %%mm6, %%mm3               \n\t" /* c */\
1173
        "paddw %%mm5, %%mm4               \n\t" /* d */\
1174
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
1175
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
1176
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1177
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
1178
        "psubw %%mm4, %%mm3               \n\t" /* -6b + 3c - d */\
1179 dea00a46 Michael Niedermayer
        "paddw %5, %%mm1                  \n\t"\
1180 bb270c08 Diego Biurrun
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b + 3c - d */\
1181
        "psraw $5, %%mm3                  \n\t"\
1182
        "packuswb %%mm3, %%mm0            \n\t"\
1183 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm0, (%1), %%mm4, q)\
1184 826f429a Michael Niedermayer
        \
1185 bb270c08 Diego Biurrun
        "add %3, %0                       \n\t"\
1186
        "add %4, %1                       \n\t"\
1187
        "decl %2                          \n\t"\
1188
        " jnz 1b                          \n\t"\
1189 943032b1 Michael Niedermayer
        : "+a"(src), "+c"(dst), "+d"(h)\
1190 40d0e665 Ramiro Polla
        : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER)\
1191 0b093b6f Michael Niedermayer
        : "memory"\
1192 826f429a Michael Niedermayer
    );\
1193
}\
1194
\
1195
static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1196
    int i;\
1197
    int16_t temp[8];\
1198
    /* quick HACK, XXX FIXME MUST be optimized */\
1199
    for(i=0; i<h; i++)\
1200
    {\
1201
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1202
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1203
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1204
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1205
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1206
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
1207
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
1208
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
1209 be449fca Diego Pettenò
        __asm__ volatile(\
1210 bb270c08 Diego Biurrun
            "movq (%0), %%mm0           \n\t"\
1211
            "movq 8(%0), %%mm1          \n\t"\
1212
            "paddw %2, %%mm0            \n\t"\
1213
            "paddw %2, %%mm1            \n\t"\
1214
            "psraw $5, %%mm0            \n\t"\
1215
            "psraw $5, %%mm1            \n\t"\
1216
            "packuswb %%mm1, %%mm0      \n\t"\
1217 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1218 826f429a Michael Niedermayer
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1219 0b093b6f Michael Niedermayer
            :"memory"\
1220 826f429a Michael Niedermayer
        );\
1221
        dst+=dstStride;\
1222
        src+=srcStride;\
1223
    }\
1224 3178ee4c Michael Niedermayer
}
1225
1226
#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
1227
\
1228
static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1229
    uint64_t temp[17*4];\
1230
    uint64_t *temp_ptr= temp;\
1231
    int count= 17;\
1232
\
1233
    /*FIXME unroll */\
1234 be449fca Diego Pettenò
    __asm__ volatile(\
1235 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
1236
        "1:                             \n\t"\
1237
        "movq (%0), %%mm0               \n\t"\
1238
        "movq (%0), %%mm1               \n\t"\
1239
        "movq 8(%0), %%mm2              \n\t"\
1240
        "movq 8(%0), %%mm3              \n\t"\
1241
        "punpcklbw %%mm7, %%mm0         \n\t"\
1242
        "punpckhbw %%mm7, %%mm1         \n\t"\
1243
        "punpcklbw %%mm7, %%mm2         \n\t"\
1244
        "punpckhbw %%mm7, %%mm3         \n\t"\
1245
        "movq %%mm0, (%1)               \n\t"\
1246
        "movq %%mm1, 17*8(%1)           \n\t"\
1247
        "movq %%mm2, 2*17*8(%1)         \n\t"\
1248
        "movq %%mm3, 3*17*8(%1)         \n\t"\
1249
        "add $8, %1                     \n\t"\
1250
        "add %3, %0                     \n\t"\
1251
        "decl %2                        \n\t"\
1252
        " jnz 1b                        \n\t"\
1253 3178ee4c Michael Niedermayer
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
1254 40d0e665 Ramiro Polla
        : "r" ((x86_reg)srcStride)\
1255 0b093b6f Michael Niedermayer
        : "memory"\
1256 3178ee4c Michael Niedermayer
    );\
1257
    \
1258
    temp_ptr= temp;\
1259
    count=4;\
1260
    \
1261
/*FIXME reorder for speed */\
1262 be449fca Diego Pettenò
    __asm__ volatile(\
1263 bb270c08 Diego Biurrun
        /*"pxor %%mm7, %%mm7              \n\t"*/\
1264
        "1:                             \n\t"\
1265
        "movq (%0), %%mm0               \n\t"\
1266
        "movq 8(%0), %%mm1              \n\t"\
1267
        "movq 16(%0), %%mm2             \n\t"\
1268
        "movq 24(%0), %%mm3             \n\t"\
1269 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
1270
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
1271 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1272 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
1273 3178ee4c Michael Niedermayer
        \
1274 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
1275 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1276 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1277
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
1278 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1279 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
1280
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
1281 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1282 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
1283
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
1284 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1285 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
1286
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
1287 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1288 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
1289 3178ee4c Michael Niedermayer
        \
1290 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
1291 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"  \
1292 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
1293
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
1294 3178ee4c Michael Niedermayer
        \
1295 bb270c08 Diego Biurrun
        "add $136, %0                   \n\t"\
1296
        "add %6, %1                     \n\t"\
1297
        "decl %2                        \n\t"\
1298
        " jnz 1b                        \n\t"\
1299 3178ee4c Michael Niedermayer
        \
1300 5a508a98 Michael Niedermayer
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
1301 40d0e665 Ramiro Polla
        : "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)\
1302 0b093b6f Michael Niedermayer
        :"memory"\
1303 3178ee4c Michael Niedermayer
    );\
1304 826f429a Michael Niedermayer
}\
1305
\
1306 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1307 437525c4 Michael Niedermayer
    uint64_t temp[9*2];\
1308 826f429a Michael Niedermayer
    uint64_t *temp_ptr= temp;\
1309
    int count= 9;\
1310
\
1311
    /*FIXME unroll */\
1312 be449fca Diego Pettenò
    __asm__ volatile(\
1313 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
1314
        "1:                             \n\t"\
1315
        "movq (%0), %%mm0               \n\t"\
1316
        "movq (%0), %%mm1               \n\t"\
1317
        "punpcklbw %%mm7, %%mm0         \n\t"\
1318
        "punpckhbw %%mm7, %%mm1         \n\t"\
1319
        "movq %%mm0, (%1)               \n\t"\
1320
        "movq %%mm1, 9*8(%1)            \n\t"\
1321
        "add $8, %1                     \n\t"\
1322
        "add %3, %0                     \n\t"\
1323
        "decl %2                        \n\t"\
1324
        " jnz 1b                        \n\t"\
1325 826f429a Michael Niedermayer
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
1326 40d0e665 Ramiro Polla
        : "r" ((x86_reg)srcStride)\
1327 0b093b6f Michael Niedermayer
        : "memory"\
1328 826f429a Michael Niedermayer
    );\
1329
    \
1330
    temp_ptr= temp;\
1331
    count=2;\
1332
    \
1333
/*FIXME reorder for speed */\
1334 be449fca Diego Pettenò
    __asm__ volatile(\
1335 bb270c08 Diego Biurrun
        /*"pxor %%mm7, %%mm7              \n\t"*/\
1336
        "1:                             \n\t"\
1337
        "movq (%0), %%mm0               \n\t"\
1338
        "movq 8(%0), %%mm1              \n\t"\
1339
        "movq 16(%0), %%mm2             \n\t"\
1340
        "movq 24(%0), %%mm3             \n\t"\
1341 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
1342
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
1343 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1344 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
1345 826f429a Michael Niedermayer
        \
1346 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
1347 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1348 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
1349 826f429a Michael Niedermayer
        \
1350 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
1351 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
1352 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
1353
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
1354 826f429a Michael Niedermayer
                \
1355 bb270c08 Diego Biurrun
        "add $72, %0                    \n\t"\
1356
        "add %6, %1                     \n\t"\
1357
        "decl %2                        \n\t"\
1358
        " jnz 1b                        \n\t"\
1359 826f429a Michael Niedermayer
         \
1360 c296f66b Michael Niedermayer
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
1361 40d0e665 Ramiro Polla
        : "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)\
1362 0b093b6f Michael Niedermayer
        : "memory"\
1363
   );\
1364 3178ee4c Michael Niedermayer
}\
1365 826f429a Michael Niedermayer
\
1366 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1367 6c01d006 Loren Merritt
    OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);\
1368 826f429a Michael Niedermayer
}\
1369
\
1370 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1371 db794953 Michael Niedermayer
    uint64_t temp[8];\
1372 826f429a Michael Niedermayer
    uint8_t * const half= (uint8_t*)temp;\
1373
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1374 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
1375 826f429a Michael Niedermayer
}\
1376
\
1377 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1378 826f429a Michael Niedermayer
    OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
1379
}\
1380
\
1381 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1382 db794953 Michael Niedermayer
    uint64_t temp[8];\
1383 826f429a Michael Niedermayer
    uint8_t * const half= (uint8_t*)temp;\
1384
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
1385 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, src+1, half, stride, stride, 8);\
1386 826f429a Michael Niedermayer
}\
1387
\
1388 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1389 db794953 Michael Niedermayer
    uint64_t temp[8];\
1390 826f429a Michael Niedermayer
    uint8_t * const half= (uint8_t*)temp;\
1391 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
1392 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, src, half, stride, stride, 8);\
1393 826f429a Michael Niedermayer
}\
1394
\
1395 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1396 3178ee4c Michael Niedermayer
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
1397 826f429a Michael Niedermayer
}\
1398
\
1399 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1400 db794953 Michael Niedermayer
    uint64_t temp[8];\
1401 826f429a Michael Niedermayer
    uint8_t * const half= (uint8_t*)temp;\
1402 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
1403 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, src+stride, half, stride, stride, 8);\
1404 826f429a Michael Niedermayer
}\
1405 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1406 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1407
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1408
    uint8_t * const halfHV= ((uint8_t*)half);\
1409 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1410 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1411 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1412 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1413 826f429a Michael Niedermayer
}\
1414 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1415 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1416
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1417
    uint8_t * const halfHV= ((uint8_t*)half);\
1418 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1419 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1420 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1421 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1422 826f429a Michael Niedermayer
}\
1423 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1424 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1425
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1426
    uint8_t * const halfHV= ((uint8_t*)half);\
1427 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1428 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1429 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1430 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1431 826f429a Michael Niedermayer
}\
1432 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1433 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1434
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1435
    uint8_t * const halfHV= ((uint8_t*)half);\
1436
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1437 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1438 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1439 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1440 826f429a Michael Niedermayer
}\
1441 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1442 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1443 826f429a Michael Niedermayer
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1444
    uint8_t * const halfHV= ((uint8_t*)half);\
1445
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1446 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1447 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV, stride, 8, 8);\
1448 826f429a Michael Niedermayer
}\
1449 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1450 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1451 826f429a Michael Niedermayer
    uint8_t * const halfH= ((uint8_t*)half) + 64;\
1452
    uint8_t * const halfHV= ((uint8_t*)half);\
1453
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1454 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
1455 d6af6b03 Michael Niedermayer
    OPNAME ## pixels8_l2_ ## MMX(dst, halfH+8, halfHV, stride, 8, 8);\
1456 826f429a Michael Niedermayer
}\
1457 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1458 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1459
    uint8_t * const halfH= ((uint8_t*)half);\
1460 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1461 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8, stride, 9);\
1462 db794953 Michael Niedermayer
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1463 826f429a Michael Niedermayer
}\
1464 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1465 db794953 Michael Niedermayer
    uint64_t half[8 + 9];\
1466
    uint8_t * const halfH= ((uint8_t*)half);\
1467 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1468 d6af6b03 Michael Niedermayer
    put ## RND ## pixels8_l2_ ## MMX(halfH, src+1, halfH, 8, stride, 9);\
1469 db794953 Michael Niedermayer
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1470 826f429a Michael Niedermayer
}\
1471 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1472 db794953 Michael Niedermayer
    uint64_t half[9];\
1473 826f429a Michael Niedermayer
    uint8_t * const halfH= ((uint8_t*)half);\
1474
    put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
1475 3178ee4c Michael Niedermayer
    OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
1476 826f429a Michael Niedermayer
}\
1477 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
1478 6c01d006 Loren Merritt
    OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);\
1479 826f429a Michael Niedermayer
}\
1480
\
1481 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1482 826f429a Michael Niedermayer
    uint64_t temp[32];\
1483
    uint8_t * const half= (uint8_t*)temp;\
1484
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1485 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
1486 826f429a Michael Niedermayer
}\
1487
\
1488 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1489 826f429a Michael Niedermayer
    OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
1490
}\
1491
\
1492 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1493 826f429a Michael Niedermayer
    uint64_t temp[32];\
1494
    uint8_t * const half= (uint8_t*)temp;\
1495
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
1496 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, src+1, half, stride, stride, 16);\
1497 826f429a Michael Niedermayer
}\
1498
\
1499 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1500 826f429a Michael Niedermayer
    uint64_t temp[32];\
1501
    uint8_t * const half= (uint8_t*)temp;\
1502 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
1503 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride, stride, 16);\
1504 826f429a Michael Niedermayer
}\
1505
\
1506 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1507 3178ee4c Michael Niedermayer
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
1508 826f429a Michael Niedermayer
}\
1509
\
1510 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1511 826f429a Michael Niedermayer
    uint64_t temp[32];\
1512
    uint8_t * const half= (uint8_t*)temp;\
1513 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
1514 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half, stride, stride, 16);\
1515 826f429a Michael Niedermayer
}\
1516 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1517 db794953 Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1518
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1519
    uint8_t * const halfHV= ((uint8_t*)half);\
1520 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1521 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1522 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1523 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1524 826f429a Michael Niedermayer
}\
1525 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1526 db794953 Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1527
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1528
    uint8_t * const halfHV= ((uint8_t*)half);\
1529 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1530 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1531 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1532 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1533 826f429a Michael Niedermayer
}\
1534 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1535 db794953 Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1536
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1537
    uint8_t * const halfHV= ((uint8_t*)half);\
1538 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1539 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1540 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1541 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1542 826f429a Michael Niedermayer
}\
1543 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1544 db794953 Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1545
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1546
    uint8_t * const halfHV= ((uint8_t*)half);\
1547
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1548 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1549 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1550 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1551 826f429a Michael Niedermayer
}\
1552 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1553 826f429a Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1554
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1555
    uint8_t * const halfHV= ((uint8_t*)half);\
1556
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1557 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1558 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV, stride, 16, 16);\
1559 826f429a Michael Niedermayer
}\
1560 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1561 826f429a Michael Niedermayer
    uint64_t half[16*2 + 17*2];\
1562
    uint8_t * const halfH= ((uint8_t*)half) + 256;\
1563
    uint8_t * const halfHV= ((uint8_t*)half);\
1564
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1565 3178ee4c Michael Niedermayer
    put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
1566 d6af6b03 Michael Niedermayer
    OPNAME ## pixels16_l2_ ## MMX(dst, halfH+16, halfHV, stride, 16, 16);\
1567 826f429a Michael Niedermayer
}\
1568 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1569 db794953 Michael Niedermayer
    uint64_t half[17*2];\
1570
    uint8_t * const halfH= ((uint8_t*)half);\
1571 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1572 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16, stride, 17);\
1573 db794953 Michael Niedermayer
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1574 826f429a Michael Niedermayer
}\
1575 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1576 db794953 Michael Niedermayer
    uint64_t half[17*2];\
1577
    uint8_t * const halfH= ((uint8_t*)half);\
1578 826f429a Michael Niedermayer
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1579 d6af6b03 Michael Niedermayer
    put ## RND ## pixels16_l2_ ## MMX(halfH, src+1, halfH, 16, stride, 17);\
1580 db794953 Michael Niedermayer
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1581 826f429a Michael Niedermayer
}\
1582 0c1a9eda Zdenek Kabelac
static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1583 826f429a Michael Niedermayer
    uint64_t half[17*2];\
1584
    uint8_t * const halfH= ((uint8_t*)half);\
1585
    put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
1586 3178ee4c Michael Niedermayer
    OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
1587 826f429a Michael Niedermayer
}
1588
1589 bb270c08 Diego Biurrun
#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b "        \n\t"
1590 3178ee4c Michael Niedermayer
#define AVG_3DNOW_OP(a,b,temp, size) \
1591 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
1592
"pavgusb " #temp ", " #a "        \n\t"\
1593
"mov" #size " " #a ", " #b "      \n\t"
1594 3178ee4c Michael Niedermayer
#define AVG_MMX2_OP(a,b,temp, size) \
1595 bb270c08 Diego Biurrun
"mov" #size " " #b ", " #temp "   \n\t"\
1596
"pavgb " #temp ", " #a "          \n\t"\
1597
"mov" #size " " #a ", " #b "      \n\t"
1598 3178ee4c Michael Niedermayer
1599
QPEL_BASE(put_       , ff_pw_16, _       , PUT_OP, PUT_OP)
1600
QPEL_BASE(avg_       , ff_pw_16, _       , AVG_MMX2_OP, AVG_3DNOW_OP)
1601
QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
1602
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, 3dnow)
1603
QPEL_OP(avg_       , ff_pw_16, _       , AVG_3DNOW_OP, 3dnow)
1604
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
1605 826f429a Michael Niedermayer
QPEL_OP(put_       , ff_pw_16, _       , PUT_OP, mmx2)
1606 3178ee4c Michael Niedermayer
QPEL_OP(avg_       , ff_pw_16, _       , AVG_MMX2_OP, mmx2)
1607 826f429a Michael Niedermayer
QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
1608
1609 2833fc46 Loren Merritt
/***********************************/
1610
/* bilinear qpel: not compliant to any spec, only for -lavdopts fast */
1611
1612
#define QPEL_2TAP_XY(OPNAME, SIZE, MMX, XY, HPEL)\
1613
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1614
    OPNAME ## pixels ## SIZE ## HPEL(dst, src, stride, SIZE);\
1615
}
1616
#define QPEL_2TAP_L3(OPNAME, SIZE, MMX, XY, S0, S1, S2)\
1617
static void OPNAME ## 2tap_qpel ## SIZE ## _mc ## XY ## _ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1618
    OPNAME ## 2tap_qpel ## SIZE ## _l3_ ## MMX(dst, src+S0, stride, SIZE, S1, S2);\
1619
}
1620
1621
#define QPEL_2TAP(OPNAME, SIZE, MMX)\
1622
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 20, _x2_ ## MMX)\
1623
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 02, _y2_ ## MMX)\
1624
QPEL_2TAP_XY(OPNAME, SIZE, MMX, 22, _xy2_mmx)\
1625
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc00_ ## MMX =\
1626
                          OPNAME ## qpel ## SIZE ## _mc00_ ## MMX;\
1627
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc21_ ## MMX =\
1628
                          OPNAME ## 2tap_qpel ## SIZE ## _mc20_ ## MMX;\
1629
static const qpel_mc_func OPNAME ## 2tap_qpel ## SIZE ## _mc12_ ## MMX =\
1630
                          OPNAME ## 2tap_qpel ## SIZE ## _mc02_ ## MMX;\
1631
static void OPNAME ## 2tap_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1632
    OPNAME ## pixels ## SIZE ## _y2_ ## MMX(dst, src+1, stride, SIZE);\
1633
}\
1634
static void OPNAME ## 2tap_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
1635
    OPNAME ## pixels ## SIZE ## _x2_ ## MMX(dst, src+stride, stride, SIZE);\
1636
}\
1637
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 10, 0,         1,       0)\
1638
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 30, 1,        -1,       0)\
1639
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 01, 0,         stride,  0)\
1640
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 03, stride,   -stride,  0)\
1641
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 11, 0,         stride,  1)\
1642
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 31, 1,         stride, -1)\
1643
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 13, stride,   -stride,  1)\
1644
QPEL_2TAP_L3(OPNAME, SIZE, MMX, 33, stride+1, -stride, -1)\
1645
1646
QPEL_2TAP(put_, 16, mmx2)
1647
QPEL_2TAP(avg_, 16, mmx2)
1648
QPEL_2TAP(put_,  8, mmx2)
1649
QPEL_2TAP(avg_,  8, mmx2)
1650
QPEL_2TAP(put_, 16, 3dnow)
1651
QPEL_2TAP(avg_, 16, 3dnow)
1652
QPEL_2TAP(put_,  8, 3dnow)
1653
QPEL_2TAP(avg_,  8, 3dnow)
1654
1655
1656 61a4e8ae Fabrice Bellard
#if 0
1657 c47d146b Diego Biurrun
static void just_return(void) { return; }
1658 61a4e8ae Fabrice Bellard
#endif
1659 d6a4c0b1 Zdenek Kabelac
1660 703c8195 Loren Merritt
static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
1661
                    int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){
1662
    const int w = 8;
1663
    const int ix = ox>>(16+shift);
1664
    const int iy = oy>>(16+shift);
1665
    const int oxs = ox>>4;
1666
    const int oys = oy>>4;
1667
    const int dxxs = dxx>>4;
1668
    const int dxys = dxy>>4;
1669
    const int dyxs = dyx>>4;
1670
    const int dyys = dyy>>4;
1671
    const uint16_t r4[4] = {r,r,r,r};
1672
    const uint16_t dxy4[4] = {dxys,dxys,dxys,dxys};
1673
    const uint16_t dyy4[4] = {dyys,dyys,dyys,dyys};
1674
    const uint64_t shift2 = 2*shift;
1675
    uint8_t edge_buf[(h+1)*stride];
1676
    int x, y;
1677
1678
    const int dxw = (dxx-(1<<(16+shift)))*(w-1);
1679
    const int dyh = (dyy-(1<<(16+shift)))*(h-1);
1680
    const int dxh = dxy*(h-1);
1681
    const int dyw = dyx*(w-1);
1682
    if( // non-constant fullpel offset (3% of blocks)
1683 066e0cc5 Baptiste Coudurier
        ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) |
1684
         (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift)
1685 703c8195 Loren Merritt
        // uses more than 16 bits of subpel mv (only at huge resolution)
1686
        || (dxx|dxy|dyx|dyy)&15 )
1687
    {
1688
        //FIXME could still use mmx for some of the rows
1689
        ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r, width, height);
1690
        return;
1691
    }
1692
1693 75ca1a5f Loren Merritt
    src += ix + iy*stride;
1694 703c8195 Loren Merritt
    if( (unsigned)ix >= width-w ||
1695
        (unsigned)iy >= height-h )
1696
    {
1697 75ca1a5f Loren Merritt
        ff_emulated_edge_mc(edge_buf, src, stride, w+1, h+1, ix, iy, width, height);
1698 703c8195 Loren Merritt
        src = edge_buf;
1699
    }
1700 75ca1a5f Loren Merritt
1701 be449fca Diego Pettenò
    __asm__ volatile(
1702 75ca1a5f Loren Merritt
        "movd         %0, %%mm6 \n\t"
1703
        "pxor      %%mm7, %%mm7 \n\t"
1704
        "punpcklwd %%mm6, %%mm6 \n\t"
1705
        "punpcklwd %%mm6, %%mm6 \n\t"
1706
        :: "r"(1<<shift)
1707
    );
1708 703c8195 Loren Merritt
1709
    for(x=0; x<w; x+=4){
1710
        uint16_t dx4[4] = { oxs - dxys + dxxs*(x+0),
1711
                            oxs - dxys + dxxs*(x+1),
1712
                            oxs - dxys + dxxs*(x+2),
1713
                            oxs - dxys + dxxs*(x+3) };
1714
        uint16_t dy4[4] = { oys - dyys + dyxs*(x+0),
1715
                            oys - dyys + dyxs*(x+1),
1716
                            oys - dyys + dyxs*(x+2),
1717
                            oys - dyys + dyxs*(x+3) };
1718
1719
        for(y=0; y<h; y++){
1720 be449fca Diego Pettenò
            __asm__ volatile(
1721 703c8195 Loren Merritt
                "movq   %0,  %%mm4 \n\t"
1722
                "movq   %1,  %%mm5 \n\t"
1723
                "paddw  %2,  %%mm4 \n\t"
1724
                "paddw  %3,  %%mm5 \n\t"
1725
                "movq   %%mm4, %0  \n\t"
1726
                "movq   %%mm5, %1  \n\t"
1727
                "psrlw  $12, %%mm4 \n\t"
1728
                "psrlw  $12, %%mm5 \n\t"
1729
                : "+m"(*dx4), "+m"(*dy4)
1730
                : "m"(*dxy4), "m"(*dyy4)
1731
            );
1732
1733 be449fca Diego Pettenò
            __asm__ volatile(
1734 703c8195 Loren Merritt
                "movq   %%mm6, %%mm2 \n\t"
1735
                "movq   %%mm6, %%mm1 \n\t"
1736
                "psubw  %%mm4, %%mm2 \n\t"
1737
                "psubw  %%mm5, %%mm1 \n\t"
1738
                "movq   %%mm2, %%mm0 \n\t"
1739
                "movq   %%mm4, %%mm3 \n\t"
1740
                "pmullw %%mm1, %%mm0 \n\t" // (s-dx)*(s-dy)
1741
                "pmullw %%mm5, %%mm3 \n\t" // dx*dy
1742
                "pmullw %%mm5, %%mm2 \n\t" // (s-dx)*dy
1743
                "pmullw %%mm4, %%mm1 \n\t" // dx*(s-dy)
1744
1745
                "movd   %4,    %%mm5 \n\t"
1746
                "movd   %3,    %%mm4 \n\t"
1747
                "punpcklbw %%mm7, %%mm5 \n\t"
1748
                "punpcklbw %%mm7, %%mm4 \n\t"
1749
                "pmullw %%mm5, %%mm3 \n\t" // src[1,1] * dx*dy
1750
                "pmullw %%mm4, %%mm2 \n\t" // src[0,1] * (s-dx)*dy
1751
1752
                "movd   %2,    %%mm5 \n\t"
1753
                "movd   %1,    %%mm4 \n\t"
1754
                "punpcklbw %%mm7, %%mm5 \n\t"
1755
                "punpcklbw %%mm7, %%mm4 \n\t"
1756
                "pmullw %%mm5, %%mm1 \n\t" // src[1,0] * dx*(s-dy)
1757
                "pmullw %%mm4, %%mm0 \n\t" // src[0,0] * (s-dx)*(s-dy)
1758 75ca1a5f Loren Merritt
                "paddw  %5,    %%mm1 \n\t"
1759 703c8195 Loren Merritt
                "paddw  %%mm3, %%mm2 \n\t"
1760
                "paddw  %%mm1, %%mm0 \n\t"
1761
                "paddw  %%mm2, %%mm0 \n\t"
1762
1763
                "psrlw    %6,    %%mm0 \n\t"
1764
                "packuswb %%mm0, %%mm0 \n\t"
1765
                "movd     %%mm0, %0    \n\t"
1766
1767
                : "=m"(dst[x+y*stride])
1768
                : "m"(src[0]), "m"(src[1]),
1769
                  "m"(src[stride]), "m"(src[stride+1]),
1770
                  "m"(*r4), "m"(shift2)
1771
            );
1772
            src += stride;
1773
        }
1774
        src += 4-h*stride;
1775
    }
1776
}
1777
1778 513fbd8e Loren Merritt
#define PREFETCH(name, op) \
1779 bb54f6ab Måns Rullgård
static void name(void *mem, int stride, int h){\
1780 513fbd8e Loren Merritt
    const uint8_t *p= mem;\
1781
    do{\
1782 be449fca Diego Pettenò
        __asm__ volatile(#op" %0" :: "m"(*p));\
1783 513fbd8e Loren Merritt
        p+= stride;\
1784
    }while(--h);\
1785
}
1786
PREFETCH(prefetch_mmx2,  prefetcht0)
1787
PREFETCH(prefetch_3dnow, prefetch)
1788
#undef PREFETCH
1789
1790 d2bb7db1 Loren Merritt
#include "h264dsp_mmx.c"
1791 21ff7689 Mathieu Velten
#include "rv40dsp_mmx.c"
1792 115329f1 Diego Biurrun
1793 571bf37f Diego Biurrun
/* CAVS specific */
1794 595e7bd9 Stefan Gehrer
void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx);
1795 9e8e6d31 Zuxy Meng
void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx);
1796 595e7bd9 Stefan Gehrer
1797
void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1798
    put_pixels8_mmx(dst, src, stride, 8);
1799
}
1800
void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1801
    avg_pixels8_mmx(dst, src, stride, 8);
1802
}
1803
void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1804
    put_pixels16_mmx(dst, src, stride, 16);
1805
}
1806
void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) {
1807
    avg_pixels16_mmx(dst, src, stride, 16);
1808
}
1809
1810 5b67ce2a Aurelien Jacobs
/* VC1 specific */
1811
void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx);
1812
1813
void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
1814
    put_pixels8_mmx(dst, src, stride, 8);
1815
}
1816
1817 b0368839 Michael Niedermayer
/* external functions, from idct_mmx.c */
1818
void ff_mmx_idct(DCTELEM *block);
1819
void ff_mmxext_idct(DCTELEM *block);
1820
1821
/* XXX: those functions should be suppressed ASAP when all IDCTs are
1822
   converted */
1823 b250f9c6 Aurelien Jacobs
#if CONFIG_GPL
1824 b0368839 Michael Niedermayer
static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1825
{
1826
    ff_mmx_idct (block);
1827
    put_pixels_clamped_mmx(block, dest, line_size);
1828
}
1829
static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1830
{
1831
    ff_mmx_idct (block);
1832
    add_pixels_clamped_mmx(block, dest, line_size);
1833
}
1834
static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
1835
{
1836
    ff_mmxext_idct (block);
1837
    put_pixels_clamped_mmx(block, dest, line_size);
1838
}
1839
static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
1840
{
1841
    ff_mmxext_idct (block);
1842
    add_pixels_clamped_mmx(block, dest, line_size);
1843
}
1844 7c428ea6 Diego Biurrun
#endif
1845 84740d59 Michael Niedermayer
static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block)
1846
{
1847
    ff_idct_xvid_mmx (block);
1848
    put_pixels_clamped_mmx(block, dest, line_size);
1849
}
1850
static void ff_idct_xvid_mmx_add(uint8_t *dest, int line_size, DCTELEM *block)
1851
{
1852
    ff_idct_xvid_mmx (block);
1853
    add_pixels_clamped_mmx(block, dest, line_size);
1854
}
1855
static void ff_idct_xvid_mmx2_put(uint8_t *dest, int line_size, DCTELEM *block)
1856
{
1857
    ff_idct_xvid_mmx2 (block);
1858
    put_pixels_clamped_mmx(block, dest, line_size);
1859
}
1860
static void ff_idct_xvid_mmx2_add(uint8_t *dest, int line_size, DCTELEM *block)
1861
{
1862
    ff_idct_xvid_mmx2 (block);
1863
    add_pixels_clamped_mmx(block, dest, line_size);
1864
}
1865 115329f1 Diego Biurrun
1866 cd035a60 Loren Merritt
static void vorbis_inverse_coupling_3dnow(float *mag, float *ang, int blocksize)
1867 2dac4acf Loren Merritt
{
1868
    int i;
1869 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7":);
1870 2dac4acf Loren Merritt
    for(i=0; i<blocksize; i+=2) {
1871 be449fca Diego Pettenò
        __asm__ volatile(
1872 2dac4acf Loren Merritt
            "movq    %0,    %%mm0 \n\t"
1873
            "movq    %1,    %%mm1 \n\t"
1874
            "movq    %%mm0, %%mm2 \n\t"
1875
            "movq    %%mm1, %%mm3 \n\t"
1876
            "pfcmpge %%mm7, %%mm2 \n\t" // m <= 0.0
1877
            "pfcmpge %%mm7, %%mm3 \n\t" // a <= 0.0
1878
            "pslld   $31,   %%mm2 \n\t" // keep only the sign bit
1879
            "pxor    %%mm2, %%mm1 \n\t"
1880
            "movq    %%mm3, %%mm4 \n\t"
1881
            "pand    %%mm1, %%mm3 \n\t"
1882
            "pandn   %%mm1, %%mm4 \n\t"
1883
            "pfadd   %%mm0, %%mm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1884
            "pfsub   %%mm4, %%mm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1885
            "movq    %%mm3, %1    \n\t"
1886
            "movq    %%mm0, %0    \n\t"
1887
            :"+m"(mag[i]), "+m"(ang[i])
1888
            ::"memory"
1889
        );
1890
    }
1891 be449fca Diego Pettenò
    __asm__ volatile("femms");
1892 2dac4acf Loren Merritt
}
1893 21bb884f Michael Niedermayer
static void vorbis_inverse_coupling_sse(float *mag, float *ang, int blocksize)
1894 2dac4acf Loren Merritt
{
1895
    int i;
1896 21bb884f Michael Niedermayer
1897 be449fca Diego Pettenò
    __asm__ volatile(
1898 21bb884f Michael Niedermayer
            "movaps  %0,     %%xmm5 \n\t"
1899
        ::"m"(ff_pdw_80000000[0])
1900
    );
1901 2dac4acf Loren Merritt
    for(i=0; i<blocksize; i+=4) {
1902 be449fca Diego Pettenò
        __asm__ volatile(
1903 2dac4acf Loren Merritt
            "movaps  %0,     %%xmm0 \n\t"
1904
            "movaps  %1,     %%xmm1 \n\t"
1905 21bb884f Michael Niedermayer
            "xorps   %%xmm2, %%xmm2 \n\t"
1906
            "xorps   %%xmm3, %%xmm3 \n\t"
1907 2dac4acf Loren Merritt
            "cmpleps %%xmm0, %%xmm2 \n\t" // m <= 0.0
1908
            "cmpleps %%xmm1, %%xmm3 \n\t" // a <= 0.0
1909 21bb884f Michael Niedermayer
            "andps   %%xmm5, %%xmm2 \n\t" // keep only the sign bit
1910
            "xorps   %%xmm2, %%xmm1 \n\t"
1911 2dac4acf Loren Merritt
            "movaps  %%xmm3, %%xmm4 \n\t"
1912 21bb884f Michael Niedermayer
            "andps   %%xmm1, %%xmm3 \n\t"
1913
            "andnps  %%xmm1, %%xmm4 \n\t"
1914 2dac4acf Loren Merritt
            "addps   %%xmm0, %%xmm3 \n\t" // a = m + ((a<0) & (a ^ sign(m)))
1915
            "subps   %%xmm4, %%xmm0 \n\t" // m = m + ((a>0) & (a ^ sign(m)))
1916
            "movaps  %%xmm3, %1     \n\t"
1917
            "movaps  %%xmm0, %0     \n\t"
1918
            :"+m"(mag[i]), "+m"(ang[i])
1919
            ::"memory"
1920
        );
1921
    }
1922
}
1923
1924 ac2e5564 Loren Merritt
#define IF1(x) x
1925
#define IF0(x)
1926
1927
#define MIX5(mono,stereo)\
1928 be449fca Diego Pettenò
    __asm__ volatile(\
1929 ac2e5564 Loren Merritt
        "movss          0(%2), %%xmm5 \n"\
1930
        "movss          8(%2), %%xmm6 \n"\
1931
        "movss         24(%2), %%xmm7 \n"\
1932
        "shufps    $0, %%xmm5, %%xmm5 \n"\
1933
        "shufps    $0, %%xmm6, %%xmm6 \n"\
1934
        "shufps    $0, %%xmm7, %%xmm7 \n"\
1935
        "1: \n"\
1936
        "movaps       (%0,%1), %%xmm0 \n"\
1937
        "movaps  0x400(%0,%1), %%xmm1 \n"\
1938
        "movaps  0x800(%0,%1), %%xmm2 \n"\
1939
        "movaps  0xc00(%0,%1), %%xmm3 \n"\
1940
        "movaps 0x1000(%0,%1), %%xmm4 \n"\
1941
        "mulps         %%xmm5, %%xmm0 \n"\
1942
        "mulps         %%xmm6, %%xmm1 \n"\
1943
        "mulps         %%xmm5, %%xmm2 \n"\
1944
        "mulps         %%xmm7, %%xmm3 \n"\
1945
        "mulps         %%xmm7, %%xmm4 \n"\
1946
 stereo("addps         %%xmm1, %%xmm0 \n")\
1947
        "addps         %%xmm1, %%xmm2 \n"\
1948
        "addps         %%xmm3, %%xmm0 \n"\
1949
        "addps         %%xmm4, %%xmm2 \n"\
1950
   mono("addps         %%xmm2, %%xmm0 \n")\
1951
        "movaps  %%xmm0,      (%0,%1) \n"\
1952
 stereo("movaps  %%xmm2, 0x400(%0,%1) \n")\
1953
        "add $16, %0 \n"\
1954
        "jl 1b \n"\
1955
        :"+&r"(i)\
1956
        :"r"(samples[0]+len), "r"(matrix)\
1957
        :"memory"\
1958
    );
1959
1960
#define MIX_MISC(stereo)\
1961 be449fca Diego Pettenò
    __asm__ volatile(\
1962 ac2e5564 Loren Merritt
        "1: \n"\
1963
        "movaps  (%3,%0), %%xmm0 \n"\
1964
 stereo("movaps   %%xmm0, %%xmm1 \n")\
1965
        "mulps    %%xmm6, %%xmm0 \n"\
1966
 stereo("mulps    %%xmm7, %%xmm1 \n")\
1967
        "lea 1024(%3,%0), %1 \n"\
1968
        "mov %5, %2 \n"\
1969
        "2: \n"\
1970
        "movaps   (%1),   %%xmm2 \n"\
1971
 stereo("movaps   %%xmm2, %%xmm3 \n")\
1972
        "mulps   (%4,%2), %%xmm2 \n"\
1973
 stereo("mulps 16(%4,%2), %%xmm3 \n")\
1974
        "addps    %%xmm2, %%xmm0 \n"\
1975
 stereo("addps    %%xmm3, %%xmm1 \n")\
1976
        "add $1024, %1 \n"\
1977
        "add $32, %2 \n"\
1978
        "jl 2b \n"\
1979
        "movaps   %%xmm0,     (%3,%0) \n"\
1980
 stereo("movaps   %%xmm1, 1024(%3,%0) \n")\
1981
        "add $16, %0 \n"\
1982
        "jl 1b \n"\
1983
        :"+&r"(i), "=&r"(j), "=&r"(k)\
1984
        :"r"(samples[0]+len), "r"(matrix_simd+in_ch), "g"((intptr_t)-32*(in_ch-1))\
1985
        :"memory"\
1986
    );
1987
1988
static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
1989
{
1990
    int (*matrix_cmp)[2] = (int(*)[2])matrix;
1991
    intptr_t i,j,k;
1992
1993
    i = -len*sizeof(float);
1994
    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]))) {
1995
        MIX5(IF0,IF1);
1996
    } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) {
1997
        MIX5(IF1,IF0);
1998
    } else {
1999
        DECLARE_ALIGNED_16(float, matrix_simd[in_ch][2][4]);
2000
        j = 2*in_ch*sizeof(float);
2001 be449fca Diego Pettenò
        __asm__ volatile(
2002 ac2e5564 Loren Merritt
            "1: \n"
2003
            "sub $8, %0 \n"
2004
            "movss     (%2,%0), %%xmm6 \n"
2005
            "movss    4(%2,%0), %%xmm7 \n"
2006
            "shufps $0, %%xmm6, %%xmm6 \n"
2007
            "shufps $0, %%xmm7, %%xmm7 \n"
2008
            "movaps %%xmm6,   (%1,%0,4) \n"
2009
            "movaps %%xmm7, 16(%1,%0,4) \n"
2010
            "jg 1b \n"
2011
            :"+&r"(j)
2012
            :"r"(matrix_simd), "r"(matrix)
2013
            :"memory"
2014
        );
2015
        if(out_ch == 2) {
2016
            MIX_MISC(IF1);
2017
        } else {
2018
            MIX_MISC(IF0);
2019
        }
2020
    }
2021
}
2022
2023 eb4825b5 Loren Merritt
static void vector_fmul_3dnow(float *dst, const float *src, int len){
2024 40d0e665 Ramiro Polla
    x86_reg i = (len-4)*4;
2025 be449fca Diego Pettenò
    __asm__ volatile(
2026 06972056 Loren Merritt
        "1: \n\t"
2027
        "movq    (%1,%0), %%mm0 \n\t"
2028
        "movq   8(%1,%0), %%mm1 \n\t"
2029
        "pfmul   (%2,%0), %%mm0 \n\t"
2030
        "pfmul  8(%2,%0), %%mm1 \n\t"
2031
        "movq   %%mm0,  (%1,%0) \n\t"
2032
        "movq   %%mm1, 8(%1,%0) \n\t"
2033
        "sub  $16, %0 \n\t"
2034
        "jge 1b \n\t"
2035
        "femms  \n\t"
2036
        :"+r"(i)
2037
        :"r"(dst), "r"(src)
2038
        :"memory"
2039
    );
2040 eb4825b5 Loren Merritt
}
2041
static void vector_fmul_sse(float *dst, const float *src, int len){
2042 40d0e665 Ramiro Polla
    x86_reg i = (len-8)*4;
2043 be449fca Diego Pettenò
    __asm__ volatile(
2044 06972056 Loren Merritt
        "1: \n\t"
2045
        "movaps    (%1,%0), %%xmm0 \n\t"
2046
        "movaps  16(%1,%0), %%xmm1 \n\t"
2047
        "mulps     (%2,%0), %%xmm0 \n\t"
2048
        "mulps   16(%2,%0), %%xmm1 \n\t"
2049
        "movaps  %%xmm0,   (%1,%0) \n\t"
2050
        "movaps  %%xmm1, 16(%1,%0) \n\t"
2051
        "sub  $32, %0 \n\t"
2052
        "jge 1b \n\t"
2053
        :"+r"(i)
2054
        :"r"(dst), "r"(src)
2055
        :"memory"
2056
    );
2057 eb4825b5 Loren Merritt
}
2058
2059
static void vector_fmul_reverse_3dnow2(float *dst, const float *src0, const float *src1, int len){
2060 40d0e665 Ramiro Polla
    x86_reg i = len*4-16;
2061 be449fca Diego Pettenò
    __asm__ volatile(
2062 eb4825b5 Loren Merritt
        "1: \n\t"
2063
        "pswapd   8(%1), %%mm0 \n\t"
2064
        "pswapd    (%1), %%mm1 \n\t"
2065
        "pfmul  (%3,%0), %%mm0 \n\t"
2066
        "pfmul 8(%3,%0), %%mm1 \n\t"
2067
        "movq  %%mm0,  (%2,%0) \n\t"
2068
        "movq  %%mm1, 8(%2,%0) \n\t"
2069
        "add   $16, %1 \n\t"
2070
        "sub   $16, %0 \n\t"
2071
        "jge   1b \n\t"
2072
        :"+r"(i), "+r"(src1)
2073
        :"r"(dst), "r"(src0)
2074
    );
2075 be449fca Diego Pettenò
    __asm__ volatile("femms");
2076 eb4825b5 Loren Merritt
}
2077 1f1aa1d9 Michael Niedermayer
static void vector_fmul_reverse_sse(float *dst, const float *src0, const float *src1, int len){
2078 40d0e665 Ramiro Polla
    x86_reg i = len*4-32;
2079 be449fca Diego Pettenò
    __asm__ volatile(
2080 eb4825b5 Loren Merritt
        "1: \n\t"
2081 1f1aa1d9 Michael Niedermayer
        "movaps        16(%1), %%xmm0 \n\t"
2082
        "movaps          (%1), %%xmm1 \n\t"
2083
        "shufps $0x1b, %%xmm0, %%xmm0 \n\t"
2084
        "shufps $0x1b, %%xmm1, %%xmm1 \n\t"
2085 eb4825b5 Loren Merritt
        "mulps        (%3,%0), %%xmm0 \n\t"
2086
        "mulps      16(%3,%0), %%xmm1 \n\t"
2087
        "movaps     %%xmm0,   (%2,%0) \n\t"
2088
        "movaps     %%xmm1, 16(%2,%0) \n\t"
2089
        "add    $32, %1 \n\t"
2090
        "sub    $32, %0 \n\t"
2091
        "jge    1b \n\t"
2092
        :"+r"(i), "+r"(src1)
2093
        :"r"(dst), "r"(src0)
2094
    );
2095
}
2096
2097
static void vector_fmul_add_add_3dnow(float *dst, const float *src0, const float *src1,
2098
                                      const float *src2, int src3, int len, int step){
2099 40d0e665 Ramiro Polla
    x86_reg i = (len-4)*4;
2100 eb4825b5 Loren Merritt
    if(step == 2 && src3 == 0){
2101
        dst += (len-4)*2;
2102 be449fca Diego Pettenò
        __asm__ volatile(
2103 eb4825b5 Loren Merritt
            "1: \n\t"
2104
            "movq   (%2,%0),  %%mm0 \n\t"
2105
            "movq  8(%2,%0),  %%mm1 \n\t"
2106
            "pfmul  (%3,%0),  %%mm0 \n\t"
2107
            "pfmul 8(%3,%0),  %%mm1 \n\t"
2108
            "pfadd  (%4,%0),  %%mm0 \n\t"
2109
            "pfadd 8(%4,%0),  %%mm1 \n\t"
2110
            "movd     %%mm0,   (%1) \n\t"
2111
            "movd     %%mm1, 16(%1) \n\t"
2112
            "psrlq      $32,  %%mm0 \n\t"
2113
            "psrlq      $32,  %%mm1 \n\t"
2114
            "movd     %%mm0,  8(%1) \n\t"
2115
            "movd     %%mm1, 24(%1) \n\t"
2116
            "sub  $32, %1 \n\t"
2117
            "sub  $16, %0 \n\t"
2118
            "jge  1b \n\t"
2119
            :"+r"(i), "+r"(dst)
2120
            :"r"(src0), "r"(src1), "r"(src2)
2121
            :"memory"
2122
        );
2123
    }
2124
    else if(step == 1 && src3 == 0){
2125 be449fca Diego Pettenò
        __asm__ volatile(
2126 06972056 Loren Merritt
            "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 eb4825b5 Loren Merritt
    }
2142
    else
2143
        ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step);
2144 be449fca Diego Pettenò
    __asm__ volatile("femms");
2145 eb4825b5 Loren Merritt
}
2146 1f1aa1d9 Michael Niedermayer
static void vector_fmul_add_add_sse(float *dst, const float *src0, const float *src1,
2147 06972056 Loren Merritt
                                    const float *src2, int src3, int len, int step){
2148 40d0e665 Ramiro Polla
    x86_reg i = (len-8)*4;
2149 eb4825b5 Loren Merritt
    if(step == 2 && src3 == 0){
2150
        dst += (len-8)*2;
2151 be449fca Diego Pettenò
        __asm__ volatile(
2152 eb4825b5 Loren Merritt
            "1: \n\t"
2153
            "movaps   (%2,%0), %%xmm0 \n\t"
2154
            "movaps 16(%2,%0), %%xmm1 \n\t"
2155
            "mulps    (%3,%0), %%xmm0 \n\t"
2156
            "mulps  16(%3,%0), %%xmm1 \n\t"
2157
            "addps    (%4,%0), %%xmm0 \n\t"
2158