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

Annotation of /trunk/xvidcore/src/motion/x86_asm/sad_sse2.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 :     ; * sse2 sum of absolute difference
5 : Isibaar 262 ; *
6 : chl 430 ; * Copyright(C) 2002 Michael Militzer
7 :     ; * Copyright(C) 2002 Dmitry Rozhdestvensky
8 : Isibaar 262 ; *
9 : chl 430 ; * This program is an implementation of a part of one or more MPEG-4
10 :     ; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
11 :     ; * to use this software module in hardware or software products are
12 :     ; * advised that its use may infringe existing patents or copyrights, and
13 :     ; * any such use would be at such party's own risk. The original
14 :     ; * developer of this software module and his/her company, and subsequent
15 :     ; * editors and their companies, will have no liability for use of this
16 :     ; * software or modifications or derivatives thereof.
17 : Isibaar 262 ; *
18 : chl 430 ; * This program is free software; you can redistribute it and/or modify
19 :     ; * it under the terms of the GNU General Public License as published by
20 :     ; * the Free Software Foundation; either version 2 of the License, or
21 :     ; * (at your option) any later version.
22 : Isibaar 262 ; *
23 : chl 430 ; * This program is distributed in the hope that it will be useful,
24 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 :     ; * GNU General Public License for more details.
27 : Isibaar 262 ; *
28 : chl 430 ; * You should have received a copy of the GNU General Public License
29 :     ; * along with this program; if not, write to the Free Software
30 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 : Isibaar 262 ; *
32 : chl 430 , ****************************************************************************/
33 : Isibaar 262
34 :     bits 32
35 :    
36 :     %macro cglobal 1
37 :     %ifdef PREFIX
38 :     global _%1
39 :     %define %1 _%1
40 :     %else
41 :     global %1
42 :     %endif
43 :     %endmacro
44 :    
45 :     %define sad_debug 0 ;1=unaligned 2=ref unaligned 3=aligned 0=autodetect
46 :     %define dev_debug 2 ;1=unaligned 2=aligned 0=autodetect
47 :     %define test_stride_alignment 0 ;test stride for alignment while autodetect
48 :     %define early_return 0 ;use early return in sad
49 :    
50 :     section .data
51 :    
52 :     align 64
53 :     buffer times 4*8 dd 0 ;8 128-bit words
54 :     zero times 4 dd 0
55 :    
56 :     section .text
57 :    
58 :     cglobal sad16_sse2
59 :     cglobal dev16_sse2
60 :    
61 :     ;===========================================================================
62 :     ; General macros for SSE2 code
63 :     ;===========================================================================
64 :    
65 :     %macro load_stride 1
66 :     mov ecx,%1
67 :     add ecx,ecx
68 :     mov edx,ecx
69 :     add ecx,%1 ;stride*3
70 :     add edx,edx ;stride*4
71 :     %endmacro
72 :    
73 :     %macro sad8lines 1
74 :    
75 :     psadbw xmm0,[%1]
76 :     psadbw xmm1,[%1+ebx]
77 :     psadbw xmm2,[%1+ebx*2]
78 :     psadbw xmm3,[%1+ecx]
79 :    
80 :     add %1,edx
81 :    
82 :     psadbw xmm4,[%1]
83 :     psadbw xmm5,[%1+ebx]
84 :     psadbw xmm6,[%1+ebx*2]
85 :     psadbw xmm7,[%1+ecx]
86 :    
87 :     add %1,edx
88 :     %endmacro
89 :    
90 :     %macro after_sad 1 ; Summarizes 0th and 4th words of all xmm registers
91 :    
92 :     paddusw xmm0,xmm1
93 :     paddusw xmm2,xmm3
94 :     paddusw xmm4,xmm5
95 :     paddusw xmm6,xmm7
96 :    
97 :     paddusw xmm0,xmm2
98 :     paddusw xmm4,xmm6
99 :    
100 :     paddusw xmm4,xmm0
101 :     pshufd xmm5,xmm4,11111110b
102 :     paddusw xmm5,xmm4
103 :    
104 :     pextrw %1,xmm5,0 ;less latency then movd
105 :     %endmacro
106 :    
107 :     %macro restore 1 ;restores used registers
108 :    
109 :     %if %1=1
110 :     pop ebp
111 :     %endif
112 :     pop edi
113 :     pop esi
114 :     pop ebx
115 :     %endmacro
116 :    
117 :     ;===========================================================================
118 :     ;
119 :     ; uint32_t sad16_sse2 (const uint8_t * const cur,
120 :     ; const uint8_t * const ref,
121 :     ; const uint32_t stride,
122 :     ; const uint32_t best_sad);
123 :     ;
124 :     ;
125 :     ;===========================================================================
126 :    
127 :     align 16
128 :     sad16_sse2
129 :     push ebx
130 :     push esi
131 :     push edi
132 :    
133 :     mov ebx,[esp + 3*4 + 12] ;stride
134 :    
135 :     %if sad_debug<>0
136 :     mov edi,[esp + 3*4 + 4]
137 :     mov esi,[esp + 3*4 + 8]
138 :     %endif
139 :    
140 :     %if sad_debug=1
141 :     jmp sad16_sse2_ul
142 :     %endif
143 :     %if sad_debug=2
144 :     jmp sad16_sse2_semial
145 :     %endif
146 :     %if sad_debug=3
147 :     jmp sad16_sse2_al
148 :     %endif
149 :    
150 :     %if test_stride_alignment<>0
151 :     test ebx,15
152 :     jnz sad16_sse2_ul
153 :     %endif
154 :     mov edi,[esp + 3*4 + 4] ;cur (most likely aligned)
155 :    
156 :     test edi,15
157 :     cmovz esi,[esp + 3*4 + 8] ;load esi if edi is aligned
158 :     cmovnz esi,edi ;move to esi and load edi
159 :     cmovnz edi,[esp + 3*4 + 8] ;if not
160 :     jnz esi_unaligned
161 :    
162 :     test esi,15
163 :     jnz near sad16_sse2_semial
164 :     jmp sad16_sse2_al
165 :    
166 :     esi_unaligned: test edi,15
167 :     jnz near sad16_sse2_ul
168 :     jmp sad16_sse2_semial
169 :    
170 :     ;===========================================================================
171 :     ; Branch requires 16-byte alignment of esi and edi and stride
172 :     ;===========================================================================
173 :    
174 :     %macro sad16x8_al 1
175 :    
176 :     movdqa xmm0,[esi]
177 :     movdqa xmm1,[esi+ebx]
178 :     movdqa xmm2,[esi+ebx*2]
179 :     movdqa xmm3,[esi+ecx]
180 :    
181 :     add esi,edx
182 :    
183 :     movdqa xmm4,[esi]
184 :     movdqa xmm5,[esi+ebx]
185 :     movdqa xmm6,[esi+ebx*2]
186 :     movdqa xmm7,[esi+ecx]
187 :    
188 :     add esi,edx
189 :    
190 :     sad8lines edi
191 :    
192 :     after_sad %1
193 :    
194 :     %endmacro
195 :    
196 :     align 16
197 :     sad16_sse2_al
198 :    
199 :     load_stride ebx
200 :    
201 :     sad16x8_al eax
202 :    
203 :     %if early_return=1
204 :     cmp eax,[esp + 3*4 + 16] ;best_sad
205 :     jg continue_al
206 :     %endif
207 :    
208 :     sad16x8_al ebx
209 :    
210 :     add eax,ebx
211 :    
212 :     continue_al: restore 0
213 :    
214 :     ret
215 :    
216 :     ;===========================================================================
217 :     ; Branch requires 16-byte alignment of the edi and stride only
218 :     ;===========================================================================
219 :    
220 :     %macro sad16x8_semial 1
221 :    
222 :     movdqu xmm0,[esi]
223 :     movdqu xmm1,[esi+ebx]
224 :     movdqu xmm2,[esi+ebx*2]
225 :     movdqu xmm3,[esi+ecx]
226 :    
227 :     add esi,edx
228 :    
229 :     movdqu xmm4,[esi]
230 :     movdqu xmm5,[esi+ebx]
231 :     movdqu xmm6,[esi+ebx*2]
232 :     movdqu xmm7,[esi+ecx]
233 :    
234 :     add esi,edx
235 :    
236 :     sad8lines edi
237 :    
238 :     after_sad %1
239 :    
240 :     %endmacro
241 :    
242 :     align 16
243 :     sad16_sse2_semial
244 :    
245 :     load_stride ebx
246 :    
247 :     sad16x8_semial eax
248 :    
249 :     %if early_return=1
250 :     cmp eax,[esp + 3*4 + 16] ;best_sad
251 :     jg cont_semial
252 :     %endif
253 :    
254 :     sad16x8_semial ebx
255 :    
256 :     add eax,ebx
257 :    
258 :     cont_semial: restore 0
259 :    
260 :     ret
261 :    
262 :    
263 :     ;===========================================================================
264 :     ; Branch does not require alignment, even stride
265 :     ;===========================================================================
266 :    
267 :     %macro sad16x4_ul 1
268 :    
269 :     movdqu xmm0,[esi]
270 :     movdqu xmm1,[esi+ebx]
271 :     movdqu xmm2,[esi+ebx*2]
272 :     movdqu xmm3,[esi+ecx]
273 :    
274 :     add esi,edx
275 :    
276 :     movdqu xmm4,[edi]
277 :     movdqu xmm5,[edi+ebx]
278 :     movdqu xmm6,[edi+ebx*2]
279 :     movdqu xmm7,[edi+ecx]
280 :    
281 :     add edi,edx
282 :    
283 :     psadbw xmm4,xmm0
284 :     psadbw xmm5,xmm1
285 :     psadbw xmm6,xmm2
286 :     psadbw xmm7,xmm3
287 :    
288 :     paddusw xmm4,xmm5
289 :     paddusw xmm6,xmm7
290 :    
291 :     paddusw xmm4,xmm6
292 :     pshufd xmm7,xmm4,11111110b
293 :     paddusw xmm7,xmm4
294 :    
295 :     pextrw %1,xmm7,0
296 :     %endmacro
297 :    
298 :    
299 :     align 16
300 :     sad16_sse2_ul
301 :    
302 :     load_stride ebx
303 :    
304 :     push ebp
305 :    
306 :     sad16x4_ul eax
307 :    
308 :     %if early_return=1
309 :     cmp eax,[esp + 4*4 + 16] ;best_sad
310 :     jg continue_ul
311 :     %endif
312 :    
313 :     sad16x4_ul ebp
314 :     add eax,ebp
315 :    
316 :     %if early_return=1
317 :     cmp eax,[esp + 4*4 + 16] ;best_sad
318 :     jg continue_ul
319 :     %endif
320 :    
321 :     sad16x4_ul ebp
322 :     add eax,ebp
323 :    
324 :     %if early_return=1
325 :     cmp eax,[esp + 4*4 + 16] ;best_sad
326 :     jg continue_ul
327 :     %endif
328 :    
329 :     sad16x4_ul ebp
330 :     add eax,ebp
331 :    
332 :     continue_ul: restore 1
333 :    
334 :     ret
335 :    
336 :     ;===========================================================================
337 :     ;
338 :     ; uint32_t dev16_sse2(const uint8_t * const cur,
339 :     ; const uint32_t stride);
340 :     ;
341 :     ; experimental!
342 :     ;
343 :     ;===========================================================================
344 :    
345 :     align 16
346 :     dev16_sse2
347 :    
348 :     push ebx
349 :     push esi
350 :     push edi
351 :     push ebp
352 :    
353 :     mov esi, [esp + 4*4 + 4] ; cur
354 :     mov ebx, [esp + 4*4 + 8] ; stride
355 :     mov edi, buffer
356 :    
357 :     %if dev_debug=1
358 :     jmp dev16_sse2_ul
359 :     %endif
360 :    
361 :     %if dev_debug=2
362 :     jmp dev16_sse2_al
363 :     %endif
364 :    
365 :     test esi,15
366 :     jnz near dev16_sse2_ul
367 :    
368 :     %if test_stride_alignment=1
369 :     test ebx,15
370 :     jnz dev16_sse2_ul
371 :     %endif
372 :    
373 :     mov edi,esi
374 :     jmp dev16_sse2_al
375 :    
376 :     ;===========================================================================
377 :     ; Branch requires alignment of both the cur and stride
378 :     ;===========================================================================
379 :    
380 :     %macro make_mean 0
381 :     add eax,ebp ;mean 16-bit
382 :     mov al,ah ;eax= {0 0 mean/256 mean/256}
383 :     mov ebp,eax
384 :     shl ebp,16
385 :     or eax,ebp
386 :     %endmacro
387 :    
388 :     %macro sad_mean16x8_al 3 ;destination,0=zero,1=mean from eax,source
389 :    
390 :     %if %2=0
391 :     pxor xmm0,xmm0
392 :     %else
393 :     movd xmm0,eax
394 :     pshufd xmm0,xmm0,0
395 :     %endif
396 :     movdqa xmm1,xmm0
397 :     movdqa xmm2,xmm0
398 :     movdqa xmm3,xmm0
399 :     movdqa xmm4,xmm0
400 :     movdqa xmm5,xmm0
401 :     movdqa xmm6,xmm0
402 :     movdqa xmm7,xmm0
403 :    
404 :     sad8lines %3
405 :    
406 :     after_sad %1
407 :    
408 :     %endmacro
409 :    
410 :     align 16
411 :     dev16_sse2_al
412 :    
413 :     load_stride ebx
414 :    
415 :     sad_mean16x8_al eax,0,esi
416 :     sad_mean16x8_al ebp,0,esi
417 :    
418 :     make_mean
419 :    
420 :     sad_mean16x8_al ebp,1,edi
421 :     sad_mean16x8_al eax,1,edi
422 :    
423 :     add eax,ebp
424 :    
425 :     restore 1
426 :    
427 :     ret
428 :    
429 :     ;===========================================================================
430 :     ; Branch does not require alignment
431 :     ;===========================================================================
432 :    
433 :     %macro sad_mean16x8_ul 2
434 :    
435 :     pxor xmm7,xmm7
436 :    
437 :     movdqu xmm0,[%1]
438 :     movdqu xmm1,[%1+ebx]
439 :     movdqu xmm2,[%1+ebx*2]
440 :     movdqu xmm3,[%1+ecx]
441 :    
442 :     add %1,edx
443 :    
444 :     movdqa [buffer+16*0],xmm0
445 :     movdqa [buffer+16*1],xmm1
446 :     movdqa [buffer+16*2],xmm2
447 :     movdqa [buffer+16*3],xmm3
448 :    
449 :     movdqu xmm4,[%1]
450 :     movdqu xmm5,[%1+ebx]
451 :     movdqu xmm6,[%1+ebx*2]
452 :     movdqa [buffer+16*4],xmm4
453 :     movdqa [buffer+16*5],xmm5
454 :     movdqa [buffer+16*6],xmm6
455 :    
456 :     psadbw xmm0,xmm7
457 :     psadbw xmm1,xmm7
458 :     psadbw xmm2,xmm7
459 :     psadbw xmm3,xmm7
460 :     psadbw xmm4,xmm7
461 :     psadbw xmm5,xmm7
462 :     psadbw xmm6,xmm7
463 :    
464 :     movdqu xmm7,[%1+ecx]
465 :     movdqa [buffer+16*7],xmm7
466 :     psadbw xmm7,[zero]
467 :    
468 :     add %1,edx
469 :    
470 :     after_sad %2
471 :     %endmacro
472 :    
473 :     align 16
474 :     dev16_sse2_ul
475 :    
476 :     load_stride ebx
477 :    
478 :     sad_mean16x8_ul esi,eax
479 :     sad_mean16x8_ul esi,ebp
480 :    
481 :     make_mean
482 :    
483 :     sad_mean16x8_al ebp,1,edi
484 :     sad_mean16x8_al eax,1,edi
485 :    
486 :     add eax,ebp
487 :    
488 :     restore 1
489 :    
490 :     ret

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