[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 430 - (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 : chl 430 ; * This program is an implementation of a part of one or more MPEG-4
9 :     ; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
10 :     ; * to use this software module in hardware or software products are
11 :     ; * advised that its use may infringe existing patents or copyrights, and
12 :     ; * any such use would be at such party's own risk. The original
13 :     ; * developer of this software module and his/her company, and subsequent
14 :     ; * editors and their companies, will have no liability for use of this
15 :     ; * software or modifications or derivatives thereof.
16 : Isibaar 262 ; *
17 : chl 430 ; * This program is free software; you can redistribute it and/or modify
18 :     ; * it under the terms of the GNU General Public License as published by
19 :     ; * the Free Software Foundation; either version 2 of the License, or
20 :     ; * (at your option) any later version.
21 : Isibaar 262 ; *
22 : chl 430 ; * This program is distributed in the hope that it will be useful,
23 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 :     ; * GNU General Public License for more details.
26 : Isibaar 262 ; *
27 : chl 430 ; * You should have received a copy of the GNU General Public License
28 :     ; * along with this program; if not, write to the Free Software
29 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 : Isibaar 262 ; *
31 : chl 430 , ****************************************************************************/
32 : Isibaar 262
33 :     bits 32
34 :    
35 :     %macro cglobal 1
36 : suxen_drol 329 %ifdef PREFIX
37 : Isibaar 262 global _%1
38 :     %define %1 _%1
39 :     %else
40 :     global %1
41 :     %endif
42 :     %endmacro
43 :    
44 :     section .data
45 :    
46 :     align 16
47 :     mmx_one times 4 dw 1
48 :    
49 :     section .text
50 :    
51 :     cglobal sad16_mmx
52 :     cglobal sad8_mmx
53 :     cglobal sad16bi_mmx
54 :     cglobal sad8bi_mmx
55 :     cglobal dev16_mmx
56 :    
57 :     ;===========================================================================
58 :     ;
59 :     ; uint32_t sad16_mmx(const uint8_t * const cur,
60 :     ; const uint8_t * const ref,
61 :     ; const uint32_t stride,
62 : suxen_drol 329 ; const uint32_t best_sad);
63 :     ;
64 : Isibaar 262 ; (early termination ignore; slows this down)
65 :     ;
66 :     ;===========================================================================
67 :    
68 :     %macro SAD_16x16_MMX 0
69 :     movq mm0, [eax]
70 :     movq mm1, [edx]
71 :    
72 :     movq mm2, [eax+8]
73 :     movq mm3, [edx+8]
74 :    
75 :     movq mm4, mm0
76 :     psubusb mm0, mm1
77 :     lea eax,[eax+ecx]
78 :     movq mm5, mm2
79 :     psubusb mm2, mm3
80 :     lea edx,[edx+ecx]
81 :    
82 :     psubusb mm1, mm4
83 :     por mm0, mm1
84 :     psubusb mm3, mm5
85 :     por mm2, mm3
86 :    
87 :     movq mm1,mm0
88 :     movq mm3,mm2
89 :    
90 :     punpcklbw mm0,mm7
91 :     punpckhbw mm1,mm7
92 :     punpcklbw mm2,mm7
93 :     punpckhbw mm3,mm7
94 :    
95 :     paddusw mm0,mm1
96 :     paddusw mm6,mm0
97 :     paddusw mm2,mm3
98 :     paddusw mm6,mm2
99 :     %endmacro
100 :    
101 :     align 16
102 :     sad16_mmx:
103 :    
104 :     mov eax, [esp+ 4] ; Src1
105 :     mov edx, [esp+ 8] ; Src2
106 :     mov ecx, [esp+12] ; Stride
107 :    
108 :     pxor mm6, mm6 ; accum
109 :     pxor mm7, mm7 ; zero
110 :    
111 :     SAD_16x16_MMX
112 :     SAD_16x16_MMX
113 :     SAD_16x16_MMX
114 :     SAD_16x16_MMX
115 :     SAD_16x16_MMX
116 :     SAD_16x16_MMX
117 :     SAD_16x16_MMX
118 :     SAD_16x16_MMX
119 :    
120 :     SAD_16x16_MMX
121 :     SAD_16x16_MMX
122 :     SAD_16x16_MMX
123 :     SAD_16x16_MMX
124 :     SAD_16x16_MMX
125 :     SAD_16x16_MMX
126 :     SAD_16x16_MMX
127 :     SAD_16x16_MMX
128 :    
129 :     pmaddwd mm6, [mmx_one] ; collapse
130 :     movq mm7, mm6
131 :     psrlq mm7, 32
132 :     paddd mm6, mm7
133 :    
134 :     movd eax, mm6
135 :    
136 :     ret
137 :    
138 :    
139 :     ;===========================================================================
140 :     ;
141 :     ; uint32_t sad8_mmx(const uint8_t * const cur,
142 :     ; const uint8_t * const ref,
143 :     ; const uint32_t stride);
144 :     ;
145 :     ;===========================================================================
146 :    
147 :     %macro SAD_8x8_MMX 0
148 :     movq mm0, [eax]
149 :     movq mm1, [edx]
150 :    
151 :     movq mm2, [eax+ecx]
152 :     movq mm3, [edx+ecx]
153 :    
154 :     lea eax,[eax+2*ecx]
155 :     lea edx,[edx+2*ecx]
156 :    
157 :     movq mm4, mm0
158 :     psubusb mm0, mm1
159 :     movq mm5, mm2
160 :     psubusb mm2, mm3
161 :    
162 :     psubusb mm1, mm4
163 :     por mm0, mm1
164 :     psubusb mm3, mm5
165 :     por mm2, mm3
166 :    
167 :     movq mm1,mm0
168 :     movq mm3,mm2
169 :    
170 :     punpcklbw mm0,mm7
171 :     punpckhbw mm1,mm7
172 :     punpcklbw mm2,mm7
173 :     punpckhbw mm3,mm7
174 :    
175 :     paddusw mm0,mm1
176 :     paddusw mm6,mm0
177 :     paddusw mm2,mm3
178 :     paddusw mm6,mm2
179 :     %endmacro
180 :    
181 :     align 16
182 :     sad8_mmx:
183 :    
184 :     mov eax, [esp+ 4] ; Src1
185 :     mov edx, [esp+ 8] ; Src2
186 :     mov ecx, [esp+12] ; Stride
187 :    
188 :     pxor mm6, mm6 ; accum
189 :     pxor mm7, mm7 ; zero
190 :    
191 :     SAD_8x8_MMX
192 :     SAD_8x8_MMX
193 :     SAD_8x8_MMX
194 :     SAD_8x8_MMX
195 :    
196 :     pmaddwd mm6, [mmx_one] ; collapse
197 :     movq mm7, mm6
198 :     psrlq mm7, 32
199 :     paddd mm6, mm7
200 :    
201 :     movd eax, mm6
202 :    
203 :     ret
204 :    
205 :    
206 :    
207 :    
208 :    
209 :     ;===========================================================================
210 :     ;
211 :     ; uint32_t sad16bi_mmx(const uint8_t * const cur,
212 :     ; const uint8_t * const ref1,
213 : suxen_drol 329 ; const uint8_t * const ref2,
214 :     ; const uint32_t stride);
215 :     ;
216 :     ;===========================================================================
217 :     %macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
218 :    
219 :     movq mm0, [edx+%1]
220 :     movq mm2, [ebx+%1]
221 :     movq mm1, mm0
222 :     movq mm3, mm2
223 :    
224 :     %if %2 != 0
225 :     add edx, ecx
226 :     %endif
227 :    
228 :     punpcklbw mm0, mm7
229 :     punpckhbw mm1, mm7
230 :     punpcklbw mm2, mm7
231 :     punpckhbw mm3, mm7
232 :    
233 :     %if %2 != 0
234 :     add ebx, ecx
235 :     %endif
236 :    
237 :     paddusw mm0, mm2 ; mm01 = ref1 + ref2
238 :     paddusw mm1, mm3
239 :     paddusw mm0, [mmx_one] ; mm01 += 1
240 :     paddusw mm1, [mmx_one]
241 :     psrlw mm0, 1 ; mm01 >>= 1
242 :     psrlw mm1, 1
243 :    
244 :     movq mm2, [eax+%1]
245 :     movq mm3, mm2
246 :     punpcklbw mm2, mm7 ; mm23 = src
247 :     punpckhbw mm3, mm7
248 :    
249 :     %if %2 != 0
250 :     add eax, ecx
251 :     %endif
252 :    
253 :     movq mm4, mm0
254 :     movq mm5, mm1
255 :     psubusw mm0, mm2
256 :     psubusw mm1, mm3
257 :     psubusw mm2, mm4
258 :     psubusw mm3, mm5
259 :     por mm0, mm2 ; mm01 = ABS(mm01 - mm23)
260 :     por mm1, mm3
261 :    
262 :     paddusw mm6,mm0 ; mm6 += mm01
263 :     paddusw mm6,mm1
264 :    
265 :     %endmacro
266 :    
267 :     align 16
268 :     sad16bi_mmx:
269 :     push ebx
270 :     mov eax, [esp+4+ 4] ; Src
271 :     mov edx, [esp+4+ 8] ; Ref1
272 :     mov ebx, [esp+4+12] ; Ref2
273 :     mov ecx, [esp+4+16] ; Stride
274 :    
275 :     pxor mm6, mm6 ; accum2
276 :     pxor mm7, mm7
277 :     .Loop
278 :     SADBI_16x16_MMX 0, 0
279 :     SADBI_16x16_MMX 8, 1
280 :     SADBI_16x16_MMX 0, 0
281 :     SADBI_16x16_MMX 8, 1
282 :     SADBI_16x16_MMX 0, 0
283 :     SADBI_16x16_MMX 8, 1
284 :     SADBI_16x16_MMX 0, 0
285 :     SADBI_16x16_MMX 8, 1
286 :     SADBI_16x16_MMX 0, 0
287 :     SADBI_16x16_MMX 8, 1
288 :     SADBI_16x16_MMX 0, 0
289 :     SADBI_16x16_MMX 8, 1
290 :     SADBI_16x16_MMX 0, 0
291 :     SADBI_16x16_MMX 8, 1
292 :     SADBI_16x16_MMX 0, 0
293 :     SADBI_16x16_MMX 8, 1
294 :    
295 :     SADBI_16x16_MMX 0, 0
296 :     SADBI_16x16_MMX 8, 1
297 :     SADBI_16x16_MMX 0, 0
298 :     SADBI_16x16_MMX 8, 1
299 :     SADBI_16x16_MMX 0, 0
300 :     SADBI_16x16_MMX 8, 1
301 :     SADBI_16x16_MMX 0, 0
302 :     SADBI_16x16_MMX 8, 1
303 :     SADBI_16x16_MMX 0, 0
304 :     SADBI_16x16_MMX 8, 1
305 :     SADBI_16x16_MMX 0, 0
306 :     SADBI_16x16_MMX 8, 1
307 :     SADBI_16x16_MMX 0, 0
308 :     SADBI_16x16_MMX 8, 1
309 :     SADBI_16x16_MMX 0, 0
310 :     SADBI_16x16_MMX 8, 1
311 :    
312 :     pmaddwd mm6, [mmx_one] ; collapse
313 :     movq mm7, mm6
314 :     psrlq mm7, 32
315 :     paddd mm6, mm7
316 :    
317 :     movd eax, mm6
318 :     pop ebx
319 :     ret
320 :    
321 :     ;===========================================================================
322 :     ;
323 :     ; uint32_t sad8bi_mmx(const uint8_t * const cur,
324 :     ; const uint8_t * const ref1,
325 :     ; const uint8_t * const ref2,
326 :     ; const uint32_t stride);
327 :     ;
328 :     ;===========================================================================
329 :     align 16
330 :     sad8bi_mmx:
331 :     push ebx
332 :     mov eax, [esp+4+ 4] ; Src
333 :     mov edx, [esp+4+ 8] ; Ref1
334 :     mov ebx, [esp+4+12] ; Ref2
335 :     mov ecx, [esp+4+16] ; Stride
336 :    
337 :     pxor mm6, mm6 ; accum2
338 :     pxor mm7, mm7
339 :     .Loop
340 :     SADBI_16x16_MMX 0, 1
341 :     SADBI_16x16_MMX 0, 1
342 :     SADBI_16x16_MMX 0, 1
343 :     SADBI_16x16_MMX 0, 1
344 :     SADBI_16x16_MMX 0, 1
345 :     SADBI_16x16_MMX 0, 1
346 :     SADBI_16x16_MMX 0, 1
347 :     SADBI_16x16_MMX 0, 1
348 :    
349 :     pmaddwd mm6, [mmx_one] ; collapse
350 :     movq mm7, mm6
351 :     psrlq mm7, 32
352 :     paddd mm6, mm7
353 :    
354 :     movd eax, mm6
355 :     pop ebx
356 :     ret
357 :    
358 :    
359 :    
360 :    
361 :     ;===========================================================================
362 :     ;
363 :     ; uint32_t dev16_mmx(const uint8_t * const cur,
364 :     ; const uint32_t stride);
365 :     ;
366 :     ;===========================================================================
367 :    
368 :     %macro MEAN_16x16_MMX 0
369 : Isibaar 262 movq mm0, [eax]
370 :     movq mm2, [eax+8]
371 :     lea eax,[eax+ecx]
372 :     movq mm1, mm0
373 :     movq mm3, mm2
374 :     punpcklbw mm0,mm7
375 :     punpcklbw mm2,mm7
376 :     punpckhbw mm1,mm7
377 :     punpckhbw mm3,mm7
378 :     paddw mm5, mm0
379 :     paddw mm6, mm1
380 :     paddw mm5, mm2
381 :     paddw mm6, mm3
382 :     %endmacro
383 :    
384 :     %macro ABS_16x16_MMX 0
385 :     movq mm0, [eax]
386 :     movq mm2, [eax+8]
387 :     lea eax,[eax+ecx]
388 :     movq mm1, mm0
389 :     movq mm3, mm2
390 :     punpcklbw mm0, mm7
391 :     punpcklbw mm2, mm7
392 :     punpckhbw mm1, mm7
393 :     punpckhbw mm3, mm7
394 :     movq mm4, mm6
395 :     psubusw mm4, mm0
396 :    
397 :     psubusw mm0, mm6
398 :     por mm0, mm4
399 :     movq mm4, mm6
400 :     psubusw mm4, mm1
401 :     psubusw mm1, mm6
402 :     por mm1, mm4
403 :    
404 :     movq mm4, mm6
405 :     psubusw mm4, mm2
406 :     psubusw mm2, mm6
407 :     por mm2, mm4
408 :     movq mm4, mm6
409 :     psubusw mm4, mm3
410 :     psubusw mm3, mm6
411 :     por mm3, mm4
412 :    
413 :     paddw mm0, mm1
414 :     paddw mm2, mm3
415 :     paddw mm5, mm0
416 :     paddw mm5, mm2
417 :     %endmacro
418 :    
419 :     align 16
420 :     dev16_mmx:
421 :     mov eax, [esp+ 4] ; Src
422 :     mov ecx, [esp+ 8] ; Stride
423 :    
424 :     pxor mm7, mm7 ; zero
425 :     pxor mm5, mm5 ; accum1
426 :     pxor mm6, mm6 ; accum2
427 :    
428 :     MEAN_16x16_MMX
429 :     MEAN_16x16_MMX
430 :     MEAN_16x16_MMX
431 :     MEAN_16x16_MMX
432 :     MEAN_16x16_MMX
433 :     MEAN_16x16_MMX
434 :     MEAN_16x16_MMX
435 :     MEAN_16x16_MMX
436 :    
437 :     MEAN_16x16_MMX
438 :     MEAN_16x16_MMX
439 :     MEAN_16x16_MMX
440 :     MEAN_16x16_MMX
441 :     MEAN_16x16_MMX
442 :     MEAN_16x16_MMX
443 :     MEAN_16x16_MMX
444 :     MEAN_16x16_MMX
445 :    
446 :     paddusw mm6, mm5
447 :     pmaddwd mm6, [mmx_one] ; collapse
448 :     movq mm5, mm6
449 :     psrlq mm5, 32
450 :     paddd mm6, mm5
451 :    
452 :     psllq mm6, 32 ; blank upper dword
453 :     psrlq mm6, 32 + 8 ; /= (16*16)
454 :    
455 :     punpckldq mm6, mm6
456 :     packssdw mm6, mm6
457 :    
458 :     ; mm6 contains the mean
459 :     ; mm5 is the new accum
460 :    
461 :     pxor mm5, mm5
462 :     mov eax, [esp+ 4] ; Src
463 :    
464 :     ABS_16x16_MMX
465 :     ABS_16x16_MMX
466 :     ABS_16x16_MMX
467 :     ABS_16x16_MMX
468 :     ABS_16x16_MMX
469 :     ABS_16x16_MMX
470 :     ABS_16x16_MMX
471 :     ABS_16x16_MMX
472 :    
473 :     ABS_16x16_MMX
474 :     ABS_16x16_MMX
475 :     ABS_16x16_MMX
476 :     ABS_16x16_MMX
477 :     ABS_16x16_MMX
478 :     ABS_16x16_MMX
479 :     ABS_16x16_MMX
480 :     ABS_16x16_MMX
481 :    
482 :     pmaddwd mm5, [mmx_one] ; collapse
483 :     movq mm6, mm5
484 :     psrlq mm6, 32
485 :     paddd mm6, mm5
486 :    
487 :     movd eax, mm6
488 : chl 430 ret
489 :    

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