Statistics
| Branch: | Revision:

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

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