[svn] / branches / dev-api-4 / xvidcore / src / motion / x86_asm / sad_mmx.asm Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/motion/x86_asm/sad_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 329 - (view) (download)
Original Path: trunk/xvidcore/src/motion/x86_asm/sad_mmx.asm

1 : Isibaar 262 ;/**************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * mmx sum of absolute difference
5 :     ; *
6 :     ; * This program is free software; you can redistribute it and/or modify
7 :     ; * it under the terms of the GNU General Public License as published by
8 :     ; * the Free Software Foundation; either version 2 of the License, or
9 :     ; * (at your option) any later version.
10 :     ; *
11 :     ; * This program 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
14 :     ; * GNU General Public License for more details.
15 :     ; *
16 :     ; * You should have received a copy of the GNU General Public License
17 :     ; * along with this program; if not, write to the Free Software
18 :     ; * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 :     ; *
20 :     ; *************************************************************************/
21 :    
22 :     ;/**************************************************************************
23 :     ; *
24 :     ; * History:
25 :     ; *
26 :     ; * 23.07.2002 sad[16,8]bi_xmm; <pross@xvid.org>
27 :     ; * 04.06.2002 cleanup -Skal-
28 :     ; * 12.11.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
29 :     ; *
30 :     ; *************************************************************************/
31 :    
32 :     bits 32
33 :    
34 :     %macro cglobal 1
35 : suxen_drol 329 %ifdef PREFIX
36 : Isibaar 262 global _%1
37 :     %define %1 _%1
38 :     %else
39 :     global %1
40 :     %endif
41 :     %endmacro
42 :    
43 :     section .data
44 :    
45 :     align 16
46 :     mmx_one times 4 dw 1
47 :    
48 :     section .text
49 :    
50 :     cglobal sad16_mmx
51 :     cglobal sad8_mmx
52 :     cglobal sad16bi_mmx
53 :     cglobal sad8bi_mmx
54 :     cglobal dev16_mmx
55 :    
56 :     ;===========================================================================
57 :     ;
58 :     ; uint32_t sad16_mmx(const uint8_t * const cur,
59 :     ; const uint8_t * const ref,
60 :     ; const uint32_t stride,
61 : suxen_drol 329 ; const uint32_t best_sad);
62 :     ;
63 : Isibaar 262 ; (early termination ignore; slows this down)
64 :     ;
65 :     ;===========================================================================
66 :    
67 :     %macro SAD_16x16_MMX 0
68 :     movq mm0, [eax]
69 :     movq mm1, [edx]
70 :    
71 :     movq mm2, [eax+8]
72 :     movq mm3, [edx+8]
73 :    
74 :     movq mm4, mm0
75 :     psubusb mm0, mm1
76 :     lea eax,[eax+ecx]
77 :     movq mm5, mm2
78 :     psubusb mm2, mm3
79 :     lea edx,[edx+ecx]
80 :    
81 :     psubusb mm1, mm4
82 :     por mm0, mm1
83 :     psubusb mm3, mm5
84 :     por mm2, mm3
85 :    
86 :     movq mm1,mm0
87 :     movq mm3,mm2
88 :    
89 :     punpcklbw mm0,mm7
90 :     punpckhbw mm1,mm7
91 :     punpcklbw mm2,mm7
92 :     punpckhbw mm3,mm7
93 :    
94 :     paddusw mm0,mm1
95 :     paddusw mm6,mm0
96 :     paddusw mm2,mm3
97 :     paddusw mm6,mm2
98 :     %endmacro
99 :    
100 :     align 16
101 :     sad16_mmx:
102 :    
103 :     mov eax, [esp+ 4] ; Src1
104 :     mov edx, [esp+ 8] ; Src2
105 :     mov ecx, [esp+12] ; Stride
106 :    
107 :     pxor mm6, mm6 ; accum
108 :     pxor mm7, mm7 ; zero
109 :    
110 :     SAD_16x16_MMX
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 :    
119 :     SAD_16x16_MMX
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 :    
128 :     pmaddwd mm6, [mmx_one] ; collapse
129 :     movq mm7, mm6
130 :     psrlq mm7, 32
131 :     paddd mm6, mm7
132 :    
133 :     movd eax, mm6
134 :    
135 :     ret
136 :    
137 :    
138 :     ;===========================================================================
139 :     ;
140 :     ; uint32_t sad8_mmx(const uint8_t * const cur,
141 :     ; const uint8_t * const ref,
142 :     ; const uint32_t stride);
143 :     ;
144 :     ;===========================================================================
145 :    
146 :     %macro SAD_8x8_MMX 0
147 :     movq mm0, [eax]
148 :     movq mm1, [edx]
149 :    
150 :     movq mm2, [eax+ecx]
151 :     movq mm3, [edx+ecx]
152 :    
153 :     lea eax,[eax+2*ecx]
154 :     lea edx,[edx+2*ecx]
155 :    
156 :     movq mm4, mm0
157 :     psubusb mm0, mm1
158 :     movq mm5, mm2
159 :     psubusb mm2, mm3
160 :    
161 :     psubusb mm1, mm4
162 :     por mm0, mm1
163 :     psubusb mm3, mm5
164 :     por mm2, mm3
165 :    
166 :     movq mm1,mm0
167 :     movq mm3,mm2
168 :    
169 :     punpcklbw mm0,mm7
170 :     punpckhbw mm1,mm7
171 :     punpcklbw mm2,mm7
172 :     punpckhbw mm3,mm7
173 :    
174 :     paddusw mm0,mm1
175 :     paddusw mm6,mm0
176 :     paddusw mm2,mm3
177 :     paddusw mm6,mm2
178 :     %endmacro
179 :    
180 :     align 16
181 :     sad8_mmx:
182 :    
183 :     mov eax, [esp+ 4] ; Src1
184 :     mov edx, [esp+ 8] ; Src2
185 :     mov ecx, [esp+12] ; Stride
186 :    
187 :     pxor mm6, mm6 ; accum
188 :     pxor mm7, mm7 ; zero
189 :    
190 :     SAD_8x8_MMX
191 :     SAD_8x8_MMX
192 :     SAD_8x8_MMX
193 :     SAD_8x8_MMX
194 :    
195 :     pmaddwd mm6, [mmx_one] ; collapse
196 :     movq mm7, mm6
197 :     psrlq mm7, 32
198 :     paddd mm6, mm7
199 :    
200 :     movd eax, mm6
201 :    
202 :     ret
203 :    
204 :    
205 :    
206 :    
207 :    
208 :     ;===========================================================================
209 :     ;
210 :     ; uint32_t sad16bi_mmx(const uint8_t * const cur,
211 :     ; const uint8_t * const ref1,
212 : suxen_drol 329 ; const uint8_t * const ref2,
213 :     ; const uint32_t stride);
214 :     ;
215 :     ;===========================================================================
216 :     %macro SADBI_16x16_MMX 2 ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
217 :    
218 :     movq mm0, [edx+%1]
219 :     movq mm2, [ebx+%1]
220 :     movq mm1, mm0
221 :     movq mm3, mm2
222 :    
223 :     %if %2 != 0
224 :     add edx, ecx
225 :     %endif
226 :    
227 :     punpcklbw mm0, mm7
228 :     punpckhbw mm1, mm7
229 :     punpcklbw mm2, mm7
230 :     punpckhbw mm3, mm7
231 :    
232 :     %if %2 != 0
233 :     add ebx, ecx
234 :     %endif
235 :    
236 :     paddusw mm0, mm2 ; mm01 = ref1 + ref2
237 :     paddusw mm1, mm3
238 :     paddusw mm0, [mmx_one] ; mm01 += 1
239 :     paddusw mm1, [mmx_one]
240 :     psrlw mm0, 1 ; mm01 >>= 1
241 :     psrlw mm1, 1
242 :    
243 :     movq mm2, [eax+%1]
244 :     movq mm3, mm2
245 :     punpcklbw mm2, mm7 ; mm23 = src
246 :     punpckhbw mm3, mm7
247 :    
248 :     %if %2 != 0
249 :     add eax, ecx
250 :     %endif
251 :    
252 :     movq mm4, mm0
253 :     movq mm5, mm1
254 :     psubusw mm0, mm2
255 :     psubusw mm1, mm3
256 :     psubusw mm2, mm4
257 :     psubusw mm3, mm5
258 :     por mm0, mm2 ; mm01 = ABS(mm01 - mm23)
259 :     por mm1, mm3
260 :    
261 :     paddusw mm6,mm0 ; mm6 += mm01
262 :     paddusw mm6,mm1
263 :    
264 :     %endmacro
265 :    
266 :     align 16
267 :     sad16bi_mmx:
268 :     push ebx
269 :     mov eax, [esp+4+ 4] ; Src
270 :     mov edx, [esp+4+ 8] ; Ref1
271 :     mov ebx, [esp+4+12] ; Ref2
272 :     mov ecx, [esp+4+16] ; Stride
273 :    
274 :     pxor mm6, mm6 ; accum2
275 :     pxor mm7, mm7
276 :     .Loop
277 :     SADBI_16x16_MMX 0, 0
278 :     SADBI_16x16_MMX 8, 1
279 :     SADBI_16x16_MMX 0, 0
280 :     SADBI_16x16_MMX 8, 1
281 :     SADBI_16x16_MMX 0, 0
282 :     SADBI_16x16_MMX 8, 1
283 :     SADBI_16x16_MMX 0, 0
284 :     SADBI_16x16_MMX 8, 1
285 :     SADBI_16x16_MMX 0, 0
286 :     SADBI_16x16_MMX 8, 1
287 :     SADBI_16x16_MMX 0, 0
288 :     SADBI_16x16_MMX 8, 1
289 :     SADBI_16x16_MMX 0, 0
290 :     SADBI_16x16_MMX 8, 1
291 :     SADBI_16x16_MMX 0, 0
292 :     SADBI_16x16_MMX 8, 1
293 :    
294 :     SADBI_16x16_MMX 0, 0
295 :     SADBI_16x16_MMX 8, 1
296 :     SADBI_16x16_MMX 0, 0
297 :     SADBI_16x16_MMX 8, 1
298 :     SADBI_16x16_MMX 0, 0
299 :     SADBI_16x16_MMX 8, 1
300 :     SADBI_16x16_MMX 0, 0
301 :     SADBI_16x16_MMX 8, 1
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 :    
311 :     pmaddwd mm6, [mmx_one] ; collapse
312 :     movq mm7, mm6
313 :     psrlq mm7, 32
314 :     paddd mm6, mm7
315 :    
316 :     movd eax, mm6
317 :     pop ebx
318 :     ret
319 :    
320 :     ;===========================================================================
321 :     ;
322 :     ; uint32_t sad8bi_mmx(const uint8_t * const cur,
323 :     ; const uint8_t * const ref1,
324 :     ; const uint8_t * const ref2,
325 :     ; const uint32_t stride);
326 :     ;
327 :     ;===========================================================================
328 :     align 16
329 :     sad8bi_mmx:
330 :     push ebx
331 :     mov eax, [esp+4+ 4] ; Src
332 :     mov edx, [esp+4+ 8] ; Ref1
333 :     mov ebx, [esp+4+12] ; Ref2
334 :     mov ecx, [esp+4+16] ; Stride
335 :    
336 :     pxor mm6, mm6 ; accum2
337 :     pxor mm7, mm7
338 :     .Loop
339 :     SADBI_16x16_MMX 0, 1
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 :    
348 :     pmaddwd mm6, [mmx_one] ; collapse
349 :     movq mm7, mm6
350 :     psrlq mm7, 32
351 :     paddd mm6, mm7
352 :    
353 :     movd eax, mm6
354 :     pop ebx
355 :     ret
356 :    
357 :    
358 :    
359 :    
360 :     ;===========================================================================
361 :     ;
362 :     ; uint32_t dev16_mmx(const uint8_t * const cur,
363 :     ; const uint32_t stride);
364 :     ;
365 :     ;===========================================================================
366 :    
367 :     %macro MEAN_16x16_MMX 0
368 : Isibaar 262 movq mm0, [eax]
369 :     movq mm2, [eax+8]
370 :     lea eax,[eax+ecx]
371 :     movq mm1, mm0
372 :     movq mm3, mm2
373 :     punpcklbw mm0,mm7
374 :     punpcklbw mm2,mm7
375 :     punpckhbw mm1,mm7
376 :     punpckhbw mm3,mm7
377 :     paddw mm5, mm0
378 :     paddw mm6, mm1
379 :     paddw mm5, mm2
380 :     paddw mm6, mm3
381 :     %endmacro
382 :    
383 :     %macro ABS_16x16_MMX 0
384 :     movq mm0, [eax]
385 :     movq mm2, [eax+8]
386 :     lea eax,[eax+ecx]
387 :     movq mm1, mm0
388 :     movq mm3, mm2
389 :     punpcklbw mm0, mm7
390 :     punpcklbw mm2, mm7
391 :     punpckhbw mm1, mm7
392 :     punpckhbw mm3, mm7
393 :     movq mm4, mm6
394 :     psubusw mm4, mm0
395 :    
396 :     psubusw mm0, mm6
397 :     por mm0, mm4
398 :     movq mm4, mm6
399 :     psubusw mm4, mm1
400 :     psubusw mm1, mm6
401 :     por mm1, mm4
402 :    
403 :     movq mm4, mm6
404 :     psubusw mm4, mm2
405 :     psubusw mm2, mm6
406 :     por mm2, mm4
407 :     movq mm4, mm6
408 :     psubusw mm4, mm3
409 :     psubusw mm3, mm6
410 :     por mm3, mm4
411 :    
412 :     paddw mm0, mm1
413 :     paddw mm2, mm3
414 :     paddw mm5, mm0
415 :     paddw mm5, mm2
416 :     %endmacro
417 :    
418 :     align 16
419 :     dev16_mmx:
420 :     mov eax, [esp+ 4] ; Src
421 :     mov ecx, [esp+ 8] ; Stride
422 :    
423 :     pxor mm7, mm7 ; zero
424 :     pxor mm5, mm5 ; accum1
425 :     pxor mm6, mm6 ; accum2
426 :    
427 :     MEAN_16x16_MMX
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 :    
436 :     MEAN_16x16_MMX
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 :    
445 :     paddusw mm6, mm5
446 :     pmaddwd mm6, [mmx_one] ; collapse
447 :     movq mm5, mm6
448 :     psrlq mm5, 32
449 :     paddd mm6, mm5
450 :    
451 :     psllq mm6, 32 ; blank upper dword
452 :     psrlq mm6, 32 + 8 ; /= (16*16)
453 :    
454 :     punpckldq mm6, mm6
455 :     packssdw mm6, mm6
456 :    
457 :     ; mm6 contains the mean
458 :     ; mm5 is the new accum
459 :    
460 :     pxor mm5, mm5
461 :     mov eax, [esp+ 4] ; Src
462 :    
463 :     ABS_16x16_MMX
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 :    
472 :     ABS_16x16_MMX
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 :    
481 :     pmaddwd mm5, [mmx_one] ; collapse
482 :     movq mm6, mm5
483 :     psrlq mm6, 32
484 :     paddd mm6, mm5
485 :    
486 :     movd eax, mm6
487 :     ret

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