Add missing multiple inclusion guards.
[libav.git] / libavcodec / i386 / dsputil_mmx_rnd.h
1 /*
2 * DSP utils mmx functions are compiled twice for rnd/no_rnd
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 * Copyright (c) 2003-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
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 *
10 * This file is part of FFmpeg.
11 *
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.
16 *
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.
21 *
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
25 */
26
27 #ifndef FFMPEG_DSPUTIL_MMX_RND_H
28 #define FFMPEG_DSPUTIL_MMX_RND_H
29
30 // put_pixels
31 static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
32 {
33 MOVQ_BFE(mm6);
34 __asm __volatile(
35 "lea (%3, %3), %%"REG_a" \n\t"
36 ASMALIGN(3)
37 "1: \n\t"
38 "movq (%1), %%mm0 \n\t"
39 "movq 1(%1), %%mm1 \n\t"
40 "movq (%1, %3), %%mm2 \n\t"
41 "movq 1(%1, %3), %%mm3 \n\t"
42 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
43 "movq %%mm4, (%2) \n\t"
44 "movq %%mm5, (%2, %3) \n\t"
45 "add %%"REG_a", %1 \n\t"
46 "add %%"REG_a", %2 \n\t"
47 "movq (%1), %%mm0 \n\t"
48 "movq 1(%1), %%mm1 \n\t"
49 "movq (%1, %3), %%mm2 \n\t"
50 "movq 1(%1, %3), %%mm3 \n\t"
51 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
52 "movq %%mm4, (%2) \n\t"
53 "movq %%mm5, (%2, %3) \n\t"
54 "add %%"REG_a", %1 \n\t"
55 "add %%"REG_a", %2 \n\t"
56 "subl $4, %0 \n\t"
57 "jnz 1b \n\t"
58 :"+g"(h), "+S"(pixels), "+D"(block)
59 :"r"((long)line_size)
60 :REG_a, "memory");
61 }
62
63 static void av_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
64 {
65 MOVQ_BFE(mm6);
66 __asm __volatile(
67 "testl $1, %0 \n\t"
68 " jz 1f \n\t"
69 "movq (%1), %%mm0 \n\t"
70 "movq (%2), %%mm1 \n\t"
71 "add %4, %1 \n\t"
72 "add $8, %2 \n\t"
73 PAVGB(%%mm0, %%mm1, %%mm4, %%mm6)
74 "movq %%mm4, (%3) \n\t"
75 "add %5, %3 \n\t"
76 "decl %0 \n\t"
77 ASMALIGN(3)
78 "1: \n\t"
79 "movq (%1), %%mm0 \n\t"
80 "movq (%2), %%mm1 \n\t"
81 "add %4, %1 \n\t"
82 "movq (%1), %%mm2 \n\t"
83 "movq 8(%2), %%mm3 \n\t"
84 "add %4, %1 \n\t"
85 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
86 "movq %%mm4, (%3) \n\t"
87 "add %5, %3 \n\t"
88 "movq %%mm5, (%3) \n\t"
89 "add %5, %3 \n\t"
90 "movq (%1), %%mm0 \n\t"
91 "movq 16(%2), %%mm1 \n\t"
92 "add %4, %1 \n\t"
93 "movq (%1), %%mm2 \n\t"
94 "movq 24(%2), %%mm3 \n\t"
95 "add %4, %1 \n\t"
96 "add $32, %2 \n\t"
97 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
98 "movq %%mm4, (%3) \n\t"
99 "add %5, %3 \n\t"
100 "movq %%mm5, (%3) \n\t"
101 "add %5, %3 \n\t"
102 "subl $4, %0 \n\t"
103 "jnz 1b \n\t"
104 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
105 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
106 #else
107 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
108 #endif
109 :"S"((long)src1Stride), "D"((long)dstStride)
110 :"memory");
111 }
112
113 static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
114 {
115 MOVQ_BFE(mm6);
116 __asm __volatile(
117 "lea (%3, %3), %%"REG_a" \n\t"
118 ASMALIGN(3)
119 "1: \n\t"
120 "movq (%1), %%mm0 \n\t"
121 "movq 1(%1), %%mm1 \n\t"
122 "movq (%1, %3), %%mm2 \n\t"
123 "movq 1(%1, %3), %%mm3 \n\t"
124 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
125 "movq %%mm4, (%2) \n\t"
126 "movq %%mm5, (%2, %3) \n\t"
127 "movq 8(%1), %%mm0 \n\t"
128 "movq 9(%1), %%mm1 \n\t"
129 "movq 8(%1, %3), %%mm2 \n\t"
130 "movq 9(%1, %3), %%mm3 \n\t"
131 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
132 "movq %%mm4, 8(%2) \n\t"
133 "movq %%mm5, 8(%2, %3) \n\t"
134 "add %%"REG_a", %1 \n\t"
135 "add %%"REG_a", %2 \n\t"
136 "movq (%1), %%mm0 \n\t"
137 "movq 1(%1), %%mm1 \n\t"
138 "movq (%1, %3), %%mm2 \n\t"
139 "movq 1(%1, %3), %%mm3 \n\t"
140 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
141 "movq %%mm4, (%2) \n\t"
142 "movq %%mm5, (%2, %3) \n\t"
143 "movq 8(%1), %%mm0 \n\t"
144 "movq 9(%1), %%mm1 \n\t"
145 "movq 8(%1, %3), %%mm2 \n\t"
146 "movq 9(%1, %3), %%mm3 \n\t"
147 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
148 "movq %%mm4, 8(%2) \n\t"
149 "movq %%mm5, 8(%2, %3) \n\t"
150 "add %%"REG_a", %1 \n\t"
151 "add %%"REG_a", %2 \n\t"
152 "subl $4, %0 \n\t"
153 "jnz 1b \n\t"
154 :"+g"(h), "+S"(pixels), "+D"(block)
155 :"r"((long)line_size)
156 :REG_a, "memory");
157 }
158
159 static void av_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
160 {
161 MOVQ_BFE(mm6);
162 __asm __volatile(
163 "testl $1, %0 \n\t"
164 " jz 1f \n\t"
165 "movq (%1), %%mm0 \n\t"
166 "movq (%2), %%mm1 \n\t"
167 "movq 8(%1), %%mm2 \n\t"
168 "movq 8(%2), %%mm3 \n\t"
169 "add %4, %1 \n\t"
170 "add $16, %2 \n\t"
171 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
172 "movq %%mm4, (%3) \n\t"
173 "movq %%mm5, 8(%3) \n\t"
174 "add %5, %3 \n\t"
175 "decl %0 \n\t"
176 ASMALIGN(3)
177 "1: \n\t"
178 "movq (%1), %%mm0 \n\t"
179 "movq (%2), %%mm1 \n\t"
180 "movq 8(%1), %%mm2 \n\t"
181 "movq 8(%2), %%mm3 \n\t"
182 "add %4, %1 \n\t"
183 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
184 "movq %%mm4, (%3) \n\t"
185 "movq %%mm5, 8(%3) \n\t"
186 "add %5, %3 \n\t"
187 "movq (%1), %%mm0 \n\t"
188 "movq 16(%2), %%mm1 \n\t"
189 "movq 8(%1), %%mm2 \n\t"
190 "movq 24(%2), %%mm3 \n\t"
191 "add %4, %1 \n\t"
192 PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
193 "movq %%mm4, (%3) \n\t"
194 "movq %%mm5, 8(%3) \n\t"
195 "add %5, %3 \n\t"
196 "add $32, %2 \n\t"
197 "subl $2, %0 \n\t"
198 "jnz 1b \n\t"
199 #ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used
200 :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
201 #else
202 :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
203 #endif
204 :"S"((long)src1Stride), "D"((long)dstStride)
205 :"memory");
206 }
207
208 static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
209 {
210 MOVQ_BFE(mm6);
211 __asm __volatile(
212 "lea (%3, %3), %%"REG_a" \n\t"
213 "movq (%1), %%mm0 \n\t"
214 ASMALIGN(3)
215 "1: \n\t"
216 "movq (%1, %3), %%mm1 \n\t"
217 "movq (%1, %%"REG_a"),%%mm2 \n\t"
218 PAVGBP(%%mm1, %%mm0, %%mm4, %%mm2, %%mm1, %%mm5)
219 "movq %%mm4, (%2) \n\t"
220 "movq %%mm5, (%2, %3) \n\t"
221 "add %%"REG_a", %1 \n\t"
222 "add %%"REG_a", %2 \n\t"
223 "movq (%1, %3), %%mm1 \n\t"
224 "movq (%1, %%"REG_a"),%%mm0 \n\t"
225 PAVGBP(%%mm1, %%mm2, %%mm4, %%mm0, %%mm1, %%mm5)
226 "movq %%mm4, (%2) \n\t"
227 "movq %%mm5, (%2, %3) \n\t"
228 "add %%"REG_a", %1 \n\t"
229 "add %%"REG_a", %2 \n\t"
230 "subl $4, %0 \n\t"
231 "jnz 1b \n\t"
232 :"+g"(h), "+S"(pixels), "+D"(block)
233 :"r"((long)line_size)
234 :REG_a, "memory");
235 }
236
237 static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
238 {
239 MOVQ_ZERO(mm7);
240 SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
241 __asm __volatile(
242 "movq (%1), %%mm0 \n\t"
243 "movq 1(%1), %%mm4 \n\t"
244 "movq %%mm0, %%mm1 \n\t"
245 "movq %%mm4, %%mm5 \n\t"
246 "punpcklbw %%mm7, %%mm0 \n\t"
247 "punpcklbw %%mm7, %%mm4 \n\t"
248 "punpckhbw %%mm7, %%mm1 \n\t"
249 "punpckhbw %%mm7, %%mm5 \n\t"
250 "paddusw %%mm0, %%mm4 \n\t"
251 "paddusw %%mm1, %%mm5 \n\t"
252 "xor %%"REG_a", %%"REG_a" \n\t"
253 "add %3, %1 \n\t"
254 ASMALIGN(3)
255 "1: \n\t"
256 "movq (%1, %%"REG_a"), %%mm0 \n\t"
257 "movq 1(%1, %%"REG_a"), %%mm2 \n\t"
258 "movq %%mm0, %%mm1 \n\t"
259 "movq %%mm2, %%mm3 \n\t"
260 "punpcklbw %%mm7, %%mm0 \n\t"
261 "punpcklbw %%mm7, %%mm2 \n\t"
262 "punpckhbw %%mm7, %%mm1 \n\t"
263 "punpckhbw %%mm7, %%mm3 \n\t"
264 "paddusw %%mm2, %%mm0 \n\t"
265 "paddusw %%mm3, %%mm1 \n\t"
266 "paddusw %%mm6, %%mm4 \n\t"
267 "paddusw %%mm6, %%mm5 \n\t"
268 "paddusw %%mm0, %%mm4 \n\t"
269 "paddusw %%mm1, %%mm5 \n\t"
270 "psrlw $2, %%mm4 \n\t"
271 "psrlw $2, %%mm5 \n\t"
272 "packuswb %%mm5, %%mm4 \n\t"
273 "movq %%mm4, (%2, %%"REG_a") \n\t"
274 "add %3, %%"REG_a" \n\t"
275
276 "movq (%1, %%"REG_a"), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
277 "movq 1(%1, %%"REG_a"), %%mm4 \n\t"
278 "movq %%mm2, %%mm3 \n\t"
279 "movq %%mm4, %%mm5 \n\t"
280 "punpcklbw %%mm7, %%mm2 \n\t"
281 "punpcklbw %%mm7, %%mm4 \n\t"
282 "punpckhbw %%mm7, %%mm3 \n\t"
283 "punpckhbw %%mm7, %%mm5 \n\t"
284 "paddusw %%mm2, %%mm4 \n\t"
285 "paddusw %%mm3, %%mm5 \n\t"
286 "paddusw %%mm6, %%mm0 \n\t"
287 "paddusw %%mm6, %%mm1 \n\t"
288 "paddusw %%mm4, %%mm0 \n\t"
289 "paddusw %%mm5, %%mm1 \n\t"
290 "psrlw $2, %%mm0 \n\t"
291 "psrlw $2, %%mm1 \n\t"
292 "packuswb %%mm1, %%mm0 \n\t"
293 "movq %%mm0, (%2, %%"REG_a") \n\t"
294 "add %3, %%"REG_a" \n\t"
295
296 "subl $2, %0 \n\t"
297 "jnz 1b \n\t"
298 :"+g"(h), "+S"(pixels)
299 :"D"(block), "r"((long)line_size)
300 :REG_a, "memory");
301 }
302
303 // avg_pixels
304 static void av_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
305 {
306 MOVQ_BFE(mm6);
307 JUMPALIGN();
308 do {
309 __asm __volatile(
310 "movd %0, %%mm0 \n\t"
311 "movd %1, %%mm1 \n\t"
312 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
313 "movd %%mm2, %0 \n\t"
314 :"+m"(*block)
315 :"m"(*pixels)
316 :"memory");
317 pixels += line_size;
318 block += line_size;
319 }
320 while (--h);
321 }
322
323 // in case more speed is needed - unroling would certainly help
324 static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
325 {
326 MOVQ_BFE(mm6);
327 JUMPALIGN();
328 do {
329 __asm __volatile(
330 "movq %0, %%mm0 \n\t"
331 "movq %1, %%mm1 \n\t"
332 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
333 "movq %%mm2, %0 \n\t"
334 :"+m"(*block)
335 :"m"(*pixels)
336 :"memory");
337 pixels += line_size;
338 block += line_size;
339 }
340 while (--h);
341 }
342
343 static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
344 {
345 MOVQ_BFE(mm6);
346 JUMPALIGN();
347 do {
348 __asm __volatile(
349 "movq %0, %%mm0 \n\t"
350 "movq %1, %%mm1 \n\t"
351 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
352 "movq %%mm2, %0 \n\t"
353 "movq 8%0, %%mm0 \n\t"
354 "movq 8%1, %%mm1 \n\t"
355 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
356 "movq %%mm2, 8%0 \n\t"
357 :"+m"(*block)
358 :"m"(*pixels)
359 :"memory");
360 pixels += line_size;
361 block += line_size;
362 }
363 while (--h);
364 }
365
366 static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
367 {
368 MOVQ_BFE(mm6);
369 JUMPALIGN();
370 do {
371 __asm __volatile(
372 "movq %1, %%mm0 \n\t"
373 "movq 1%1, %%mm1 \n\t"
374 "movq %0, %%mm3 \n\t"
375 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
376 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
377 "movq %%mm0, %0 \n\t"
378 :"+m"(*block)
379 :"m"(*pixels)
380 :"memory");
381 pixels += line_size;
382 block += line_size;
383 } while (--h);
384 }
385
386 static av_unused void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
387 {
388 MOVQ_BFE(mm6);
389 JUMPALIGN();
390 do {
391 __asm __volatile(
392 "movq %1, %%mm0 \n\t"
393 "movq %2, %%mm1 \n\t"
394 "movq %0, %%mm3 \n\t"
395 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
396 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
397 "movq %%mm0, %0 \n\t"
398 :"+m"(*dst)
399 :"m"(*src1), "m"(*src2)
400 :"memory");
401 dst += dstStride;
402 src1 += src1Stride;
403 src2 += 8;
404 } while (--h);
405 }
406
407 static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
408 {
409 MOVQ_BFE(mm6);
410 JUMPALIGN();
411 do {
412 __asm __volatile(
413 "movq %1, %%mm0 \n\t"
414 "movq 1%1, %%mm1 \n\t"
415 "movq %0, %%mm3 \n\t"
416 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
417 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
418 "movq %%mm0, %0 \n\t"
419 "movq 8%1, %%mm0 \n\t"
420 "movq 9%1, %%mm1 \n\t"
421 "movq 8%0, %%mm3 \n\t"
422 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
423 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
424 "movq %%mm0, 8%0 \n\t"
425 :"+m"(*block)
426 :"m"(*pixels)
427 :"memory");
428 pixels += line_size;
429 block += line_size;
430 } while (--h);
431 }
432
433 static av_unused void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
434 {
435 MOVQ_BFE(mm6);
436 JUMPALIGN();
437 do {
438 __asm __volatile(
439 "movq %1, %%mm0 \n\t"
440 "movq %2, %%mm1 \n\t"
441 "movq %0, %%mm3 \n\t"
442 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
443 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
444 "movq %%mm0, %0 \n\t"
445 "movq 8%1, %%mm0 \n\t"
446 "movq 8%2, %%mm1 \n\t"
447 "movq 8%0, %%mm3 \n\t"
448 PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
449 PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
450 "movq %%mm0, 8%0 \n\t"
451 :"+m"(*dst)
452 :"m"(*src1), "m"(*src2)
453 :"memory");
454 dst += dstStride;
455 src1 += src1Stride;
456 src2 += 16;
457 } while (--h);
458 }
459
460 static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
461 {
462 MOVQ_BFE(mm6);
463 __asm __volatile(
464 "lea (%3, %3), %%"REG_a" \n\t"
465 "movq (%1), %%mm0 \n\t"
466 ASMALIGN(3)
467 "1: \n\t"
468 "movq (%1, %3), %%mm1 \n\t"
469 "movq (%1, %%"REG_a"), %%mm2 \n\t"
470 PAVGBP(%%mm1, %%mm0, %%mm4, %%mm2, %%mm1, %%mm5)
471 "movq (%2), %%mm3 \n\t"
472 PAVGB(%%mm3, %%mm4, %%mm0, %%mm6)
473 "movq (%2, %3), %%mm3 \n\t"
474 PAVGB(%%mm3, %%mm5, %%mm1, %%mm6)
475 "movq %%mm0, (%2) \n\t"
476 "movq %%mm1, (%2, %3) \n\t"
477 "add %%"REG_a", %1 \n\t"
478 "add %%"REG_a", %2 \n\t"
479
480 "movq (%1, %3), %%mm1 \n\t"
481 "movq (%1, %%"REG_a"), %%mm0 \n\t"
482 PAVGBP(%%mm1, %%mm2, %%mm4, %%mm0, %%mm1, %%mm5)
483 "movq (%2), %%mm3 \n\t"
484 PAVGB(%%mm3, %%mm4, %%mm2, %%mm6)
485 "movq (%2, %3), %%mm3 \n\t"
486 PAVGB(%%mm3, %%mm5, %%mm1, %%mm6)
487 "movq %%mm2, (%2) \n\t"
488 "movq %%mm1, (%2, %3) \n\t"
489 "add %%"REG_a", %1 \n\t"
490 "add %%"REG_a", %2 \n\t"
491
492 "subl $4, %0 \n\t"
493 "jnz 1b \n\t"
494 :"+g"(h), "+S"(pixels), "+D"(block)
495 :"r"((long)line_size)
496 :REG_a, "memory");
497 }
498
499 // this routine is 'slightly' suboptimal but mostly unused
500 static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
501 {
502 MOVQ_ZERO(mm7);
503 SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
504 __asm __volatile(
505 "movq (%1), %%mm0 \n\t"
506 "movq 1(%1), %%mm4 \n\t"
507 "movq %%mm0, %%mm1 \n\t"
508 "movq %%mm4, %%mm5 \n\t"
509 "punpcklbw %%mm7, %%mm0 \n\t"
510 "punpcklbw %%mm7, %%mm4 \n\t"
511 "punpckhbw %%mm7, %%mm1 \n\t"
512 "punpckhbw %%mm7, %%mm5 \n\t"
513 "paddusw %%mm0, %%mm4 \n\t"
514 "paddusw %%mm1, %%mm5 \n\t"
515 "xor %%"REG_a", %%"REG_a" \n\t"
516 "add %3, %1 \n\t"
517 ASMALIGN(3)
518 "1: \n\t"
519 "movq (%1, %%"REG_a"), %%mm0 \n\t"
520 "movq 1(%1, %%"REG_a"), %%mm2 \n\t"
521 "movq %%mm0, %%mm1 \n\t"
522 "movq %%mm2, %%mm3 \n\t"
523 "punpcklbw %%mm7, %%mm0 \n\t"
524 "punpcklbw %%mm7, %%mm2 \n\t"
525 "punpckhbw %%mm7, %%mm1 \n\t"
526 "punpckhbw %%mm7, %%mm3 \n\t"
527 "paddusw %%mm2, %%mm0 \n\t"
528 "paddusw %%mm3, %%mm1 \n\t"
529 "paddusw %%mm6, %%mm4 \n\t"
530 "paddusw %%mm6, %%mm5 \n\t"
531 "paddusw %%mm0, %%mm4 \n\t"
532 "paddusw %%mm1, %%mm5 \n\t"
533 "psrlw $2, %%mm4 \n\t"
534 "psrlw $2, %%mm5 \n\t"
535 "movq (%2, %%"REG_a"), %%mm3 \n\t"
536 "packuswb %%mm5, %%mm4 \n\t"
537 "pcmpeqd %%mm2, %%mm2 \n\t"
538 "paddb %%mm2, %%mm2 \n\t"
539 PAVGB(%%mm3, %%mm4, %%mm5, %%mm2)
540 "movq %%mm5, (%2, %%"REG_a") \n\t"
541 "add %3, %%"REG_a" \n\t"
542
543 "movq (%1, %%"REG_a"), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
544 "movq 1(%1, %%"REG_a"), %%mm4 \n\t"
545 "movq %%mm2, %%mm3 \n\t"
546 "movq %%mm4, %%mm5 \n\t"
547 "punpcklbw %%mm7, %%mm2 \n\t"
548 "punpcklbw %%mm7, %%mm4 \n\t"
549 "punpckhbw %%mm7, %%mm3 \n\t"
550 "punpckhbw %%mm7, %%mm5 \n\t"
551 "paddusw %%mm2, %%mm4 \n\t"
552 "paddusw %%mm3, %%mm5 \n\t"
553 "paddusw %%mm6, %%mm0 \n\t"
554 "paddusw %%mm6, %%mm1 \n\t"
555 "paddusw %%mm4, %%mm0 \n\t"
556 "paddusw %%mm5, %%mm1 \n\t"
557 "psrlw $2, %%mm0 \n\t"
558 "psrlw $2, %%mm1 \n\t"
559 "movq (%2, %%"REG_a"), %%mm3 \n\t"
560 "packuswb %%mm1, %%mm0 \n\t"
561 "pcmpeqd %%mm2, %%mm2 \n\t"
562 "paddb %%mm2, %%mm2 \n\t"
563 PAVGB(%%mm3, %%mm0, %%mm1, %%mm2)
564 "movq %%mm1, (%2, %%"REG_a") \n\t"
565 "add %3, %%"REG_a" \n\t"
566
567 "subl $2, %0 \n\t"
568 "jnz 1b \n\t"
569 :"+g"(h), "+S"(pixels)
570 :"D"(block), "r"((long)line_size)
571 :REG_a, "memory");
572 }
573
574 //FIXME optimize
575 static void DEF(put, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
576 DEF(put, pixels8_y2)(block , pixels , line_size, h);
577 DEF(put, pixels8_y2)(block+8, pixels+8, line_size, h);
578 }
579
580 static void DEF(put, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
581 DEF(put, pixels8_xy2)(block , pixels , line_size, h);
582 DEF(put, pixels8_xy2)(block+8, pixels+8, line_size, h);
583 }
584
585 static void DEF(avg, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
586 DEF(avg, pixels8_y2)(block , pixels , line_size, h);
587 DEF(avg, pixels8_y2)(block+8, pixels+8, line_size, h);
588 }
589
590 static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
591 DEF(avg, pixels8_xy2)(block , pixels , line_size, h);
592 DEF(avg, pixels8_xy2)(block+8, pixels+8, line_size, h);
593 }
594
595 #endif /* FFMPEG_DSPUTIL_MMX_RND_H */