[svn] / trunk / xvidcore / src / motion / x86_asm / sad_mmx.asm Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/motion/x86_asm/sad_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 652 - (view) (download)

1 : chl 430 ;/*****************************************************************************
2 : Isibaar 262 ; *
3 : chl 430 ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * mmx sum of absolute difference
5 : Isibaar 262 ; *
6 : chl 430 ; * Copyright(C) 2002 Peter Ross <pross@xvid.org>
7 : Isibaar 262 ; *
8 : edgomez 652 ; * This file is part of XviD, a free MPEG-4 video encoder/decoder
9 : Isibaar 262 ; *
10 : edgomez 652 ; * XviD is free software; you can redistribute it and/or modify it
11 :     ; * under the terms of the GNU General Public License as published by
12 : chl 430 ; * the Free Software Foundation; either version 2 of the License, or
13 :     ; * (at your option) any later version.
14 : Isibaar 262 ; *
15 : chl 430 ; * This program is distributed in the hope that it will be useful,
16 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     ; * GNU General Public License for more details.
19 : Isibaar 262 ; *
20 : chl 430 ; * You should have received a copy of the GNU General Public License
21 :     ; * along with this program; if not, write to the Free Software
22 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 : Isibaar 262 ; *
24 : edgomez 652 ; * Under section 8 of the GNU General Public License, the copyright
25 :     ; * holders of XVID explicitly forbid distribution in the following
26 :     ; * countries:
27 :     ; *
28 :     ; * - Japan
29 :     ; * - United States of America
30 :     ; *
31 :     ; * Linking XviD statically or dynamically with other modules is making a
32 :     ; * combined work based on XviD. Thus, the terms and conditions of the
33 :     ; * GNU General Public License cover the whole combination.
34 :     ; *
35 :     ; * As a special exception, the copyright holders of XviD give you
36 :     ; * permission to link XviD with independent modules that communicate with
37 :     ; * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
38 :     ; * license terms of these independent modules, and to copy and distribute
39 :     ; * the resulting combined work under terms of your choice, provided that
40 :     ; * every copy of the combined work is accompanied by a complete copy of
41 :     ; * the source code of XviD (the version of XviD used to produce the
42 :     ; * combined work), being distributed under the terms of the GNU General
43 :     ; * Public License plus this exception. An independent module is a module
44 :     ; * which is not derived from or based on XviD.
45 :     ; *
46 :     ; * Note that people who make modified versions of XviD are not obligated
47 :     ; * to grant this special exception for their modified versions; it is
48 :     ; * their choice whether to do so. The GNU General Public License gives
49 :     ; * permission to release a modified version without this exception; this
50 :     ; * exception also makes it possible to release a modified version which
51 :     ; * carries forward this exception.
52 :     ; *
53 :     ; * $Id: sad_mmx.asm,v 1.10 2002-11-17 00:32:06 edgomez Exp $
54 :     ; *
55 : chl 431 ; ****************************************************************************/
56 : Isibaar 262
57 :     bits 32
58 :    
59 :     %macro cglobal 1
60 : suxen_drol 329 %ifdef PREFIX
61 : Isibaar 262 global _%1
62 :     %define %1 _%1
63 :     %else
64 :     global %1
65 :     %endif
66 :     %endmacro
67 :    
68 :     section .data
69 :    
70 :     align 16
71 :     mmx_one times 4 dw 1
72 :    
73 :     section .text
74 :    
75 :     cglobal sad16_mmx
76 :     cglobal sad8_mmx
77 :     cglobal sad16bi_mmx
78 :     cglobal sad8bi_mmx
79 :     cglobal dev16_mmx
80 :    
81 :     ;===========================================================================
82 :     ;
83 :     ; uint32_t sad16_mmx(const uint8_t * const cur,
84 :     ; const uint8_t * const ref,
85 :     ; const uint32_t stride,
86 : suxen_drol 329 ; const uint32_t best_sad);
87 :     ;
88 : Isibaar 262 ; (early termination ignore; slows this down)
89 :     ;
90 :     ;===========================================================================
91 :    
92 :     %macro SAD_16x16_MMX 0
93 :     movq mm0, [eax]
94 :     movq mm1, [edx]
95 :    
96 :     movq mm2, [eax+8]
97 :     movq mm3, [edx+8]
98 :    
99 :     movq mm4, mm0
100 :     psubusb mm0, mm1
101 :     lea eax,[eax+ecx]
102 :     movq mm5, mm2
103 :     psubusb mm2, mm3
104 :     lea edx,[edx+ecx]
105 :    
106 :     psubusb mm1, mm4
107 :     por mm0, mm1
108 :     psubusb mm3, mm5
109 :     por mm2, mm3
110 :    
111 :     movq mm1,mm0
112 :     movq mm3,mm2
113 :    
114 :     punpcklbw mm0,mm7
115 :     punpckhbw mm1,mm7
116 :     punpcklbw mm2,mm7
117 :     punpckhbw mm3,mm7
118 :    
119 :     paddusw mm0,mm1
120 :     paddusw mm6,mm0
121 :     paddusw mm2,mm3
122 :     paddusw mm6,mm2
123 :     %endmacro
124 :    
125 :     align 16
126 :     sad16_mmx:
127 :    
128 :     mov eax, [esp+ 4] ; Src1
129 :     mov edx, [esp+ 8] ; Src2
130 :     mov ecx, [esp+12] ; Stride
131 :    
132 :     pxor mm6, mm6 ; accum
133 :     pxor mm7, mm7 ; zero
134 :    
135 :     SAD_16x16_MMX
136 :     SAD_16x16_MMX
137 :     SAD_16x16_MMX
138 :     SAD_16x16_MMX
139 :     SAD_16x16_MMX
140 :     SAD_16x16_MMX
141 :     SAD_16x16_MMX
142 :     SAD_16x16_MMX
143 :    
144 :     SAD_16x16_MMX
145 :     SAD_16x16_MMX
146 :     SAD_16x16_MMX
147 :     SAD_16x16_MMX
148 :     SAD_16x16_MMX
149 :     SAD_16x16_MMX
150 :     SAD_16x16_MMX
151 :     SAD_16x16_MMX
152 :    
153 :     pmaddwd mm6, [mmx_one] ; collapse
154 :     movq mm7, mm6
155 :     psrlq mm7, 32
156 :     paddd mm6, mm7
157 :    
158 :     movd eax, mm6
159 :    
160 :     ret
161 :    
162 :    
163 :     ;===========================================================================
164 :     ;
165 :     ; uint32_t sad8_mmx(const uint8_t * const cur,
166 :     ; const uint8_t * const ref,
167 :     ; const uint32_t stride);
168 :     ;
169 :     ;===========================================================================
170 :    
171 :     %macro SAD_8x8_MMX 0
172 :     movq mm0, [eax]
173 :     movq mm1, [edx]
174 :    
175 :     movq mm2, [eax+ecx]
176 :     movq mm3, [edx+ecx]
177 :    
178 :     lea eax,[eax+2*ecx]
179 :     lea edx,[edx+2*ecx]
180 :    
181 :     movq mm4, mm0
182 :     psubusb mm0, mm1
183 :     movq mm5, mm2
184 :     psubusb mm2, mm3
185 :    
186 :     psubusb mm1, mm4
187 :     por mm0, mm1
188 :     psubusb mm3, mm5
189 :     por mm2, mm3
190 :    
191 :     movq mm1,mm0
192 :     movq mm3,mm2
193 :    
194 :     punpcklbw mm0,mm7
195 :     punpckhbw mm1,mm7
196 :     punpcklbw mm2,mm7
197 :     punpckhbw mm3,mm7
198 :    
199 :     paddusw mm0,mm1
200 :     paddusw mm6,mm0
201 :     paddusw mm2,mm3
202 :     paddusw mm6,mm2
203 :     %endmacro
204 :    
205 :     align 16
206 :     sad8_mmx:
207 :    
208 :     mov eax, [esp+ 4] ; Src1
209 :     mov edx, [esp+ 8] ; Src2
210 :     mov ecx, [esp+12] ; Stride
211 :    
212 :     pxor mm6, mm6 ; accum
213 :     pxor mm7, mm7 ; zero
214 :    
215 :     SAD_8x8_MMX
216 :     SAD_8x8_MMX
217 :     SAD_8x8_MMX
218 :     SAD_8x8_MMX
219 :    
220 :     pmaddwd mm6, [mmx_one] ; collapse
221 :     movq mm7, mm6
222 :     psrlq mm7, 32
223 :     paddd mm6, mm7
224 :    
225 :     movd eax, mm6
226 :    
227 :     ret
228 :    
229 :    
230 :    
231 :    
232 :    
233 :     ;===========================================================================
234 :     ;
235 :     ; uint32_t sad16bi_mmx(const uint8_t * const cur,
236 :     ; const uint8_t * const ref1,
237 : suxen_drol 329 ; const uint8_t * const ref2,
238 :     ; const uint32_t stride);
239 :     ;
240 :     ;===========================================================================
241 :     %macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
242 :    
243 :     movq mm0, [edx+%1]
244 :     movq mm2, [ebx+%1]
245 :     movq mm1, mm0
246 :     movq mm3, mm2
247 :    
248 :     %if %2 != 0
249 :     add edx, ecx
250 :     %endif
251 :    
252 :     punpcklbw mm0, mm7
253 :     punpckhbw mm1, mm7
254 :     punpcklbw mm2, mm7
255 :     punpckhbw mm3, mm7
256 :    
257 :     %if %2 != 0
258 :     add ebx, ecx
259 :     %endif
260 :    
261 :     paddusw mm0, mm2 ; mm01 = ref1 + ref2
262 :     paddusw mm1, mm3
263 :     paddusw mm0, [mmx_one] ; mm01 += 1
264 :     paddusw mm1, [mmx_one]
265 :     psrlw mm0, 1 ; mm01 >>= 1
266 :     psrlw mm1, 1
267 :    
268 :     movq mm2, [eax+%1]
269 :     movq mm3, mm2
270 :     punpcklbw mm2, mm7 ; mm23 = src
271 :     punpckhbw mm3, mm7
272 :    
273 :     %if %2 != 0
274 :     add eax, ecx
275 :     %endif
276 :    
277 :     movq mm4, mm0
278 :     movq mm5, mm1
279 :     psubusw mm0, mm2
280 :     psubusw mm1, mm3
281 :     psubusw mm2, mm4
282 :     psubusw mm3, mm5
283 :     por mm0, mm2 ; mm01 = ABS(mm01 - mm23)
284 :     por mm1, mm3
285 :    
286 :     paddusw mm6,mm0 ; mm6 += mm01
287 :     paddusw mm6,mm1
288 :    
289 :     %endmacro
290 :    
291 :     align 16
292 :     sad16bi_mmx:
293 :     push ebx
294 :     mov eax, [esp+4+ 4] ; Src
295 :     mov edx, [esp+4+ 8] ; Ref1
296 :     mov ebx, [esp+4+12] ; Ref2
297 :     mov ecx, [esp+4+16] ; Stride
298 :    
299 :     pxor mm6, mm6 ; accum2
300 :     pxor mm7, mm7
301 :     .Loop
302 :     SADBI_16x16_MMX 0, 0
303 :     SADBI_16x16_MMX 8, 1
304 :     SADBI_16x16_MMX 0, 0
305 :     SADBI_16x16_MMX 8, 1
306 :     SADBI_16x16_MMX 0, 0
307 :     SADBI_16x16_MMX 8, 1
308 :     SADBI_16x16_MMX 0, 0
309 :     SADBI_16x16_MMX 8, 1
310 :     SADBI_16x16_MMX 0, 0
311 :     SADBI_16x16_MMX 8, 1
312 :     SADBI_16x16_MMX 0, 0
313 :     SADBI_16x16_MMX 8, 1
314 :     SADBI_16x16_MMX 0, 0
315 :     SADBI_16x16_MMX 8, 1
316 :     SADBI_16x16_MMX 0, 0
317 :     SADBI_16x16_MMX 8, 1
318 :    
319 :     SADBI_16x16_MMX 0, 0
320 :     SADBI_16x16_MMX 8, 1
321 :     SADBI_16x16_MMX 0, 0
322 :     SADBI_16x16_MMX 8, 1
323 :     SADBI_16x16_MMX 0, 0
324 :     SADBI_16x16_MMX 8, 1
325 :     SADBI_16x16_MMX 0, 0
326 :     SADBI_16x16_MMX 8, 1
327 :     SADBI_16x16_MMX 0, 0
328 :     SADBI_16x16_MMX 8, 1
329 :     SADBI_16x16_MMX 0, 0
330 :     SADBI_16x16_MMX 8, 1
331 :     SADBI_16x16_MMX 0, 0
332 :     SADBI_16x16_MMX 8, 1
333 :     SADBI_16x16_MMX 0, 0
334 :     SADBI_16x16_MMX 8, 1
335 :    
336 :     pmaddwd mm6, [mmx_one] ; collapse
337 :     movq mm7, mm6
338 :     psrlq mm7, 32
339 :     paddd mm6, mm7
340 :    
341 :     movd eax, mm6
342 :     pop ebx
343 :     ret
344 :    
345 :     ;===========================================================================
346 :     ;
347 :     ; uint32_t sad8bi_mmx(const uint8_t * const cur,
348 :     ; const uint8_t * const ref1,
349 :     ; const uint8_t * const ref2,
350 :     ; const uint32_t stride);
351 :     ;
352 :     ;===========================================================================
353 :     align 16
354 :     sad8bi_mmx:
355 :     push ebx
356 :     mov eax, [esp+4+ 4] ; Src
357 :     mov edx, [esp+4+ 8] ; Ref1
358 :     mov ebx, [esp+4+12] ; Ref2
359 :     mov ecx, [esp+4+16] ; Stride
360 :    
361 :     pxor mm6, mm6 ; accum2
362 :     pxor mm7, mm7
363 :     .Loop
364 :     SADBI_16x16_MMX 0, 1
365 :     SADBI_16x16_MMX 0, 1
366 :     SADBI_16x16_MMX 0, 1
367 :     SADBI_16x16_MMX 0, 1
368 :     SADBI_16x16_MMX 0, 1
369 :     SADBI_16x16_MMX 0, 1
370 :     SADBI_16x16_MMX 0, 1
371 :     SADBI_16x16_MMX 0, 1
372 :    
373 :     pmaddwd mm6, [mmx_one] ; collapse
374 :     movq mm7, mm6
375 :     psrlq mm7, 32
376 :     paddd mm6, mm7
377 :    
378 :     movd eax, mm6
379 :     pop ebx
380 :     ret
381 :    
382 :    
383 :    
384 :    
385 :     ;===========================================================================
386 :     ;
387 :     ; uint32_t dev16_mmx(const uint8_t * const cur,
388 :     ; const uint32_t stride);
389 :     ;
390 :     ;===========================================================================
391 :    
392 :     %macro MEAN_16x16_MMX 0
393 : Isibaar 262 movq mm0, [eax]
394 :     movq mm2, [eax+8]
395 :     lea eax,[eax+ecx]
396 :     movq mm1, mm0
397 :     movq mm3, mm2
398 :     punpcklbw mm0,mm7
399 :     punpcklbw mm2,mm7
400 :     punpckhbw mm1,mm7
401 :     punpckhbw mm3,mm7
402 :     paddw mm5, mm0
403 :     paddw mm6, mm1
404 :     paddw mm5, mm2
405 :     paddw mm6, mm3
406 :     %endmacro
407 :    
408 :     %macro ABS_16x16_MMX 0
409 :     movq mm0, [eax]
410 :     movq mm2, [eax+8]
411 :     lea eax,[eax+ecx]
412 :     movq mm1, mm0
413 :     movq mm3, mm2
414 :     punpcklbw mm0, mm7
415 :     punpcklbw mm2, mm7
416 :     punpckhbw mm1, mm7
417 :     punpckhbw mm3, mm7
418 :     movq mm4, mm6
419 :     psubusw mm4, mm0
420 :    
421 :     psubusw mm0, mm6
422 :     por mm0, mm4
423 :     movq mm4, mm6
424 :     psubusw mm4, mm1
425 :     psubusw mm1, mm6
426 :     por mm1, mm4
427 :    
428 :     movq mm4, mm6
429 :     psubusw mm4, mm2
430 :     psubusw mm2, mm6
431 :     por mm2, mm4
432 :     movq mm4, mm6
433 :     psubusw mm4, mm3
434 :     psubusw mm3, mm6
435 :     por mm3, mm4
436 :    
437 :     paddw mm0, mm1
438 :     paddw mm2, mm3
439 :     paddw mm5, mm0
440 :     paddw mm5, mm2
441 :     %endmacro
442 :    
443 :     align 16
444 :     dev16_mmx:
445 :     mov eax, [esp+ 4] ; Src
446 :     mov ecx, [esp+ 8] ; Stride
447 :    
448 :     pxor mm7, mm7 ; zero
449 :     pxor mm5, mm5 ; accum1
450 :     pxor mm6, mm6 ; accum2
451 :    
452 :     MEAN_16x16_MMX
453 :     MEAN_16x16_MMX
454 :     MEAN_16x16_MMX
455 :     MEAN_16x16_MMX
456 :     MEAN_16x16_MMX
457 :     MEAN_16x16_MMX
458 :     MEAN_16x16_MMX
459 :     MEAN_16x16_MMX
460 :    
461 :     MEAN_16x16_MMX
462 :     MEAN_16x16_MMX
463 :     MEAN_16x16_MMX
464 :     MEAN_16x16_MMX
465 :     MEAN_16x16_MMX
466 :     MEAN_16x16_MMX
467 :     MEAN_16x16_MMX
468 :     MEAN_16x16_MMX
469 :    
470 :     paddusw mm6, mm5
471 :     pmaddwd mm6, [mmx_one] ; collapse
472 :     movq mm5, mm6
473 :     psrlq mm5, 32
474 :     paddd mm6, mm5
475 :    
476 :     psllq mm6, 32 ; blank upper dword
477 :     psrlq mm6, 32 + 8 ; /= (16*16)
478 :    
479 :     punpckldq mm6, mm6
480 :     packssdw mm6, mm6
481 :    
482 :     ; mm6 contains the mean
483 :     ; mm5 is the new accum
484 :    
485 :     pxor mm5, mm5
486 :     mov eax, [esp+ 4] ; Src
487 :    
488 :     ABS_16x16_MMX
489 :     ABS_16x16_MMX
490 :     ABS_16x16_MMX
491 :     ABS_16x16_MMX
492 :     ABS_16x16_MMX
493 :     ABS_16x16_MMX
494 :     ABS_16x16_MMX
495 :     ABS_16x16_MMX
496 :    
497 :     ABS_16x16_MMX
498 :     ABS_16x16_MMX
499 :     ABS_16x16_MMX
500 :     ABS_16x16_MMX
501 :     ABS_16x16_MMX
502 :     ABS_16x16_MMX
503 :     ABS_16x16_MMX
504 :     ABS_16x16_MMX
505 :    
506 :     pmaddwd mm5, [mmx_one] ; collapse
507 :     movq mm6, mm5
508 :     psrlq mm6, 32
509 :     paddd mm6, mm5
510 :    
511 :     movd eax, mm6
512 : chl 430 ret
513 :    

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4