2 * DSP utils : average functions are compiled twice for 3dnow/mmxext
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer
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>
10 * This file is part of FFmpeg.
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 /* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm
28 clobber bug - now it will work with 2.95.2 and also with -fPIC
30 static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
33 "lea (%3, %3), %%"REG_a" \n\t"
35 "movq (%1), %%mm0 \n\t"
36 "movq (%1, %3), %%mm1 \n\t"
37 PAVGB" 1(%1), %%mm0 \n\t"
38 PAVGB" 1(%1, %3), %%mm1 \n\t"
39 "movq %%mm0, (%2) \n\t"
40 "movq %%mm1, (%2, %3) \n\t"
41 "add %%"REG_a", %1 \n\t"
42 "add %%"REG_a", %2 \n\t"
43 "movq (%1), %%mm0 \n\t"
44 "movq (%1, %3), %%mm1 \n\t"
45 PAVGB" 1(%1), %%mm0 \n\t"
46 PAVGB" 1(%1, %3), %%mm1 \n\t"
47 "add %%"REG_a", %1 \n\t"
48 "movq %%mm0, (%2) \n\t"
49 "movq %%mm1, (%2, %3) \n\t"
50 "add %%"REG_a", %2 \n\t"
53 :"+g"(h), "+S"(pixels), "+D"(block)
54 :"r" ((x86_reg)line_size)
58 #ifndef SKIP_FOR_3DNOW
59 static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
64 "movq (%1), %%mm0 \n\t"
65 "movq (%2), %%mm1 \n\t"
68 PAVGB" %%mm1, %%mm0 \n\t"
69 "movq %%mm0, (%3) \n\t"
73 "movq (%1), %%mm0 \n\t"
75 "movq (%1), %%mm1 \n\t"
77 PAVGB" (%2), %%mm0 \n\t"
78 PAVGB" 8(%2), %%mm1 \n\t"
79 "movq %%mm0, (%3) \n\t"
81 "movq %%mm1, (%3) \n\t"
83 "movq (%1), %%mm0 \n\t"
85 "movq (%1), %%mm1 \n\t"
87 PAVGB" 16(%2), %%mm0 \n\t"
88 PAVGB" 24(%2), %%mm1 \n\t"
89 "movq %%mm0, (%3) \n\t"
91 "movq %%mm1, (%3) \n\t"
96 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
97 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
99 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
101 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
103 //the following should be used, though better not with gcc ...
104 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
105 :"r"(src1Stride), "r"(dstStride)
109 static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
112 "pcmpeqb %%mm6, %%mm6 \n\t"
115 "movq (%1), %%mm0 \n\t"
116 "movq (%2), %%mm1 \n\t"
119 "pxor %%mm6, %%mm0 \n\t"
120 "pxor %%mm6, %%mm1 \n\t"
121 PAVGB" %%mm1, %%mm0 \n\t"
122 "pxor %%mm6, %%mm0 \n\t"
123 "movq %%mm0, (%3) \n\t"
127 "movq (%1), %%mm0 \n\t"
129 "movq (%1), %%mm1 \n\t"
131 "movq (%2), %%mm2 \n\t"
132 "movq 8(%2), %%mm3 \n\t"
133 "pxor %%mm6, %%mm0 \n\t"
134 "pxor %%mm6, %%mm1 \n\t"
135 "pxor %%mm6, %%mm2 \n\t"
136 "pxor %%mm6, %%mm3 \n\t"
137 PAVGB" %%mm2, %%mm0 \n\t"
138 PAVGB" %%mm3, %%mm1 \n\t"
139 "pxor %%mm6, %%mm0 \n\t"
140 "pxor %%mm6, %%mm1 \n\t"
141 "movq %%mm0, (%3) \n\t"
143 "movq %%mm1, (%3) \n\t"
145 "movq (%1), %%mm0 \n\t"
147 "movq (%1), %%mm1 \n\t"
149 "movq 16(%2), %%mm2 \n\t"
150 "movq 24(%2), %%mm3 \n\t"
151 "pxor %%mm6, %%mm0 \n\t"
152 "pxor %%mm6, %%mm1 \n\t"
153 "pxor %%mm6, %%mm2 \n\t"
154 "pxor %%mm6, %%mm3 \n\t"
155 PAVGB" %%mm2, %%mm0 \n\t"
156 PAVGB" %%mm3, %%mm1 \n\t"
157 "pxor %%mm6, %%mm0 \n\t"
158 "pxor %%mm6, %%mm1 \n\t"
159 "movq %%mm0, (%3) \n\t"
161 "movq %%mm1, (%3) \n\t"
166 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
167 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
169 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
171 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
173 //the following should be used, though better not with gcc ...
174 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
175 :"r"(src1Stride), "r"(dstStride)
179 static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
184 "movq (%1), %%mm0 \n\t"
185 "movq (%2), %%mm1 \n\t"
188 PAVGB" %%mm1, %%mm0 \n\t"
189 PAVGB" (%3), %%mm0 \n\t"
190 "movq %%mm0, (%3) \n\t"
194 "movq (%1), %%mm0 \n\t"
196 "movq (%1), %%mm1 \n\t"
198 PAVGB" (%2), %%mm0 \n\t"
199 PAVGB" 8(%2), %%mm1 \n\t"
200 PAVGB" (%3), %%mm0 \n\t"
201 "movq %%mm0, (%3) \n\t"
203 PAVGB" (%3), %%mm1 \n\t"
204 "movq %%mm1, (%3) \n\t"
206 "movq (%1), %%mm0 \n\t"
208 "movq (%1), %%mm1 \n\t"
210 PAVGB" 16(%2), %%mm0 \n\t"
211 PAVGB" 24(%2), %%mm1 \n\t"
212 PAVGB" (%3), %%mm0 \n\t"
213 "movq %%mm0, (%3) \n\t"
215 PAVGB" (%3), %%mm1 \n\t"
216 "movq %%mm1, (%3) \n\t"
221 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
222 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
224 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
226 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
228 //the following should be used, though better not with gcc ...
229 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
230 :"r"(src1Stride), "r"(dstStride)
233 #endif /* SKIP_FOR_3DNOW */
235 static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
238 "lea (%3, %3), %%"REG_a" \n\t"
240 "movq (%1), %%mm0 \n\t"
241 "movq (%1, %3), %%mm1 \n\t"
242 "movq 8(%1), %%mm2 \n\t"
243 "movq 8(%1, %3), %%mm3 \n\t"
244 PAVGB" 1(%1), %%mm0 \n\t"
245 PAVGB" 1(%1, %3), %%mm1 \n\t"
246 PAVGB" 9(%1), %%mm2 \n\t"
247 PAVGB" 9(%1, %3), %%mm3 \n\t"
248 "movq %%mm0, (%2) \n\t"
249 "movq %%mm1, (%2, %3) \n\t"
250 "movq %%mm2, 8(%2) \n\t"
251 "movq %%mm3, 8(%2, %3) \n\t"
252 "add %%"REG_a", %1 \n\t"
253 "add %%"REG_a", %2 \n\t"
254 "movq (%1), %%mm0 \n\t"
255 "movq (%1, %3), %%mm1 \n\t"
256 "movq 8(%1), %%mm2 \n\t"
257 "movq 8(%1, %3), %%mm3 \n\t"
258 PAVGB" 1(%1), %%mm0 \n\t"
259 PAVGB" 1(%1, %3), %%mm1 \n\t"
260 PAVGB" 9(%1), %%mm2 \n\t"
261 PAVGB" 9(%1, %3), %%mm3 \n\t"
262 "add %%"REG_a", %1 \n\t"
263 "movq %%mm0, (%2) \n\t"
264 "movq %%mm1, (%2, %3) \n\t"
265 "movq %%mm2, 8(%2) \n\t"
266 "movq %%mm3, 8(%2, %3) \n\t"
267 "add %%"REG_a", %2 \n\t"
270 :"+g"(h), "+S"(pixels), "+D"(block)
271 :"r" ((x86_reg)line_size)
272 :"%"REG_a, "memory");
275 #ifndef SKIP_FOR_3DNOW
276 static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
281 "movq (%1), %%mm0 \n\t"
282 "movq 8(%1), %%mm1 \n\t"
283 PAVGB" (%2), %%mm0 \n\t"
284 PAVGB" 8(%2), %%mm1 \n\t"
287 "movq %%mm0, (%3) \n\t"
288 "movq %%mm1, 8(%3) \n\t"
292 "movq (%1), %%mm0 \n\t"
293 "movq 8(%1), %%mm1 \n\t"
295 PAVGB" (%2), %%mm0 \n\t"
296 PAVGB" 8(%2), %%mm1 \n\t"
297 "movq %%mm0, (%3) \n\t"
298 "movq %%mm1, 8(%3) \n\t"
300 "movq (%1), %%mm0 \n\t"
301 "movq 8(%1), %%mm1 \n\t"
303 PAVGB" 16(%2), %%mm0 \n\t"
304 PAVGB" 24(%2), %%mm1 \n\t"
305 "movq %%mm0, (%3) \n\t"
306 "movq %%mm1, 8(%3) \n\t"
311 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
312 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
314 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
316 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
318 //the following should be used, though better not with gcc ...
319 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
320 :"r"(src1Stride), "r"(dstStride)
324 static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
329 "movq (%1), %%mm0 \n\t"
330 "movq 8(%1), %%mm1 \n\t"
331 PAVGB" (%2), %%mm0 \n\t"
332 PAVGB" 8(%2), %%mm1 \n\t"
335 PAVGB" (%3), %%mm0 \n\t"
336 PAVGB" 8(%3), %%mm1 \n\t"
337 "movq %%mm0, (%3) \n\t"
338 "movq %%mm1, 8(%3) \n\t"
342 "movq (%1), %%mm0 \n\t"
343 "movq 8(%1), %%mm1 \n\t"
345 PAVGB" (%2), %%mm0 \n\t"
346 PAVGB" 8(%2), %%mm1 \n\t"
347 PAVGB" (%3), %%mm0 \n\t"
348 PAVGB" 8(%3), %%mm1 \n\t"
349 "movq %%mm0, (%3) \n\t"
350 "movq %%mm1, 8(%3) \n\t"
352 "movq (%1), %%mm0 \n\t"
353 "movq 8(%1), %%mm1 \n\t"
355 PAVGB" 16(%2), %%mm0 \n\t"
356 PAVGB" 24(%2), %%mm1 \n\t"
357 PAVGB" (%3), %%mm0 \n\t"
358 PAVGB" 8(%3), %%mm1 \n\t"
359 "movq %%mm0, (%3) \n\t"
360 "movq %%mm1, 8(%3) \n\t"
365 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
366 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
368 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
370 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
372 //the following should be used, though better not with gcc ...
373 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
374 :"r"(src1Stride), "r"(dstStride)
378 static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
381 "pcmpeqb %%mm6, %%mm6 \n\t"
384 "movq (%1), %%mm0 \n\t"
385 "movq 8(%1), %%mm1 \n\t"
386 "movq (%2), %%mm2 \n\t"
387 "movq 8(%2), %%mm3 \n\t"
388 "pxor %%mm6, %%mm0 \n\t"
389 "pxor %%mm6, %%mm1 \n\t"
390 "pxor %%mm6, %%mm2 \n\t"
391 "pxor %%mm6, %%mm3 \n\t"
392 PAVGB" %%mm2, %%mm0 \n\t"
393 PAVGB" %%mm3, %%mm1 \n\t"
394 "pxor %%mm6, %%mm0 \n\t"
395 "pxor %%mm6, %%mm1 \n\t"
398 "movq %%mm0, (%3) \n\t"
399 "movq %%mm1, 8(%3) \n\t"
403 "movq (%1), %%mm0 \n\t"
404 "movq 8(%1), %%mm1 \n\t"
406 "movq (%2), %%mm2 \n\t"
407 "movq 8(%2), %%mm3 \n\t"
408 "pxor %%mm6, %%mm0 \n\t"
409 "pxor %%mm6, %%mm1 \n\t"
410 "pxor %%mm6, %%mm2 \n\t"
411 "pxor %%mm6, %%mm3 \n\t"
412 PAVGB" %%mm2, %%mm0 \n\t"
413 PAVGB" %%mm3, %%mm1 \n\t"
414 "pxor %%mm6, %%mm0 \n\t"
415 "pxor %%mm6, %%mm1 \n\t"
416 "movq %%mm0, (%3) \n\t"
417 "movq %%mm1, 8(%3) \n\t"
419 "movq (%1), %%mm0 \n\t"
420 "movq 8(%1), %%mm1 \n\t"
422 "movq 16(%2), %%mm2 \n\t"
423 "movq 24(%2), %%mm3 \n\t"
424 "pxor %%mm6, %%mm0 \n\t"
425 "pxor %%mm6, %%mm1 \n\t"
426 "pxor %%mm6, %%mm2 \n\t"
427 "pxor %%mm6, %%mm3 \n\t"
428 PAVGB" %%mm2, %%mm0 \n\t"
429 PAVGB" %%mm3, %%mm1 \n\t"
430 "pxor %%mm6, %%mm0 \n\t"
431 "pxor %%mm6, %%mm1 \n\t"
432 "movq %%mm0, (%3) \n\t"
433 "movq %%mm1, 8(%3) \n\t"
438 #if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
439 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
441 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
443 :"S"((x86_reg)src1Stride), "D"((x86_reg)dstStride)
445 //the following should be used, though better not with gcc ...
446 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
447 :"r"(src1Stride), "r"(dstStride)
450 #endif /* SKIP_FOR_3DNOW */
452 /* GL: this function does incorrect rounding if overflow */
453 static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
457 "lea (%3, %3), %%"REG_a" \n\t"
459 "movq (%1), %%mm0 \n\t"
460 "movq (%1, %3), %%mm2 \n\t"
461 "movq 1(%1), %%mm1 \n\t"
462 "movq 1(%1, %3), %%mm3 \n\t"
463 "add %%"REG_a", %1 \n\t"
464 "psubusb %%mm6, %%mm0 \n\t"
465 "psubusb %%mm6, %%mm2 \n\t"
466 PAVGB" %%mm1, %%mm0 \n\t"
467 PAVGB" %%mm3, %%mm2 \n\t"
468 "movq %%mm0, (%2) \n\t"
469 "movq %%mm2, (%2, %3) \n\t"
470 "movq (%1), %%mm0 \n\t"
471 "movq 1(%1), %%mm1 \n\t"
472 "movq (%1, %3), %%mm2 \n\t"
473 "movq 1(%1, %3), %%mm3 \n\t"
474 "add %%"REG_a", %2 \n\t"
475 "add %%"REG_a", %1 \n\t"
476 "psubusb %%mm6, %%mm0 \n\t"
477 "psubusb %%mm6, %%mm2 \n\t"
478 PAVGB" %%mm1, %%mm0 \n\t"
479 PAVGB" %%mm3, %%mm2 \n\t"
480 "movq %%mm0, (%2) \n\t"
481 "movq %%mm2, (%2, %3) \n\t"
482 "add %%"REG_a", %2 \n\t"
485 :"+g"(h), "+S"(pixels), "+D"(block)
486 :"r" ((x86_reg)line_size)
487 :"%"REG_a, "memory");
490 static void DEF(put_no_rnd_pixels8_x2_exact)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
493 "pcmpeqb %%mm6, %%mm6 \n\t"
495 "movq (%1), %%mm0 \n\t"
496 "movq (%1, %3), %%mm2 \n\t"
497 "movq 1(%1), %%mm1 \n\t"
498 "movq 1(%1, %3), %%mm3 \n\t"
499 "pxor %%mm6, %%mm0 \n\t"
500 "pxor %%mm6, %%mm2 \n\t"
501 "pxor %%mm6, %%mm1 \n\t"
502 "pxor %%mm6, %%mm3 \n\t"
503 PAVGB" %%mm1, %%mm0 \n\t"
504 PAVGB" %%mm3, %%mm2 \n\t"
505 "pxor %%mm6, %%mm0 \n\t"
506 "pxor %%mm6, %%mm2 \n\t"
507 "movq %%mm0, (%2) \n\t"
508 "movq %%mm2, (%2, %3) \n\t"
509 "movq (%1, %3,2), %%mm0 \n\t"
510 "movq 1(%1, %3,2), %%mm1 \n\t"
511 "movq (%1, %4), %%mm2 \n\t"
512 "movq 1(%1, %4), %%mm3 \n\t"
513 "pxor %%mm6, %%mm0 \n\t"
514 "pxor %%mm6, %%mm1 \n\t"
515 "pxor %%mm6, %%mm2 \n\t"
516 "pxor %%mm6, %%mm3 \n\t"
517 PAVGB" %%mm1, %%mm0 \n\t"
518 PAVGB" %%mm3, %%mm2 \n\t"
519 "pxor %%mm6, %%mm0 \n\t"
520 "pxor %%mm6, %%mm2 \n\t"
521 "movq %%mm0, (%2, %3,2) \n\t"
522 "movq %%mm2, (%2, %4) \n\t"
523 "lea (%1, %3,4), %1 \n\t"
524 "lea (%2, %3,4), %2 \n\t"
527 : "+g"(h), "+r"(pixels), "+r"(block)
528 : "r" ((x86_reg)line_size), "r"((x86_reg)3*line_size)
533 static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
536 "lea (%3, %3), %%"REG_a" \n\t"
537 "movq (%1), %%mm0 \n\t"
540 "movq (%1, %3), %%mm1 \n\t"
541 "movq (%1, %%"REG_a"), %%mm2 \n\t"
542 "add %%"REG_a", %1 \n\t"
543 PAVGB" %%mm1, %%mm0 \n\t"
544 PAVGB" %%mm2, %%mm1 \n\t"
545 "movq %%mm0, (%2, %3) \n\t"
546 "movq %%mm1, (%2, %%"REG_a") \n\t"
547 "movq (%1, %3), %%mm1 \n\t"
548 "movq (%1, %%"REG_a"), %%mm0 \n\t"
549 "add %%"REG_a", %2 \n\t"
550 "add %%"REG_a", %1 \n\t"
551 PAVGB" %%mm1, %%mm2 \n\t"
552 PAVGB" %%mm0, %%mm1 \n\t"
553 "movq %%mm2, (%2, %3) \n\t"
554 "movq %%mm1, (%2, %%"REG_a") \n\t"
555 "add %%"REG_a", %2 \n\t"
558 :"+g"(h), "+S"(pixels), "+D" (block)
559 :"r" ((x86_reg)line_size)
560 :"%"REG_a, "memory");
563 /* GL: this function does incorrect rounding if overflow */
564 static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
568 "lea (%3, %3), %%"REG_a" \n\t"
569 "movq (%1), %%mm0 \n\t"
572 "movq (%1, %3), %%mm1 \n\t"
573 "movq (%1, %%"REG_a"), %%mm2 \n\t"
574 "add %%"REG_a", %1 \n\t"
575 "psubusb %%mm6, %%mm1 \n\t"
576 PAVGB" %%mm1, %%mm0 \n\t"
577 PAVGB" %%mm2, %%mm1 \n\t"
578 "movq %%mm0, (%2, %3) \n\t"
579 "movq %%mm1, (%2, %%"REG_a") \n\t"
580 "movq (%1, %3), %%mm1 \n\t"
581 "movq (%1, %%"REG_a"), %%mm0 \n\t"
582 "add %%"REG_a", %2 \n\t"
583 "add %%"REG_a", %1 \n\t"
584 "psubusb %%mm6, %%mm1 \n\t"
585 PAVGB" %%mm1, %%mm2 \n\t"
586 PAVGB" %%mm0, %%mm1 \n\t"
587 "movq %%mm2, (%2, %3) \n\t"
588 "movq %%mm1, (%2, %%"REG_a") \n\t"
589 "add %%"REG_a", %2 \n\t"
592 :"+g"(h), "+S"(pixels), "+D" (block)
593 :"r" ((x86_reg)line_size)
594 :"%"REG_a, "memory");
597 static void DEF(put_no_rnd_pixels8_y2_exact)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
600 "movq (%1), %%mm0 \n\t"
601 "pcmpeqb %%mm6, %%mm6 \n\t"
603 "pxor %%mm6, %%mm0 \n\t"
605 "movq (%1), %%mm1 \n\t"
606 "movq (%1, %3), %%mm2 \n\t"
607 "pxor %%mm6, %%mm1 \n\t"
608 "pxor %%mm6, %%mm2 \n\t"
609 PAVGB" %%mm1, %%mm0 \n\t"
610 PAVGB" %%mm2, %%mm1 \n\t"
611 "pxor %%mm6, %%mm0 \n\t"
612 "pxor %%mm6, %%mm1 \n\t"
613 "movq %%mm0, (%2) \n\t"
614 "movq %%mm1, (%2, %3) \n\t"
615 "movq (%1, %3,2), %%mm1 \n\t"
616 "movq (%1, %4), %%mm0 \n\t"
617 "pxor %%mm6, %%mm1 \n\t"
618 "pxor %%mm6, %%mm0 \n\t"
619 PAVGB" %%mm1, %%mm2 \n\t"
620 PAVGB" %%mm0, %%mm1 \n\t"
621 "pxor %%mm6, %%mm2 \n\t"
622 "pxor %%mm6, %%mm1 \n\t"
623 "movq %%mm2, (%2, %3,2) \n\t"
624 "movq %%mm1, (%2, %4) \n\t"
625 "lea (%1, %3,4), %1 \n\t"
626 "lea (%2, %3,4), %2 \n\t"
629 :"+g"(h), "+r"(pixels), "+r" (block)
630 :"r" ((x86_reg)line_size), "r"((x86_reg)3*line_size)
635 static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
638 "lea (%3, %3), %%"REG_a" \n\t"
640 "movq (%2), %%mm0 \n\t"
641 "movq (%2, %3), %%mm1 \n\t"
642 PAVGB" (%1), %%mm0 \n\t"
643 PAVGB" (%1, %3), %%mm1 \n\t"
644 "movq %%mm0, (%2) \n\t"
645 "movq %%mm1, (%2, %3) \n\t"
646 "add %%"REG_a", %1 \n\t"
647 "add %%"REG_a", %2 \n\t"
648 "movq (%2), %%mm0 \n\t"
649 "movq (%2, %3), %%mm1 \n\t"
650 PAVGB" (%1), %%mm0 \n\t"
651 PAVGB" (%1, %3), %%mm1 \n\t"
652 "add %%"REG_a", %1 \n\t"
653 "movq %%mm0, (%2) \n\t"
654 "movq %%mm1, (%2, %3) \n\t"
655 "add %%"REG_a", %2 \n\t"
658 :"+g"(h), "+S"(pixels), "+D"(block)
659 :"r" ((x86_reg)line_size)
660 :"%"REG_a, "memory");
663 static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
666 "lea (%3, %3), %%"REG_a" \n\t"
668 "movq (%1), %%mm0 \n\t"
669 "movq (%1, %3), %%mm2 \n\t"
670 PAVGB" 1(%1), %%mm0 \n\t"
671 PAVGB" 1(%1, %3), %%mm2 \n\t"
672 PAVGB" (%2), %%mm0 \n\t"
673 PAVGB" (%2, %3), %%mm2 \n\t"
674 "add %%"REG_a", %1 \n\t"
675 "movq %%mm0, (%2) \n\t"
676 "movq %%mm2, (%2, %3) \n\t"
677 "movq (%1), %%mm0 \n\t"
678 "movq (%1, %3), %%mm2 \n\t"
679 PAVGB" 1(%1), %%mm0 \n\t"
680 PAVGB" 1(%1, %3), %%mm2 \n\t"
681 "add %%"REG_a", %2 \n\t"
682 "add %%"REG_a", %1 \n\t"
683 PAVGB" (%2), %%mm0 \n\t"
684 PAVGB" (%2, %3), %%mm2 \n\t"
685 "movq %%mm0, (%2) \n\t"
686 "movq %%mm2, (%2, %3) \n\t"
687 "add %%"REG_a", %2 \n\t"
690 :"+g"(h), "+S"(pixels), "+D"(block)
691 :"r" ((x86_reg)line_size)
692 :"%"REG_a, "memory");
695 static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
698 "lea (%3, %3), %%"REG_a" \n\t"
699 "movq (%1), %%mm0 \n\t"
702 "movq (%1, %3), %%mm1 \n\t"
703 "movq (%1, %%"REG_a"), %%mm2 \n\t"
704 "add %%"REG_a", %1 \n\t"
705 PAVGB" %%mm1, %%mm0 \n\t"
706 PAVGB" %%mm2, %%mm1 \n\t"
707 "movq (%2, %3), %%mm3 \n\t"
708 "movq (%2, %%"REG_a"), %%mm4 \n\t"
709 PAVGB" %%mm3, %%mm0 \n\t"
710 PAVGB" %%mm4, %%mm1 \n\t"
711 "movq %%mm0, (%2, %3) \n\t"
712 "movq %%mm1, (%2, %%"REG_a") \n\t"
713 "movq (%1, %3), %%mm1 \n\t"
714 "movq (%1, %%"REG_a"), %%mm0 \n\t"
715 PAVGB" %%mm1, %%mm2 \n\t"
716 PAVGB" %%mm0, %%mm1 \n\t"
717 "add %%"REG_a", %2 \n\t"
718 "add %%"REG_a", %1 \n\t"
719 "movq (%2, %3), %%mm3 \n\t"
720 "movq (%2, %%"REG_a"), %%mm4 \n\t"
721 PAVGB" %%mm3, %%mm2 \n\t"
722 PAVGB" %%mm4, %%mm1 \n\t"
723 "movq %%mm2, (%2, %3) \n\t"
724 "movq %%mm1, (%2, %%"REG_a") \n\t"
725 "add %%"REG_a", %2 \n\t"
728 :"+g"(h), "+S"(pixels), "+D"(block)
729 :"r" ((x86_reg)line_size)
730 :"%"REG_a, "memory");
733 /* Note this is not correctly rounded, but this function is only
734 * used for B-frames so it does not matter. */
735 static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
739 "lea (%3, %3), %%"REG_a" \n\t"
740 "movq (%1), %%mm0 \n\t"
741 PAVGB" 1(%1), %%mm0 \n\t"
744 "movq (%1, %%"REG_a"), %%mm2 \n\t"
745 "movq (%1, %3), %%mm1 \n\t"
746 "psubusb %%mm6, %%mm2 \n\t"
747 PAVGB" 1(%1, %3), %%mm1 \n\t"
748 PAVGB" 1(%1, %%"REG_a"), %%mm2 \n\t"
749 "add %%"REG_a", %1 \n\t"
750 PAVGB" %%mm1, %%mm0 \n\t"
751 PAVGB" %%mm2, %%mm1 \n\t"
752 PAVGB" (%2), %%mm0 \n\t"
753 PAVGB" (%2, %3), %%mm1 \n\t"
754 "movq %%mm0, (%2) \n\t"
755 "movq %%mm1, (%2, %3) \n\t"
756 "movq (%1, %3), %%mm1 \n\t"
757 "movq (%1, %%"REG_a"), %%mm0 \n\t"
758 PAVGB" 1(%1, %3), %%mm1 \n\t"
759 PAVGB" 1(%1, %%"REG_a"), %%mm0 \n\t"
760 "add %%"REG_a", %2 \n\t"
761 "add %%"REG_a", %1 \n\t"
762 PAVGB" %%mm1, %%mm2 \n\t"
763 PAVGB" %%mm0, %%mm1 \n\t"
764 PAVGB" (%2), %%mm2 \n\t"
765 PAVGB" (%2, %3), %%mm1 \n\t"
766 "movq %%mm2, (%2) \n\t"
767 "movq %%mm1, (%2, %3) \n\t"
768 "add %%"REG_a", %2 \n\t"
771 :"+g"(h), "+S"(pixels), "+D"(block)
772 :"r" ((x86_reg)line_size)
773 :"%"REG_a, "memory");
776 //FIXME the following could be optimized too ...
777 static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
778 DEF(put_no_rnd_pixels8_x2)(block , pixels , line_size, h);
779 DEF(put_no_rnd_pixels8_x2)(block+8, pixels+8, line_size, h);
781 static void DEF(put_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
782 DEF(put_pixels8_y2)(block , pixels , line_size, h);
783 DEF(put_pixels8_y2)(block+8, pixels+8, line_size, h);
785 static void DEF(put_no_rnd_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
786 DEF(put_no_rnd_pixels8_y2)(block , pixels , line_size, h);
787 DEF(put_no_rnd_pixels8_y2)(block+8, pixels+8, line_size, h);
789 static void DEF(avg_pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
790 DEF(avg_pixels8)(block , pixels , line_size, h);
791 DEF(avg_pixels8)(block+8, pixels+8, line_size, h);
793 static void DEF(avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
794 DEF(avg_pixels8_x2)(block , pixels , line_size, h);
795 DEF(avg_pixels8_x2)(block+8, pixels+8, line_size, h);
797 static void DEF(avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
798 DEF(avg_pixels8_y2)(block , pixels , line_size, h);
799 DEF(avg_pixels8_y2)(block+8, pixels+8, line_size, h);
801 static void DEF(avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
802 DEF(avg_pixels8_xy2)(block , pixels , line_size, h);
803 DEF(avg_pixels8_xy2)(block+8, pixels+8, line_size, h);