Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / motion_est_mmx.c @ 05aec7bb

History | View | Annotate | Download (15.7 KB)

1 694ec061 Fabrice Bellard
/*
2
 * MMX optimized motion estimation
3 406792e7 Diego Biurrun
 * Copyright (c) 2001 Fabrice Bellard
4 8f2ab833 Michael Niedermayer
 * Copyright (c) 2002-2004 Michael Niedermayer
5 694ec061 Fabrice Bellard
 *
6 7b94177e Diego Biurrun
 * mostly by Michael Niedermayer <michaelni@gmx.at>
7
 *
8 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
9
 *
10
 * FFmpeg is free software; you can redistribute it and/or
11 ff4ec49e Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
12
 * License as published by the Free Software Foundation; either
13 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
14 694ec061 Fabrice Bellard
 *
15 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
16 694ec061 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ff4ec49e Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
 * Lesser General Public License for more details.
19 694ec061 Fabrice Bellard
 *
20 ff4ec49e Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
21 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
22 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 694ec061 Fabrice Bellard
 */
24 245976da Diego Biurrun
25
#include "libavutil/x86_cpu.h"
26
#include "libavcodec/dsputil.h"
27 4e36a5b4 Måns Rullgård
#include "dsputil_mmx.h"
28 694ec061 Fabrice Bellard
29 c6727809 Måns Rullgård
DECLARE_ASM_CONST(8, uint64_t, round_tab)[3]={
30 1b245cc2 Panagiotis Issaris
0x0000000000000000ULL,
31
0x0001000100010001ULL,
32
0x0002000200020002ULL,
33 ba6802de Michael Niedermayer
};
34 694ec061 Fabrice Bellard
35 766324fc Reimar Döffinger
DECLARE_ASM_CONST(8, uint64_t, bone)= 0x0101010101010101LL;
36 ba8d0be9 Michael Niedermayer
37 bb198e19 Michael Niedermayer
static inline void sad8_1_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
38 694ec061 Fabrice Bellard
{
39 40d0e665 Ramiro Polla
    x86_reg len= -(stride*h);
40 be449fca Diego Pettenò
    __asm__ volatile(
41 4454dc1b John Dalgliesh
        ASMALIGN(4)
42 bb270c08 Diego Biurrun
        "1:                             \n\t"
43
        "movq (%1, %%"REG_a"), %%mm0    \n\t"
44
        "movq (%2, %%"REG_a"), %%mm2    \n\t"
45
        "movq (%2, %%"REG_a"), %%mm4    \n\t"
46
        "add %3, %%"REG_a"              \n\t"
47
        "psubusb %%mm0, %%mm2           \n\t"
48
        "psubusb %%mm4, %%mm0           \n\t"
49
        "movq (%1, %%"REG_a"), %%mm1    \n\t"
50
        "movq (%2, %%"REG_a"), %%mm3    \n\t"
51
        "movq (%2, %%"REG_a"), %%mm5    \n\t"
52
        "psubusb %%mm1, %%mm3           \n\t"
53
        "psubusb %%mm5, %%mm1           \n\t"
54
        "por %%mm2, %%mm0               \n\t"
55
        "por %%mm1, %%mm3               \n\t"
56
        "movq %%mm0, %%mm1              \n\t"
57
        "movq %%mm3, %%mm2              \n\t"
58
        "punpcklbw %%mm7, %%mm0         \n\t"
59
        "punpckhbw %%mm7, %%mm1         \n\t"
60
        "punpcklbw %%mm7, %%mm3         \n\t"
61
        "punpckhbw %%mm7, %%mm2         \n\t"
62
        "paddw %%mm1, %%mm0             \n\t"
63
        "paddw %%mm3, %%mm2             \n\t"
64
        "paddw %%mm2, %%mm0             \n\t"
65
        "paddw %%mm0, %%mm6             \n\t"
66
        "add %3, %%"REG_a"              \n\t"
67
        " js 1b                         \n\t"
68 ba6802de Michael Niedermayer
        : "+a" (len)
69 40d0e665 Ramiro Polla
        : "r" (blk1 - len), "r" (blk2 - len), "r" ((x86_reg)stride)
70 ba6802de Michael Niedermayer
    );
71 694ec061 Fabrice Bellard
}
72
73 bb198e19 Michael Niedermayer
static inline void sad8_1_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
74 694ec061 Fabrice Bellard
{
75 be449fca Diego Pettenò
    __asm__ volatile(
76 4454dc1b John Dalgliesh
        ASMALIGN(4)
77 bb270c08 Diego Biurrun
        "1:                             \n\t"
78 164d75eb Loren Merritt
        "movq (%1), %%mm0               \n\t"
79
        "movq (%1, %3), %%mm1           \n\t"
80
        "psadbw (%2), %%mm0             \n\t"
81
        "psadbw (%2, %3), %%mm1         \n\t"
82 bb270c08 Diego Biurrun
        "paddw %%mm0, %%mm6             \n\t"
83 164d75eb Loren Merritt
        "paddw %%mm1, %%mm6             \n\t"
84
        "lea (%1,%3,2), %1              \n\t"
85
        "lea (%2,%3,2), %2              \n\t"
86
        "sub $2, %0                     \n\t"
87
        " jg 1b                         \n\t"
88
        : "+r" (h), "+r" (blk1), "+r" (blk2)
89 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
90 ba6802de Michael Niedermayer
    );
91 694ec061 Fabrice Bellard
}
92
93 72946825 Loren Merritt
static int sad16_sse2(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)
94
{
95
    int ret;
96 be449fca Diego Pettenò
    __asm__ volatile(
97 72946825 Loren Merritt
        "pxor %%xmm6, %%xmm6            \n\t"
98
        ASMALIGN(4)
99
        "1:                             \n\t"
100
        "movdqu (%1), %%xmm0            \n\t"
101
        "movdqu (%1, %3), %%xmm1        \n\t"
102
        "psadbw (%2), %%xmm0            \n\t"
103
        "psadbw (%2, %3), %%xmm1        \n\t"
104
        "paddw %%xmm0, %%xmm6           \n\t"
105
        "paddw %%xmm1, %%xmm6           \n\t"
106
        "lea (%1,%3,2), %1              \n\t"
107
        "lea (%2,%3,2), %2              \n\t"
108
        "sub $2, %0                     \n\t"
109
        " jg 1b                         \n\t"
110
        : "+r" (h), "+r" (blk1), "+r" (blk2)
111 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
112 72946825 Loren Merritt
    );
113 be449fca Diego Pettenò
    __asm__ volatile(
114 72946825 Loren Merritt
        "movhlps %%xmm6, %%xmm0         \n\t"
115
        "paddw   %%xmm0, %%xmm6         \n\t"
116
        "movd    %%xmm6, %0             \n\t"
117
        : "=r"(ret)
118
    );
119
    return ret;
120
}
121
122 164d75eb Loren Merritt
static inline void sad8_x2a_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
123 694ec061 Fabrice Bellard
{
124 be449fca Diego Pettenò
    __asm__ volatile(
125 4454dc1b John Dalgliesh
        ASMALIGN(4)
126 bb270c08 Diego Biurrun
        "1:                             \n\t"
127 164d75eb Loren Merritt
        "movq (%1), %%mm0               \n\t"
128
        "movq (%1, %3), %%mm1           \n\t"
129
        "pavgb 1(%1), %%mm0             \n\t"
130
        "pavgb 1(%1, %3), %%mm1         \n\t"
131
        "psadbw (%2), %%mm0             \n\t"
132
        "psadbw (%2, %3), %%mm1         \n\t"
133 bb270c08 Diego Biurrun
        "paddw %%mm0, %%mm6             \n\t"
134 164d75eb Loren Merritt
        "paddw %%mm1, %%mm6             \n\t"
135
        "lea (%1,%3,2), %1              \n\t"
136
        "lea (%2,%3,2), %2              \n\t"
137
        "sub $2, %0                     \n\t"
138
        " jg 1b                         \n\t"
139
        : "+r" (h), "+r" (blk1), "+r" (blk2)
140 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
141 164d75eb Loren Merritt
    );
142
}
143
144
static inline void sad8_y2a_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
145
{
146 be449fca Diego Pettenò
    __asm__ volatile(
147 164d75eb Loren Merritt
        "movq (%1), %%mm0               \n\t"
148
        "add %3, %1                     \n\t"
149
        ASMALIGN(4)
150
        "1:                             \n\t"
151
        "movq (%1), %%mm1               \n\t"
152
        "movq (%1, %3), %%mm2           \n\t"
153
        "pavgb %%mm1, %%mm0             \n\t"
154
        "pavgb %%mm2, %%mm1             \n\t"
155
        "psadbw (%2), %%mm0             \n\t"
156
        "psadbw (%2, %3), %%mm1         \n\t"
157
        "paddw %%mm0, %%mm6             \n\t"
158
        "paddw %%mm1, %%mm6             \n\t"
159
        "movq %%mm2, %%mm0              \n\t"
160
        "lea (%1,%3,2), %1              \n\t"
161
        "lea (%2,%3,2), %2              \n\t"
162
        "sub $2, %0                     \n\t"
163
        " jg 1b                         \n\t"
164
        : "+r" (h), "+r" (blk1), "+r" (blk2)
165 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
166 ba6802de Michael Niedermayer
    );
167 694ec061 Fabrice Bellard
}
168
169 0c1a9eda Zdenek Kabelac
static inline void sad8_4_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
170 164d75eb Loren Merritt
{
171 be449fca Diego Pettenò
    __asm__ volatile(
172 bb270c08 Diego Biurrun
        "movq "MANGLE(bone)", %%mm5     \n\t"
173 164d75eb Loren Merritt
        "movq (%1), %%mm0               \n\t"
174
        "pavgb 1(%1), %%mm0             \n\t"
175
        "add %3, %1                     \n\t"
176 eca3810e Loren Merritt
        ASMALIGN(4)
177 bb270c08 Diego Biurrun
        "1:                             \n\t"
178 164d75eb Loren Merritt
        "movq (%1), %%mm1               \n\t"
179
        "movq (%1,%3), %%mm2            \n\t"
180
        "pavgb 1(%1), %%mm1             \n\t"
181
        "pavgb 1(%1,%3), %%mm2          \n\t"
182 eca3810e Loren Merritt
        "psubusb %%mm5, %%mm1           \n\t"
183
        "pavgb %%mm1, %%mm0             \n\t"
184 164d75eb Loren Merritt
        "pavgb %%mm2, %%mm1             \n\t"
185
        "psadbw (%2), %%mm0             \n\t"
186
        "psadbw (%2,%3), %%mm1          \n\t"
187 bb270c08 Diego Biurrun
        "paddw %%mm0, %%mm6             \n\t"
188 164d75eb Loren Merritt
        "paddw %%mm1, %%mm6             \n\t"
189
        "movq %%mm2, %%mm0              \n\t"
190
        "lea (%1,%3,2), %1              \n\t"
191
        "lea (%2,%3,2), %2              \n\t"
192
        "sub $2, %0                     \n\t"
193
        " jg 1b                         \n\t"
194
        : "+r" (h), "+r" (blk1), "+r" (blk2)
195 40d0e665 Ramiro Polla
        : "r" ((x86_reg)stride)
196 ba6802de Michael Niedermayer
    );
197 694ec061 Fabrice Bellard
}
198
199 0c1a9eda Zdenek Kabelac
static inline void sad8_2_mmx(uint8_t *blk1a, uint8_t *blk1b, uint8_t *blk2, int stride, int h)
200 694ec061 Fabrice Bellard
{
201 40d0e665 Ramiro Polla
    x86_reg len= -(stride*h);
202 be449fca Diego Pettenò
    __asm__ volatile(
203 4454dc1b John Dalgliesh
        ASMALIGN(4)
204 bb270c08 Diego Biurrun
        "1:                             \n\t"
205
        "movq (%1, %%"REG_a"), %%mm0    \n\t"
206
        "movq (%2, %%"REG_a"), %%mm1    \n\t"
207
        "movq (%1, %%"REG_a"), %%mm2    \n\t"
208
        "movq (%2, %%"REG_a"), %%mm3    \n\t"
209
        "punpcklbw %%mm7, %%mm0         \n\t"
210
        "punpcklbw %%mm7, %%mm1         \n\t"
211
        "punpckhbw %%mm7, %%mm2         \n\t"
212
        "punpckhbw %%mm7, %%mm3         \n\t"
213
        "paddw %%mm0, %%mm1             \n\t"
214
        "paddw %%mm2, %%mm3             \n\t"
215
        "movq (%3, %%"REG_a"), %%mm4    \n\t"
216
        "movq (%3, %%"REG_a"), %%mm2    \n\t"
217
        "paddw %%mm5, %%mm1             \n\t"
218
        "paddw %%mm5, %%mm3             \n\t"
219
        "psrlw $1, %%mm1                \n\t"
220
        "psrlw $1, %%mm3                \n\t"
221
        "packuswb %%mm3, %%mm1          \n\t"
222
        "psubusb %%mm1, %%mm4           \n\t"
223
        "psubusb %%mm2, %%mm1           \n\t"
224
        "por %%mm4, %%mm1               \n\t"
225
        "movq %%mm1, %%mm0              \n\t"
226
        "punpcklbw %%mm7, %%mm0         \n\t"
227
        "punpckhbw %%mm7, %%mm1         \n\t"
228
        "paddw %%mm1, %%mm0             \n\t"
229
        "paddw %%mm0, %%mm6             \n\t"
230
        "add %4, %%"REG_a"              \n\t"
231
        " js 1b                         \n\t"
232 ba6802de Michael Niedermayer
        : "+a" (len)
233 40d0e665 Ramiro Polla
        : "r" (blk1a - len), "r" (blk1b -len), "r" (blk2 - len), "r" ((x86_reg)stride)
234 ba6802de Michael Niedermayer
    );
235 694ec061 Fabrice Bellard
}
236
237 0c1a9eda Zdenek Kabelac
static inline void sad8_4_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
238 694ec061 Fabrice Bellard
{
239 40d0e665 Ramiro Polla
    x86_reg len= -(stride*h);
240 be449fca Diego Pettenò
    __asm__ volatile(
241 bb270c08 Diego Biurrun
        "movq (%1, %%"REG_a"), %%mm0    \n\t"
242
        "movq 1(%1, %%"REG_a"), %%mm2   \n\t"
243 164d75eb Loren Merritt
        "movq %%mm0, %%mm1              \n\t"
244
        "movq %%mm2, %%mm3              \n\t"
245
        "punpcklbw %%mm7, %%mm0         \n\t"
246 bb270c08 Diego Biurrun
        "punpckhbw %%mm7, %%mm1         \n\t"
247 164d75eb Loren Merritt
        "punpcklbw %%mm7, %%mm2         \n\t"
248
        "punpckhbw %%mm7, %%mm3         \n\t"
249
        "paddw %%mm2, %%mm0             \n\t"
250
        "paddw %%mm3, %%mm1             \n\t"
251
        ASMALIGN(4)
252
        "1:                             \n\t"
253
        "movq (%2, %%"REG_a"), %%mm2    \n\t"
254
        "movq 1(%2, %%"REG_a"), %%mm4   \n\t"
255
        "movq %%mm2, %%mm3              \n\t"
256
        "movq %%mm4, %%mm5              \n\t"
257
        "punpcklbw %%mm7, %%mm2         \n\t"
258
        "punpckhbw %%mm7, %%mm3         \n\t"
259
        "punpcklbw %%mm7, %%mm4         \n\t"
260
        "punpckhbw %%mm7, %%mm5         \n\t"
261
        "paddw %%mm4, %%mm2             \n\t"
262
        "paddw %%mm5, %%mm3             \n\t"
263
        "movq 16+"MANGLE(round_tab)", %%mm5 \n\t"
264
        "paddw %%mm2, %%mm0             \n\t"
265
        "paddw %%mm3, %%mm1             \n\t"
266
        "paddw %%mm5, %%mm0             \n\t"
267 bb270c08 Diego Biurrun
        "paddw %%mm5, %%mm1             \n\t"
268 164d75eb Loren Merritt
        "movq (%3, %%"REG_a"), %%mm4    \n\t"
269
        "movq (%3, %%"REG_a"), %%mm5    \n\t"
270
        "psrlw $2, %%mm0                \n\t"
271 bb270c08 Diego Biurrun
        "psrlw $2, %%mm1                \n\t"
272 164d75eb Loren Merritt
        "packuswb %%mm1, %%mm0          \n\t"
273
        "psubusb %%mm0, %%mm4           \n\t"
274
        "psubusb %%mm5, %%mm0           \n\t"
275
        "por %%mm4, %%mm0               \n\t"
276
        "movq %%mm0, %%mm4              \n\t"
277 bb270c08 Diego Biurrun
        "punpcklbw %%mm7, %%mm0         \n\t"
278 164d75eb Loren Merritt
        "punpckhbw %%mm7, %%mm4         \n\t"
279 bb270c08 Diego Biurrun
        "paddw %%mm0, %%mm6             \n\t"
280 164d75eb Loren Merritt
        "paddw %%mm4, %%mm6             \n\t"
281
        "movq  %%mm2, %%mm0             \n\t"
282
        "movq  %%mm3, %%mm1             \n\t"
283 bb270c08 Diego Biurrun
        "add %4, %%"REG_a"              \n\t"
284
        " js 1b                         \n\t"
285 ba6802de Michael Niedermayer
        : "+a" (len)
286 40d0e665 Ramiro Polla
        : "r" (blk1 - len), "r" (blk1 -len + stride), "r" (blk2 - len), "r" ((x86_reg)stride)
287 ba6802de Michael Niedermayer
    );
288 694ec061 Fabrice Bellard
}
289
290 5c91a675 Zdenek Kabelac
static inline int sum_mmx(void)
291 694ec061 Fabrice Bellard
{
292 ba6802de Michael Niedermayer
    int ret;
293 be449fca Diego Pettenò
    __asm__ volatile(
294 bb270c08 Diego Biurrun
        "movq %%mm6, %%mm0              \n\t"
295
        "psrlq $32, %%mm6               \n\t"
296
        "paddw %%mm0, %%mm6             \n\t"
297
        "movq %%mm6, %%mm0              \n\t"
298
        "psrlq $16, %%mm6               \n\t"
299
        "paddw %%mm0, %%mm6             \n\t"
300
        "movd %%mm6, %0                 \n\t"
301 ba6802de Michael Niedermayer
        : "=r" (ret)
302
    );
303
    return ret&0xFFFF;
304 694ec061 Fabrice Bellard
}
305
306 5c91a675 Zdenek Kabelac
static inline int sum_mmx2(void)
307 694ec061 Fabrice Bellard
{
308 ba6802de Michael Niedermayer
    int ret;
309 be449fca Diego Pettenò
    __asm__ volatile(
310 bb270c08 Diego Biurrun
        "movd %%mm6, %0                 \n\t"
311 ba6802de Michael Niedermayer
        : "=r" (ret)
312
    );
313
    return ret;
314 694ec061 Fabrice Bellard
}
315
316 164d75eb Loren Merritt
static inline void sad8_x2a_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
317
{
318
    sad8_2_mmx(blk1, blk1+1, blk2, stride, h);
319
}
320
static inline void sad8_y2a_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
321
{
322
    sad8_2_mmx(blk1, blk1+stride, blk2, stride, h);
323
}
324
325 843342ef Michael Niedermayer
326 ba6802de Michael Niedermayer
#define PIX_SAD(suf)\
327 bb198e19 Michael Niedermayer
static int sad8_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
328 ba6802de Michael Niedermayer
{\
329 bb198e19 Michael Niedermayer
    assert(h==8);\
330 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
331 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t":);\
332 ba6802de Michael Niedermayer
\
333 bb198e19 Michael Niedermayer
    sad8_1_ ## suf(blk1, blk2, stride, 8);\
334 ba6802de Michael Niedermayer
\
335
    return sum_ ## suf();\
336
}\
337 bb198e19 Michael Niedermayer
static int sad8_x2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
338 ba6802de Michael Niedermayer
{\
339 bb198e19 Michael Niedermayer
    assert(h==8);\
340 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
341 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
342 ba53071a Loren Merritt
                 "movq %0, %%mm5        \n\t"\
343 ba6802de Michael Niedermayer
                 :: "m"(round_tab[1]) \
344
                 );\
345
\
346 164d75eb Loren Merritt
    sad8_x2a_ ## suf(blk1, blk2, stride, 8);\
347 ba6802de Michael Niedermayer
\
348
    return sum_ ## suf();\
349
}\
350
\
351 bb198e19 Michael Niedermayer
static int sad8_y2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
352 ba6802de Michael Niedermayer
{\
353 bb198e19 Michael Niedermayer
    assert(h==8);\
354 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
355 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
356
                 "movq %0, %%mm5        \n\t"\
357 ba6802de Michael Niedermayer
                 :: "m"(round_tab[1]) \
358
                 );\
359
\
360 164d75eb Loren Merritt
    sad8_y2a_ ## suf(blk1, blk2, stride, 8);\
361 ba6802de Michael Niedermayer
\
362
    return sum_ ## suf();\
363
}\
364
\
365 bb198e19 Michael Niedermayer
static int sad8_xy2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
366 ba6802de Michael Niedermayer
{\
367 bb198e19 Michael Niedermayer
    assert(h==8);\
368 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
369 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
370 164d75eb Loren Merritt
                 ::);\
371 ba6802de Michael Niedermayer
\
372 bb198e19 Michael Niedermayer
    sad8_4_ ## suf(blk1, blk2, stride, 8);\
373 ba6802de Michael Niedermayer
\
374
    return sum_ ## suf();\
375
}\
376
\
377 bb198e19 Michael Niedermayer
static int sad16_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
378 1457ab52 Michael Niedermayer
{\
379 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
380 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t":);\
381 1457ab52 Michael Niedermayer
\
382 bb198e19 Michael Niedermayer
    sad8_1_ ## suf(blk1  , blk2  , stride, h);\
383
    sad8_1_ ## suf(blk1+8, blk2+8, stride, h);\
384 1457ab52 Michael Niedermayer
\
385
    return sum_ ## suf();\
386
}\
387 bb198e19 Michael Niedermayer
static int sad16_x2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
388 ba6802de Michael Niedermayer
{\
389 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
390 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
391
                 "movq %0, %%mm5        \n\t"\
392 ba6802de Michael Niedermayer
                 :: "m"(round_tab[1]) \
393
                 );\
394
\
395 164d75eb Loren Merritt
    sad8_x2a_ ## suf(blk1  , blk2  , stride, h);\
396
    sad8_x2a_ ## suf(blk1+8, blk2+8, stride, h);\
397 ba6802de Michael Niedermayer
\
398
    return sum_ ## suf();\
399
}\
400 bb198e19 Michael Niedermayer
static int sad16_y2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
401 ba6802de Michael Niedermayer
{\
402 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
403 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
404
                 "movq %0, %%mm5        \n\t"\
405 ba6802de Michael Niedermayer
                 :: "m"(round_tab[1]) \
406
                 );\
407
\
408 164d75eb Loren Merritt
    sad8_y2a_ ## suf(blk1  , blk2  , stride, h);\
409
    sad8_y2a_ ## suf(blk1+8, blk2+8, stride, h);\
410 ba6802de Michael Niedermayer
\
411
    return sum_ ## suf();\
412
}\
413 bb198e19 Michael Niedermayer
static int sad16_xy2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\
414 ba6802de Michael Niedermayer
{\
415 be449fca Diego Pettenò
    __asm__ volatile("pxor %%mm7, %%mm7     \n\t"\
416 bb270c08 Diego Biurrun
                 "pxor %%mm6, %%mm6     \n\t"\
417 164d75eb Loren Merritt
                 ::);\
418 ba6802de Michael Niedermayer
\
419 bb198e19 Michael Niedermayer
    sad8_4_ ## suf(blk1  , blk2  , stride, h);\
420
    sad8_4_ ## suf(blk1+8, blk2+8, stride, h);\
421 ba6802de Michael Niedermayer
\
422
    return sum_ ## suf();\
423
}\
424 694ec061 Fabrice Bellard
425 ba6802de Michael Niedermayer
PIX_SAD(mmx)
426
PIX_SAD(mmx2)
427 5c91a675 Zdenek Kabelac
428 b0368839 Michael Niedermayer
void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx)
429 5c91a675 Zdenek Kabelac
{
430 82d1605f Dominik Mierzejewski
    if (mm_flags & FF_MM_MMX) {
431 bb198e19 Michael Niedermayer
        c->pix_abs[0][0] = sad16_mmx;
432
        c->pix_abs[0][1] = sad16_x2_mmx;
433
        c->pix_abs[0][2] = sad16_y2_mmx;
434
        c->pix_abs[0][3] = sad16_xy2_mmx;
435
        c->pix_abs[1][0] = sad8_mmx;
436
        c->pix_abs[1][1] = sad8_x2_mmx;
437
        c->pix_abs[1][2] = sad8_y2_mmx;
438
        c->pix_abs[1][3] = sad8_xy2_mmx;
439 5c91a675 Zdenek Kabelac
440 bb270c08 Diego Biurrun
        c->sad[0]= sad16_mmx;
441 bb198e19 Michael Niedermayer
        c->sad[1]= sad8_mmx;
442 5c91a675 Zdenek Kabelac
    }
443 6b434361 Stefano Sabatini
    if (mm_flags & FF_MM_MMX2) {
444 bb270c08 Diego Biurrun
        c->pix_abs[0][0] = sad16_mmx2;
445
        c->pix_abs[1][0] = sad8_mmx2;
446 5c91a675 Zdenek Kabelac
447 bb270c08 Diego Biurrun
        c->sad[0]= sad16_mmx2;
448
        c->sad[1]= sad8_mmx2;
449 115329f1 Diego Biurrun
450 b0368839 Michael Niedermayer
        if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
451 bb198e19 Michael Niedermayer
            c->pix_abs[0][1] = sad16_x2_mmx2;
452
            c->pix_abs[0][2] = sad16_y2_mmx2;
453
            c->pix_abs[0][3] = sad16_xy2_mmx2;
454
            c->pix_abs[1][1] = sad8_x2_mmx2;
455
            c->pix_abs[1][2] = sad8_y2_mmx2;
456
            c->pix_abs[1][3] = sad8_xy2_mmx2;
457 b0368839 Michael Niedermayer
        }
458 5c91a675 Zdenek Kabelac
    }
459 cfe67526 Michael Niedermayer
    if ((mm_flags & FF_MM_SSE2) && !(mm_flags & FF_MM_3DNOW) && avctx->codec_id != CODEC_ID_SNOW) {
460 72946825 Loren Merritt
        c->sad[0]= sad16_sse2;
461
    }
462 5c91a675 Zdenek Kabelac
}