Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / motion_est_mmx.c @ be449fca

History | View | Annotate | Download (15.7 KB)

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