[svn] / trunk / xvidcore / src / motion / x86_64_asm / sad_xmm.asm Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/motion/x86_64_asm/sad_xmm.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1793 - (view) (download)

1 : edgomez 1586 ;/****************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * - K7 optimized SAD operators -
5 :     ; *
6 :     ; * Copyright(C) 2001 Peter Ross <pross@xvid.org>
7 :     ; * 2001 Michael Militzer <isibaar@xvid.org>
8 :     ; * 2002 Pascal Massimino <skal@planet-d.net>
9 :     ; * 2004 Andre Werthmann <wertmann@aei.mpg.de>
10 :     ; *
11 :     ; * This program is free software; you can redistribute it and/or modify it
12 :     ; * under the terms of the GNU General Public License as published by
13 :     ; * the Free Software Foundation; either version 2 of the License, or
14 :     ; * (at your option) any later version.
15 :     ; *
16 :     ; * This program is distributed in the hope that it will be useful,
17 :     ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 :     ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 :     ; * GNU General Public License for more details.
20 :     ; *
21 :     ; * You should have received a copy of the GNU General Public License
22 :     ; * along with this program; if not, write to the Free Software
23 :     ; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 :     ; *
25 : Isibaar 1793 ; * $Id: sad_xmm.asm,v 1.3 2008-11-11 20:46:24 Isibaar Exp $
26 : edgomez 1586 ; *
27 :     ; ***************************************************************************/
28 :    
29 :     BITS 64
30 :    
31 :     %macro cglobal 1
32 :     %ifdef PREFIX
33 :     %ifdef MARK_FUNCS
34 :     global _%1:function %1.endfunc-%1
35 :     %define %1 _%1:function %1.endfunc-%1
36 : Isibaar 1793 %define ENDFUNC .endfunc
37 : edgomez 1586 %else
38 :     global _%1
39 :     %define %1 _%1
40 : Isibaar 1793 %define ENDFUNC
41 : edgomez 1586 %endif
42 :     %else
43 :     %ifdef MARK_FUNCS
44 :     global %1:function %1.endfunc-%1
45 : Isibaar 1793 %define ENDFUNC .endfunc
46 : edgomez 1586 %else
47 :     global %1
48 : Isibaar 1793 %define ENDFUNC
49 : edgomez 1586 %endif
50 :     %endif
51 :     %endmacro
52 :    
53 :     ;=============================================================================
54 :     ; Read only data
55 :     ;=============================================================================
56 :    
57 :     %ifdef FORMAT_COFF
58 :     SECTION .rodata
59 :     %else
60 :     SECTION .rodata align=16
61 :     %endif
62 :    
63 :     ALIGN 16
64 :     mmx_one: times 4 dw 1
65 :    
66 :     ;=============================================================================
67 :     ; Helper macros
68 :     ;=============================================================================
69 :    
70 :     %macro SAD_16x16_SSE 0
71 :     movq mm0, [rax]
72 :     psadbw mm0, [rdx]
73 :     movq mm1, [rax+8]
74 :     add rax, rcx
75 :     psadbw mm1, [rdx+8]
76 :     paddusw mm5, mm0
77 :     add rdx, rcx
78 :     paddusw mm6, mm1
79 :     %endmacro
80 :    
81 :     %macro SAD_8x8_SSE 0
82 :     movq mm0, [rax]
83 :     movq mm1, [rax+rcx]
84 :     psadbw mm0, [rdx]
85 :     psadbw mm1, [rdx+rcx]
86 :     add rax, rbx
87 :     add rdx, rbx
88 :     paddusw mm5, mm0
89 :     paddusw mm6, mm1
90 :     %endmacro
91 :    
92 :     %macro SADBI_16x16_SSE 0
93 :     movq mm0, [rax]
94 :     movq mm1, [rax+8]
95 :     movq mm2, [rdx]
96 :     movq mm3, [rdx+8]
97 :     pavgb mm2, [rbx]
98 :     add rdx, rcx
99 :     pavgb mm3, [rbx+8]
100 :     add rbx, rcx
101 :     psadbw mm0, mm2
102 :     add rax, rcx
103 :     psadbw mm1, mm3
104 :     paddusw mm5, mm0
105 :     paddusw mm6, mm1
106 :     %endmacro
107 :    
108 :     %macro SADBI_8x8_XMM 0
109 :     movq mm0, [rax]
110 :     movq mm1, [rax+rcx]
111 :     movq mm2, [rdx]
112 :     movq mm3, [rdx+rcx]
113 :     pavgb mm2, [rbx]
114 :     lea rdx, [rdx+2*rcx]
115 :     pavgb mm3, [rbx+rcx]
116 :     lea rbx, [rbx+2*rcx]
117 :     psadbw mm0, mm2
118 :     lea rax, [rax+2*rcx]
119 :     psadbw mm1, mm3
120 :     paddusw mm5, mm0
121 :     paddusw mm6, mm1
122 :     %endmacro
123 :    
124 :     %macro MEAN_16x16_SSE 0
125 :     movq mm0, [rax]
126 :     movq mm1, [rax+8]
127 :     psadbw mm0, mm7
128 :     psadbw mm1, mm7
129 :     add rax, rcx
130 :     paddw mm5, mm0
131 :     paddw mm6, mm1
132 :     %endmacro
133 :    
134 :     %macro ABS_16x16_SSE 0
135 :     movq mm0, [rax]
136 :     movq mm1, [rax+8]
137 :     psadbw mm0, mm4
138 :     psadbw mm1, mm4
139 :     lea rax, [rax+rcx]
140 :     paddw mm5, mm0
141 :     paddw mm6, mm1
142 :     %endmacro
143 :    
144 :     ;=============================================================================
145 :     ; Code
146 :     ;=============================================================================
147 :    
148 :     SECTION .text align=16
149 :    
150 :     cglobal sad16_x86_64
151 :     cglobal sad8_x86_64
152 :     cglobal sad16bi_x86_64
153 :     cglobal sad8bi_x86_64
154 :     cglobal dev16_x86_64
155 :     cglobal sad16v_x86_64
156 :    
157 :     ;-----------------------------------------------------------------------------
158 :     ;
159 :     ; uint32_t sad16_x86_64(const uint8_t * const cur,
160 :     ; const uint8_t * const ref,
161 :     ; const uint32_t stride,
162 :     ; const uint32_t best_sad);
163 :     ;
164 :     ;-----------------------------------------------------------------------------
165 :    
166 :     ALIGN 16
167 :     sad16_x86_64:
168 :     mov rcx, rdx ; stride
169 :     mov rdx, rsi ; src2 (64bit pointer)
170 :     mov rax, rdi ; src1 (64bit pointer)
171 :    
172 :     pxor mm5, mm5 ; accum1
173 :     pxor mm6, mm6 ; accum2
174 :    
175 :     SAD_16x16_SSE
176 :     SAD_16x16_SSE
177 :     SAD_16x16_SSE
178 :     SAD_16x16_SSE
179 :     SAD_16x16_SSE
180 :     SAD_16x16_SSE
181 :     SAD_16x16_SSE
182 :     SAD_16x16_SSE
183 :    
184 :     SAD_16x16_SSE
185 :     SAD_16x16_SSE
186 :     SAD_16x16_SSE
187 :     SAD_16x16_SSE
188 :     SAD_16x16_SSE
189 :     SAD_16x16_SSE
190 :     SAD_16x16_SSE
191 :     SAD_16x16_SSE
192 :    
193 :     paddusw mm6,mm5
194 :     movd eax, mm6
195 :     ret
196 : Isibaar 1793 ENDFUNC
197 : edgomez 1586
198 :     ;-----------------------------------------------------------------------------
199 :     ;
200 :     ; uint32_t sad8_x86_64(const uint8_t * const cur,
201 :     ; const uint8_t * const ref,
202 :     ; const uint32_t stride);
203 :     ;
204 :     ;-----------------------------------------------------------------------------
205 :    
206 :     ALIGN 16
207 :     sad8_x86_64:
208 :     mov rcx, rdx ; stride
209 :     mov rdx, rsi ; src2
210 :     mov rax, rdi ; src1
211 :    
212 :     push rbx
213 :    
214 :     lea rbx, [rcx+rcx]
215 :    
216 :     pxor mm5, mm5 ; accum1
217 :     pxor mm6, mm6 ; accum2
218 :    
219 :     SAD_8x8_SSE
220 :     SAD_8x8_SSE
221 :     SAD_8x8_SSE
222 :    
223 :     movq mm0, [rax]
224 :     movq mm1, [rax+rcx]
225 :     psadbw mm0, [rdx]
226 :     psadbw mm1, [rdx+rcx]
227 :    
228 :     pop rbx
229 :    
230 :     paddusw mm5,mm0
231 :     paddusw mm6,mm1
232 :    
233 :     paddusw mm6,mm5
234 :     movd eax, mm6
235 :    
236 :     ret
237 : Isibaar 1793 ENDFUNC
238 : edgomez 1586
239 :     ;-----------------------------------------------------------------------------
240 :     ;
241 :     ; uint32_t sad16bi_x86_64(const uint8_t * const cur,
242 :     ; const uint8_t * const ref1,
243 :     ; const uint8_t * const ref2,
244 :     ; const uint32_t stride);
245 :     ;
246 :     ;-----------------------------------------------------------------------------
247 :    
248 :     ALIGN 16
249 :     sad16bi_x86_64:
250 :     push rbx
251 :     ; rcx is stride (4. arg)
252 :     mov rbx, rdx ; ref2
253 :     mov rdx, rsi ; ref1
254 :     mov rax, rdi ; src
255 :    
256 :     pxor mm5, mm5 ; accum1
257 :     pxor mm6, mm6 ; accum2
258 :    
259 :     SADBI_16x16_SSE
260 :     SADBI_16x16_SSE
261 :     SADBI_16x16_SSE
262 :     SADBI_16x16_SSE
263 :     SADBI_16x16_SSE
264 :     SADBI_16x16_SSE
265 :     SADBI_16x16_SSE
266 :     SADBI_16x16_SSE
267 :    
268 :     SADBI_16x16_SSE
269 :     SADBI_16x16_SSE
270 :     SADBI_16x16_SSE
271 :     SADBI_16x16_SSE
272 :     SADBI_16x16_SSE
273 :     SADBI_16x16_SSE
274 :     SADBI_16x16_SSE
275 :     SADBI_16x16_SSE
276 :    
277 :     paddusw mm6,mm5
278 :     movd eax, mm6
279 :     pop rbx
280 :     ret
281 : Isibaar 1793 ENDFUNC
282 : edgomez 1586
283 :     ;-----------------------------------------------------------------------------
284 :     ;
285 :     ; uint32_t sad8bi_x86_64(const uint8_t * const cur,
286 :     ; const uint8_t * const ref1,
287 :     ; const uint8_t * const ref2,
288 :     ; const uint32_t stride);
289 :     ;
290 :     ;-----------------------------------------------------------------------------
291 :    
292 :     ALIGN 16
293 :     sad8bi_x86_64:
294 :     push rbx
295 :     ; rcx is stride
296 :     mov rbx, rdx ; ref2
297 :     mov rdx, rsi ; ref1
298 :     mov rax, rdi ; src
299 :    
300 :     pxor mm5, mm5 ; accum1
301 :     pxor mm6, mm6 ; accum2
302 : Isibaar 1793 .Loop:
303 : edgomez 1586 SADBI_8x8_XMM
304 :     SADBI_8x8_XMM
305 :     SADBI_8x8_XMM
306 :     SADBI_8x8_XMM
307 :    
308 :     paddusw mm6,mm5
309 :     movd eax, mm6
310 :     pop rbx
311 :     ret
312 : Isibaar 1793 ENDFUNC
313 : edgomez 1586
314 :     ;-----------------------------------------------------------------------------
315 :     ;
316 :     ; uint32_t dev16_x86_64(const uint8_t * const cur,
317 :     ; const uint32_t stride);
318 :     ;
319 :     ;-----------------------------------------------------------------------------
320 :    
321 :     ALIGN 16
322 :     dev16_x86_64:
323 :     mov rcx, rsi ; stride
324 :     mov rax, rdi ; src
325 :    
326 :     pxor mm7, mm7 ; zero
327 :     pxor mm5, mm5 ; mean accums
328 :     pxor mm6, mm6
329 :    
330 :     MEAN_16x16_SSE
331 :     MEAN_16x16_SSE
332 :     MEAN_16x16_SSE
333 :     MEAN_16x16_SSE
334 :     MEAN_16x16_SSE
335 :     MEAN_16x16_SSE
336 :     MEAN_16x16_SSE
337 :     MEAN_16x16_SSE
338 :    
339 :     MEAN_16x16_SSE
340 :     MEAN_16x16_SSE
341 :     MEAN_16x16_SSE
342 :     MEAN_16x16_SSE
343 :     MEAN_16x16_SSE
344 :     MEAN_16x16_SSE
345 :     MEAN_16x16_SSE
346 :     MEAN_16x16_SSE
347 :    
348 :     paddusw mm6, mm5
349 :    
350 :     movq mm4, mm6
351 :     psllq mm4, 32
352 :     paddd mm4, mm6
353 :     psrld mm4, 8 ; /= (16*16)
354 :    
355 :     packssdw mm4, mm4
356 :     packuswb mm4, mm4
357 :    
358 :     ; mm4 contains the mean
359 :    
360 :     mov rax, rdi ; src
361 :    
362 :     pxor mm5, mm5 ; sums
363 :     pxor mm6, mm6
364 :    
365 :     ABS_16x16_SSE
366 :     ABS_16x16_SSE
367 :     ABS_16x16_SSE
368 :     ABS_16x16_SSE
369 :     ABS_16x16_SSE
370 :     ABS_16x16_SSE
371 :     ABS_16x16_SSE
372 :     ABS_16x16_SSE
373 :    
374 :     ABS_16x16_SSE
375 :     ABS_16x16_SSE
376 :     ABS_16x16_SSE
377 :     ABS_16x16_SSE
378 :     ABS_16x16_SSE
379 :     ABS_16x16_SSE
380 :     ABS_16x16_SSE
381 :     ABS_16x16_SSE
382 :    
383 :     paddusw mm6, mm5
384 :     movq mm7, mm6
385 :     psllq mm7, 32
386 :     paddd mm6, mm7
387 :    
388 :     movd eax, mm6
389 :     ret
390 : Isibaar 1793 ENDFUNC
391 : edgomez 1586
392 :     ;-----------------------------------------------------------------------------
393 :     ;int sad16v_x86_64(const uint8_t * const cur,
394 :     ; const uint8_t * const ref,
395 :     ; const uint32_t stride,
396 :     ; int* sad8);
397 :     ;-----------------------------------------------------------------------------
398 :    
399 :     ALIGN 16
400 :     sad16v_x86_64:
401 :     push rbx
402 :    
403 :     mov rbx, rcx ; sad ptr (64bit)
404 :     mov rcx, rdx ; stride
405 :     mov rdx, rsi ; src2
406 :     mov rax, rdi ; src1
407 :    
408 :     pxor mm5, mm5 ; accum1
409 :     pxor mm6, mm6 ; accum2
410 :     pxor mm7, mm7 ; total
411 :    
412 :     SAD_16x16_SSE
413 :     SAD_16x16_SSE
414 :     SAD_16x16_SSE
415 :     SAD_16x16_SSE
416 :     SAD_16x16_SSE
417 :     SAD_16x16_SSE
418 :     SAD_16x16_SSE
419 :     SAD_16x16_SSE
420 :    
421 :     paddusw mm7, mm5
422 :     paddusw mm7, mm6
423 :     movd [rbx], mm5
424 :     movd [rbx+4], mm6
425 :    
426 :     pxor mm5, mm5 ; accum1
427 :     pxor mm6, mm6 ; accum2
428 :    
429 :     SAD_16x16_SSE
430 :     SAD_16x16_SSE
431 :     SAD_16x16_SSE
432 :     SAD_16x16_SSE
433 :     SAD_16x16_SSE
434 :     SAD_16x16_SSE
435 :     SAD_16x16_SSE
436 :     SAD_16x16_SSE
437 :    
438 :     paddusw mm7, mm5
439 :     paddusw mm7, mm6
440 :     movd [rbx+8], mm5
441 :     movd [rbx+12], mm6
442 :    
443 :     movd eax, mm7
444 :     pop rbx
445 :     ret
446 : Isibaar 1793 ENDFUNC
447 : Isibaar 1790
448 :     %ifidn __OUTPUT_FORMAT__,elf
449 :     section ".note.GNU-stack" noalloc noexec nowrite progbits
450 :     %endif
451 :    

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