2 * DSP utils : average functions are compiled twice for 3dnow/mmx2
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 * Copyright (c) 2002-2004 Michael Niedermayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
21 * mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
22 * and improved by Zdenek Kabelac <kabi@users.sf.net>
25 /* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm
26 clobber bug - now it will work with 2.95.2 and also with -fPIC
28 static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
31 "lea (%3, %3), %%"REG_a" \n\t"
33 "movq (%1), %%mm0 \n\t"
34 "movq (%1, %3), %%mm1 \n\t"
35 PAVGB" 1(%1), %%mm0 \n\t"
36 PAVGB" 1(%1, %3), %%mm1 \n\t"
37 "movq %%mm0, (%2) \n\t"
38 "movq %%mm1, (%2, %3) \n\t"
39 "add %%"REG_a", %1 \n\t"
40 "add %%"REG_a", %2 \n\t"
41 "movq (%1), %%mm0 \n\t"
42 "movq (%1, %3), %%mm1 \n\t"
43 PAVGB" 1(%1), %%mm0 \n\t"
44 PAVGB" 1(%1, %3), %%mm1 \n\t"
45 "add %%"REG_a", %1 \n\t"
46 "movq %%mm0, (%2) \n\t"
47 "movq %%mm1, (%2, %3) \n\t"
48 "add %%"REG_a", %2 \n\t"
51 :"+g"(h), "+S"(pixels), "+D"(block)
52 :"r" ((long)line_size)
56 static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
61 "movd (%1), %%mm0 \n\t"
62 "movd (%2), %%mm1 \n\t"
65 PAVGB" %%mm1, %%mm0 \n\t"
66 "movd %%mm0, (%3) \n\t"
70 "movd (%1), %%mm0 \n\t"
72 "movd (%1), %%mm1 \n\t"
74 PAVGB" (%2), %%mm0 \n\t"
75 PAVGB" 4(%2), %%mm1 \n\t"
76 "movd %%mm0, (%3) \n\t"
78 "movd %%mm1, (%3) \n\t"
80 "movd (%1), %%mm0 \n\t"
82 "movd (%1), %%mm1 \n\t"
84 PAVGB" 8(%2), %%mm0 \n\t"
85 PAVGB" 12(%2), %%mm1 \n\t"
86 "movd %%mm0, (%3) \n\t"
88 "movd %%mm1, (%3) \n\t"
93 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
94 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
96 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
98 :"S"((long)src1Stride), "D"((long)dstStride)
103 static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
108 "movq (%1), %%mm0 \n\t"
109 "movq (%2), %%mm1 \n\t"
112 PAVGB" %%mm1, %%mm0 \n\t"
113 "movq %%mm0, (%3) \n\t"
117 "movq (%1), %%mm0 \n\t"
119 "movq (%1), %%mm1 \n\t"
121 PAVGB" (%2), %%mm0 \n\t"
122 PAVGB" 8(%2), %%mm1 \n\t"
123 "movq %%mm0, (%3) \n\t"
125 "movq %%mm1, (%3) \n\t"
127 "movq (%1), %%mm0 \n\t"
129 "movq (%1), %%mm1 \n\t"
131 PAVGB" 16(%2), %%mm0 \n\t"
132 PAVGB" 24(%2), %%mm1 \n\t"
133 "movq %%mm0, (%3) \n\t"
135 "movq %%mm1, (%3) \n\t"
140 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
141 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
143 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
145 :"S"((long)src1Stride), "D"((long)dstStride)
147 //the following should be used, though better not with gcc ...
148 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
149 :"r"(src1Stride), "r"(dstStride)
153 static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
156 "pcmpeqb %%mm6, %%mm6 \n\t"
159 "movq (%1), %%mm0 \n\t"
160 "movq (%2), %%mm1 \n\t"
163 "pxor %%mm6, %%mm0 \n\t"
164 "pxor %%mm6, %%mm1 \n\t"
165 PAVGB" %%mm1, %%mm0 \n\t"
166 "pxor %%mm6, %%mm0 \n\t"
167 "movq %%mm0, (%3) \n\t"
171 "movq (%1), %%mm0 \n\t"
173 "movq (%1), %%mm1 \n\t"
175 "movq (%2), %%mm2 \n\t"
176 "movq 8(%2), %%mm3 \n\t"
177 "pxor %%mm6, %%mm0 \n\t"
178 "pxor %%mm6, %%mm1 \n\t"
179 "pxor %%mm6, %%mm2 \n\t"
180 "pxor %%mm6, %%mm3 \n\t"
181 PAVGB" %%mm2, %%mm0 \n\t"
182 PAVGB" %%mm3, %%mm1 \n\t"
183 "pxor %%mm6, %%mm0 \n\t"
184 "pxor %%mm6, %%mm1 \n\t"
185 "movq %%mm0, (%3) \n\t"
187 "movq %%mm1, (%3) \n\t"
189 "movq (%1), %%mm0 \n\t"
191 "movq (%1), %%mm1 \n\t"
193 "movq 16(%2), %%mm2 \n\t"
194 "movq 24(%2), %%mm3 \n\t"
195 "pxor %%mm6, %%mm0 \n\t"
196 "pxor %%mm6, %%mm1 \n\t"
197 "pxor %%mm6, %%mm2 \n\t"
198 "pxor %%mm6, %%mm3 \n\t"
199 PAVGB" %%mm2, %%mm0 \n\t"
200 PAVGB" %%mm3, %%mm1 \n\t"
201 "pxor %%mm6, %%mm0 \n\t"
202 "pxor %%mm6, %%mm1 \n\t"
203 "movq %%mm0, (%3) \n\t"
205 "movq %%mm1, (%3) \n\t"
210 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
211 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
213 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
215 :"S"((long)src1Stride), "D"((long)dstStride)
217 //the following should be used, though better not with gcc ...
218 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
219 :"r"(src1Stride), "r"(dstStride)
223 static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
228 "movd (%1), %%mm0 \n\t"
229 "movd (%2), %%mm1 \n\t"
232 PAVGB" %%mm1, %%mm0 \n\t"
233 PAVGB" (%3), %%mm0 \n\t"
234 "movd %%mm0, (%3) \n\t"
238 "movd (%1), %%mm0 \n\t"
240 "movd (%1), %%mm1 \n\t"
242 PAVGB" (%2), %%mm0 \n\t"
243 PAVGB" 4(%2), %%mm1 \n\t"
244 PAVGB" (%3), %%mm0 \n\t"
245 "movd %%mm0, (%3) \n\t"
247 PAVGB" (%3), %%mm1 \n\t"
248 "movd %%mm1, (%3) \n\t"
250 "movd (%1), %%mm0 \n\t"
252 "movd (%1), %%mm1 \n\t"
254 PAVGB" 8(%2), %%mm0 \n\t"
255 PAVGB" 12(%2), %%mm1 \n\t"
256 PAVGB" (%3), %%mm0 \n\t"
257 "movd %%mm0, (%3) \n\t"
259 PAVGB" (%3), %%mm1 \n\t"
260 "movd %%mm1, (%3) \n\t"
265 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
266 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
268 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
270 :"S"((long)src1Stride), "D"((long)dstStride)
275 static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
280 "movq (%1), %%mm0 \n\t"
281 "movq (%2), %%mm1 \n\t"
284 PAVGB" %%mm1, %%mm0 \n\t"
285 PAVGB" (%3), %%mm0 \n\t"
286 "movq %%mm0, (%3) \n\t"
290 "movq (%1), %%mm0 \n\t"
292 "movq (%1), %%mm1 \n\t"
294 PAVGB" (%2), %%mm0 \n\t"
295 PAVGB" 8(%2), %%mm1 \n\t"
296 PAVGB" (%3), %%mm0 \n\t"
297 "movq %%mm0, (%3) \n\t"
299 PAVGB" (%3), %%mm1 \n\t"
300 "movq %%mm1, (%3) \n\t"
302 "movq (%1), %%mm0 \n\t"
304 "movq (%1), %%mm1 \n\t"
306 PAVGB" 16(%2), %%mm0 \n\t"
307 PAVGB" 24(%2), %%mm1 \n\t"
308 PAVGB" (%3), %%mm0 \n\t"
309 "movq %%mm0, (%3) \n\t"
311 PAVGB" (%3), %%mm1 \n\t"
312 "movq %%mm1, (%3) \n\t"
317 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
318 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
320 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
322 :"S"((long)src1Stride), "D"((long)dstStride)
324 //the following should be used, though better not with gcc ...
325 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
326 :"r"(src1Stride), "r"(dstStride)
330 static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
333 "lea (%3, %3), %%"REG_a" \n\t"
335 "movq (%1), %%mm0 \n\t"
336 "movq (%1, %3), %%mm1 \n\t"
337 "movq 8(%1), %%mm2 \n\t"
338 "movq 8(%1, %3), %%mm3 \n\t"
339 PAVGB" 1(%1), %%mm0 \n\t"
340 PAVGB" 1(%1, %3), %%mm1 \n\t"
341 PAVGB" 9(%1), %%mm2 \n\t"
342 PAVGB" 9(%1, %3), %%mm3 \n\t"
343 "movq %%mm0, (%2) \n\t"
344 "movq %%mm1, (%2, %3) \n\t"
345 "movq %%mm2, 8(%2) \n\t"
346 "movq %%mm3, 8(%2, %3) \n\t"
347 "add %%"REG_a", %1 \n\t"
348 "add %%"REG_a", %2 \n\t"
349 "movq (%1), %%mm0 \n\t"
350 "movq (%1, %3), %%mm1 \n\t"
351 "movq 8(%1), %%mm2 \n\t"
352 "movq 8(%1, %3), %%mm3 \n\t"
353 PAVGB" 1(%1), %%mm0 \n\t"
354 PAVGB" 1(%1, %3), %%mm1 \n\t"
355 PAVGB" 9(%1), %%mm2 \n\t"
356 PAVGB" 9(%1, %3), %%mm3 \n\t"
357 "add %%"REG_a", %1 \n\t"
358 "movq %%mm0, (%2) \n\t"
359 "movq %%mm1, (%2, %3) \n\t"
360 "movq %%mm2, 8(%2) \n\t"
361 "movq %%mm3, 8(%2, %3) \n\t"
362 "add %%"REG_a", %2 \n\t"
365 :"+g"(h), "+S"(pixels), "+D"(block)
366 :"r" ((long)line_size)
367 :"%"REG_a, "memory");
370 static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
375 "movq (%1), %%mm0 \n\t"
376 "movq 8(%1), %%mm1 \n\t"
377 PAVGB" (%2), %%mm0 \n\t"
378 PAVGB" 8(%2), %%mm1 \n\t"
381 "movq %%mm0, (%3) \n\t"
382 "movq %%mm1, 8(%3) \n\t"
386 "movq (%1), %%mm0 \n\t"
387 "movq 8(%1), %%mm1 \n\t"
389 PAVGB" (%2), %%mm0 \n\t"
390 PAVGB" 8(%2), %%mm1 \n\t"
391 "movq %%mm0, (%3) \n\t"
392 "movq %%mm1, 8(%3) \n\t"
394 "movq (%1), %%mm0 \n\t"
395 "movq 8(%1), %%mm1 \n\t"
397 PAVGB" 16(%2), %%mm0 \n\t"
398 PAVGB" 24(%2), %%mm1 \n\t"
399 "movq %%mm0, (%3) \n\t"
400 "movq %%mm1, 8(%3) \n\t"
405 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
406 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
408 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
410 :"S"((long)src1Stride), "D"((long)dstStride)
412 //the following should be used, though better not with gcc ...
413 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
414 :"r"(src1Stride), "r"(dstStride)
418 static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
423 "movq (%1), %%mm0 \n\t"
424 "movq 8(%1), %%mm1 \n\t"
425 PAVGB" (%2), %%mm0 \n\t"
426 PAVGB" 8(%2), %%mm1 \n\t"
429 PAVGB" (%3), %%mm0 \n\t"
430 PAVGB" 8(%3), %%mm1 \n\t"
431 "movq %%mm0, (%3) \n\t"
432 "movq %%mm1, 8(%3) \n\t"
436 "movq (%1), %%mm0 \n\t"
437 "movq 8(%1), %%mm1 \n\t"
439 PAVGB" (%2), %%mm0 \n\t"
440 PAVGB" 8(%2), %%mm1 \n\t"
441 PAVGB" (%3), %%mm0 \n\t"
442 PAVGB" 8(%3), %%mm1 \n\t"
443 "movq %%mm0, (%3) \n\t"
444 "movq %%mm1, 8(%3) \n\t"
446 "movq (%1), %%mm0 \n\t"
447 "movq 8(%1), %%mm1 \n\t"
449 PAVGB" 16(%2), %%mm0 \n\t"
450 PAVGB" 24(%2), %%mm1 \n\t"
451 PAVGB" (%3), %%mm0 \n\t"
452 PAVGB" 8(%3), %%mm1 \n\t"
453 "movq %%mm0, (%3) \n\t"
454 "movq %%mm1, 8(%3) \n\t"
459 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
460 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
462 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
464 :"S"((long)src1Stride), "D"((long)dstStride)
466 //the following should be used, though better not with gcc ...
467 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
468 :"r"(src1Stride), "r"(dstStride)
472 static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
475 "pcmpeqb %%mm6, %%mm6\n\t"
478 "movq (%1), %%mm0 \n\t"
479 "movq 8(%1), %%mm1 \n\t"
480 "movq (%2), %%mm2 \n\t"
481 "movq 8(%2), %%mm3 \n\t"
482 "pxor %%mm6, %%mm0 \n\t"
483 "pxor %%mm6, %%mm1 \n\t"
484 "pxor %%mm6, %%mm2 \n\t"
485 "pxor %%mm6, %%mm3 \n\t"
486 PAVGB" %%mm2, %%mm0 \n\t"
487 PAVGB" %%mm3, %%mm1 \n\t"
488 "pxor %%mm6, %%mm0 \n\t"
489 "pxor %%mm6, %%mm1 \n\t"
492 "movq %%mm0, (%3) \n\t"
493 "movq %%mm1, 8(%3) \n\t"
497 "movq (%1), %%mm0 \n\t"
498 "movq 8(%1), %%mm1 \n\t"
500 "movq (%2), %%mm2 \n\t"
501 "movq 8(%2), %%mm3 \n\t"
502 "pxor %%mm6, %%mm0 \n\t"
503 "pxor %%mm6, %%mm1 \n\t"
504 "pxor %%mm6, %%mm2 \n\t"
505 "pxor %%mm6, %%mm3 \n\t"
506 PAVGB" %%mm2, %%mm0 \n\t"
507 PAVGB" %%mm3, %%mm1 \n\t"
508 "pxor %%mm6, %%mm0 \n\t"
509 "pxor %%mm6, %%mm1 \n\t"
510 "movq %%mm0, (%3) \n\t"
511 "movq %%mm1, 8(%3) \n\t"
513 "movq (%1), %%mm0 \n\t"
514 "movq 8(%1), %%mm1 \n\t"
516 "movq 16(%2), %%mm2 \n\t"
517 "movq 24(%2), %%mm3 \n\t"
518 "pxor %%mm6, %%mm0 \n\t"
519 "pxor %%mm6, %%mm1 \n\t"
520 "pxor %%mm6, %%mm2 \n\t"
521 "pxor %%mm6, %%mm3 \n\t"
522 PAVGB" %%mm2, %%mm0 \n\t"
523 PAVGB" %%mm3, %%mm1 \n\t"
524 "pxor %%mm6, %%mm0 \n\t"
525 "pxor %%mm6, %%mm1 \n\t"
526 "movq %%mm0, (%3) \n\t"
527 "movq %%mm1, 8(%3) \n\t"
532 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
533 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
535 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
537 :"S"((long)src1Stride), "D"((long)dstStride)
539 //the following should be used, though better not with gcc ...
540 /* :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
541 :"r"(src1Stride), "r"(dstStride)
545 /* GL: this function does incorrect rounding if overflow */
546 static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
550 "lea (%3, %3), %%"REG_a" \n\t"
552 "movq (%1), %%mm0 \n\t"
553 "movq (%1, %3), %%mm2 \n\t"
554 "movq 1(%1), %%mm1 \n\t"
555 "movq 1(%1, %3), %%mm3 \n\t"
556 "add %%"REG_a", %1 \n\t"
557 "psubusb %%mm6, %%mm0 \n\t"
558 "psubusb %%mm6, %%mm2 \n\t"
559 PAVGB" %%mm1, %%mm0 \n\t"
560 PAVGB" %%mm3, %%mm2 \n\t"
561 "movq %%mm0, (%2) \n\t"
562 "movq %%mm2, (%2, %3) \n\t"
563 "movq (%1), %%mm0 \n\t"
564 "movq 1(%1), %%mm1 \n\t"
565 "movq (%1, %3), %%mm2 \n\t"
566 "movq 1(%1, %3), %%mm3 \n\t"
567 "add %%"REG_a", %2 \n\t"
568 "add %%"REG_a", %1 \n\t"
569 "psubusb %%mm6, %%mm0 \n\t"
570 "psubusb %%mm6, %%mm2 \n\t"
571 PAVGB" %%mm1, %%mm0 \n\t"
572 PAVGB" %%mm3, %%mm2 \n\t"
573 "movq %%mm0, (%2) \n\t"
574 "movq %%mm2, (%2, %3) \n\t"
575 "add %%"REG_a", %2 \n\t"
578 :"+g"(h), "+S"(pixels), "+D"(block)
579 :"r" ((long)line_size)
580 :"%"REG_a, "memory");
583 static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
586 "lea (%3, %3), %%"REG_a" \n\t"
587 "movq (%1), %%mm0 \n\t"
590 "movq (%1, %3), %%mm1 \n\t"
591 "movq (%1, %%"REG_a"), %%mm2 \n\t"
592 "add %%"REG_a", %1 \n\t"
593 PAVGB" %%mm1, %%mm0 \n\t"
594 PAVGB" %%mm2, %%mm1 \n\t"
595 "movq %%mm0, (%2, %3) \n\t"
596 "movq %%mm1, (%2, %%"REG_a") \n\t"
597 "movq (%1, %3), %%mm1 \n\t"
598 "movq (%1, %%"REG_a"), %%mm0 \n\t"
599 "add %%"REG_a", %2 \n\t"
600 "add %%"REG_a", %1 \n\t"
601 PAVGB" %%mm1, %%mm2 \n\t"
602 PAVGB" %%mm0, %%mm1 \n\t"
603 "movq %%mm2, (%2, %3) \n\t"
604 "movq %%mm1, (%2, %%"REG_a") \n\t"
605 "add %%"REG_a", %2 \n\t"
608 :"+g"(h), "+S"(pixels), "+D" (block)
609 :"r" ((long)line_size)
610 :"%"REG_a, "memory");
613 /* GL: this function does incorrect rounding if overflow */
614 static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
618 "lea (%3, %3), %%"REG_a" \n\t"
619 "movq (%1), %%mm0 \n\t"
622 "movq (%1, %3), %%mm1 \n\t"
623 "movq (%1, %%"REG_a"), %%mm2 \n\t"
624 "add %%"REG_a", %1 \n\t"
625 "psubusb %%mm6, %%mm1 \n\t"
626 PAVGB" %%mm1, %%mm0 \n\t"
627 PAVGB" %%mm2, %%mm1 \n\t"
628 "movq %%mm0, (%2, %3) \n\t"
629 "movq %%mm1, (%2, %%"REG_a") \n\t"
630 "movq (%1, %3), %%mm1 \n\t"
631 "movq (%1, %%"REG_a"), %%mm0 \n\t"
632 "add %%"REG_a", %2 \n\t"
633 "add %%"REG_a", %1 \n\t"
634 "psubusb %%mm6, %%mm1 \n\t"
635 PAVGB" %%mm1, %%mm2 \n\t"
636 PAVGB" %%mm0, %%mm1 \n\t"
637 "movq %%mm2, (%2, %3) \n\t"
638 "movq %%mm1, (%2, %%"REG_a") \n\t"
639 "add %%"REG_a", %2 \n\t"
642 :"+g"(h), "+S"(pixels), "+D" (block)
643 :"r" ((long)line_size)
644 :"%"REG_a, "memory");
647 static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
650 "lea (%3, %3), %%"REG_a" \n\t"
652 "movq (%2), %%mm0 \n\t"
653 "movq (%2, %3), %%mm1 \n\t"
654 PAVGB" (%1), %%mm0 \n\t"
655 PAVGB" (%1, %3), %%mm1 \n\t"
656 "movq %%mm0, (%2) \n\t"
657 "movq %%mm1, (%2, %3) \n\t"
658 "add %%"REG_a", %1 \n\t"
659 "add %%"REG_a", %2 \n\t"
660 "movq (%2), %%mm0 \n\t"
661 "movq (%2, %3), %%mm1 \n\t"
662 PAVGB" (%1), %%mm0 \n\t"
663 PAVGB" (%1, %3), %%mm1 \n\t"
664 "add %%"REG_a", %1 \n\t"
665 "movq %%mm0, (%2) \n\t"
666 "movq %%mm1, (%2, %3) \n\t"
667 "add %%"REG_a", %2 \n\t"
670 :"+g"(h), "+S"(pixels), "+D"(block)
671 :"r" ((long)line_size)
672 :"%"REG_a, "memory");
675 static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
678 "lea (%3, %3), %%"REG_a" \n\t"
680 "movq (%1), %%mm0 \n\t"
681 "movq (%1, %3), %%mm2 \n\t"
682 PAVGB" 1(%1), %%mm0 \n\t"
683 PAVGB" 1(%1, %3), %%mm2 \n\t"
684 PAVGB" (%2), %%mm0 \n\t"
685 PAVGB" (%2, %3), %%mm2 \n\t"
686 "add %%"REG_a", %1 \n\t"
687 "movq %%mm0, (%2) \n\t"
688 "movq %%mm2, (%2, %3) \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 "add %%"REG_a", %2 \n\t"
694 "add %%"REG_a", %1 \n\t"
695 PAVGB" (%2), %%mm0 \n\t"
696 PAVGB" (%2, %3), %%mm2 \n\t"
697 "movq %%mm0, (%2) \n\t"
698 "movq %%mm2, (%2, %3) \n\t"
699 "add %%"REG_a", %2 \n\t"
702 :"+g"(h), "+S"(pixels), "+D"(block)
703 :"r" ((long)line_size)
704 :"%"REG_a, "memory");
707 static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
710 "lea (%3, %3), %%"REG_a" \n\t"
711 "movq (%1), %%mm0 \n\t"
714 "movq (%1, %3), %%mm1 \n\t"
715 "movq (%1, %%"REG_a"), %%mm2 \n\t"
716 "add %%"REG_a", %1 \n\t"
717 PAVGB" %%mm1, %%mm0 \n\t"
718 PAVGB" %%mm2, %%mm1 \n\t"
719 "movq (%2, %3), %%mm3 \n\t"
720 "movq (%2, %%"REG_a"), %%mm4 \n\t"
721 PAVGB" %%mm3, %%mm0 \n\t"
722 PAVGB" %%mm4, %%mm1 \n\t"
723 "movq %%mm0, (%2, %3) \n\t"
724 "movq %%mm1, (%2, %%"REG_a") \n\t"
725 "movq (%1, %3), %%mm1 \n\t"
726 "movq (%1, %%"REG_a"), %%mm0 \n\t"
727 PAVGB" %%mm1, %%mm2 \n\t"
728 PAVGB" %%mm0, %%mm1 \n\t"
729 "add %%"REG_a", %2 \n\t"
730 "add %%"REG_a", %1 \n\t"
731 "movq (%2, %3), %%mm3 \n\t"
732 "movq (%2, %%"REG_a"), %%mm4 \n\t"
733 PAVGB" %%mm3, %%mm2 \n\t"
734 PAVGB" %%mm4, %%mm1 \n\t"
735 "movq %%mm2, (%2, %3) \n\t"
736 "movq %%mm1, (%2, %%"REG_a") \n\t"
737 "add %%"REG_a", %2 \n\t"
740 :"+g"(h), "+S"(pixels), "+D"(block)
741 :"r" ((long)line_size)
742 :"%"REG_a, "memory");
745 // Note this is not correctly rounded, but this function is only used for b frames so it doesnt matter
746 static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
750 "lea (%3, %3), %%"REG_a" \n\t"
751 "movq (%1), %%mm0 \n\t"
752 PAVGB" 1(%1), %%mm0 \n\t"
755 "movq (%1, %%"REG_a"), %%mm2 \n\t"
756 "movq (%1, %3), %%mm1 \n\t"
757 "psubusb %%mm6, %%mm2 \n\t"
758 PAVGB" 1(%1, %3), %%mm1 \n\t"
759 PAVGB" 1(%1, %%"REG_a"), %%mm2 \n\t"
760 "add %%"REG_a", %1 \n\t"
761 PAVGB" %%mm1, %%mm0 \n\t"
762 PAVGB" %%mm2, %%mm1 \n\t"
763 PAVGB" (%2), %%mm0 \n\t"
764 PAVGB" (%2, %3), %%mm1 \n\t"
765 "movq %%mm0, (%2) \n\t"
766 "movq %%mm1, (%2, %3) \n\t"
767 "movq (%1, %3), %%mm1 \n\t"
768 "movq (%1, %%"REG_a"), %%mm0 \n\t"
769 PAVGB" 1(%1, %3), %%mm1 \n\t"
770 PAVGB" 1(%1, %%"REG_a"), %%mm0 \n\t"
771 "add %%"REG_a", %2 \n\t"
772 "add %%"REG_a", %1 \n\t"
773 PAVGB" %%mm1, %%mm2 \n\t"
774 PAVGB" %%mm0, %%mm1 \n\t"
775 PAVGB" (%2), %%mm2 \n\t"
776 PAVGB" (%2, %3), %%mm1 \n\t"
777 "movq %%mm2, (%2) \n\t"
778 "movq %%mm1, (%2, %3) \n\t"
779 "add %%"REG_a", %2 \n\t"
782 :"+g"(h), "+S"(pixels), "+D"(block)
783 :"r" ((long)line_size)
784 :"%"REG_a, "memory");
787 //FIXME the following could be optimized too ...
788 static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
789 DEF(put_no_rnd_pixels8_x2)(block , pixels , line_size, h);
790 DEF(put_no_rnd_pixels8_x2)(block+8, pixels+8, line_size, h);
792 static void DEF(put_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
793 DEF(put_pixels8_y2)(block , pixels , line_size, h);
794 DEF(put_pixels8_y2)(block+8, pixels+8, line_size, h);
796 static void DEF(put_no_rnd_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
797 DEF(put_no_rnd_pixels8_y2)(block , pixels , line_size, h);
798 DEF(put_no_rnd_pixels8_y2)(block+8, pixels+8, line_size, h);
800 static void DEF(avg_pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
801 DEF(avg_pixels8)(block , pixels , line_size, h);
802 DEF(avg_pixels8)(block+8, pixels+8, line_size, h);
804 static void DEF(avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
805 DEF(avg_pixels8_x2)(block , pixels , line_size, h);
806 DEF(avg_pixels8_x2)(block+8, pixels+8, line_size, h);
808 static void DEF(avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
809 DEF(avg_pixels8_y2)(block , pixels , line_size, h);
810 DEF(avg_pixels8_y2)(block+8, pixels+8, line_size, h);
812 static void DEF(avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
813 DEF(avg_pixels8_xy2)(block , pixels , line_size, h);
814 DEF(avg_pixels8_xy2)(block+8, pixels+8, line_size, h);