Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / dsputil_mmx.c @ d19b744a

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