Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / dsputil_mmx.c @ 59006372

History | View | Annotate | Download (136 KB)

1 de6d9b64 Fabrice Bellard
/*
2
 * MMX optimized DSP utils
3 ff4ec49e Fabrice Bellard
 * 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
#include "../dsputil.h"
26 b0368839 Michael Niedermayer
#include "../simple_idct.h"
27 1ec4df0f Michael Niedermayer
#include "../mpegvideo.h"
28 9c39071d Luca Abeni
#include "x86_cpu.h"
29 f9ed9d85 Mike Melanson
#include "mmx.h"
30 de6d9b64 Fabrice Bellard
31 622348f9 Michael Niedermayer
//#undef NDEBUG
32
//#include <assert.h>
33
34 84740d59 Michael Niedermayer
extern void ff_idct_xvid_mmx(short *block);
35
extern void ff_idct_xvid_mmx2(short *block);
36 359f98de Michael Niedermayer
37 486497e0 Måns Rullgård
int mm_flags; /* multimedia extension flags */
38 1457ab52 Michael Niedermayer
39 de6d9b64 Fabrice Bellard
/* pixel operations */
40 5c0513bd Dmitry Baryshkov
static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
41
static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
42
static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
43 de6d9b64 Fabrice Bellard
44 21bb884f Michael Niedermayer
static const uint64_t ff_pdw_80000000[2] attribute_used __attribute__ ((aligned(16))) =
45
{0x8000000080000000ULL, 0x8000000080000000ULL};
46
47 5c0513bd Dmitry Baryshkov
static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
48
static const uint64_t ff_pw_3  attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
49 42251a2a Loren Merritt
static const uint64_t ff_pw_4  attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL;
50 437525c4 Michael Niedermayer
static const uint64_t ff_pw_5  attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL;
51 a6624e21 Loren Merritt
static const uint64_t ff_pw_8  attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL;
52 5c0513bd Dmitry Baryshkov
static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
53 437525c4 Michael Niedermayer
static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL;
54 d2bb7db1 Loren Merritt
static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL;
55 5c0513bd Dmitry Baryshkov
static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
56 826f429a Michael Niedermayer
57 3e20143e Loren Merritt
static const uint64_t ff_pb_1  attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
58
static const uint64_t ff_pb_3  attribute_used __attribute__ ((aligned(8))) = 0x0303030303030303ULL;
59
static const uint64_t ff_pb_7  attribute_used __attribute__ ((aligned(8))) = 0x0707070707070707ULL;
60 5cf08f23 Loren Merritt
static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL;
61 e9f1885c Michael Niedermayer
static const uint64_t ff_pb_A1 attribute_used __attribute__ ((aligned(8))) = 0xA1A1A1A1A1A1A1A1ULL;
62
static const uint64_t ff_pb_5F attribute_used __attribute__ ((aligned(8))) = 0x5F5F5F5F5F5F5F5FULL;
63 5c0513bd Dmitry Baryshkov
static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL;
64 359f98de Michael Niedermayer
65 4454dc1b John Dalgliesh
#define JUMPALIGN() __asm __volatile (ASMALIGN(3)::)
66 d6a4c0b1 Zdenek Kabelac
#define MOVQ_ZERO(regd)  __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
67
68 fca0f0e5 Zdenek Kabelac
#define MOVQ_WONE(regd) \
69
    __asm __volatile ( \
70
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
71
    "psrlw $15, %%" #regd ::)
72
73
#define MOVQ_BFE(regd) \
74
    __asm __volatile ( \
75
    "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
76
    "paddb %%" #regd ", %%" #regd " \n\t" ::)
77
78 d6a4c0b1 Zdenek Kabelac
#ifndef PIC
79 fca0f0e5 Zdenek Kabelac
#define MOVQ_BONE(regd)  __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
80 d6a4c0b1 Zdenek Kabelac
#define MOVQ_WTWO(regd)  __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
81
#else
82
// for shared library it's better to use this way for accessing constants
83
// pcmpeqd -> -1
84 fca0f0e5 Zdenek Kabelac
#define MOVQ_BONE(regd) \
85 d6a4c0b1 Zdenek Kabelac
    __asm __volatile ( \
86 fca0f0e5 Zdenek Kabelac
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
87
    "psrlw $15, %%" #regd " \n\t" \
88
    "packuswb %%" #regd ", %%" #regd " \n\t" ::)
89 d6a4c0b1 Zdenek Kabelac
90
#define MOVQ_WTWO(regd) \
91
    __asm __volatile ( \
92 fca0f0e5 Zdenek Kabelac
    "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
93
    "psrlw $15, %%" #regd " \n\t" \
94
    "psllw $1, %%" #regd " \n\t"::)
95 a7bd8797 Michael Niedermayer
96 d6a4c0b1 Zdenek Kabelac
#endif
97
98 fca0f0e5 Zdenek Kabelac
// using regr as temporary and for the output result
99 def60345 Zdenek Kabelac
// first argument is unmodifed and second is trashed
100 39825f31 Zdenek Kabelac
// regfe is supposed to contain 0xfefefefefefefefe
101
#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
102 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
103
    "pand " #regb ", " #regr "  \n\t"\
104
    "pxor " #rega ", " #regb "  \n\t"\
105
    "pand " #regfe "," #regb "  \n\t"\
106
    "psrlq $1, " #regb "        \n\t"\
107
    "paddb " #regb ", " #regr " \n\t"
108 def60345 Zdenek Kabelac
109 39825f31 Zdenek Kabelac
#define PAVGB_MMX(rega, regb, regr, regfe) \
110 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
111
    "por  " #regb ", " #regr "  \n\t"\
112
    "pxor " #rega ", " #regb "  \n\t"\
113
    "pand " #regfe "," #regb "  \n\t"\
114
    "psrlq $1, " #regb "        \n\t"\
115
    "psubb " #regb ", " #regr " \n\t"
116 def60345 Zdenek Kabelac
117 39825f31 Zdenek Kabelac
// mm6 is supposed to contain 0xfefefefefefefefe
118 6aa6ea8e Zdenek Kabelac
#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp) \
119 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
120
    "movq " #regc ", " #regp "  \n\t"\
121
    "pand " #regb ", " #regr "  \n\t"\
122
    "pand " #regd ", " #regp "  \n\t"\
123
    "pxor " #rega ", " #regb "  \n\t"\
124
    "pxor " #regc ", " #regd "  \n\t"\
125
    "pand %%mm6, " #regb "      \n\t"\
126
    "pand %%mm6, " #regd "      \n\t"\
127
    "psrlq $1, " #regb "        \n\t"\
128
    "psrlq $1, " #regd "        \n\t"\
129
    "paddb " #regb ", " #regr " \n\t"\
130
    "paddb " #regd ", " #regp " \n\t"
131 6aa6ea8e Zdenek Kabelac
132
#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
133 bb270c08 Diego Biurrun
    "movq " #rega ", " #regr "  \n\t"\
134
    "movq " #regc ", " #regp "  \n\t"\
135
    "por  " #regb ", " #regr "  \n\t"\
136
    "por  " #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, " #regd "        \n\t"\
142
    "psrlq $1, " #regb "        \n\t"\
143
    "psubb " #regb ", " #regr " \n\t"\
144
    "psubb " #regd ", " #regp " \n\t"
145 6aa6ea8e Zdenek Kabelac
146 91abb473 Zdenek Kabelac
/***********************************/
147
/* MMX no rounding */
148
#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
149 fca0f0e5 Zdenek Kabelac
#define SET_RND  MOVQ_WONE
150 bb270c08 Diego Biurrun
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
151
#define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
152 fca0f0e5 Zdenek Kabelac
153 91abb473 Zdenek Kabelac
#include "dsputil_mmx_rnd.h"
154
155
#undef DEF
156 fca0f0e5 Zdenek Kabelac
#undef SET_RND
157 6aa6ea8e Zdenek Kabelac
#undef PAVGBP
158 39825f31 Zdenek Kabelac
#undef PAVGB
159 91abb473 Zdenek Kabelac
/***********************************/
160
/* MMX rounding */
161
162
#define DEF(x, y) x ## _ ## y ##_mmx
163 fca0f0e5 Zdenek Kabelac
#define SET_RND  MOVQ_WTWO
164 bb270c08 Diego Biurrun
#define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
165
#define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
166 fca0f0e5 Zdenek Kabelac
167 91abb473 Zdenek Kabelac
#include "dsputil_mmx_rnd.h"
168
169
#undef DEF
170 fca0f0e5 Zdenek Kabelac
#undef SET_RND
171 6aa6ea8e Zdenek Kabelac
#undef PAVGBP
172 39825f31 Zdenek Kabelac
#undef PAVGB
173 a7bd8797 Michael Niedermayer
174 de6d9b64 Fabrice Bellard
/***********************************/
175
/* 3Dnow specific */
176
177
#define DEF(x) x ## _3dnow
178
/* for Athlons PAVGUSB is prefered */
179
#define PAVGB "pavgusb"
180
181
#include "dsputil_mmx_avg.h"
182
183
#undef DEF
184
#undef PAVGB
185
186
/***********************************/
187
/* MMX2 specific */
188
189 607dce96 Michael Niedermayer
#define DEF(x) x ## _mmx2
190 de6d9b64 Fabrice Bellard
191
/* Introduced only in MMX2 set */
192
#define PAVGB "pavgb"
193
194
#include "dsputil_mmx_avg.h"
195
196
#undef DEF
197
#undef PAVGB
198
199 98d417cb Måns Rullgård
#define SBUTTERFLY(a,b,t,n)\
200
    "movq " #a ", " #t "              \n\t" /* abcd */\
201
    "punpckl" #n " " #b ", " #a "     \n\t" /* aebf */\
202
    "punpckh" #n " " #b ", " #t "     \n\t" /* cgdh */\
203
204 de6d9b64 Fabrice Bellard
/***********************************/
205
/* standard MMX */
206
207 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
208 0c1a9eda Zdenek Kabelac
static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
209 de6d9b64 Fabrice Bellard
{
210 607dce96 Michael Niedermayer
    asm volatile(
211 bb270c08 Diego Biurrun
        "mov $-128, %%"REG_a"           \n\t"
212
        "pxor %%mm7, %%mm7              \n\t"
213 4454dc1b John Dalgliesh
        ASMALIGN(4)
214 bb270c08 Diego Biurrun
        "1:                             \n\t"
215
        "movq (%0), %%mm0               \n\t"
216
        "movq (%0, %2), %%mm2           \n\t"
217
        "movq %%mm0, %%mm1              \n\t"
218
        "movq %%mm2, %%mm3              \n\t"
219
        "punpcklbw %%mm7, %%mm0         \n\t"
220
        "punpckhbw %%mm7, %%mm1         \n\t"
221
        "punpcklbw %%mm7, %%mm2         \n\t"
222
        "punpckhbw %%mm7, %%mm3         \n\t"
223
        "movq %%mm0, (%1, %%"REG_a")    \n\t"
224
        "movq %%mm1, 8(%1, %%"REG_a")   \n\t"
225
        "movq %%mm2, 16(%1, %%"REG_a")  \n\t"
226
        "movq %%mm3, 24(%1, %%"REG_a")  \n\t"
227
        "add %3, %0                     \n\t"
228
        "add $32, %%"REG_a"             \n\t"
229
        "js 1b                          \n\t"
230 607dce96 Michael Niedermayer
        : "+r" (pixels)
231 053dea12 Aurelien Jacobs
        : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2)
232
        : "%"REG_a
233 607dce96 Michael Niedermayer
    );
234 de6d9b64 Fabrice Bellard
}
235
236 0c1a9eda Zdenek Kabelac
static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
237 9dbcbd92 Michael Niedermayer
{
238
    asm volatile(
239 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"
240
        "mov $-128, %%"REG_a"           \n\t"
241 4454dc1b John Dalgliesh
        ASMALIGN(4)
242 bb270c08 Diego Biurrun
        "1:                             \n\t"
243
        "movq (%0), %%mm0               \n\t"
244
        "movq (%1), %%mm2               \n\t"
245
        "movq %%mm0, %%mm1              \n\t"
246
        "movq %%mm2, %%mm3              \n\t"
247
        "punpcklbw %%mm7, %%mm0         \n\t"
248
        "punpckhbw %%mm7, %%mm1         \n\t"
249
        "punpcklbw %%mm7, %%mm2         \n\t"
250
        "punpckhbw %%mm7, %%mm3         \n\t"
251
        "psubw %%mm2, %%mm0             \n\t"
252
        "psubw %%mm3, %%mm1             \n\t"
253
        "movq %%mm0, (%2, %%"REG_a")    \n\t"
254
        "movq %%mm1, 8(%2, %%"REG_a")   \n\t"
255
        "add %3, %0                     \n\t"
256
        "add %3, %1                     \n\t"
257
        "add $16, %%"REG_a"             \n\t"
258
        "jnz 1b                         \n\t"
259 9dbcbd92 Michael Niedermayer
        : "+r" (s1), "+r" (s2)
260 053dea12 Aurelien Jacobs
        : "r" (block+64), "r" ((long)stride)
261
        : "%"REG_a
262 9dbcbd92 Michael Niedermayer
    );
263
}
264 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
265 9dbcbd92 Michael Niedermayer
266 0c1a9eda Zdenek Kabelac
void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
267 de6d9b64 Fabrice Bellard
{
268
    const DCTELEM *p;
269 0c1a9eda Zdenek Kabelac
    uint8_t *pix;
270 de6d9b64 Fabrice Bellard
271
    /* read the pixels */
272
    p = block;
273
    pix = pixels;
274 d6a4c0b1 Zdenek Kabelac
    /* unrolled loop */
275 bb270c08 Diego Biurrun
        __asm __volatile(
276
                "movq   %3, %%mm0               \n\t"
277
                "movq   8%3, %%mm1              \n\t"
278
                "movq   16%3, %%mm2             \n\t"
279
                "movq   24%3, %%mm3             \n\t"
280
                "movq   32%3, %%mm4             \n\t"
281
                "movq   40%3, %%mm5             \n\t"
282
                "movq   48%3, %%mm6             \n\t"
283
                "movq   56%3, %%mm7             \n\t"
284
                "packuswb %%mm1, %%mm0          \n\t"
285
                "packuswb %%mm3, %%mm2          \n\t"
286
                "packuswb %%mm5, %%mm4          \n\t"
287
                "packuswb %%mm7, %%mm6          \n\t"
288
                "movq   %%mm0, (%0)             \n\t"
289
                "movq   %%mm2, (%0, %1)         \n\t"
290
                "movq   %%mm4, (%0, %1, 2)      \n\t"
291
                "movq   %%mm6, (%0, %2)         \n\t"
292
                ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "m"(*p)
293
                :"memory");
294 de6d9b64 Fabrice Bellard
        pix += line_size*4;
295
        p += 32;
296 d6a4c0b1 Zdenek Kabelac
297
    // if here would be an exact copy of the code above
298
    // compiler would generate some very strange code
299
    // thus using "r"
300
    __asm __volatile(
301 bb270c08 Diego Biurrun
            "movq       (%3), %%mm0             \n\t"
302
            "movq       8(%3), %%mm1            \n\t"
303
            "movq       16(%3), %%mm2           \n\t"
304
            "movq       24(%3), %%mm3           \n\t"
305
            "movq       32(%3), %%mm4           \n\t"
306
            "movq       40(%3), %%mm5           \n\t"
307
            "movq       48(%3), %%mm6           \n\t"
308
            "movq       56(%3), %%mm7           \n\t"
309
            "packuswb %%mm1, %%mm0              \n\t"
310
            "packuswb %%mm3, %%mm2              \n\t"
311
            "packuswb %%mm5, %%mm4              \n\t"
312
            "packuswb %%mm7, %%mm6              \n\t"
313
            "movq       %%mm0, (%0)             \n\t"
314
            "movq       %%mm2, (%0, %1)         \n\t"
315
            "movq       %%mm4, (%0, %1, 2)      \n\t"
316
            "movq       %%mm6, (%0, %2)         \n\t"
317
            ::"r" (pix), "r" ((long)line_size), "r" ((long)line_size*3), "r"(p)
318
            :"memory");
319 de6d9b64 Fabrice Bellard
}
320
321 68b51e58 Steve L'Homme
static DECLARE_ALIGNED_8(const unsigned char, vector128[8]) =
322 7daabccb Mike Melanson
  { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
323
324 f9ed9d85 Mike Melanson
void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
325
{
326
    int i;
327
328
    movq_m2r(*vector128, mm1);
329
    for (i = 0; i < 8; i++) {
330
        movq_m2r(*(block), mm0);
331
        packsswb_m2r(*(block + 4), mm0);
332
        block += 8;
333
        paddb_r2r(mm1, mm0);
334
        movq_r2m(mm0, *pixels);
335
        pixels += line_size;
336
    }
337
}
338
339 0c1a9eda Zdenek Kabelac
void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
340 de6d9b64 Fabrice Bellard
{
341
    const DCTELEM *p;
342 0c1a9eda Zdenek Kabelac
    uint8_t *pix;
343 de6d9b64 Fabrice Bellard
    int i;
344
345
    /* read the pixels */
346
    p = block;
347
    pix = pixels;
348 d6a4c0b1 Zdenek Kabelac
    MOVQ_ZERO(mm7);
349
    i = 4;
350 cd8e5f96 Zdenek Kabelac
    do {
351 bb270c08 Diego Biurrun
        __asm __volatile(
352
                "movq   (%2), %%mm0     \n\t"
353
                "movq   8(%2), %%mm1    \n\t"
354
                "movq   16(%2), %%mm2   \n\t"
355
                "movq   24(%2), %%mm3   \n\t"
356
                "movq   %0, %%mm4       \n\t"
357
                "movq   %1, %%mm6       \n\t"
358
                "movq   %%mm4, %%mm5    \n\t"
359
                "punpcklbw %%mm7, %%mm4 \n\t"
360
                "punpckhbw %%mm7, %%mm5 \n\t"
361
                "paddsw %%mm4, %%mm0    \n\t"
362
                "paddsw %%mm5, %%mm1    \n\t"
363
                "movq   %%mm6, %%mm5    \n\t"
364
                "punpcklbw %%mm7, %%mm6 \n\t"
365
                "punpckhbw %%mm7, %%mm5 \n\t"
366
                "paddsw %%mm6, %%mm2    \n\t"
367
                "paddsw %%mm5, %%mm3    \n\t"
368
                "packuswb %%mm1, %%mm0  \n\t"
369
                "packuswb %%mm3, %%mm2  \n\t"
370
                "movq   %%mm0, %0       \n\t"
371
                "movq   %%mm2, %1       \n\t"
372
                :"+m"(*pix), "+m"(*(pix+line_size))
373
                :"r"(p)
374
                :"memory");
375 de6d9b64 Fabrice Bellard
        pix += line_size*2;
376
        p += 16;
377 cd8e5f96 Zdenek Kabelac
    } while (--i);
378 de6d9b64 Fabrice Bellard
}
379
380 437525c4 Michael Niedermayer
static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
381
{
382
    __asm __volatile(
383 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
384 4454dc1b John Dalgliesh
         ASMALIGN(3)
385 bb270c08 Diego Biurrun
         "1:                            \n\t"
386
         "movd (%1), %%mm0              \n\t"
387
         "movd (%1, %3), %%mm1          \n\t"
388
         "movd %%mm0, (%2)              \n\t"
389
         "movd %%mm1, (%2, %3)          \n\t"
390
         "add %%"REG_a", %1             \n\t"
391
         "add %%"REG_a", %2             \n\t"
392
         "movd (%1), %%mm0              \n\t"
393
         "movd (%1, %3), %%mm1          \n\t"
394
         "movd %%mm0, (%2)              \n\t"
395
         "movd %%mm1, (%2, %3)          \n\t"
396
         "add %%"REG_a", %1             \n\t"
397
         "add %%"REG_a", %2             \n\t"
398
         "subl $4, %0                   \n\t"
399
         "jnz 1b                        \n\t"
400
         : "+g"(h), "+r" (pixels),  "+r" (block)
401
         : "r"((long)line_size)
402
         : "%"REG_a, "memory"
403
        );
404 437525c4 Michael Niedermayer
}
405
406 0c1a9eda Zdenek Kabelac
static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
407 de6d9b64 Fabrice Bellard
{
408 39825f31 Zdenek Kabelac
    __asm __volatile(
409 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
410 4454dc1b John Dalgliesh
         ASMALIGN(3)
411 bb270c08 Diego Biurrun
         "1:                            \n\t"
412
         "movq (%1), %%mm0              \n\t"
413
         "movq (%1, %3), %%mm1          \n\t"
414
         "movq %%mm0, (%2)              \n\t"
415
         "movq %%mm1, (%2, %3)          \n\t"
416
         "add %%"REG_a", %1             \n\t"
417
         "add %%"REG_a", %2             \n\t"
418
         "movq (%1), %%mm0              \n\t"
419
         "movq (%1, %3), %%mm1          \n\t"
420
         "movq %%mm0, (%2)              \n\t"
421
         "movq %%mm1, (%2, %3)          \n\t"
422
         "add %%"REG_a", %1             \n\t"
423
         "add %%"REG_a", %2             \n\t"
424
         "subl $4, %0                   \n\t"
425
         "jnz 1b                        \n\t"
426
         : "+g"(h), "+r" (pixels),  "+r" (block)
427
         : "r"((long)line_size)
428
         : "%"REG_a, "memory"
429
        );
430 de6d9b64 Fabrice Bellard
}
431
432 0c1a9eda Zdenek Kabelac
static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
433 b3184779 Michael Niedermayer
{
434
    __asm __volatile(
435 bb270c08 Diego Biurrun
         "lea (%3, %3), %%"REG_a"       \n\t"
436 4454dc1b John Dalgliesh
         ASMALIGN(3)
437 bb270c08 Diego Biurrun
         "1:                            \n\t"
438
         "movq (%1), %%mm0              \n\t"
439
         "movq 8(%1), %%mm4             \n\t"
440
         "movq (%1, %3), %%mm1          \n\t"
441
         "movq 8(%1, %3), %%mm5         \n\t"
442
         "movq %%mm0, (%2)              \n\t"
443
         "movq %%mm4, 8(%2)             \n\t"
444
         "movq %%mm1, (%2, %3)          \n\t"
445
         "movq %%mm5, 8(%2, %3)         \n\t"
446
         "add %%"REG_a", %1             \n\t"
447
         "add %%"REG_a", %2             \n\t"
448
         "movq (%1), %%mm0              \n\t"
449
         "movq 8(%1), %%mm4             \n\t"
450
         "movq (%1, %3), %%mm1          \n\t"
451
         "movq 8(%1, %3), %%mm5         \n\t"
452
         "movq %%mm0, (%2)              \n\t"
453
         "movq %%mm4, 8(%2)             \n\t"
454
         "movq %%mm1, (%2, %3)          \n\t"
455
         "movq %%mm5, 8(%2, %3)         \n\t"
456
         "add %%"REG_a", %1             \n\t"
457
         "add %%"REG_a", %2             \n\t"
458
         "subl $4, %0                   \n\t"
459
         "jnz 1b                        \n\t"
460
         : "+g"(h), "+r" (pixels),  "+r" (block)
461
         : "r"((long)line_size)
462
         : "%"REG_a, "memory"
463
        );
464 b3184779 Michael Niedermayer
}
465
466 649c00c9 Michael Niedermayer
static void clear_blocks_mmx(DCTELEM *blocks)
467
{
468 39825f31 Zdenek Kabelac
    __asm __volatile(
469 bb270c08 Diego Biurrun
                "pxor %%mm7, %%mm7              \n\t"
470
                "mov $-128*6, %%"REG_a"         \n\t"
471
                "1:                             \n\t"
472
                "movq %%mm7, (%0, %%"REG_a")    \n\t"
473
                "movq %%mm7, 8(%0, %%"REG_a")   \n\t"
474
                "movq %%mm7, 16(%0, %%"REG_a")  \n\t"
475
                "movq %%mm7, 24(%0, %%"REG_a")  \n\t"
476
                "add $32, %%"REG_a"             \n\t"
477
                " js 1b                         \n\t"
478 053dea12 Aurelien Jacobs
                : : "r" (((uint8_t *)blocks)+128*6)
479
                : "%"REG_a
480 649c00c9 Michael Niedermayer
        );
481
}
482
483 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
484 0c1a9eda Zdenek Kabelac
static int pix_sum16_mmx(uint8_t * pix, int line_size){
485 084c726b Michael Niedermayer
    const int h=16;
486
    int sum;
487 053dea12 Aurelien Jacobs
    long index= -line_size*h;
488 084c726b Michael Niedermayer
489
    __asm __volatile(
490 bb270c08 Diego Biurrun
                "pxor %%mm7, %%mm7              \n\t"
491
                "pxor %%mm6, %%mm6              \n\t"
492
                "1:                             \n\t"
493
                "movq (%2, %1), %%mm0           \n\t"
494
                "movq (%2, %1), %%mm1           \n\t"
495
                "movq 8(%2, %1), %%mm2          \n\t"
496
                "movq 8(%2, %1), %%mm3          \n\t"
497
                "punpcklbw %%mm7, %%mm0         \n\t"
498
                "punpckhbw %%mm7, %%mm1         \n\t"
499
                "punpcklbw %%mm7, %%mm2         \n\t"
500
                "punpckhbw %%mm7, %%mm3         \n\t"
501
                "paddw %%mm0, %%mm1             \n\t"
502
                "paddw %%mm2, %%mm3             \n\t"
503
                "paddw %%mm1, %%mm3             \n\t"
504
                "paddw %%mm3, %%mm6             \n\t"
505
                "add %3, %1                     \n\t"
506
                " js 1b                         \n\t"
507
                "movq %%mm6, %%mm5              \n\t"
508
                "psrlq $32, %%mm6               \n\t"
509
                "paddw %%mm5, %%mm6             \n\t"
510
                "movq %%mm6, %%mm5              \n\t"
511
                "psrlq $16, %%mm6               \n\t"
512
                "paddw %%mm5, %%mm6             \n\t"
513
                "movd %%mm6, %0                 \n\t"
514
                "andl $0xFFFF, %0               \n\t"
515 084c726b Michael Niedermayer
                : "=&r" (sum), "+r" (index)
516 053dea12 Aurelien Jacobs
                : "r" (pix - index), "r" ((long)line_size)
517 084c726b Michael Niedermayer
        );
518
519
        return sum;
520
}
521 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
522 084c726b Michael Niedermayer
523 11f18faf Michael Niedermayer
static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
524 053dea12 Aurelien Jacobs
    long i=0;
525 11f18faf Michael Niedermayer
    asm volatile(
526 bb270c08 Diego Biurrun
        "1:                             \n\t"
527
        "movq  (%1, %0), %%mm0          \n\t"
528
        "movq  (%2, %0), %%mm1          \n\t"
529
        "paddb %%mm0, %%mm1             \n\t"
530
        "movq %%mm1, (%2, %0)           \n\t"
531
        "movq 8(%1, %0), %%mm0          \n\t"
532
        "movq 8(%2, %0), %%mm1          \n\t"
533
        "paddb %%mm0, %%mm1             \n\t"
534
        "movq %%mm1, 8(%2, %0)          \n\t"
535
        "add $16, %0                    \n\t"
536
        "cmp %3, %0                     \n\t"
537
        " jb 1b                         \n\t"
538 11f18faf Michael Niedermayer
        : "+r" (i)
539 053dea12 Aurelien Jacobs
        : "r"(src), "r"(dst), "r"((long)w-15)
540 11f18faf Michael Niedermayer
    );
541
    for(; i<w; i++)
542
        dst[i+0] += src[i+0];
543
}
544
545 3615e2be Michael Niedermayer
#define H263_LOOP_FILTER \
546 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
547
        "movq  %0, %%mm0                \n\t"\
548
        "movq  %0, %%mm1                \n\t"\
549
        "movq  %3, %%mm2                \n\t"\
550
        "movq  %3, %%mm3                \n\t"\
551
        "punpcklbw %%mm7, %%mm0         \n\t"\
552
        "punpckhbw %%mm7, %%mm1         \n\t"\
553
        "punpcklbw %%mm7, %%mm2         \n\t"\
554
        "punpckhbw %%mm7, %%mm3         \n\t"\
555
        "psubw %%mm2, %%mm0             \n\t"\
556
        "psubw %%mm3, %%mm1             \n\t"\
557
        "movq  %1, %%mm2                \n\t"\
558
        "movq  %1, %%mm3                \n\t"\
559
        "movq  %2, %%mm4                \n\t"\
560
        "movq  %2, %%mm5                \n\t"\
561
        "punpcklbw %%mm7, %%mm2         \n\t"\
562
        "punpckhbw %%mm7, %%mm3         \n\t"\
563
        "punpcklbw %%mm7, %%mm4         \n\t"\
564
        "punpckhbw %%mm7, %%mm5         \n\t"\
565
        "psubw %%mm2, %%mm4             \n\t"\
566
        "psubw %%mm3, %%mm5             \n\t"\
567
        "psllw $2, %%mm4                \n\t"\
568
        "psllw $2, %%mm5                \n\t"\
569
        "paddw %%mm0, %%mm4             \n\t"\
570
        "paddw %%mm1, %%mm5             \n\t"\
571
        "pxor %%mm6, %%mm6              \n\t"\
572
        "pcmpgtw %%mm4, %%mm6           \n\t"\
573
        "pcmpgtw %%mm5, %%mm7           \n\t"\
574
        "pxor %%mm6, %%mm4              \n\t"\
575
        "pxor %%mm7, %%mm5              \n\t"\
576
        "psubw %%mm6, %%mm4             \n\t"\
577
        "psubw %%mm7, %%mm5             \n\t"\
578
        "psrlw $3, %%mm4                \n\t"\
579
        "psrlw $3, %%mm5                \n\t"\
580
        "packuswb %%mm5, %%mm4          \n\t"\
581
        "packsswb %%mm7, %%mm6          \n\t"\
582
        "pxor %%mm7, %%mm7              \n\t"\
583
        "movd %4, %%mm2                 \n\t"\
584
        "punpcklbw %%mm2, %%mm2         \n\t"\
585
        "punpcklbw %%mm2, %%mm2         \n\t"\
586
        "punpcklbw %%mm2, %%mm2         \n\t"\
587
        "psubusb %%mm4, %%mm2           \n\t"\
588
        "movq %%mm2, %%mm3              \n\t"\
589
        "psubusb %%mm4, %%mm3           \n\t"\
590
        "psubb %%mm3, %%mm2             \n\t"\
591
        "movq %1, %%mm3                 \n\t"\
592
        "movq %2, %%mm4                 \n\t"\
593
        "pxor %%mm6, %%mm3              \n\t"\
594
        "pxor %%mm6, %%mm4              \n\t"\
595
        "paddusb %%mm2, %%mm3           \n\t"\
596
        "psubusb %%mm2, %%mm4           \n\t"\
597
        "pxor %%mm6, %%mm3              \n\t"\
598
        "pxor %%mm6, %%mm4              \n\t"\
599
        "paddusb %%mm2, %%mm2           \n\t"\
600
        "packsswb %%mm1, %%mm0          \n\t"\
601
        "pcmpgtb %%mm0, %%mm7           \n\t"\
602
        "pxor %%mm7, %%mm0              \n\t"\
603
        "psubb %%mm7, %%mm0             \n\t"\
604
        "movq %%mm0, %%mm1              \n\t"\
605
        "psubusb %%mm2, %%mm0           \n\t"\
606
        "psubb %%mm0, %%mm1             \n\t"\
607
        "pand %5, %%mm1                 \n\t"\
608
        "psrlw $2, %%mm1                \n\t"\
609
        "pxor %%mm7, %%mm1              \n\t"\
610
        "psubb %%mm7, %%mm1             \n\t"\
611
        "movq %0, %%mm5                 \n\t"\
612
        "movq %3, %%mm6                 \n\t"\
613
        "psubb %%mm1, %%mm5             \n\t"\
614
        "paddb %%mm1, %%mm6             \n\t"
615 3615e2be Michael Niedermayer
616 359f98de Michael Niedermayer
static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){
617
    const int strength= ff_h263_loop_filter_strength[qscale];
618
619
    asm volatile(
620 115329f1 Diego Biurrun
621 3615e2be Michael Niedermayer
        H263_LOOP_FILTER
622 115329f1 Diego Biurrun
623 bb270c08 Diego Biurrun
        "movq %%mm3, %1                 \n\t"
624
        "movq %%mm4, %2                 \n\t"
625
        "movq %%mm5, %0                 \n\t"
626
        "movq %%mm6, %3                 \n\t"
627 359f98de Michael Niedermayer
        : "+m" (*(uint64_t*)(src - 2*stride)),
628
          "+m" (*(uint64_t*)(src - 1*stride)),
629
          "+m" (*(uint64_t*)(src + 0*stride)),
630
          "+m" (*(uint64_t*)(src + 1*stride))
631
        : "g" (2*strength), "m"(ff_pb_FC)
632
    );
633
}
634
635 3615e2be Michael Niedermayer
static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride){
636
    asm volatile( //FIXME could save 1 instruction if done as 8x4 ...
637 bb270c08 Diego Biurrun
        "movd  %4, %%mm0                \n\t"
638
        "movd  %5, %%mm1                \n\t"
639
        "movd  %6, %%mm2                \n\t"
640
        "movd  %7, %%mm3                \n\t"
641
        "punpcklbw %%mm1, %%mm0         \n\t"
642
        "punpcklbw %%mm3, %%mm2         \n\t"
643
        "movq %%mm0, %%mm1              \n\t"
644
        "punpcklwd %%mm2, %%mm0         \n\t"
645
        "punpckhwd %%mm2, %%mm1         \n\t"
646
        "movd  %%mm0, %0                \n\t"
647
        "punpckhdq %%mm0, %%mm0         \n\t"
648
        "movd  %%mm0, %1                \n\t"
649
        "movd  %%mm1, %2                \n\t"
650
        "punpckhdq %%mm1, %%mm1         \n\t"
651
        "movd  %%mm1, %3                \n\t"
652 115329f1 Diego Biurrun
653 3615e2be Michael Niedermayer
        : "=m" (*(uint32_t*)(dst + 0*dst_stride)),
654
          "=m" (*(uint32_t*)(dst + 1*dst_stride)),
655
          "=m" (*(uint32_t*)(dst + 2*dst_stride)),
656
          "=m" (*(uint32_t*)(dst + 3*dst_stride))
657
        :  "m" (*(uint32_t*)(src + 0*src_stride)),
658
           "m" (*(uint32_t*)(src + 1*src_stride)),
659
           "m" (*(uint32_t*)(src + 2*src_stride)),
660
           "m" (*(uint32_t*)(src + 3*src_stride))
661
    );
662
}
663
664
static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
665
    const int strength= ff_h263_loop_filter_strength[qscale];
666
    uint64_t temp[4] __attribute__ ((aligned(8)));
667
    uint8_t *btemp= (uint8_t*)temp;
668 115329f1 Diego Biurrun
669 3615e2be Michael Niedermayer
    src -= 2;
670
671
    transpose4x4(btemp  , src           , 8, stride);
672
    transpose4x4(btemp+4, src + 4*stride, 8, stride);
673
    asm volatile(
674
        H263_LOOP_FILTER // 5 3 4 6
675 115329f1 Diego Biurrun
676 3615e2be Michael Niedermayer
        : "+m" (temp[0]),
677
          "+m" (temp[1]),
678
          "+m" (temp[2]),
679
          "+m" (temp[3])
680
        : "g" (2*strength), "m"(ff_pb_FC)
681
    );
682
683
    asm volatile(
684 bb270c08 Diego Biurrun
        "movq %%mm5, %%mm1              \n\t"
685
        "movq %%mm4, %%mm0              \n\t"
686
        "punpcklbw %%mm3, %%mm5         \n\t"
687
        "punpcklbw %%mm6, %%mm4         \n\t"
688
        "punpckhbw %%mm3, %%mm1         \n\t"
689
        "punpckhbw %%mm6, %%mm0         \n\t"
690
        "movq %%mm5, %%mm3              \n\t"
691
        "movq %%mm1, %%mm6              \n\t"
692
        "punpcklwd %%mm4, %%mm5         \n\t"
693
        "punpcklwd %%mm0, %%mm1         \n\t"
694
        "punpckhwd %%mm4, %%mm3         \n\t"
695
        "punpckhwd %%mm0, %%mm6         \n\t"
696
        "movd %%mm5, (%0)               \n\t"
697
        "punpckhdq %%mm5, %%mm5         \n\t"
698
        "movd %%mm5, (%0,%2)            \n\t"
699
        "movd %%mm3, (%0,%2,2)          \n\t"
700
        "punpckhdq %%mm3, %%mm3         \n\t"
701
        "movd %%mm3, (%0,%3)            \n\t"
702
        "movd %%mm1, (%1)               \n\t"
703
        "punpckhdq %%mm1, %%mm1         \n\t"
704
        "movd %%mm1, (%1,%2)            \n\t"
705
        "movd %%mm6, (%1,%2,2)          \n\t"
706
        "punpckhdq %%mm6, %%mm6         \n\t"
707
        "movd %%mm6, (%1,%3)            \n\t"
708 4d9ae03b Martin Drab
        :: "r" (src),
709
           "r" (src + 4*stride),
710
           "r" ((long)   stride ),
711
           "r" ((long)(3*stride))
712 3615e2be Michael Niedermayer
    );
713
}
714
715 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
716 2a006cd3 Felix von Leitner
static int pix_norm1_mmx(uint8_t *pix, int line_size) {
717
    int tmp;
718
  asm volatile (
719
      "movl $16,%%ecx\n"
720
      "pxor %%mm0,%%mm0\n"
721
      "pxor %%mm7,%%mm7\n"
722
      "1:\n"
723 bb270c08 Diego Biurrun
      "movq (%0),%%mm2\n"       /* mm2 = pix[0-7] */
724
      "movq 8(%0),%%mm3\n"      /* mm3 = pix[8-15] */
725 2a006cd3 Felix von Leitner
726 bb270c08 Diego Biurrun
      "movq %%mm2,%%mm1\n"      /* mm1 = mm2 = pix[0-7] */
727 2a006cd3 Felix von Leitner
728 bb270c08 Diego Biurrun
      "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
729
      "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
730 2a006cd3 Felix von Leitner
731 bb270c08 Diego Biurrun
      "movq %%mm3,%%mm4\n"      /* mm4 = mm3 = pix[8-15] */
732
      "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
733
      "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
734 2a006cd3 Felix von Leitner
735 bb270c08 Diego Biurrun
      "pmaddwd %%mm1,%%mm1\n"   /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
736
      "pmaddwd %%mm2,%%mm2\n"   /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
737 2a006cd3 Felix von Leitner
738
      "pmaddwd %%mm3,%%mm3\n"
739
      "pmaddwd %%mm4,%%mm4\n"
740
741 bb270c08 Diego Biurrun
      "paddd %%mm1,%%mm2\n"     /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
742
                                          pix2^2+pix3^2+pix6^2+pix7^2) */
743 2a006cd3 Felix von Leitner
      "paddd %%mm3,%%mm4\n"
744
      "paddd %%mm2,%%mm7\n"
745
746 053dea12 Aurelien Jacobs
      "add %2, %0\n"
747 2a006cd3 Felix von Leitner
      "paddd %%mm4,%%mm7\n"
748
      "dec %%ecx\n"
749
      "jnz 1b\n"
750
751
      "movq %%mm7,%%mm1\n"
752 bb270c08 Diego Biurrun
      "psrlq $32, %%mm7\n"      /* shift hi dword to lo */
753 2a006cd3 Felix von Leitner
      "paddd %%mm7,%%mm1\n"
754
      "movd %%mm1,%1\n"
755 053dea12 Aurelien Jacobs
      : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" );
756 2a006cd3 Felix von Leitner
    return tmp;
757
}
758
759 1ec4df0f Michael Niedermayer
static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
760
    int tmp;
761
  asm volatile (
762
      "movl %4,%%ecx\n"
763 5693c083 Loren Merritt
      "shr $1,%%ecx\n"
764 bb270c08 Diego Biurrun
      "pxor %%mm0,%%mm0\n"      /* mm0 = 0 */
765
      "pxor %%mm7,%%mm7\n"      /* mm7 holds the sum */
766 1ec4df0f Michael Niedermayer
      "1:\n"
767 bb270c08 Diego Biurrun
      "movq (%0),%%mm1\n"       /* mm1 = pix1[0][0-7] */
768
      "movq (%1),%%mm2\n"       /* mm2 = pix2[0][0-7] */
769
      "movq (%0,%3),%%mm3\n"    /* mm3 = pix1[1][0-7] */
770
      "movq (%1,%3),%%mm4\n"    /* mm4 = pix2[1][0-7] */
771 1ec4df0f Michael Niedermayer
772 5693c083 Loren Merritt
      /* todo: mm1-mm2, mm3-mm4 */
773
      /* algo: substract mm1 from mm2 with saturation and vice versa */
774
      /*       OR the results to get absolute difference */
775 1ec4df0f Michael Niedermayer
      "movq %%mm1,%%mm5\n"
776 5693c083 Loren Merritt
      "movq %%mm3,%%mm6\n"
777 1ec4df0f Michael Niedermayer
      "psubusb %%mm2,%%mm1\n"
778 5693c083 Loren Merritt
      "psubusb %%mm4,%%mm3\n"
779 1ec4df0f Michael Niedermayer
      "psubusb %%mm5,%%mm2\n"
780 5693c083 Loren Merritt
      "psubusb %%mm6,%%mm4\n"
781 1ec4df0f Michael Niedermayer
782
      "por %%mm1,%%mm2\n"
783 5693c083 Loren Merritt
      "por %%mm3,%%mm4\n"
784 1ec4df0f Michael Niedermayer
785 5693c083 Loren Merritt
      /* now convert to 16-bit vectors so we can square them */
786 1ec4df0f Michael Niedermayer
      "movq %%mm2,%%mm1\n"
787 5693c083 Loren Merritt
      "movq %%mm4,%%mm3\n"
788 1ec4df0f Michael Niedermayer
789
      "punpckhbw %%mm0,%%mm2\n"
790 5693c083 Loren Merritt
      "punpckhbw %%mm0,%%mm4\n"
791 bb270c08 Diego Biurrun
      "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
792
      "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
793 1ec4df0f Michael Niedermayer
794
      "pmaddwd %%mm2,%%mm2\n"
795 5693c083 Loren Merritt
      "pmaddwd %%mm4,%%mm4\n"
796 1ec4df0f Michael Niedermayer
      "pmaddwd %%mm1,%%mm1\n"
797 5693c083 Loren Merritt
      "pmaddwd %%mm3,%%mm3\n"
798 1ec4df0f Michael Niedermayer
799 bb270c08 Diego Biurrun
      "lea (%0,%3,2), %0\n"     /* pix1 += 2*line_size */
800
      "lea (%1,%3,2), %1\n"     /* pix2 += 2*line_size */
801 1ec4df0f Michael Niedermayer
802
      "paddd %%mm2,%%mm1\n"
803 5693c083 Loren Merritt
      "paddd %%mm4,%%mm3\n"
804 1ec4df0f Michael Niedermayer
      "paddd %%mm1,%%mm7\n"
805 5693c083 Loren Merritt
      "paddd %%mm3,%%mm7\n"
806 1ec4df0f Michael Niedermayer
807
      "decl %%ecx\n"
808
      "jnz 1b\n"
809
810
      "movq %%mm7,%%mm1\n"
811 bb270c08 Diego Biurrun
      "psrlq $32, %%mm7\n"      /* shift hi dword to lo */
812 1ec4df0f Michael Niedermayer
      "paddd %%mm7,%%mm1\n"
813
      "movd %%mm1,%2\n"
814 115329f1 Diego Biurrun
      : "+r" (pix1), "+r" (pix2), "=r"(tmp)
815 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
816 1ec4df0f Michael Niedermayer
      : "%ecx");
817
    return tmp;
818
}
819
820 bb198e19 Michael Niedermayer
static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
821 2a006cd3 Felix von Leitner
    int tmp;
822
  asm volatile (
823 bb198e19 Michael Niedermayer
      "movl %4,%%ecx\n"
824 bb270c08 Diego Biurrun
      "pxor %%mm0,%%mm0\n"      /* mm0 = 0 */
825
      "pxor %%mm7,%%mm7\n"      /* mm7 holds the sum */
826 2a006cd3 Felix von Leitner
      "1:\n"
827 bb270c08 Diego Biurrun
      "movq (%0),%%mm1\n"       /* mm1 = pix1[0-7] */
828
      "movq (%1),%%mm2\n"       /* mm2 = pix2[0-7] */
829
      "movq 8(%0),%%mm3\n"      /* mm3 = pix1[8-15] */
830
      "movq 8(%1),%%mm4\n"      /* mm4 = pix2[8-15] */
831 2a006cd3 Felix von Leitner
832
      /* todo: mm1-mm2, mm3-mm4 */
833
      /* algo: substract mm1 from mm2 with saturation and vice versa */
834
      /*       OR the results to get absolute difference */
835
      "movq %%mm1,%%mm5\n"
836
      "movq %%mm3,%%mm6\n"
837
      "psubusb %%mm2,%%mm1\n"
838
      "psubusb %%mm4,%%mm3\n"
839
      "psubusb %%mm5,%%mm2\n"
840
      "psubusb %%mm6,%%mm4\n"
841
842
      "por %%mm1,%%mm2\n"
843
      "por %%mm3,%%mm4\n"
844
845
      /* now convert to 16-bit vectors so we can square them */
846
      "movq %%mm2,%%mm1\n"
847
      "movq %%mm4,%%mm3\n"
848
849
      "punpckhbw %%mm0,%%mm2\n"
850
      "punpckhbw %%mm0,%%mm4\n"
851 bb270c08 Diego Biurrun
      "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
852
      "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
853 2a006cd3 Felix von Leitner
854
      "pmaddwd %%mm2,%%mm2\n"
855
      "pmaddwd %%mm4,%%mm4\n"
856
      "pmaddwd %%mm1,%%mm1\n"
857
      "pmaddwd %%mm3,%%mm3\n"
858
859 053dea12 Aurelien Jacobs
      "add %3,%0\n"
860
      "add %3,%1\n"
861 2a006cd3 Felix von Leitner
862
      "paddd %%mm2,%%mm1\n"
863
      "paddd %%mm4,%%mm3\n"
864
      "paddd %%mm1,%%mm7\n"
865
      "paddd %%mm3,%%mm7\n"
866
867
      "decl %%ecx\n"
868
      "jnz 1b\n"
869
870
      "movq %%mm7,%%mm1\n"
871 bb270c08 Diego Biurrun
      "psrlq $32, %%mm7\n"      /* shift hi dword to lo */
872 2a006cd3 Felix von Leitner
      "paddd %%mm7,%%mm1\n"
873
      "movd %%mm1,%2\n"
874 115329f1 Diego Biurrun
      : "+r" (pix1), "+r" (pix2), "=r"(tmp)
875 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
876 bb198e19 Michael Niedermayer
      : "%ecx");
877 2a006cd3 Felix von Leitner
    return tmp;
878
}
879
880 5693c083 Loren Merritt
static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
881
    int tmp;
882
  asm volatile (
883
      "shr $1,%2\n"
884 bb270c08 Diego Biurrun
      "pxor %%xmm0,%%xmm0\n"    /* mm0 = 0 */
885
      "pxor %%xmm7,%%xmm7\n"    /* mm7 holds the sum */
886 5693c083 Loren Merritt
      "1:\n"
887 bb270c08 Diego Biurrun
      "movdqu (%0),%%xmm1\n"    /* mm1 = pix1[0][0-15] */
888
      "movdqu (%1),%%xmm2\n"    /* mm2 = pix2[0][0-15] */
889
      "movdqu (%0,%4),%%xmm3\n" /* mm3 = pix1[1][0-15] */
890
      "movdqu (%1,%4),%%xmm4\n" /* mm4 = pix2[1][0-15] */
891 5693c083 Loren Merritt
892
      /* todo: mm1-mm2, mm3-mm4 */
893
      /* algo: substract mm1 from mm2 with saturation and vice versa */
894
      /*       OR the results to get absolute difference */
895
      "movdqa %%xmm1,%%xmm5\n"
896
      "movdqa %%xmm3,%%xmm6\n"
897
      "psubusb %%xmm2,%%xmm1\n"
898
      "psubusb %%xmm4,%%xmm3\n"
899
      "psubusb %%xmm5,%%xmm2\n"
900
      "psubusb %%xmm6,%%xmm4\n"
901
902
      "por %%xmm1,%%xmm2\n"
903
      "por %%xmm3,%%xmm4\n"
904
905
      /* now convert to 16-bit vectors so we can square them */
906
      "movdqa %%xmm2,%%xmm1\n"
907
      "movdqa %%xmm4,%%xmm3\n"
908
909
      "punpckhbw %%xmm0,%%xmm2\n"
910
      "punpckhbw %%xmm0,%%xmm4\n"
911 bb270c08 Diego Biurrun
      "punpcklbw %%xmm0,%%xmm1\n"  /* mm1 now spread over (mm1,mm2) */
912
      "punpcklbw %%xmm0,%%xmm3\n"  /* mm4 now spread over (mm3,mm4) */
913 5693c083 Loren Merritt
914
      "pmaddwd %%xmm2,%%xmm2\n"
915
      "pmaddwd %%xmm4,%%xmm4\n"
916
      "pmaddwd %%xmm1,%%xmm1\n"
917
      "pmaddwd %%xmm3,%%xmm3\n"
918
919 bb270c08 Diego Biurrun
      "lea (%0,%4,2), %0\n"        /* pix1 += 2*line_size */
920
      "lea (%1,%4,2), %1\n"        /* pix2 += 2*line_size */
921 5693c083 Loren Merritt
922
      "paddd %%xmm2,%%xmm1\n"
923
      "paddd %%xmm4,%%xmm3\n"
924
      "paddd %%xmm1,%%xmm7\n"
925
      "paddd %%xmm3,%%xmm7\n"
926
927
      "decl %2\n"
928
      "jnz 1b\n"
929
930
      "movdqa %%xmm7,%%xmm1\n"
931 bb270c08 Diego Biurrun
      "psrldq $8, %%xmm7\n"        /* shift hi qword to lo */
932 5693c083 Loren Merritt
      "paddd %%xmm1,%%xmm7\n"
933
      "movdqa %%xmm7,%%xmm1\n"
934 bb270c08 Diego Biurrun
      "psrldq $4, %%xmm7\n"        /* shift hi dword to lo */
935 5693c083 Loren Merritt
      "paddd %%xmm1,%%xmm7\n"
936
      "movd %%xmm7,%3\n"
937 115329f1 Diego Biurrun
      : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp)
938 5693c083 Loren Merritt
      : "r" ((long)line_size));
939
    return tmp;
940
}
941
942 1ec4df0f Michael Niedermayer
static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
943
    int tmp;
944
  asm volatile (
945
      "movl %3,%%ecx\n"
946
      "pxor %%mm7,%%mm7\n"
947
      "pxor %%mm6,%%mm6\n"
948 115329f1 Diego Biurrun
949 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm0\n"
950
      "movq %%mm0, %%mm1\n"
951
      "psllq $8, %%mm0\n"
952
      "psrlq $8, %%mm1\n"
953
      "psrlq $8, %%mm0\n"
954
      "movq %%mm0, %%mm2\n"
955
      "movq %%mm1, %%mm3\n"
956
      "punpcklbw %%mm7,%%mm0\n"
957
      "punpcklbw %%mm7,%%mm1\n"
958
      "punpckhbw %%mm7,%%mm2\n"
959
      "punpckhbw %%mm7,%%mm3\n"
960
      "psubw %%mm1, %%mm0\n"
961
      "psubw %%mm3, %%mm2\n"
962 115329f1 Diego Biurrun
963 053dea12 Aurelien Jacobs
      "add %2,%0\n"
964 115329f1 Diego Biurrun
965 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm4\n"
966
      "movq %%mm4, %%mm1\n"
967
      "psllq $8, %%mm4\n"
968
      "psrlq $8, %%mm1\n"
969
      "psrlq $8, %%mm4\n"
970
      "movq %%mm4, %%mm5\n"
971
      "movq %%mm1, %%mm3\n"
972
      "punpcklbw %%mm7,%%mm4\n"
973
      "punpcklbw %%mm7,%%mm1\n"
974
      "punpckhbw %%mm7,%%mm5\n"
975
      "punpckhbw %%mm7,%%mm3\n"
976
      "psubw %%mm1, %%mm4\n"
977
      "psubw %%mm3, %%mm5\n"
978
      "psubw %%mm4, %%mm0\n"
979
      "psubw %%mm5, %%mm2\n"
980
      "pxor %%mm3, %%mm3\n"
981
      "pxor %%mm1, %%mm1\n"
982
      "pcmpgtw %%mm0, %%mm3\n\t"
983
      "pcmpgtw %%mm2, %%mm1\n\t"
984
      "pxor %%mm3, %%mm0\n"
985
      "pxor %%mm1, %%mm2\n"
986 115329f1 Diego Biurrun
      "psubw %%mm3, %%mm0\n"
987 1ec4df0f Michael Niedermayer
      "psubw %%mm1, %%mm2\n"
988
      "paddw %%mm0, %%mm2\n"
989
      "paddw %%mm2, %%mm6\n"
990
991 053dea12 Aurelien Jacobs
      "add %2,%0\n"
992 1ec4df0f Michael Niedermayer
      "1:\n"
993 115329f1 Diego Biurrun
994 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm0\n"
995
      "movq %%mm0, %%mm1\n"
996
      "psllq $8, %%mm0\n"
997
      "psrlq $8, %%mm1\n"
998
      "psrlq $8, %%mm0\n"
999
      "movq %%mm0, %%mm2\n"
1000
      "movq %%mm1, %%mm3\n"
1001
      "punpcklbw %%mm7,%%mm0\n"
1002
      "punpcklbw %%mm7,%%mm1\n"
1003
      "punpckhbw %%mm7,%%mm2\n"
1004
      "punpckhbw %%mm7,%%mm3\n"
1005
      "psubw %%mm1, %%mm0\n"
1006
      "psubw %%mm3, %%mm2\n"
1007
      "psubw %%mm0, %%mm4\n"
1008
      "psubw %%mm2, %%mm5\n"
1009
      "pxor %%mm3, %%mm3\n"
1010
      "pxor %%mm1, %%mm1\n"
1011
      "pcmpgtw %%mm4, %%mm3\n\t"
1012
      "pcmpgtw %%mm5, %%mm1\n\t"
1013
      "pxor %%mm3, %%mm4\n"
1014
      "pxor %%mm1, %%mm5\n"
1015 115329f1 Diego Biurrun
      "psubw %%mm3, %%mm4\n"
1016 1ec4df0f Michael Niedermayer
      "psubw %%mm1, %%mm5\n"
1017
      "paddw %%mm4, %%mm5\n"
1018
      "paddw %%mm5, %%mm6\n"
1019 115329f1 Diego Biurrun
1020 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1021 115329f1 Diego Biurrun
1022 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm4\n"
1023
      "movq %%mm4, %%mm1\n"
1024
      "psllq $8, %%mm4\n"
1025
      "psrlq $8, %%mm1\n"
1026
      "psrlq $8, %%mm4\n"
1027
      "movq %%mm4, %%mm5\n"
1028
      "movq %%mm1, %%mm3\n"
1029
      "punpcklbw %%mm7,%%mm4\n"
1030
      "punpcklbw %%mm7,%%mm1\n"
1031
      "punpckhbw %%mm7,%%mm5\n"
1032
      "punpckhbw %%mm7,%%mm3\n"
1033
      "psubw %%mm1, %%mm4\n"
1034
      "psubw %%mm3, %%mm5\n"
1035
      "psubw %%mm4, %%mm0\n"
1036
      "psubw %%mm5, %%mm2\n"
1037
      "pxor %%mm3, %%mm3\n"
1038
      "pxor %%mm1, %%mm1\n"
1039
      "pcmpgtw %%mm0, %%mm3\n\t"
1040
      "pcmpgtw %%mm2, %%mm1\n\t"
1041
      "pxor %%mm3, %%mm0\n"
1042
      "pxor %%mm1, %%mm2\n"
1043 115329f1 Diego Biurrun
      "psubw %%mm3, %%mm0\n"
1044 1ec4df0f Michael Niedermayer
      "psubw %%mm1, %%mm2\n"
1045
      "paddw %%mm0, %%mm2\n"
1046
      "paddw %%mm2, %%mm6\n"
1047
1048 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1049 1ec4df0f Michael Niedermayer
      "subl $2, %%ecx\n"
1050
      " jnz 1b\n"
1051
1052
      "movq %%mm6, %%mm0\n"
1053
      "punpcklwd %%mm7,%%mm0\n"
1054
      "punpckhwd %%mm7,%%mm6\n"
1055
      "paddd %%mm0, %%mm6\n"
1056 115329f1 Diego Biurrun
1057 1ec4df0f Michael Niedermayer
      "movq %%mm6,%%mm0\n"
1058
      "psrlq $32, %%mm6\n"
1059
      "paddd %%mm6,%%mm0\n"
1060
      "movd %%mm0,%1\n"
1061 115329f1 Diego Biurrun
      : "+r" (pix1), "=r"(tmp)
1062 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "g" (h-2)
1063 1ec4df0f Michael Niedermayer
      : "%ecx");
1064
      return tmp;
1065
}
1066
1067
static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
1068
    int tmp;
1069
    uint8_t * pix= pix1;
1070
  asm volatile (
1071
      "movl %3,%%ecx\n"
1072
      "pxor %%mm7,%%mm7\n"
1073
      "pxor %%mm6,%%mm6\n"
1074 115329f1 Diego Biurrun
1075 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm0\n"
1076
      "movq 1(%0),%%mm1\n"
1077
      "movq %%mm0, %%mm2\n"
1078
      "movq %%mm1, %%mm3\n"
1079
      "punpcklbw %%mm7,%%mm0\n"
1080
      "punpcklbw %%mm7,%%mm1\n"
1081
      "punpckhbw %%mm7,%%mm2\n"
1082
      "punpckhbw %%mm7,%%mm3\n"
1083
      "psubw %%mm1, %%mm0\n"
1084
      "psubw %%mm3, %%mm2\n"
1085 115329f1 Diego Biurrun
1086 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1087 115329f1 Diego Biurrun
1088 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm4\n"
1089
      "movq 1(%0),%%mm1\n"
1090
      "movq %%mm4, %%mm5\n"
1091
      "movq %%mm1, %%mm3\n"
1092
      "punpcklbw %%mm7,%%mm4\n"
1093
      "punpcklbw %%mm7,%%mm1\n"
1094
      "punpckhbw %%mm7,%%mm5\n"
1095
      "punpckhbw %%mm7,%%mm3\n"
1096
      "psubw %%mm1, %%mm4\n"
1097
      "psubw %%mm3, %%mm5\n"
1098
      "psubw %%mm4, %%mm0\n"
1099
      "psubw %%mm5, %%mm2\n"
1100
      "pxor %%mm3, %%mm3\n"
1101
      "pxor %%mm1, %%mm1\n"
1102
      "pcmpgtw %%mm0, %%mm3\n\t"
1103
      "pcmpgtw %%mm2, %%mm1\n\t"
1104
      "pxor %%mm3, %%mm0\n"
1105
      "pxor %%mm1, %%mm2\n"
1106 115329f1 Diego Biurrun
      "psubw %%mm3, %%mm0\n"
1107 1ec4df0f Michael Niedermayer
      "psubw %%mm1, %%mm2\n"
1108
      "paddw %%mm0, %%mm2\n"
1109
      "paddw %%mm2, %%mm6\n"
1110
1111 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1112 1ec4df0f Michael Niedermayer
      "1:\n"
1113 115329f1 Diego Biurrun
1114 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm0\n"
1115
      "movq 1(%0),%%mm1\n"
1116
      "movq %%mm0, %%mm2\n"
1117
      "movq %%mm1, %%mm3\n"
1118
      "punpcklbw %%mm7,%%mm0\n"
1119
      "punpcklbw %%mm7,%%mm1\n"
1120
      "punpckhbw %%mm7,%%mm2\n"
1121
      "punpckhbw %%mm7,%%mm3\n"
1122
      "psubw %%mm1, %%mm0\n"
1123
      "psubw %%mm3, %%mm2\n"
1124
      "psubw %%mm0, %%mm4\n"
1125
      "psubw %%mm2, %%mm5\n"
1126
      "pxor %%mm3, %%mm3\n"
1127
      "pxor %%mm1, %%mm1\n"
1128
      "pcmpgtw %%mm4, %%mm3\n\t"
1129
      "pcmpgtw %%mm5, %%mm1\n\t"
1130
      "pxor %%mm3, %%mm4\n"
1131
      "pxor %%mm1, %%mm5\n"
1132
      "psubw %%mm3, %%mm4\n"
1133
      "psubw %%mm1, %%mm5\n"
1134
      "paddw %%mm4, %%mm5\n"
1135
      "paddw %%mm5, %%mm6\n"
1136 115329f1 Diego Biurrun
1137 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1138 115329f1 Diego Biurrun
1139 1ec4df0f Michael Niedermayer
      "movq (%0),%%mm4\n"
1140
      "movq 1(%0),%%mm1\n"
1141
      "movq %%mm4, %%mm5\n"
1142
      "movq %%mm1, %%mm3\n"
1143
      "punpcklbw %%mm7,%%mm4\n"
1144
      "punpcklbw %%mm7,%%mm1\n"
1145
      "punpckhbw %%mm7,%%mm5\n"
1146
      "punpckhbw %%mm7,%%mm3\n"
1147
      "psubw %%mm1, %%mm4\n"
1148
      "psubw %%mm3, %%mm5\n"
1149
      "psubw %%mm4, %%mm0\n"
1150
      "psubw %%mm5, %%mm2\n"
1151
      "pxor %%mm3, %%mm3\n"
1152
      "pxor %%mm1, %%mm1\n"
1153
      "pcmpgtw %%mm0, %%mm3\n\t"
1154
      "pcmpgtw %%mm2, %%mm1\n\t"
1155
      "pxor %%mm3, %%mm0\n"
1156
      "pxor %%mm1, %%mm2\n"
1157 115329f1 Diego Biurrun
      "psubw %%mm3, %%mm0\n"
1158 1ec4df0f Michael Niedermayer
      "psubw %%mm1, %%mm2\n"
1159
      "paddw %%mm0, %%mm2\n"
1160
      "paddw %%mm2, %%mm6\n"
1161
1162 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1163 1ec4df0f Michael Niedermayer
      "subl $2, %%ecx\n"
1164
      " jnz 1b\n"
1165
1166
      "movq %%mm6, %%mm0\n"
1167
      "punpcklwd %%mm7,%%mm0\n"
1168
      "punpckhwd %%mm7,%%mm6\n"
1169
      "paddd %%mm0, %%mm6\n"
1170 115329f1 Diego Biurrun
1171 1ec4df0f Michael Niedermayer
      "movq %%mm6,%%mm0\n"
1172
      "psrlq $32, %%mm6\n"
1173
      "paddd %%mm6,%%mm0\n"
1174
      "movd %%mm0,%1\n"
1175 115329f1 Diego Biurrun
      : "+r" (pix1), "=r"(tmp)
1176 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "g" (h-2)
1177 1ec4df0f Michael Niedermayer
      : "%ecx");
1178
      return tmp + hf_noise8_mmx(pix+8, line_size, h);
1179
}
1180
1181 79396ac6 Måns Rullgård
static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1182
    MpegEncContext *c = p;
1183 ea15df80 Loren Merritt
    int score1, score2;
1184
1185
    if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h);
1186
    else  score1 = sse16_mmx(c, pix1, pix2, line_size, h);
1187
    score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
1188 1ec4df0f Michael Niedermayer
1189 c26abfa5 Diego Biurrun
    if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
1190
    else  return score1 + FFABS(score2)*8;
1191 1ec4df0f Michael Niedermayer
}
1192
1193 79396ac6 Måns Rullgård
static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1194
    MpegEncContext *c = p;
1195 1ec4df0f Michael Niedermayer
    int score1= sse8_mmx(c, pix1, pix2, line_size, h);
1196
    int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
1197
1198 c26abfa5 Diego Biurrun
    if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
1199
    else  return score1 + FFABS(score2)*8;
1200 1ec4df0f Michael Niedermayer
}
1201
1202 622348f9 Michael Niedermayer
static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1203
    int tmp;
1204 115329f1 Diego Biurrun
1205 622348f9 Michael Niedermayer
    assert( (((int)pix) & 7) == 0);
1206
    assert((line_size &7) ==0);
1207 115329f1 Diego Biurrun
1208 622348f9 Michael Niedermayer
#define SUM(in0, in1, out0, out1) \
1209
      "movq (%0), %%mm2\n"\
1210
      "movq 8(%0), %%mm3\n"\
1211 053dea12 Aurelien Jacobs
      "add %2,%0\n"\
1212 622348f9 Michael Niedermayer
      "movq %%mm2, " #out0 "\n"\
1213
      "movq %%mm3, " #out1 "\n"\
1214
      "psubusb " #in0 ", %%mm2\n"\
1215
      "psubusb " #in1 ", %%mm3\n"\
1216
      "psubusb " #out0 ", " #in0 "\n"\
1217
      "psubusb " #out1 ", " #in1 "\n"\
1218
      "por %%mm2, " #in0 "\n"\
1219
      "por %%mm3, " #in1 "\n"\
1220
      "movq " #in0 ", %%mm2\n"\
1221
      "movq " #in1 ", %%mm3\n"\
1222
      "punpcklbw %%mm7, " #in0 "\n"\
1223
      "punpcklbw %%mm7, " #in1 "\n"\
1224
      "punpckhbw %%mm7, %%mm2\n"\
1225
      "punpckhbw %%mm7, %%mm3\n"\
1226
      "paddw " #in1 ", " #in0 "\n"\
1227
      "paddw %%mm3, %%mm2\n"\
1228
      "paddw %%mm2, " #in0 "\n"\
1229
      "paddw " #in0 ", %%mm6\n"
1230
1231 115329f1 Diego Biurrun
1232 622348f9 Michael Niedermayer
  asm volatile (
1233
      "movl %3,%%ecx\n"
1234
      "pxor %%mm6,%%mm6\n"
1235
      "pxor %%mm7,%%mm7\n"
1236
      "movq (%0),%%mm0\n"
1237
      "movq 8(%0),%%mm1\n"
1238 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1239 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1240
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1241
      "1:\n"
1242 115329f1 Diego Biurrun
1243 622348f9 Michael Niedermayer
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1244 115329f1 Diego Biurrun
1245 622348f9 Michael Niedermayer
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1246 115329f1 Diego Biurrun
1247 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1248
      "jnz 1b\n"
1249
1250
      "movq %%mm6,%%mm0\n"
1251
      "psrlq $32, %%mm6\n"
1252
      "paddw %%mm6,%%mm0\n"
1253
      "movq %%mm0,%%mm6\n"
1254
      "psrlq $16, %%mm0\n"
1255
      "paddw %%mm6,%%mm0\n"
1256
      "movd %%mm0,%1\n"
1257 115329f1 Diego Biurrun
      : "+r" (pix), "=r"(tmp)
1258 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
1259 622348f9 Michael Niedermayer
      : "%ecx");
1260
    return tmp & 0xFFFF;
1261
}
1262
#undef SUM
1263
1264
static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
1265
    int tmp;
1266 115329f1 Diego Biurrun
1267 622348f9 Michael Niedermayer
    assert( (((int)pix) & 7) == 0);
1268
    assert((line_size &7) ==0);
1269 115329f1 Diego Biurrun
1270 622348f9 Michael Niedermayer
#define SUM(in0, in1, out0, out1) \
1271
      "movq (%0), " #out0 "\n"\
1272
      "movq 8(%0), " #out1 "\n"\
1273 053dea12 Aurelien Jacobs
      "add %2,%0\n"\
1274 622348f9 Michael Niedermayer
      "psadbw " #out0 ", " #in0 "\n"\
1275
      "psadbw " #out1 ", " #in1 "\n"\
1276
      "paddw " #in1 ", " #in0 "\n"\
1277
      "paddw " #in0 ", %%mm6\n"
1278
1279
  asm volatile (
1280
      "movl %3,%%ecx\n"
1281
      "pxor %%mm6,%%mm6\n"
1282
      "pxor %%mm7,%%mm7\n"
1283
      "movq (%0),%%mm0\n"
1284
      "movq 8(%0),%%mm1\n"
1285 053dea12 Aurelien Jacobs
      "add %2,%0\n"
1286 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1287
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1288
      "1:\n"
1289 115329f1 Diego Biurrun
1290 622348f9 Michael Niedermayer
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1291 115329f1 Diego Biurrun
1292 622348f9 Michael Niedermayer
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1293 115329f1 Diego Biurrun
1294 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1295
      "jnz 1b\n"
1296
1297
      "movd %%mm6,%1\n"
1298 115329f1 Diego Biurrun
      : "+r" (pix), "=r"(tmp)
1299 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
1300 622348f9 Michael Niedermayer
      : "%ecx");
1301
    return tmp;
1302
}
1303
#undef SUM
1304
1305
static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1306
    int tmp;
1307 115329f1 Diego Biurrun
1308 622348f9 Michael Niedermayer
    assert( (((int)pix1) & 7) == 0);
1309
    assert( (((int)pix2) & 7) == 0);
1310
    assert((line_size &7) ==0);
1311 115329f1 Diego Biurrun
1312 622348f9 Michael Niedermayer
#define SUM(in0, in1, out0, out1) \
1313
      "movq (%0),%%mm2\n"\
1314
      "movq (%1)," #out0 "\n"\
1315
      "movq 8(%0),%%mm3\n"\
1316
      "movq 8(%1)," #out1 "\n"\
1317 053dea12 Aurelien Jacobs
      "add %3,%0\n"\
1318
      "add %3,%1\n"\
1319 622348f9 Michael Niedermayer
      "psubb " #out0 ", %%mm2\n"\
1320
      "psubb " #out1 ", %%mm3\n"\
1321
      "pxor %%mm7, %%mm2\n"\
1322
      "pxor %%mm7, %%mm3\n"\
1323
      "movq %%mm2, " #out0 "\n"\
1324
      "movq %%mm3, " #out1 "\n"\
1325
      "psubusb " #in0 ", %%mm2\n"\
1326
      "psubusb " #in1 ", %%mm3\n"\
1327
      "psubusb " #out0 ", " #in0 "\n"\
1328
      "psubusb " #out1 ", " #in1 "\n"\
1329
      "por %%mm2, " #in0 "\n"\
1330
      "por %%mm3, " #in1 "\n"\
1331
      "movq " #in0 ", %%mm2\n"\
1332
      "movq " #in1 ", %%mm3\n"\
1333
      "punpcklbw %%mm7, " #in0 "\n"\
1334
      "punpcklbw %%mm7, " #in1 "\n"\
1335
      "punpckhbw %%mm7, %%mm2\n"\
1336
      "punpckhbw %%mm7, %%mm3\n"\
1337
      "paddw " #in1 ", " #in0 "\n"\
1338
      "paddw %%mm3, %%mm2\n"\
1339
      "paddw %%mm2, " #in0 "\n"\
1340
      "paddw " #in0 ", %%mm6\n"
1341
1342 115329f1 Diego Biurrun
1343 622348f9 Michael Niedermayer
  asm volatile (
1344
      "movl %4,%%ecx\n"
1345
      "pxor %%mm6,%%mm6\n"
1346
      "pcmpeqw %%mm7,%%mm7\n"
1347
      "psllw $15, %%mm7\n"
1348
      "packsswb %%mm7, %%mm7\n"
1349
      "movq (%0),%%mm0\n"
1350
      "movq (%1),%%mm2\n"
1351
      "movq 8(%0),%%mm1\n"
1352
      "movq 8(%1),%%mm3\n"
1353 053dea12 Aurelien Jacobs
      "add %3,%0\n"
1354
      "add %3,%1\n"
1355 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1356
      "psubb %%mm2, %%mm0\n"
1357
      "psubb %%mm3, %%mm1\n"
1358
      "pxor %%mm7, %%mm0\n"
1359
      "pxor %%mm7, %%mm1\n"
1360
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1361
      "1:\n"
1362 115329f1 Diego Biurrun
1363 622348f9 Michael Niedermayer
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1364 115329f1 Diego Biurrun
1365 622348f9 Michael Niedermayer
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1366 115329f1 Diego Biurrun
1367 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1368
      "jnz 1b\n"
1369
1370
      "movq %%mm6,%%mm0\n"
1371
      "psrlq $32, %%mm6\n"
1372
      "paddw %%mm6,%%mm0\n"
1373
      "movq %%mm0,%%mm6\n"
1374
      "psrlq $16, %%mm0\n"
1375
      "paddw %%mm6,%%mm0\n"
1376
      "movd %%mm0,%2\n"
1377 115329f1 Diego Biurrun
      : "+r" (pix1), "+r" (pix2), "=r"(tmp)
1378 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
1379 622348f9 Michael Niedermayer
      : "%ecx");
1380
    return tmp & 0x7FFF;
1381
}
1382
#undef SUM
1383
1384
static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
1385
    int tmp;
1386 115329f1 Diego Biurrun
1387 622348f9 Michael Niedermayer
    assert( (((int)pix1) & 7) == 0);
1388
    assert( (((int)pix2) & 7) == 0);
1389
    assert((line_size &7) ==0);
1390 115329f1 Diego Biurrun
1391 622348f9 Michael Niedermayer
#define SUM(in0, in1, out0, out1) \
1392
      "movq (%0)," #out0 "\n"\
1393
      "movq (%1),%%mm2\n"\
1394
      "movq 8(%0)," #out1 "\n"\
1395
      "movq 8(%1),%%mm3\n"\
1396 053dea12 Aurelien Jacobs
      "add %3,%0\n"\
1397
      "add %3,%1\n"\
1398 622348f9 Michael Niedermayer
      "psubb %%mm2, " #out0 "\n"\
1399
      "psubb %%mm3, " #out1 "\n"\
1400
      "pxor %%mm7, " #out0 "\n"\
1401
      "pxor %%mm7, " #out1 "\n"\
1402
      "psadbw " #out0 ", " #in0 "\n"\
1403
      "psadbw " #out1 ", " #in1 "\n"\
1404
      "paddw " #in1 ", " #in0 "\n"\
1405
      "paddw " #in0 ", %%mm6\n"
1406
1407
  asm volatile (
1408
      "movl %4,%%ecx\n"
1409
      "pxor %%mm6,%%mm6\n"
1410
      "pcmpeqw %%mm7,%%mm7\n"
1411
      "psllw $15, %%mm7\n"
1412
      "packsswb %%mm7, %%mm7\n"
1413
      "movq (%0),%%mm0\n"
1414
      "movq (%1),%%mm2\n"
1415
      "movq 8(%0),%%mm1\n"
1416
      "movq 8(%1),%%mm3\n"
1417 053dea12 Aurelien Jacobs
      "add %3,%0\n"
1418
      "add %3,%1\n"
1419 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1420
      "psubb %%mm2, %%mm0\n"
1421
      "psubb %%mm3, %%mm1\n"
1422
      "pxor %%mm7, %%mm0\n"
1423
      "pxor %%mm7, %%mm1\n"
1424
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1425
      "1:\n"
1426 115329f1 Diego Biurrun
1427 622348f9 Michael Niedermayer
      SUM(%%mm4, %%mm5, %%mm0, %%mm1)
1428 115329f1 Diego Biurrun
1429 622348f9 Michael Niedermayer
      SUM(%%mm0, %%mm1, %%mm4, %%mm5)
1430 115329f1 Diego Biurrun
1431 622348f9 Michael Niedermayer
      "subl $2, %%ecx\n"
1432
      "jnz 1b\n"
1433
1434
      "movd %%mm6,%2\n"
1435 115329f1 Diego Biurrun
      : "+r" (pix1), "+r" (pix2), "=r"(tmp)
1436 053dea12 Aurelien Jacobs
      : "r" ((long)line_size) , "m" (h)
1437 622348f9 Michael Niedermayer
      : "%ecx");
1438
    return tmp;
1439
}
1440
#undef SUM
1441
1442 11f18faf Michael Niedermayer
static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
1443 053dea12 Aurelien Jacobs
    long i=0;
1444 11f18faf Michael Niedermayer
    asm volatile(
1445 bb270c08 Diego Biurrun
        "1:                             \n\t"
1446
        "movq  (%2, %0), %%mm0          \n\t"
1447
        "movq  (%1, %0), %%mm1          \n\t"
1448
        "psubb %%mm0, %%mm1             \n\t"
1449
        "movq %%mm1, (%3, %0)           \n\t"
1450
        "movq 8(%2, %0), %%mm0          \n\t"
1451
        "movq 8(%1, %0), %%mm1          \n\t"
1452
        "psubb %%mm0, %%mm1             \n\t"
1453
        "movq %%mm1, 8(%3, %0)          \n\t"
1454
        "add $16, %0                    \n\t"
1455
        "cmp %4, %0                     \n\t"
1456
        " jb 1b                         \n\t"
1457 11f18faf Michael Niedermayer
        : "+r" (i)
1458 053dea12 Aurelien Jacobs
        : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15)
1459 11f18faf Michael Niedermayer
    );
1460
    for(; i<w; i++)
1461
        dst[i+0] = src1[i+0]-src2[i+0];
1462
}
1463 84705403 Michael Niedermayer
1464
static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
1465 053dea12 Aurelien Jacobs
    long i=0;
1466 84705403 Michael Niedermayer
    uint8_t l, lt;
1467 115329f1 Diego Biurrun
1468 84705403 Michael Niedermayer
    asm volatile(
1469 bb270c08 Diego Biurrun
        "1:                             \n\t"
1470
        "movq  -1(%1, %0), %%mm0        \n\t" // LT
1471
        "movq  (%1, %0), %%mm1          \n\t" // T
1472
        "movq  -1(%2, %0), %%mm2        \n\t" // L
1473
        "movq  (%2, %0), %%mm3          \n\t" // X
1474
        "movq %%mm2, %%mm4              \n\t" // L
1475
        "psubb %%mm0, %%mm2             \n\t"
1476
        "paddb %%mm1, %%mm2             \n\t" // L + T - LT
1477
        "movq %%mm4, %%mm5              \n\t" // L
1478
        "pmaxub %%mm1, %%mm4            \n\t" // max(T, L)
1479
        "pminub %%mm5, %%mm1            \n\t" // min(T, L)
1480
        "pminub %%mm2, %%mm4            \n\t"
1481
        "pmaxub %%mm1, %%mm4            \n\t"
1482
        "psubb %%mm4, %%mm3             \n\t" // dst - pred
1483
        "movq %%mm3, (%3, %0)           \n\t"
1484
        "add $8, %0                     \n\t"
1485
        "cmp %4, %0                     \n\t"
1486
        " jb 1b                         \n\t"
1487 84705403 Michael Niedermayer
        : "+r" (i)
1488 053dea12 Aurelien Jacobs
        : "r"(src1), "r"(src2), "r"(dst), "r"((long)w)
1489 84705403 Michael Niedermayer
    );
1490
1491
    l= *left;
1492
    lt= *left_top;
1493 115329f1 Diego Biurrun
1494 84705403 Michael Niedermayer
    dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
1495 115329f1 Diego Biurrun
1496 84705403 Michael Niedermayer
    *left_top= src1[w-1];
1497
    *left    = src2[w-1];
1498
}
1499
1500 8e0a3db7 Michael Niedermayer
#define LBUTTERFLY2(a1,b1,a2,b2)\
1501 bb270c08 Diego Biurrun
    "paddw " #b1 ", " #a1 "           \n\t"\
1502
    "paddw " #b2 ", " #a2 "           \n\t"\
1503
    "paddw " #b1 ", " #b1 "           \n\t"\
1504
    "paddw " #b2 ", " #b2 "           \n\t"\
1505
    "psubw " #a1 ", " #b1 "           \n\t"\
1506
    "psubw " #a2 ", " #b2 "           \n\t"
1507 1457ab52 Michael Niedermayer
1508
#define HADAMARD48\
1509 8e0a3db7 Michael Niedermayer
        LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
1510
        LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
1511
        LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
1512
        LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
1513
        LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
1514
        LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
1515 1457ab52 Michael Niedermayer
1516
#define MMABS(a,z)\
1517 bb270c08 Diego Biurrun
    "pxor " #z ", " #z "              \n\t"\
1518
    "pcmpgtw " #a ", " #z "           \n\t"\
1519
    "pxor " #z ", " #a "              \n\t"\
1520
    "psubw " #z ", " #a "             \n\t"
1521 1457ab52 Michael Niedermayer
1522
#define MMABS_SUM(a,z, sum)\
1523 bb270c08 Diego Biurrun
    "pxor " #z ", " #z "              \n\t"\
1524
    "pcmpgtw " #a ", " #z "           \n\t"\
1525
    "pxor " #z ", " #a "              \n\t"\
1526
    "psubw " #z ", " #a "             \n\t"\
1527
    "paddusw " #a ", " #sum "         \n\t"
1528 1457ab52 Michael Niedermayer
1529 8e0a3db7 Michael Niedermayer
#define MMABS_MMX2(a,z)\
1530 bb270c08 Diego Biurrun
    "pxor " #z ", " #z "              \n\t"\
1531
    "psubw " #a ", " #z "             \n\t"\
1532
    "pmaxsw " #z ", " #a "            \n\t"
1533 8e0a3db7 Michael Niedermayer
1534
#define MMABS_SUM_MMX2(a,z, sum)\
1535 bb270c08 Diego Biurrun
    "pxor " #z ", " #z "              \n\t"\
1536
    "psubw " #a ", " #z "             \n\t"\
1537
    "pmaxsw " #z ", " #a "            \n\t"\
1538
    "paddusw " #a ", " #sum "         \n\t"
1539 115329f1 Diego Biurrun
1540 1457ab52 Michael Niedermayer
#define TRANSPOSE4(a,b,c,d,t)\
1541
    SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
1542
    SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
1543
    SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
1544
    SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
1545
1546
#define LOAD4(o, a, b, c, d)\
1547 bb270c08 Diego Biurrun
        "movq "#o"(%1), " #a "        \n\t"\
1548
        "movq "#o"+16(%1), " #b "     \n\t"\
1549
        "movq "#o"+32(%1), " #c "     \n\t"\
1550
        "movq "#o"+48(%1), " #d "     \n\t"
1551 1457ab52 Michael Niedermayer
1552
#define STORE4(o, a, b, c, d)\
1553 bb270c08 Diego Biurrun
        "movq "#a", "#o"(%1)          \n\t"\
1554
        "movq "#b", "#o"+16(%1)       \n\t"\
1555
        "movq "#c", "#o"+32(%1)       \n\t"\
1556
        "movq "#d", "#o"+48(%1)       \n\t"\
1557 1457ab52 Michael Niedermayer
1558 bb198e19 Michael Niedermayer
static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
1559 68b51e58 Steve L'Homme
    DECLARE_ALIGNED_8(uint64_t, temp[16]);
1560 1457ab52 Michael Niedermayer
    int sum=0;
1561 115329f1 Diego Biurrun
1562 bb198e19 Michael Niedermayer
    assert(h==8);
1563 1457ab52 Michael Niedermayer
1564
    diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1565 11f18faf Michael Niedermayer
1566 1457ab52 Michael Niedermayer
    asm volatile(
1567
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1568
        LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1569 115329f1 Diego Biurrun
1570 1457ab52 Michael Niedermayer
        HADAMARD48
1571 115329f1 Diego Biurrun
1572 bb270c08 Diego Biurrun
        "movq %%mm7, 112(%1)            \n\t"
1573 115329f1 Diego Biurrun
1574 1457ab52 Michael Niedermayer
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1575
        STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1576 115329f1 Diego Biurrun
1577 bb270c08 Diego Biurrun
        "movq 112(%1), %%mm7            \n\t"
1578 1457ab52 Michael Niedermayer
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1579
        STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1580
1581
        LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1582
        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1583 115329f1 Diego Biurrun
1584 1457ab52 Michael Niedermayer
        HADAMARD48
1585 115329f1 Diego Biurrun
1586 bb270c08 Diego Biurrun
        "movq %%mm7, 120(%1)            \n\t"
1587 115329f1 Diego Biurrun
1588 1457ab52 Michael Niedermayer
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1589
        STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1590 115329f1 Diego Biurrun
1591 bb270c08 Diego Biurrun
        "movq 120(%1), %%mm7            \n\t"
1592 1457ab52 Michael Niedermayer
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1593 bb270c08 Diego Biurrun
        "movq %%mm7, %%mm5              \n\t"//FIXME remove
1594
        "movq %%mm6, %%mm7              \n\t"
1595
        "movq %%mm0, %%mm6              \n\t"
1596 1457ab52 Michael Niedermayer
//        STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1597 115329f1 Diego Biurrun
1598 1457ab52 Michael Niedermayer
        LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1599
//        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1600 115329f1 Diego Biurrun
1601 1457ab52 Michael Niedermayer
        HADAMARD48
1602 bb270c08 Diego Biurrun
        "movq %%mm7, 64(%1)             \n\t"
1603 1457ab52 Michael Niedermayer
        MMABS(%%mm0, %%mm7)
1604
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1605
        MMABS_SUM(%%mm2, %%mm7, %%mm0)
1606
        MMABS_SUM(%%mm3, %%mm7, %%mm0)
1607
        MMABS_SUM(%%mm4, %%mm7, %%mm0)
1608
        MMABS_SUM(%%mm5, %%mm7, %%mm0)
1609
        MMABS_SUM(%%mm6, %%mm7, %%mm0)
1610 bb270c08 Diego Biurrun
        "movq 64(%1), %%mm1             \n\t"
1611 1457ab52 Michael Niedermayer
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1612 bb270c08 Diego Biurrun
        "movq %%mm0, 64(%1)             \n\t"
1613 115329f1 Diego Biurrun
1614 1457ab52 Michael Niedermayer
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1615
        LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1616 115329f1 Diego Biurrun
1617 1457ab52 Michael Niedermayer
        HADAMARD48
1618 bb270c08 Diego Biurrun
        "movq %%mm7, (%1)               \n\t"
1619 1457ab52 Michael Niedermayer
        MMABS(%%mm0, %%mm7)
1620
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1621
        MMABS_SUM(%%mm2, %%mm7, %%mm0)
1622
        MMABS_SUM(%%mm3, %%mm7, %%mm0)
1623
        MMABS_SUM(%%mm4, %%mm7, %%mm0)
1624
        MMABS_SUM(%%mm5, %%mm7, %%mm0)
1625
        MMABS_SUM(%%mm6, %%mm7, %%mm0)
1626 bb270c08 Diego Biurrun
        "movq (%1), %%mm1               \n\t"
1627 1457ab52 Michael Niedermayer
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1628 bb270c08 Diego Biurrun
        "movq 64(%1), %%mm1             \n\t"
1629 1457ab52 Michael Niedermayer
        MMABS_SUM(%%mm1, %%mm7, %%mm0)
1630 115329f1 Diego Biurrun
1631 bb270c08 Diego Biurrun
        "movq %%mm0, %%mm1              \n\t"
1632
        "psrlq $32, %%mm0               \n\t"
1633
        "paddusw %%mm1, %%mm0           \n\t"
1634
        "movq %%mm0, %%mm1              \n\t"
1635
        "psrlq $16, %%mm0               \n\t"
1636
        "paddusw %%mm1, %%mm0           \n\t"
1637
        "movd %%mm0, %0                 \n\t"
1638 115329f1 Diego Biurrun
1639 1457ab52 Michael Niedermayer
        : "=r" (sum)
1640
        : "r"(temp)
1641
    );
1642
    return sum&0xFFFF;
1643
}
1644
1645 bb198e19 Michael Niedermayer
static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){
1646 68b51e58 Steve L'Homme
    DECLARE_ALIGNED_8(uint64_t, temp[16]);
1647 8e0a3db7 Michael Niedermayer
    int sum=0;
1648 115329f1 Diego Biurrun
1649 bb198e19 Michael Niedermayer
    assert(h==8);
1650 8e0a3db7 Michael Niedermayer
1651
    diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
1652
1653
    asm volatile(
1654
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1655
        LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
1656 115329f1 Diego Biurrun
1657 8e0a3db7 Michael Niedermayer
        HADAMARD48
1658 115329f1 Diego Biurrun
1659 bb270c08 Diego Biurrun
        "movq %%mm7, 112(%1)            \n\t"
1660 115329f1 Diego Biurrun
1661 8e0a3db7 Michael Niedermayer
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1662
        STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
1663 115329f1 Diego Biurrun
1664 bb270c08 Diego Biurrun
        "movq 112(%1), %%mm7            \n\t"
1665 8e0a3db7 Michael Niedermayer
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1666
        STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
1667
1668
        LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
1669
        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1670 115329f1 Diego Biurrun
1671 8e0a3db7 Michael Niedermayer
        HADAMARD48
1672 115329f1 Diego Biurrun
1673 bb270c08 Diego Biurrun
        "movq %%mm7, 120(%1)            \n\t"
1674 115329f1 Diego Biurrun
1675 8e0a3db7 Michael Niedermayer
        TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
1676
        STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
1677 115329f1 Diego Biurrun
1678 bb270c08 Diego Biurrun
        "movq 120(%1), %%mm7            \n\t"
1679 8e0a3db7 Michael Niedermayer
        TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
1680 bb270c08 Diego Biurrun
        "movq %%mm7, %%mm5              \n\t"//FIXME remove
1681
        "movq %%mm6, %%mm7              \n\t"
1682
        "movq %%mm0, %%mm6              \n\t"
1683 8e0a3db7 Michael Niedermayer
//        STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
1684 115329f1 Diego Biurrun
1685 8e0a3db7 Michael Niedermayer
        LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
1686
//        LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
1687 115329f1 Diego Biurrun
1688 8e0a3db7 Michael Niedermayer
        HADAMARD48
1689 bb270c08 Diego Biurrun
        "movq %%mm7, 64(%1)             \n\t"
1690 8e0a3db7 Michael Niedermayer
        MMABS_MMX2(%%mm0, %%mm7)
1691
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1692
        MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1693
        MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1694
        MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1695
        MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1696
        MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1697 bb270c08 Diego Biurrun
        "movq 64(%1), %%mm1             \n\t"
1698 8e0a3db7 Michael Niedermayer
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1699 bb270c08 Diego Biurrun
        "movq %%mm0, 64(%1)             \n\t"
1700 115329f1 Diego Biurrun
1701 8e0a3db7 Michael Niedermayer
        LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
1702
        LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
1703 115329f1 Diego Biurrun
1704 8e0a3db7 Michael Niedermayer
        HADAMARD48
1705 bb270c08 Diego Biurrun
        "movq %%mm7, (%1)               \n\t"
1706 8e0a3db7 Michael Niedermayer
        MMABS_MMX2(%%mm0, %%mm7)
1707
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1708
        MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
1709
        MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
1710
        MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
1711
        MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
1712
        MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
1713 bb270c08 Diego Biurrun
        "movq (%1), %%mm1               \n\t"
1714 8e0a3db7 Michael Niedermayer
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1715 bb270c08 Diego Biurrun
        "movq 64(%1), %%mm1             \n\t"
1716 8e0a3db7 Michael Niedermayer
        MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
1717 115329f1 Diego Biurrun
1718 12e96681 Michael Niedermayer
        "pshufw $0x0E, %%mm0, %%mm1     \n\t"
1719 bb270c08 Diego Biurrun
        "paddusw %%mm1, %%mm0           \n\t"
1720 12e96681 Michael Niedermayer
        "pshufw $0x01, %%mm0, %%mm1     \n\t"
1721 bb270c08 Diego Biurrun
        "paddusw %%mm1, %%mm0           \n\t"
1722
        "movd %%mm0, %0                 \n\t"
1723 115329f1 Diego Biurrun
1724 8e0a3db7 Michael Niedermayer
        : "=r" (sum)
1725
        : "r"(temp)
1726
    );
1727
    return sum&0xFFFF;
1728
}
1729
1730
1731 bb198e19 Michael Niedermayer
WARPER8_16_SQ(hadamard8_diff_mmx, hadamard8_diff16_mmx)
1732
WARPER8_16_SQ(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
1733 59006372 Loren Merritt
1734
static int ssd_int8_vs_int16_mmx(int8_t *pix1, int16_t *pix2, int size){
1735
    int sum;
1736
    long i=size;
1737
    asm volatile(
1738
        "pxor %%mm4, %%mm4 \n"
1739
        "1: \n"
1740
        "sub $8, %0 \n"
1741
        "movq (%2,%0), %%mm2 \n"
1742
        "movq (%3,%0,2), %%mm0 \n"
1743
        "movq 8(%3,%0,2), %%mm1 \n"
1744
        "punpckhbw %%mm2, %%mm3 \n"
1745
        "punpcklbw %%mm2, %%mm2 \n"
1746
        "psraw $8, %%mm3 \n"
1747
        "psraw $8, %%mm2 \n"
1748
        "psubw %%mm3, %%mm1 \n"
1749
        "psubw %%mm2, %%mm0 \n"
1750
        "pmaddwd %%mm1, %%mm1 \n"
1751
        "pmaddwd %%mm0, %%mm0 \n"
1752
        "paddd %%mm1, %%mm4 \n"
1753
        "paddd %%mm0, %%mm4 \n"
1754
        "jg 1b \n"
1755
        "movq %%mm4, %%mm3 \n"
1756
        "psrlq $32, %%mm3 \n"
1757
        "paddd %%mm3, %%mm4 \n"
1758
        "movd %%mm4, %1 \n"
1759
        :"+r"(i), "=r"(sum)
1760
        :"r"(pix1), "r"(pix2)
1761
    );
1762
    return sum;
1763
}
1764
1765 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
1766 11f18faf Michael Niedermayer
1767 3178ee4c Michael Niedermayer
#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
1768
#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
1769
1770 826f429a Michael Niedermayer
#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
1771 bb270c08 Diego Biurrun
        "paddw " #m4 ", " #m3 "           \n\t" /* x1 */\
1772
        "movq "MANGLE(ff_pw_20)", %%mm4   \n\t" /* 20 */\
1773
        "pmullw " #m3 ", %%mm4            \n\t" /* 20x1 */\
1774
        "movq "#in7", " #m3 "             \n\t" /* d */\
1775
        "movq "#in0", %%mm5               \n\t" /* D */\
1776
        "paddw " #m3 ", %%mm5             \n\t" /* x4 */\
1777
        "psubw %%mm5, %%mm4               \n\t" /* 20x1 - x4 */\
1778
        "movq "#in1", %%mm5               \n\t" /* C */\
1779
        "movq "#in2", %%mm6               \n\t" /* B */\
1780
        "paddw " #m6 ", %%mm5             \n\t" /* x3 */\
1781
        "paddw " #m5 ", %%mm6             \n\t" /* x2 */\
1782
        "paddw %%mm6, %%mm6               \n\t" /* 2x2 */\
1783
        "psubw %%mm6, %%mm5               \n\t" /* -2x2 + x3 */\
1784
        "pmullw "MANGLE(ff_pw_3)", %%mm5  \n\t" /* -6x2 + 3x3 */\
1785
        "paddw " #rnd ", %%mm4            \n\t" /* x2 */\
1786
        "paddw %%mm4, %%mm5               \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
1787
        "psraw $5, %%mm5                  \n\t"\
1788
        "packuswb %%mm5, %%mm5            \n\t"\
1789 826f429a Michael Niedermayer
        OP(%%mm5, out, %%mm7, d)
1790
1791 3178ee4c Michael Niedermayer
#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
1792 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1793 826f429a Michael Niedermayer
    uint64_t temp;\
1794
\
1795
    asm volatile(\
1796 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7                \n\t"\
1797
        "1:                               \n\t"\
1798
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1799
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1800
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1801
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
1802
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
1803
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
1804
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
1805
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1806
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1807
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
1808
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
1809
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
1810
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
1811
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
1812
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
1813
        "paddw %%mm3, %%mm5               \n\t" /* b */\
1814
        "paddw %%mm2, %%mm6               \n\t" /* c */\
1815
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1816
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
1817
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
1818
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
1819
        "paddw %%mm4, %%mm0               \n\t" /* a */\
1820
        "paddw %%mm1, %%mm5               \n\t" /* d */\
1821
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1822
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
1823
        "paddw %6, %%mm6                  \n\t"\
1824
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1825
        "psraw $5, %%mm0                  \n\t"\
1826
        "movq %%mm0, %5                   \n\t"\
1827 826f429a Michael Niedermayer
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1828
        \
1829 bb270c08 Diego Biurrun
        "movq 5(%0), %%mm0                \n\t" /* FGHIJKLM */\
1830
        "movq %%mm0, %%mm5                \n\t" /* FGHIJKLM */\
1831
        "movq %%mm0, %%mm6                \n\t" /* FGHIJKLM */\
1832
        "psrlq $8, %%mm0                  \n\t" /* GHIJKLM0 */\
1833
        "psrlq $16, %%mm5                 \n\t" /* HIJKLM00 */\
1834
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0G0H0I0J */\
1835
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0H0I0J0K */\
1836
        "paddw %%mm0, %%mm2               \n\t" /* b */\
1837
        "paddw %%mm5, %%mm3               \n\t" /* c */\
1838
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
1839
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
1840
        "movq %%mm6, %%mm2                \n\t" /* FGHIJKLM */\
1841
        "psrlq $24, %%mm6                 \n\t" /* IJKLM000 */\
1842
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0F0G0H0I */\
1843
        "punpcklbw %%mm7, %%mm6           \n\t" /* 0I0J0K0L */\
1844
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
1845
        "paddw %%mm2, %%mm1               \n\t" /* a */\
1846
        "paddw %%mm6, %%mm4               \n\t" /* d */\
1847
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
1848
        "psubw %%mm4, %%mm3               \n\t" /* - 6b +3c - d */\
1849
        "paddw %6, %%mm1                  \n\t"\
1850
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b +3c - d */\
1851
        "psraw $5, %%mm3                  \n\t"\
1852
        "movq %5, %%mm1                   \n\t"\
1853
        "packuswb %%mm3, %%mm1            \n\t"\
1854 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm1, (%1),%%mm4, q)\
1855 826f429a Michael Niedermayer
        /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
1856
        \
1857 bb270c08 Diego Biurrun
        "movq 9(%0), %%mm1                \n\t" /* JKLMNOPQ */\
1858
        "movq %%mm1, %%mm4                \n\t" /* JKLMNOPQ */\
1859
        "movq %%mm1, %%mm3                \n\t" /* JKLMNOPQ */\
1860
        "psrlq $8, %%mm1                  \n\t" /* KLMNOPQ0 */\
1861
        "psrlq $16, %%mm4                 \n\t" /* LMNOPQ00 */\
1862
        "punpcklbw %%mm7, %%mm1           \n\t" /* 0K0L0M0N */\
1863
        "punpcklbw %%mm7, %%mm4           \n\t" /* 0L0M0N0O */\
1864
        "paddw %%mm1, %%mm5               \n\t" /* b */\
1865
        "paddw %%mm4, %%mm0               \n\t" /* c */\
1866
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1867
        "psubw %%mm5, %%mm0               \n\t" /* c - 2b */\
1868
        "movq %%mm3, %%mm5                \n\t" /* JKLMNOPQ */\
1869
        "psrlq $24, %%mm3                 \n\t" /* MNOPQ000 */\
1870
        "pmullw "MANGLE(ff_pw_3)", %%mm0  \n\t" /* 3c - 6b */\
1871
        "punpcklbw %%mm7, %%mm3           \n\t" /* 0M0N0O0P */\
1872
        "paddw %%mm3, %%mm2               \n\t" /* d */\
1873
        "psubw %%mm2, %%mm0               \n\t" /* -6b + 3c - d */\
1874
        "movq %%mm5, %%mm2                \n\t" /* JKLMNOPQ */\
1875
        "punpcklbw %%mm7, %%mm2           \n\t" /* 0J0K0L0M */\
1876
        "punpckhbw %%mm7, %%mm5           \n\t" /* 0N0O0P0Q */\
1877
        "paddw %%mm2, %%mm6               \n\t" /* a */\
1878
        "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
1879
        "paddw %6, %%mm0                  \n\t"\
1880
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1881
        "psraw $5, %%mm0                  \n\t"\
1882 826f429a Michael Niedermayer
        /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
1883
        \
1884 bb270c08 Diego Biurrun
        "paddw %%mm5, %%mm3               \n\t" /* a */\
1885
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0O0P0Q0Q */\
1886
        "paddw %%mm4, %%mm6               \n\t" /* b */\
1887
        "pshufw $0xBE, %%mm5, %%mm4       \n\t" /* 0P0Q0Q0P */\
1888
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0Q0Q0P0O */\
1889
        "paddw %%mm1, %%mm4               \n\t" /* c */\
1890
        "paddw %%mm2, %%mm5               \n\t" /* d */\
1891
        "paddw %%mm6, %%mm6               \n\t" /* 2b */\
1892
        "psubw %%mm6, %%mm4               \n\t" /* c - 2b */\
1893
        "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
1894
        "pmullw "MANGLE(ff_pw_3)", %%mm4  \n\t" /* 3c - 6b */\
1895
        "psubw %%mm5, %%mm3               \n\t" /* -6b + 3c - d */\
1896
        "paddw %6, %%mm4                  \n\t"\
1897
        "paddw %%mm3, %%mm4               \n\t" /* 20a - 6b + 3c - d */\
1898
        "psraw $5, %%mm4                  \n\t"\
1899
        "packuswb %%mm4, %%mm0            \n\t"\
1900 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
1901 826f429a Michael Niedermayer
        \
1902 bb270c08 Diego Biurrun
        "add %3, %0                       \n\t"\
1903
        "add %4, %1                       \n\t"\
1904
        "decl %2                          \n\t"\
1905
        " jnz 1b                          \n\t"\
1906 5a508a98 Michael Niedermayer
        : "+a"(src), "+c"(dst), "+m"(h)\
1907 053dea12 Aurelien Jacobs
        : "d"((long)srcStride), "S"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
1908 0b093b6f Michael Niedermayer
        : "memory"\
1909 826f429a Michael Niedermayer
    );\
1910
}\
1911
\
1912
static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1913
    int i;\
1914
    int16_t temp[16];\
1915
    /* quick HACK, XXX FIXME MUST be optimized */\
1916
    for(i=0; i<h; i++)\
1917
    {\
1918
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
1919
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
1920
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
1921
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
1922
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
1923
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
1924
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
1925
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
1926
        temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
1927
        temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
1928
        temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
1929
        temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
1930
        temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
1931
        temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
1932
        temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
1933
        temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
1934
        asm volatile(\
1935 bb270c08 Diego Biurrun
            "movq (%0), %%mm0               \n\t"\
1936
            "movq 8(%0), %%mm1              \n\t"\
1937
            "paddw %2, %%mm0                \n\t"\
1938
            "paddw %2, %%mm1                \n\t"\
1939
            "psraw $5, %%mm0                \n\t"\
1940
            "psraw $5, %%mm1                \n\t"\
1941
            "packuswb %%mm1, %%mm0          \n\t"\
1942 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
1943 bb270c08 Diego Biurrun
            "movq 16(%0), %%mm0             \n\t"\
1944
            "movq 24(%0), %%mm1             \n\t"\
1945
            "paddw %2, %%mm0                \n\t"\
1946
            "paddw %2, %%mm1                \n\t"\
1947
            "psraw $5, %%mm0                \n\t"\
1948
            "psraw $5, %%mm1                \n\t"\
1949
            "packuswb %%mm1, %%mm0          \n\t"\
1950 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
1951 826f429a Michael Niedermayer
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
1952 0b093b6f Michael Niedermayer
            : "memory"\
1953 826f429a Michael Niedermayer
        );\
1954
        dst+=dstStride;\
1955
        src+=srcStride;\
1956
    }\
1957
}\
1958
\
1959 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
1960 826f429a Michael Niedermayer
    uint64_t temp;\
1961
\
1962
    asm volatile(\
1963 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7                \n\t"\
1964
        "1:                               \n\t"\
1965
        "movq  (%0), %%mm0                \n\t" /* ABCDEFGH */\
1966
        "movq %%mm0, %%mm1                \n\t" /* ABCDEFGH */\
1967
        "movq %%mm0, %%mm2                \n\t" /* ABCDEFGH */\
1968
        "punpcklbw %%mm7, %%mm0           \n\t" /* 0A0B0C0D */\
1969
        "punpckhbw %%mm7, %%mm1           \n\t" /* 0E0F0G0H */\
1970
        "pshufw $0x90, %%mm0, %%mm5       \n\t" /* 0A0A0B0C */\
1971
        "pshufw $0x41, %%mm0, %%mm6       \n\t" /* 0B0A0A0B */\
1972
        "movq %%mm2, %%mm3                \n\t" /* ABCDEFGH */\
1973
        "movq %%mm2, %%mm4                \n\t" /* ABCDEFGH */\
1974
        "psllq $8, %%mm2                  \n\t" /* 0ABCDEFG */\
1975
        "psllq $16, %%mm3                 \n\t" /* 00ABCDEF */\
1976
        "psllq $24, %%mm4                 \n\t" /* 000ABCDE */\
1977
        "punpckhbw %%mm7, %%mm2           \n\t" /* 0D0E0F0G */\
1978
        "punpckhbw %%mm7, %%mm3           \n\t" /* 0C0D0E0F */\
1979
        "punpckhbw %%mm7, %%mm4           \n\t" /* 0B0C0D0E */\
1980
        "paddw %%mm3, %%mm5               \n\t" /* b */\
1981
        "paddw %%mm2, %%mm6               \n\t" /* c */\
1982
        "paddw %%mm5, %%mm5               \n\t" /* 2b */\
1983
        "psubw %%mm5, %%mm6               \n\t" /* c - 2b */\
1984
        "pshufw $0x06, %%mm0, %%mm5       \n\t" /* 0C0B0A0A */\
1985
        "pmullw "MANGLE(ff_pw_3)", %%mm6  \n\t" /* 3c - 6b */\
1986
        "paddw %%mm4, %%mm0               \n\t" /* a */\
1987
        "paddw %%mm1, %%mm5               \n\t" /* d */\
1988
        "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
1989
        "psubw %%mm5, %%mm0               \n\t" /* 20a - d */\
1990
        "paddw %6, %%mm6                  \n\t"\
1991
        "paddw %%mm6, %%mm0               \n\t" /* 20a - 6b + 3c - d */\
1992
        "psraw $5, %%mm0                  \n\t"\
1993 826f429a Michael Niedermayer
        /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
1994
        \
1995 bb270c08 Diego Biurrun
        "movd 5(%0), %%mm5                \n\t" /* FGHI */\
1996
        "punpcklbw %%mm7, %%mm5           \n\t" /* 0F0G0H0I */\
1997
        "pshufw $0xF9, %%mm5, %%mm6       \n\t" /* 0G0H0I0I */\
1998
        "paddw %%mm5, %%mm1               \n\t" /* a */\
1999
        "paddw %%mm6, %%mm2               \n\t" /* b */\
2000
        "pshufw $0xBE, %%mm5, %%mm6       \n\t" /* 0H0I0I0H */\
2001
        "pshufw $0x6F, %%mm5, %%mm5       \n\t" /* 0I0I0H0G */\
2002
        "paddw %%mm6, %%mm3               \n\t" /* c */\
2003
        "paddw %%mm5, %%mm4               \n\t" /* d */\
2004
        "paddw %%mm2, %%mm2               \n\t" /* 2b */\
2005
        "psubw %%mm2, %%mm3               \n\t" /* c - 2b */\
2006
        "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
2007
        "pmullw "MANGLE(ff_pw_3)", %%mm3  \n\t" /* 3c - 6b */\
2008
        "psubw %%mm4, %%mm3               \n\t" /* -6b + 3c - d */\
2009
        "paddw %6, %%mm1                  \n\t"\
2010
        "paddw %%mm1, %%mm3               \n\t" /* 20a - 6b + 3c - d */\
2011
        "psraw $5, %%mm3                  \n\t"\
2012
        "packuswb %%mm3, %%mm0            \n\t"\
2013 3178ee4c Michael Niedermayer
        OP_MMX2(%%mm0, (%1), %%mm4, q)\
2014 826f429a Michael Niedermayer
        \
2015 bb270c08 Diego Biurrun
        "add %3, %0                       \n\t"\
2016
        "add %4, %1                       \n\t"\
2017
        "decl %2                          \n\t"\
2018
        " jnz 1b                          \n\t"\
2019 5a508a98 Michael Niedermayer
        : "+a"(src), "+c"(dst), "+m"(h)\
2020 053dea12 Aurelien Jacobs
        : "S"((long)srcStride), "D"((long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
2021 0b093b6f Michael Niedermayer
        : "memory"\
2022 826f429a Michael Niedermayer
    );\
2023
}\
2024
\
2025
static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
2026
    int i;\
2027
    int16_t temp[8];\
2028
    /* quick HACK, XXX FIXME MUST be optimized */\
2029
    for(i=0; i<h; i++)\
2030
    {\
2031
        temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
2032
        temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
2033
        temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
2034
        temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
2035
        temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
2036
        temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
2037
        temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
2038
        temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
2039
        asm volatile(\
2040 bb270c08 Diego Biurrun
            "movq (%0), %%mm0           \n\t"\
2041
            "movq 8(%0), %%mm1          \n\t"\
2042
            "paddw %2, %%mm0            \n\t"\
2043
            "paddw %2, %%mm1            \n\t"\
2044
            "psraw $5, %%mm0            \n\t"\
2045
            "psraw $5, %%mm1            \n\t"\
2046
            "packuswb %%mm1, %%mm0      \n\t"\
2047 3178ee4c Michael Niedermayer
            OP_3DNOW(%%mm0, (%1), %%mm1, q)\
2048 826f429a Michael Niedermayer
            :: "r"(temp), "r"(dst), "m"(ROUNDER)\
2049 0b093b6f Michael Niedermayer
            :"memory"\
2050 826f429a Michael Niedermayer
        );\
2051
        dst+=dstStride;\
2052
        src+=srcStride;\
2053
    }\
2054 3178ee4c Michael Niedermayer
}
2055
2056
#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
2057
\
2058
static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2059
    uint64_t temp[17*4];\
2060
    uint64_t *temp_ptr= temp;\
2061
    int count= 17;\
2062
\
2063
    /*FIXME unroll */\
2064
    asm volatile(\
2065 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
2066
        "1:                             \n\t"\
2067
        "movq (%0), %%mm0               \n\t"\
2068
        "movq (%0), %%mm1               \n\t"\
2069
        "movq 8(%0), %%mm2              \n\t"\
2070
        "movq 8(%0), %%mm3              \n\t"\
2071
        "punpcklbw %%mm7, %%mm0         \n\t"\
2072
        "punpckhbw %%mm7, %%mm1         \n\t"\
2073
        "punpcklbw %%mm7, %%mm2         \n\t"\
2074
        "punpckhbw %%mm7, %%mm3         \n\t"\
2075
        "movq %%mm0, (%1)               \n\t"\
2076
        "movq %%mm1, 17*8(%1)           \n\t"\
2077
        "movq %%mm2, 2*17*8(%1)         \n\t"\
2078
        "movq %%mm3, 3*17*8(%1)         \n\t"\
2079
        "add $8, %1                     \n\t"\
2080
        "add %3, %0                     \n\t"\
2081
        "decl %2                        \n\t"\
2082
        " jnz 1b                        \n\t"\
2083 3178ee4c Michael Niedermayer
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
2084 053dea12 Aurelien Jacobs
        : "r" ((long)srcStride)\
2085 0b093b6f Michael Niedermayer
        : "memory"\
2086 3178ee4c Michael Niedermayer
    );\
2087
    \
2088
    temp_ptr= temp;\
2089
    count=4;\
2090
    \
2091
/*FIXME reorder for speed */\
2092
    asm volatile(\
2093 bb270c08 Diego Biurrun
        /*"pxor %%mm7, %%mm7              \n\t"*/\
2094
        "1:                             \n\t"\
2095
        "movq (%0), %%mm0               \n\t"\
2096
        "movq 8(%0), %%mm1              \n\t"\
2097
        "movq 16(%0), %%mm2             \n\t"\
2098
        "movq 24(%0), %%mm3             \n\t"\
2099 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0),  8(%0),   (%0), 32(%0), (%1), OP)\
2100
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5,  8(%0),   (%0),   (%0), 40(%0), (%1, %3), OP)\
2101 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2102 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5,   (%0),   (%0),  8(%0), 48(%0), (%1), OP)\
2103 3178ee4c Michael Niedermayer
        \
2104 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5,   (%0),  8(%0), 16(%0), 56(%0), (%1, %3), OP)\
2105 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2106 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5,  8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
2107
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
2108 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2109 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
2110
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
2111 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2112 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
2113
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
2114 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2115 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
2116
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
2117 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"\
2118 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
2119 3178ee4c Michael Niedermayer
        \
2120 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
2121 bb270c08 Diego Biurrun
        "add %4, %1                     \n\t"  \
2122 c296f66b Michael Niedermayer
        QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
2123
        QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
2124 3178ee4c Michael Niedermayer
        \
2125 bb270c08 Diego Biurrun
        "add $136, %0                   \n\t"\
2126
        "add %6, %1                     \n\t"\
2127
        "decl %2                        \n\t"\
2128
        " jnz 1b                        \n\t"\
2129 3178ee4c Michael Niedermayer
        \
2130 5a508a98 Michael Niedermayer
        : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
2131 053dea12 Aurelien Jacobs
        : "r"((long)dstStride), "r"(2*(long)dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*(long)dstStride)\
2132 0b093b6f Michael Niedermayer
        :"memory"\
2133 3178ee4c Michael Niedermayer
    );\
2134 826f429a Michael Niedermayer
}\
2135
\
2136 5c91a675 Zdenek Kabelac
static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
2137 437525c4 Michael Niedermayer
    uint64_t temp[9*2];\
2138 826f429a Michael Niedermayer
    uint64_t *temp_ptr= temp;\
2139
    int count= 9;\
2140
\
2141
    /*FIXME unroll */\
2142
    asm volatile(\
2143 bb270c08 Diego Biurrun
        "pxor %%mm7, %%mm7              \n\t"\
2144
        "1:                             \n\t"\
2145
        "movq (%0), %%mm0               \n\t"\
2146
        "movq (%0), %%mm1               \n\t"\
2147
        "punpcklbw %%mm7, %%mm0         \n\t"\
2148
        "punpckhbw %%mm7, %%mm1         \n\t"\
2149
        "movq %%mm0, (%1)               \n\t"\
2150
        "movq %%mm1, 9*8(%1)            \n\t"\
2151
        "add $8, %1                     \n\t"\
2152
        "add %3, %0                     \n\t"\
2153
        "decl %2                        \n\t"\
2154
        " jnz 1b                        \n\t"\
2155 826f429a Michael Niedermayer
        : "+r" (src), "+r" (temp_ptr), "+r"(count)\
2156 053dea12 Aurelien Jacobs
        : "r" ((long)srcStride)\
2157 0b093b6f Michael Niedermayer
        : "memory"\
2158 826f429a Michael Niedermayer
    );\
2159
    \
2160
    temp_ptr= temp;\
2161
    count=2;\
2162
    \
2163
/*FIXME reorder for speed */\
2164
    asm volatile(\
2165 bb270c08 Diego Biurrun
        /*"pxor %%mm7, %%mm7              \n\t"*/\
2166
        "1:                             \n\t"\
2167
        "movq (%0), %%mm0               \n\t"\
2168
        "movq 8(%0), %%mm1              \n\t"\
2169
        "movq 16(%0), %%mm2             \n