Add missing multiple inclusion guards.
[libav.git] / libavcodec / i386 / dsputil_mmx_avg.h
CommitLineData
de6d9b64
FB
1/*
2 * DSP utils : average functions are compiled twice for 3dnow/mmx2
ff4ec49e 3 * Copyright (c) 2000, 2001 Fabrice Bellard.
8f2ab833 4 * Copyright (c) 2002-2004 Michael Niedermayer
de6d9b64 5 *
7b94177e
DB
6 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
7 * mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
8 * and improved by Zdenek Kabelac <kabi@users.sf.net>
9 *
b78e7197
DB
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
ff4ec49e
FB
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
b78e7197 15 * version 2.1 of the License, or (at your option) any later version.
de6d9b64 16 *
b78e7197 17 * FFmpeg is distributed in the hope that it will be useful,
de6d9b64 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
de6d9b64 21 *
ff4ec49e 22 * You should have received a copy of the GNU Lesser General Public
b78e7197 23 * License along with FFmpeg; if not, write to the Free Software
5509bffa 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64 25 */
115329f1 26
31b2c144
DB
27#ifndef FFMPEG_DSPUTIL_MMX_AVG_H
28#define FFMPEG_DSPUTIL_MMX_AVG_H
29
92415510 30/* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm
a213d664
ZK
31 clobber bug - now it will work with 2.95.2 and also with -fPIC
32 */
0c1a9eda 33static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 34{
de6d9b64 35 __asm __volatile(
bb270c08
DB
36 "lea (%3, %3), %%"REG_a" \n\t"
37 "1: \n\t"
38 "movq (%1), %%mm0 \n\t"
39 "movq (%1, %3), %%mm1 \n\t"
40 PAVGB" 1(%1), %%mm0 \n\t"
41 PAVGB" 1(%1, %3), %%mm1 \n\t"
42 "movq %%mm0, (%2) \n\t"
43 "movq %%mm1, (%2, %3) \n\t"
44 "add %%"REG_a", %1 \n\t"
45 "add %%"REG_a", %2 \n\t"
46 "movq (%1), %%mm0 \n\t"
47 "movq (%1, %3), %%mm1 \n\t"
48 PAVGB" 1(%1), %%mm0 \n\t"
49 PAVGB" 1(%1, %3), %%mm1 \n\t"
50 "add %%"REG_a", %1 \n\t"
51 "movq %%mm0, (%2) \n\t"
52 "movq %%mm1, (%2, %3) \n\t"
53 "add %%"REG_a", %2 \n\t"
54 "subl $4, %0 \n\t"
55 "jnz 1b \n\t"
56 :"+g"(h), "+S"(pixels), "+D"(block)
57 :"r" ((long)line_size)
58 :"%"REG_a, "memory");
607dce96 59}
b3184779 60
437525c4
MN
61static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
62{
63 __asm __volatile(
bb270c08
DB
64 "testl $1, %0 \n\t"
65 " jz 1f \n\t"
66 "movd (%1), %%mm0 \n\t"
67 "movd (%2), %%mm1 \n\t"
68 "add %4, %1 \n\t"
69 "add $4, %2 \n\t"
70 PAVGB" %%mm1, %%mm0 \n\t"
71 "movd %%mm0, (%3) \n\t"
72 "add %5, %3 \n\t"
73 "decl %0 \n\t"
74 "1: \n\t"
75 "movd (%1), %%mm0 \n\t"
76 "add %4, %1 \n\t"
77 "movd (%1), %%mm1 \n\t"
78 "movd (%2), %%mm2 \n\t"
79 "movd 4(%2), %%mm3 \n\t"
80 "add %4, %1 \n\t"
81 PAVGB" %%mm2, %%mm0 \n\t"
82 PAVGB" %%mm3, %%mm1 \n\t"
83 "movd %%mm0, (%3) \n\t"
84 "add %5, %3 \n\t"
85 "movd %%mm1, (%3) \n\t"
86 "add %5, %3 \n\t"
87 "movd (%1), %%mm0 \n\t"
88 "add %4, %1 \n\t"
89 "movd (%1), %%mm1 \n\t"
90 "movd 8(%2), %%mm2 \n\t"
91 "movd 12(%2), %%mm3 \n\t"
92 "add %4, %1 \n\t"
93 PAVGB" %%mm2, %%mm0 \n\t"
94 PAVGB" %%mm3, %%mm1 \n\t"
95 "movd %%mm0, (%3) \n\t"
96 "add %5, %3 \n\t"
97 "movd %%mm1, (%3) \n\t"
98 "add %5, %3 \n\t"
99 "add $16, %2 \n\t"
100 "subl $4, %0 \n\t"
101 "jnz 1b \n\t"
755bfeab 102#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 103 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
437525c4 104#else
bb270c08 105 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
437525c4 106#endif
bb270c08
DB
107 :"S"((long)src1Stride), "D"((long)dstStride)
108 :"memory");
437525c4
MN
109}
110
111
d6af6b03 112static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
826f429a
MN
113{
114 __asm __volatile(
bb270c08
DB
115 "testl $1, %0 \n\t"
116 " jz 1f \n\t"
117 "movq (%1), %%mm0 \n\t"
118 "movq (%2), %%mm1 \n\t"
119 "add %4, %1 \n\t"
120 "add $8, %2 \n\t"
121 PAVGB" %%mm1, %%mm0 \n\t"
122 "movq %%mm0, (%3) \n\t"
123 "add %5, %3 \n\t"
124 "decl %0 \n\t"
125 "1: \n\t"
126 "movq (%1), %%mm0 \n\t"
127 "add %4, %1 \n\t"
128 "movq (%1), %%mm1 \n\t"
129 "add %4, %1 \n\t"
130 PAVGB" (%2), %%mm0 \n\t"
131 PAVGB" 8(%2), %%mm1 \n\t"
132 "movq %%mm0, (%3) \n\t"
133 "add %5, %3 \n\t"
134 "movq %%mm1, (%3) \n\t"
135 "add %5, %3 \n\t"
136 "movq (%1), %%mm0 \n\t"
137 "add %4, %1 \n\t"
138 "movq (%1), %%mm1 \n\t"
139 "add %4, %1 \n\t"
140 PAVGB" 16(%2), %%mm0 \n\t"
141 PAVGB" 24(%2), %%mm1 \n\t"
142 "movq %%mm0, (%3) \n\t"
143 "add %5, %3 \n\t"
144 "movq %%mm1, (%3) \n\t"
145 "add %5, %3 \n\t"
146 "add $32, %2 \n\t"
147 "subl $4, %0 \n\t"
148 "jnz 1b \n\t"
755bfeab 149#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 150 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 151#else
bb270c08 152 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 153#endif
bb270c08
DB
154 :"S"((long)src1Stride), "D"((long)dstStride)
155 :"memory");
d6af6b03 156//the following should be used, though better not with gcc ...
bb270c08
DB
157/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
158 :"r"(src1Stride), "r"(dstStride)
159 :"memory");*/
d6af6b03
MN
160}
161
162static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
163{
164 __asm __volatile(
bb270c08
DB
165 "pcmpeqb %%mm6, %%mm6 \n\t"
166 "testl $1, %0 \n\t"
167 " jz 1f \n\t"
168 "movq (%1), %%mm0 \n\t"
169 "movq (%2), %%mm1 \n\t"
170 "add %4, %1 \n\t"
171 "add $8, %2 \n\t"
172 "pxor %%mm6, %%mm0 \n\t"
173 "pxor %%mm6, %%mm1 \n\t"
174 PAVGB" %%mm1, %%mm0 \n\t"
175 "pxor %%mm6, %%mm0 \n\t"
176 "movq %%mm0, (%3) \n\t"
177 "add %5, %3 \n\t"
178 "decl %0 \n\t"
179 "1: \n\t"
180 "movq (%1), %%mm0 \n\t"
181 "add %4, %1 \n\t"
182 "movq (%1), %%mm1 \n\t"
183 "add %4, %1 \n\t"
184 "movq (%2), %%mm2 \n\t"
185 "movq 8(%2), %%mm3 \n\t"
186 "pxor %%mm6, %%mm0 \n\t"
187 "pxor %%mm6, %%mm1 \n\t"
188 "pxor %%mm6, %%mm2 \n\t"
189 "pxor %%mm6, %%mm3 \n\t"
190 PAVGB" %%mm2, %%mm0 \n\t"
191 PAVGB" %%mm3, %%mm1 \n\t"
192 "pxor %%mm6, %%mm0 \n\t"
193 "pxor %%mm6, %%mm1 \n\t"
194 "movq %%mm0, (%3) \n\t"
195 "add %5, %3 \n\t"
196 "movq %%mm1, (%3) \n\t"
197 "add %5, %3 \n\t"
198 "movq (%1), %%mm0 \n\t"
199 "add %4, %1 \n\t"
200 "movq (%1), %%mm1 \n\t"
201 "add %4, %1 \n\t"
202 "movq 16(%2), %%mm2 \n\t"
203 "movq 24(%2), %%mm3 \n\t"
204 "pxor %%mm6, %%mm0 \n\t"
205 "pxor %%mm6, %%mm1 \n\t"
206 "pxor %%mm6, %%mm2 \n\t"
207 "pxor %%mm6, %%mm3 \n\t"
208 PAVGB" %%mm2, %%mm0 \n\t"
209 PAVGB" %%mm3, %%mm1 \n\t"
210 "pxor %%mm6, %%mm0 \n\t"
211 "pxor %%mm6, %%mm1 \n\t"
212 "movq %%mm0, (%3) \n\t"
213 "add %5, %3 \n\t"
214 "movq %%mm1, (%3) \n\t"
215 "add %5, %3 \n\t"
216 "add $32, %2 \n\t"
217 "subl $4, %0 \n\t"
218 "jnz 1b \n\t"
755bfeab 219#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 220 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 221#else
bb270c08 222 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 223#endif
bb270c08
DB
224 :"S"((long)src1Stride), "D"((long)dstStride)
225 :"memory");
d6af6b03 226//the following should be used, though better not with gcc ...
bb270c08
DB
227/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
228 :"r"(src1Stride), "r"(dstStride)
229 :"memory");*/
d6af6b03
MN
230}
231
437525c4
MN
232static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
233{
234 __asm __volatile(
bb270c08
DB
235 "testl $1, %0 \n\t"
236 " jz 1f \n\t"
237 "movd (%1), %%mm0 \n\t"
238 "movd (%2), %%mm1 \n\t"
239 "add %4, %1 \n\t"
240 "add $4, %2 \n\t"
241 PAVGB" %%mm1, %%mm0 \n\t"
242 PAVGB" (%3), %%mm0 \n\t"
243 "movd %%mm0, (%3) \n\t"
244 "add %5, %3 \n\t"
245 "decl %0 \n\t"
246 "1: \n\t"
247 "movd (%1), %%mm0 \n\t"
248 "add %4, %1 \n\t"
249 "movd (%1), %%mm1 \n\t"
250 "add %4, %1 \n\t"
251 PAVGB" (%2), %%mm0 \n\t"
252 PAVGB" 4(%2), %%mm1 \n\t"
253 PAVGB" (%3), %%mm0 \n\t"
254 "movd %%mm0, (%3) \n\t"
255 "add %5, %3 \n\t"
256 PAVGB" (%3), %%mm1 \n\t"
257 "movd %%mm1, (%3) \n\t"
258 "add %5, %3 \n\t"
259 "movd (%1), %%mm0 \n\t"
260 "add %4, %1 \n\t"
261 "movd (%1), %%mm1 \n\t"
262 "add %4, %1 \n\t"
263 PAVGB" 8(%2), %%mm0 \n\t"
264 PAVGB" 12(%2), %%mm1 \n\t"
265 PAVGB" (%3), %%mm0 \n\t"
266 "movd %%mm0, (%3) \n\t"
267 "add %5, %3 \n\t"
268 PAVGB" (%3), %%mm1 \n\t"
269 "movd %%mm1, (%3) \n\t"
270 "add %5, %3 \n\t"
271 "add $16, %2 \n\t"
272 "subl $4, %0 \n\t"
273 "jnz 1b \n\t"
755bfeab 274#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 275 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
437525c4 276#else
bb270c08 277 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
437525c4 278#endif
bb270c08
DB
279 :"S"((long)src1Stride), "D"((long)dstStride)
280 :"memory");
437525c4
MN
281}
282
283
d6af6b03
MN
284static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
285{
286 __asm __volatile(
bb270c08
DB
287 "testl $1, %0 \n\t"
288 " jz 1f \n\t"
289 "movq (%1), %%mm0 \n\t"
290 "movq (%2), %%mm1 \n\t"
291 "add %4, %1 \n\t"
292 "add $8, %2 \n\t"
293 PAVGB" %%mm1, %%mm0 \n\t"
294 PAVGB" (%3), %%mm0 \n\t"
295 "movq %%mm0, (%3) \n\t"
296 "add %5, %3 \n\t"
297 "decl %0 \n\t"
298 "1: \n\t"
299 "movq (%1), %%mm0 \n\t"
300 "add %4, %1 \n\t"
301 "movq (%1), %%mm1 \n\t"
302 "add %4, %1 \n\t"
303 PAVGB" (%2), %%mm0 \n\t"
304 PAVGB" 8(%2), %%mm1 \n\t"
305 PAVGB" (%3), %%mm0 \n\t"
306 "movq %%mm0, (%3) \n\t"
307 "add %5, %3 \n\t"
308 PAVGB" (%3), %%mm1 \n\t"
309 "movq %%mm1, (%3) \n\t"
310 "add %5, %3 \n\t"
311 "movq (%1), %%mm0 \n\t"
312 "add %4, %1 \n\t"
313 "movq (%1), %%mm1 \n\t"
314 "add %4, %1 \n\t"
315 PAVGB" 16(%2), %%mm0 \n\t"
316 PAVGB" 24(%2), %%mm1 \n\t"
317 PAVGB" (%3), %%mm0 \n\t"
318 "movq %%mm0, (%3) \n\t"
319 "add %5, %3 \n\t"
320 PAVGB" (%3), %%mm1 \n\t"
321 "movq %%mm1, (%3) \n\t"
322 "add %5, %3 \n\t"
323 "add $32, %2 \n\t"
324 "subl $4, %0 \n\t"
325 "jnz 1b \n\t"
755bfeab 326#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 327 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 328#else
bb270c08 329 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 330#endif
bb270c08
DB
331 :"S"((long)src1Stride), "D"((long)dstStride)
332 :"memory");
d6af6b03 333//the following should be used, though better not with gcc ...
bb270c08
DB
334/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
335 :"r"(src1Stride), "r"(dstStride)
336 :"memory");*/
826f429a
MN
337}
338
0c1a9eda 339static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
b3184779
MN
340{
341 __asm __volatile(
bb270c08
DB
342 "lea (%3, %3), %%"REG_a" \n\t"
343 "1: \n\t"
344 "movq (%1), %%mm0 \n\t"
345 "movq (%1, %3), %%mm1 \n\t"
346 "movq 8(%1), %%mm2 \n\t"
347 "movq 8(%1, %3), %%mm3 \n\t"
348 PAVGB" 1(%1), %%mm0 \n\t"
349 PAVGB" 1(%1, %3), %%mm1 \n\t"
350 PAVGB" 9(%1), %%mm2 \n\t"
351 PAVGB" 9(%1, %3), %%mm3 \n\t"
352 "movq %%mm0, (%2) \n\t"
353 "movq %%mm1, (%2, %3) \n\t"
354 "movq %%mm2, 8(%2) \n\t"
355 "movq %%mm3, 8(%2, %3) \n\t"
356 "add %%"REG_a", %1 \n\t"
357 "add %%"REG_a", %2 \n\t"
358 "movq (%1), %%mm0 \n\t"
359 "movq (%1, %3), %%mm1 \n\t"
360 "movq 8(%1), %%mm2 \n\t"
361 "movq 8(%1, %3), %%mm3 \n\t"
362 PAVGB" 1(%1), %%mm0 \n\t"
363 PAVGB" 1(%1, %3), %%mm1 \n\t"
364 PAVGB" 9(%1), %%mm2 \n\t"
365 PAVGB" 9(%1, %3), %%mm3 \n\t"
366 "add %%"REG_a", %1 \n\t"
367 "movq %%mm0, (%2) \n\t"
368 "movq %%mm1, (%2, %3) \n\t"
369 "movq %%mm2, 8(%2) \n\t"
370 "movq %%mm3, 8(%2, %3) \n\t"
371 "add %%"REG_a", %2 \n\t"
372 "subl $4, %0 \n\t"
373 "jnz 1b \n\t"
374 :"+g"(h), "+S"(pixels), "+D"(block)
375 :"r" ((long)line_size)
376 :"%"REG_a, "memory");
b3184779 377}
826f429a 378
d6af6b03 379static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
826f429a
MN
380{
381 __asm __volatile(
bb270c08
DB
382 "testl $1, %0 \n\t"
383 " jz 1f \n\t"
384 "movq (%1), %%mm0 \n\t"
385 "movq 8(%1), %%mm1 \n\t"
386 PAVGB" (%2), %%mm0 \n\t"
387 PAVGB" 8(%2), %%mm1 \n\t"
388 "add %4, %1 \n\t"
389 "add $16, %2 \n\t"
390 "movq %%mm0, (%3) \n\t"
391 "movq %%mm1, 8(%3) \n\t"
392 "add %5, %3 \n\t"
393 "decl %0 \n\t"
394 "1: \n\t"
395 "movq (%1), %%mm0 \n\t"
396 "movq 8(%1), %%mm1 \n\t"
397 "add %4, %1 \n\t"
398 PAVGB" (%2), %%mm0 \n\t"
399 PAVGB" 8(%2), %%mm1 \n\t"
400 "movq %%mm0, (%3) \n\t"
401 "movq %%mm1, 8(%3) \n\t"
402 "add %5, %3 \n\t"
403 "movq (%1), %%mm0 \n\t"
404 "movq 8(%1), %%mm1 \n\t"
405 "add %4, %1 \n\t"
406 PAVGB" 16(%2), %%mm0 \n\t"
407 PAVGB" 24(%2), %%mm1 \n\t"
408 "movq %%mm0, (%3) \n\t"
409 "movq %%mm1, 8(%3) \n\t"
410 "add %5, %3 \n\t"
411 "add $32, %2 \n\t"
412 "subl $2, %0 \n\t"
413 "jnz 1b \n\t"
755bfeab 414#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 415 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 416#else
bb270c08 417 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 418#endif
bb270c08
DB
419 :"S"((long)src1Stride), "D"((long)dstStride)
420 :"memory");
d6af6b03 421//the following should be used, though better not with gcc ...
bb270c08
DB
422/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
423 :"r"(src1Stride), "r"(dstStride)
424 :"memory");*/
d6af6b03
MN
425}
426
427static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
428{
429 __asm __volatile(
bb270c08
DB
430 "testl $1, %0 \n\t"
431 " jz 1f \n\t"
432 "movq (%1), %%mm0 \n\t"
433 "movq 8(%1), %%mm1 \n\t"
434 PAVGB" (%2), %%mm0 \n\t"
435 PAVGB" 8(%2), %%mm1 \n\t"
436 "add %4, %1 \n\t"
437 "add $16, %2 \n\t"
438 PAVGB" (%3), %%mm0 \n\t"
439 PAVGB" 8(%3), %%mm1 \n\t"
440 "movq %%mm0, (%3) \n\t"
441 "movq %%mm1, 8(%3) \n\t"
442 "add %5, %3 \n\t"
443 "decl %0 \n\t"
444 "1: \n\t"
445 "movq (%1), %%mm0 \n\t"
446 "movq 8(%1), %%mm1 \n\t"
447 "add %4, %1 \n\t"
448 PAVGB" (%2), %%mm0 \n\t"
449 PAVGB" 8(%2), %%mm1 \n\t"
450 PAVGB" (%3), %%mm0 \n\t"
451 PAVGB" 8(%3), %%mm1 \n\t"
452 "movq %%mm0, (%3) \n\t"
453 "movq %%mm1, 8(%3) \n\t"
454 "add %5, %3 \n\t"
455 "movq (%1), %%mm0 \n\t"
456 "movq 8(%1), %%mm1 \n\t"
457 "add %4, %1 \n\t"
458 PAVGB" 16(%2), %%mm0 \n\t"
459 PAVGB" 24(%2), %%mm1 \n\t"
460 PAVGB" (%3), %%mm0 \n\t"
461 PAVGB" 8(%3), %%mm1 \n\t"
462 "movq %%mm0, (%3) \n\t"
463 "movq %%mm1, 8(%3) \n\t"
464 "add %5, %3 \n\t"
465 "add $32, %2 \n\t"
466 "subl $2, %0 \n\t"
467 "jnz 1b \n\t"
755bfeab 468#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 469 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 470#else
bb270c08 471 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 472#endif
bb270c08
DB
473 :"S"((long)src1Stride), "D"((long)dstStride)
474 :"memory");
d6af6b03 475//the following should be used, though better not with gcc ...
bb270c08
DB
476/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
477 :"r"(src1Stride), "r"(dstStride)
478 :"memory");*/
d6af6b03
MN
479}
480
481static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
482{
483 __asm __volatile(
bb270c08
DB
484 "pcmpeqb %%mm6, %%mm6 \n\t"
485 "testl $1, %0 \n\t"
486 " jz 1f \n\t"
487 "movq (%1), %%mm0 \n\t"
488 "movq 8(%1), %%mm1 \n\t"
489 "movq (%2), %%mm2 \n\t"
490 "movq 8(%2), %%mm3 \n\t"
491 "pxor %%mm6, %%mm0 \n\t"
492 "pxor %%mm6, %%mm1 \n\t"
493 "pxor %%mm6, %%mm2 \n\t"
494 "pxor %%mm6, %%mm3 \n\t"
495 PAVGB" %%mm2, %%mm0 \n\t"
496 PAVGB" %%mm3, %%mm1 \n\t"
497 "pxor %%mm6, %%mm0 \n\t"
498 "pxor %%mm6, %%mm1 \n\t"
499 "add %4, %1 \n\t"
500 "add $16, %2 \n\t"
501 "movq %%mm0, (%3) \n\t"
502 "movq %%mm1, 8(%3) \n\t"
503 "add %5, %3 \n\t"
504 "decl %0 \n\t"
505 "1: \n\t"
506 "movq (%1), %%mm0 \n\t"
507 "movq 8(%1), %%mm1 \n\t"
508 "add %4, %1 \n\t"
509 "movq (%2), %%mm2 \n\t"
510 "movq 8(%2), %%mm3 \n\t"
511 "pxor %%mm6, %%mm0 \n\t"
512 "pxor %%mm6, %%mm1 \n\t"
513 "pxor %%mm6, %%mm2 \n\t"
514 "pxor %%mm6, %%mm3 \n\t"
515 PAVGB" %%mm2, %%mm0 \n\t"
516 PAVGB" %%mm3, %%mm1 \n\t"
517 "pxor %%mm6, %%mm0 \n\t"
518 "pxor %%mm6, %%mm1 \n\t"
519 "movq %%mm0, (%3) \n\t"
520 "movq %%mm1, 8(%3) \n\t"
521 "add %5, %3 \n\t"
522 "movq (%1), %%mm0 \n\t"
523 "movq 8(%1), %%mm1 \n\t"
524 "add %4, %1 \n\t"
525 "movq 16(%2), %%mm2 \n\t"
526 "movq 24(%2), %%mm3 \n\t"
527 "pxor %%mm6, %%mm0 \n\t"
528 "pxor %%mm6, %%mm1 \n\t"
529 "pxor %%mm6, %%mm2 \n\t"
530 "pxor %%mm6, %%mm3 \n\t"
531 PAVGB" %%mm2, %%mm0 \n\t"
532 PAVGB" %%mm3, %%mm1 \n\t"
533 "pxor %%mm6, %%mm0 \n\t"
534 "pxor %%mm6, %%mm1 \n\t"
535 "movq %%mm0, (%3) \n\t"
536 "movq %%mm1, 8(%3) \n\t"
537 "add %5, %3 \n\t"
538 "add $32, %2 \n\t"
539 "subl $2, %0 \n\t"
540 "jnz 1b \n\t"
755bfeab 541#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
bb270c08 542 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 543#else
bb270c08 544 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
d6af6b03 545#endif
bb270c08
DB
546 :"S"((long)src1Stride), "D"((long)dstStride)
547 :"memory");
d6af6b03 548//the following should be used, though better not with gcc ...
bb270c08
DB
549/* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
550 :"r"(src1Stride), "r"(dstStride)
551 :"memory");*/
826f429a 552}
115329f1 553
92415510 554/* GL: this function does incorrect rounding if overflow */
0c1a9eda 555static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
607dce96 556{
fca0f0e5 557 MOVQ_BONE(mm6);
de6d9b64 558 __asm __volatile(
bb270c08
DB
559 "lea (%3, %3), %%"REG_a" \n\t"
560 "1: \n\t"
561 "movq (%1), %%mm0 \n\t"
562 "movq (%1, %3), %%mm2 \n\t"
563 "movq 1(%1), %%mm1 \n\t"
564 "movq 1(%1, %3), %%mm3 \n\t"
565 "add %%"REG_a", %1 \n\t"
566 "psubusb %%mm6, %%mm0 \n\t"
567 "psubusb %%mm6, %%mm2 \n\t"
568 PAVGB" %%mm1, %%mm0 \n\t"
569 PAVGB" %%mm3, %%mm2 \n\t"
570 "movq %%mm0, (%2) \n\t"
571 "movq %%mm2, (%2, %3) \n\t"
572 "movq (%1), %%mm0 \n\t"
573 "movq 1(%1), %%mm1 \n\t"
574 "movq (%1, %3), %%mm2 \n\t"
575 "movq 1(%1, %3), %%mm3 \n\t"
576 "add %%"REG_a", %2 \n\t"
577 "add %%"REG_a", %1 \n\t"
578 "psubusb %%mm6, %%mm0 \n\t"
579 "psubusb %%mm6, %%mm2 \n\t"
580 PAVGB" %%mm1, %%mm0 \n\t"
581 PAVGB" %%mm3, %%mm2 \n\t"
582 "movq %%mm0, (%2) \n\t"
583 "movq %%mm2, (%2, %3) \n\t"
584 "add %%"REG_a", %2 \n\t"
585 "subl $4, %0 \n\t"
586 "jnz 1b \n\t"
587 :"+g"(h), "+S"(pixels), "+D"(block)
588 :"r" ((long)line_size)
589 :"%"REG_a, "memory");
de6d9b64
FB
590}
591
0c1a9eda 592static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 593{
a213d664 594 __asm __volatile(
bb270c08
DB
595 "lea (%3, %3), %%"REG_a" \n\t"
596 "movq (%1), %%mm0 \n\t"
597 "sub %3, %2 \n\t"
598 "1: \n\t"
599 "movq (%1, %3), %%mm1 \n\t"
600 "movq (%1, %%"REG_a"), %%mm2 \n\t"
601 "add %%"REG_a", %1 \n\t"
602 PAVGB" %%mm1, %%mm0 \n\t"
603 PAVGB" %%mm2, %%mm1 \n\t"
604 "movq %%mm0, (%2, %3) \n\t"
605 "movq %%mm1, (%2, %%"REG_a") \n\t"
606 "movq (%1, %3), %%mm1 \n\t"
607 "movq (%1, %%"REG_a"), %%mm0 \n\t"
608 "add %%"REG_a", %2 \n\t"
609 "add %%"REG_a", %1 \n\t"
610 PAVGB" %%mm1, %%mm2 \n\t"
611 PAVGB" %%mm0, %%mm1 \n\t"
612 "movq %%mm2, (%2, %3) \n\t"
613 "movq %%mm1, (%2, %%"REG_a") \n\t"
614 "add %%"REG_a", %2 \n\t"
615 "subl $4, %0 \n\t"
616 "jnz 1b \n\t"
617 :"+g"(h), "+S"(pixels), "+D" (block)
618 :"r" ((long)line_size)
619 :"%"REG_a, "memory");
607dce96
MN
620}
621
92415510 622/* GL: this function does incorrect rounding if overflow */
0c1a9eda 623static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
607dce96 624{
fca0f0e5 625 MOVQ_BONE(mm6);
de6d9b64 626 __asm __volatile(
bb270c08
DB
627 "lea (%3, %3), %%"REG_a" \n\t"
628 "movq (%1), %%mm0 \n\t"
629 "sub %3, %2 \n\t"
630 "1: \n\t"
631 "movq (%1, %3), %%mm1 \n\t"
632 "movq (%1, %%"REG_a"), %%mm2 \n\t"
633 "add %%"REG_a", %1 \n\t"
634 "psubusb %%mm6, %%mm1 \n\t"
635 PAVGB" %%mm1, %%mm0 \n\t"
636 PAVGB" %%mm2, %%mm1 \n\t"
637 "movq %%mm0, (%2, %3) \n\t"
638 "movq %%mm1, (%2, %%"REG_a") \n\t"
639 "movq (%1, %3), %%mm1 \n\t"
640 "movq (%1, %%"REG_a"), %%mm0 \n\t"
641 "add %%"REG_a", %2 \n\t"
642 "add %%"REG_a", %1 \n\t"
643 "psubusb %%mm6, %%mm1 \n\t"
644 PAVGB" %%mm1, %%mm2 \n\t"
645 PAVGB" %%mm0, %%mm1 \n\t"
646 "movq %%mm2, (%2, %3) \n\t"
647 "movq %%mm1, (%2, %%"REG_a") \n\t"
648 "add %%"REG_a", %2 \n\t"
649 "subl $4, %0 \n\t"
650 "jnz 1b \n\t"
651 :"+g"(h), "+S"(pixels), "+D" (block)
652 :"r" ((long)line_size)
653 :"%"REG_a, "memory");
de6d9b64
FB
654}
655
0c1a9eda 656static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 657{
de6d9b64 658 __asm __volatile(
bb270c08
DB
659 "lea (%3, %3), %%"REG_a" \n\t"
660 "1: \n\t"
661 "movq (%2), %%mm0 \n\t"
662 "movq (%2, %3), %%mm1 \n\t"
663 PAVGB" (%1), %%mm0 \n\t"
664 PAVGB" (%1, %3), %%mm1 \n\t"
665 "movq %%mm0, (%2) \n\t"
666 "movq %%mm1, (%2, %3) \n\t"
667 "add %%"REG_a", %1 \n\t"
668 "add %%"REG_a", %2 \n\t"
669 "movq (%2), %%mm0 \n\t"
670 "movq (%2, %3), %%mm1 \n\t"
671 PAVGB" (%1), %%mm0 \n\t"
672 PAVGB" (%1, %3), %%mm1 \n\t"
673 "add %%"REG_a", %1 \n\t"
674 "movq %%mm0, (%2) \n\t"
675 "movq %%mm1, (%2, %3) \n\t"
676 "add %%"REG_a", %2 \n\t"
677 "subl $4, %0 \n\t"
678 "jnz 1b \n\t"
679 :"+g"(h), "+S"(pixels), "+D"(block)
680 :"r" ((long)line_size)
681 :"%"REG_a, "memory");
de6d9b64
FB
682}
683
0c1a9eda 684static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 685{
de6d9b64 686 __asm __volatile(
bb270c08
DB
687 "lea (%3, %3), %%"REG_a" \n\t"
688 "1: \n\t"
689 "movq (%1), %%mm0 \n\t"
690 "movq (%1, %3), %%mm2 \n\t"
691 PAVGB" 1(%1), %%mm0 \n\t"
692 PAVGB" 1(%1, %3), %%mm2 \n\t"
693 PAVGB" (%2), %%mm0 \n\t"
694 PAVGB" (%2, %3), %%mm2 \n\t"
695 "add %%"REG_a", %1 \n\t"
696 "movq %%mm0, (%2) \n\t"
697 "movq %%mm2, (%2, %3) \n\t"
698 "movq (%1), %%mm0 \n\t"
699 "movq (%1, %3), %%mm2 \n\t"
700 PAVGB" 1(%1), %%mm0 \n\t"
701 PAVGB" 1(%1, %3), %%mm2 \n\t"
702 "add %%"REG_a", %2 \n\t"
703 "add %%"REG_a", %1 \n\t"
704 PAVGB" (%2), %%mm0 \n\t"
705 PAVGB" (%2, %3), %%mm2 \n\t"
706 "movq %%mm0, (%2) \n\t"
707 "movq %%mm2, (%2, %3) \n\t"
708 "add %%"REG_a", %2 \n\t"
709 "subl $4, %0 \n\t"
710 "jnz 1b \n\t"
711 :"+g"(h), "+S"(pixels), "+D"(block)
712 :"r" ((long)line_size)
713 :"%"REG_a, "memory");
de6d9b64
FB
714}
715
0c1a9eda 716static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 717{
de6d9b64 718 __asm __volatile(
bb270c08
DB
719 "lea (%3, %3), %%"REG_a" \n\t"
720 "movq (%1), %%mm0 \n\t"
721 "sub %3, %2 \n\t"
722 "1: \n\t"
723 "movq (%1, %3), %%mm1 \n\t"
724 "movq (%1, %%"REG_a"), %%mm2 \n\t"
725 "add %%"REG_a", %1 \n\t"
726 PAVGB" %%mm1, %%mm0 \n\t"
727 PAVGB" %%mm2, %%mm1 \n\t"
728 "movq (%2, %3), %%mm3 \n\t"
729 "movq (%2, %%"REG_a"), %%mm4 \n\t"
730 PAVGB" %%mm3, %%mm0 \n\t"
731 PAVGB" %%mm4, %%mm1 \n\t"
732 "movq %%mm0, (%2, %3) \n\t"
733 "movq %%mm1, (%2, %%"REG_a") \n\t"
734 "movq (%1, %3), %%mm1 \n\t"
735 "movq (%1, %%"REG_a"), %%mm0 \n\t"
736 PAVGB" %%mm1, %%mm2 \n\t"
737 PAVGB" %%mm0, %%mm1 \n\t"
738 "add %%"REG_a", %2 \n\t"
739 "add %%"REG_a", %1 \n\t"
740 "movq (%2, %3), %%mm3 \n\t"
741 "movq (%2, %%"REG_a"), %%mm4 \n\t"
742 PAVGB" %%mm3, %%mm2 \n\t"
743 PAVGB" %%mm4, %%mm1 \n\t"
744 "movq %%mm2, (%2, %3) \n\t"
745 "movq %%mm1, (%2, %%"REG_a") \n\t"
746 "add %%"REG_a", %2 \n\t"
747 "subl $4, %0 \n\t"
748 "jnz 1b \n\t"
749 :"+g"(h), "+S"(pixels), "+D"(block)
750 :"r" ((long)line_size)
751 :"%"REG_a, "memory");
de6d9b64
FB
752}
753
755bfeab
DB
754/* Note this is not correctly rounded, but this function is only
755 * used for B-frames so it does not matter. */
0c1a9eda 756static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
de6d9b64 757{
fca0f0e5 758 MOVQ_BONE(mm6);
de6d9b64 759 __asm __volatile(
bb270c08
DB
760 "lea (%3, %3), %%"REG_a" \n\t"
761 "movq (%1), %%mm0 \n\t"
762 PAVGB" 1(%1), %%mm0 \n\t"
4454dc1b 763 ASMALIGN(3)
bb270c08
DB
764 "1: \n\t"
765 "movq (%1, %%"REG_a"), %%mm2 \n\t"
766 "movq (%1, %3), %%mm1 \n\t"
767 "psubusb %%mm6, %%mm2 \n\t"
768 PAVGB" 1(%1, %3), %%mm1 \n\t"
769 PAVGB" 1(%1, %%"REG_a"), %%mm2 \n\t"
770 "add %%"REG_a", %1 \n\t"
771 PAVGB" %%mm1, %%mm0 \n\t"
772 PAVGB" %%mm2, %%mm1 \n\t"
773 PAVGB" (%2), %%mm0 \n\t"
774 PAVGB" (%2, %3), %%mm1 \n\t"
775 "movq %%mm0, (%2) \n\t"
776 "movq %%mm1, (%2, %3) \n\t"
777 "movq (%1, %3), %%mm1 \n\t"
778 "movq (%1, %%"REG_a"), %%mm0 \n\t"
779 PAVGB" 1(%1, %3), %%mm1 \n\t"
780 PAVGB" 1(%1, %%"REG_a"), %%mm0 \n\t"
781 "add %%"REG_a", %2 \n\t"
782 "add %%"REG_a", %1 \n\t"
783 PAVGB" %%mm1, %%mm2 \n\t"
784 PAVGB" %%mm0, %%mm1 \n\t"
785 PAVGB" (%2), %%mm2 \n\t"
786 PAVGB" (%2, %3), %%mm1 \n\t"
787 "movq %%mm2, (%2) \n\t"
788 "movq %%mm1, (%2, %3) \n\t"
789 "add %%"REG_a", %2 \n\t"
790 "subl $4, %0 \n\t"
791 "jnz 1b \n\t"
792 :"+g"(h), "+S"(pixels), "+D"(block)
793 :"r" ((long)line_size)
794 :"%"REG_a, "memory");
de6d9b64 795}
b3184779
MN
796
797//FIXME the following could be optimized too ...
0c1a9eda 798static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
799 DEF(put_no_rnd_pixels8_x2)(block , pixels , line_size, h);
800 DEF(put_no_rnd_pixels8_x2)(block+8, pixels+8, line_size, h);
801}
0c1a9eda 802static void DEF(put_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
803 DEF(put_pixels8_y2)(block , pixels , line_size, h);
804 DEF(put_pixels8_y2)(block+8, pixels+8, line_size, h);
805}
0c1a9eda 806static void DEF(put_no_rnd_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
807 DEF(put_no_rnd_pixels8_y2)(block , pixels , line_size, h);
808 DEF(put_no_rnd_pixels8_y2)(block+8, pixels+8, line_size, h);
809}
0c1a9eda 810static void DEF(avg_pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
811 DEF(avg_pixels8)(block , pixels , line_size, h);
812 DEF(avg_pixels8)(block+8, pixels+8, line_size, h);
813}
0c1a9eda 814static void DEF(avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
815 DEF(avg_pixels8_x2)(block , pixels , line_size, h);
816 DEF(avg_pixels8_x2)(block+8, pixels+8, line_size, h);
817}
0c1a9eda 818static void DEF(avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
819 DEF(avg_pixels8_y2)(block , pixels , line_size, h);
820 DEF(avg_pixels8_y2)(block+8, pixels+8, line_size, h);
821}
0c1a9eda 822static void DEF(avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
b3184779
MN
823 DEF(avg_pixels8_xy2)(block , pixels , line_size, h);
824 DEF(avg_pixels8_xy2)(block+8, pixels+8, line_size, h);
825}
826
2833fc46
LM
827#define QPEL_2TAP_L3(OPNAME) \
828static void DEF(OPNAME ## 2tap_qpel16_l3)(uint8_t *dst, uint8_t *src, int stride, int h, int off1, int off2){\
829 asm volatile(\
830 "1: \n\t"\
831 "movq (%1,%2), %%mm0 \n\t"\
832 "movq 8(%1,%2), %%mm1 \n\t"\
833 PAVGB" (%1,%3), %%mm0 \n\t"\
834 PAVGB" 8(%1,%3), %%mm1 \n\t"\
835 PAVGB" (%1), %%mm0 \n\t"\
836 PAVGB" 8(%1), %%mm1 \n\t"\
837 STORE_OP( (%1,%4),%%mm0)\
838 STORE_OP(8(%1,%4),%%mm1)\
839 "movq %%mm0, (%1,%4) \n\t"\
840 "movq %%mm1, 8(%1,%4) \n\t"\
841 "add %5, %1 \n\t"\
842 "decl %0 \n\t"\
843 "jnz 1b \n\t"\
844 :"+g"(h), "+r"(src)\
845 :"r"((long)off1), "r"((long)off2),\
846 "r"((long)(dst-src)), "r"((long)stride)\
847 :"memory"\
848 );\
849}\
850static void DEF(OPNAME ## 2tap_qpel8_l3)(uint8_t *dst, uint8_t *src, int stride, int h, int off1, int off2){\
851 asm volatile(\
852 "1: \n\t"\
853 "movq (%1,%2), %%mm0 \n\t"\
854 PAVGB" (%1,%3), %%mm0 \n\t"\
855 PAVGB" (%1), %%mm0 \n\t"\
856 STORE_OP((%1,%4),%%mm0)\
857 "movq %%mm0, (%1,%4) \n\t"\
858 "add %5, %1 \n\t"\
859 "decl %0 \n\t"\
860 "jnz 1b \n\t"\
861 :"+g"(h), "+r"(src)\
862 :"r"((long)off1), "r"((long)off2),\
863 "r"((long)(dst-src)), "r"((long)stride)\
864 :"memory"\
865 );\
866}
867
868#define STORE_OP(a,b) PAVGB" "#a","#b" \n\t"
869QPEL_2TAP_L3(avg_)
870#undef STORE_OP
871#define STORE_OP(a,b)
872QPEL_2TAP_L3(put_)
873#undef STORE_OP
874#undef QPEL_2TAP_L3
31b2c144
DB
875
876#endif /* FFMPEG_DSPUTIL_MMX_AVG_H */