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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 430, Fri Sep 6 16:59:47 2002 UTC revision 1382, Mon Mar 22 22:36:25 2004 UTC
# Line 1  Line 1 
1  ;/*****************************************************************************  ;/****************************************************************************
2  ; *  ; *
3  ; *  XVID MPEG-4 VIDEO CODEC  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *  mmx sum of absolute difference  ; *  - K7 optimized SAD operators -
5  ; *  ; *
6  ; *  Copyright(C) 2002 Peter Ross <pross@xvid.org>  ; *  Copyright(C) 2001 Peter Ross <pross@xvid.org>
7    ; *               2002 Pascal Massimino <skal@planet-d.net>
8  ; *  ; *
9  ; *  This program is an implementation of a part of one or more MPEG-4  ; *  This program is free software; you can redistribute it and/or modify it
10  ; *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  ; *  under the terms of the GNU General Public License as published by
 ; *  to use this software module in hardware or software products are  
 ; *  advised that its use may infringe existing patents or copyrights, and  
 ; *  any such use would be at such party's own risk.  The original  
 ; *  developer of this software module and his/her company, and subsequent  
 ; *  editors and their companies, will have no liability for use of this  
 ; *  software or modifications or derivatives thereof.  
 ; *  
 ; *  This program is free software; you can redistribute it and/or modify  
 ; *  it under the terms of the GNU General Public License as published by  
11  ; *  the Free Software Foundation; either version 2 of the License, or  ; *  the Free Software Foundation; either version 2 of the License, or
12  ; *  (at your option) any later version.  ; *  (at your option) any later version.
13  ; *  ; *
# Line 28  Line 20 
20  ; *  along with this program; if not, write to the Free Software  ; *  along with this program; if not, write to the Free Software
21  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  ; *  ; *
23  , ****************************************************************************/  ; * $Id: sad_mmx.asm,v 1.12 2004-03-22 22:36:24 edgomez Exp $
24    ; *
25    ; ***************************************************************************/
26    
27  bits 32  BITS 32
28    
29  %macro cglobal 1  %macro cglobal 1
30          %ifdef PREFIX          %ifdef PREFIX
# Line 41  Line 35 
35          %endif          %endif
36  %endmacro  %endmacro
37    
38  section .data  ;=============================================================================
39    ; Read only data
40  align 16  ;=============================================================================
 mmx_one times 4 dw 1  
41    
42  section .text  %ifdef FORMAT_COFF
43    SECTION .rodata data
44  cglobal  sad16_mmx  %else
45  cglobal  sad8_mmx  SECTION .rodata data align=16
46  cglobal  sad16bi_mmx  %endif
 cglobal  sad8bi_mmx  
 cglobal  dev16_mmx  
47    
48  ;===========================================================================  ALIGN 16
49  ;  mmx_one:
50  ; uint32_t sad16_mmx(const uint8_t * const cur,          times 4 dw 1
51  ;                                        const uint8_t * const ref,  
52  ;                                        const uint32_t stride,  ;=============================================================================
53  ;                                        const uint32_t best_sad);  ; Helper macros
54  ;  ;=============================================================================
 ; (early termination ignore; slows this down)  
 ;  
 ;===========================================================================  
55    
56  %macro SAD_16x16_MMX 0  %macro SAD_16x16_MMX 0
57      movq mm0, [eax]      movq mm0, [eax]
# Line 98  Line 86 
86      paddusw mm6,mm2      paddusw mm6,mm2
87  %endmacro  %endmacro
88    
 align 16  
 sad16_mmx:  
   
     mov eax, [esp+ 4] ; Src1  
     mov edx, [esp+ 8] ; Src2  
     mov ecx, [esp+12] ; Stride  
   
     pxor mm6, mm6 ; accum  
     pxor mm7, mm7 ; zero  
   
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
   
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
   
     pmaddwd mm6, [mmx_one] ; collapse  
     movq mm7, mm6  
     psrlq mm7, 32  
     paddd mm6, mm7  
   
     movd eax, mm6  
   
     ret  
   
   
 ;===========================================================================  
 ;  
 ; uint32_t sad8_mmx(const uint8_t * const cur,  
 ;                                       const uint8_t * const ref,  
 ;                                       const uint32_t stride);  
 ;  
 ;===========================================================================  
   
89  %macro SAD_8x8_MMX  0  %macro SAD_8x8_MMX  0
90      movq mm0, [eax]      movq mm0, [eax]
91      movq mm1, [edx]      movq mm1, [edx]
# Line 178  Line 120 
120      paddusw mm6,mm2      paddusw mm6,mm2
121  %endmacro  %endmacro
122    
123  align 16  %macro SADV_16x16_MMX 0
124  sad8_mmx:    movq mm0, [eax]
125      movq mm1, [edx]
     mov eax, [esp+ 4] ; Src1  
     mov edx, [esp+ 8] ; Src2  
     mov ecx, [esp+12] ; Stride  
126    
127      pxor mm6, mm6 ; accum    movq mm2, [eax+8]
128      pxor mm7, mm7 ; zero    movq mm3, [edx+8]
129    
130      SAD_8x8_MMX    movq mm4, mm0
131      SAD_8x8_MMX    psubusb mm0, mm1
     SAD_8x8_MMX  
     SAD_8x8_MMX  
132    
133      pmaddwd mm6, [mmx_one] ; collapse    psubusb mm1, mm4
134      movq mm7, mm6    por mm0, mm1
135      psrlq mm7, 32    lea eax,[eax+ecx]
     paddd mm6, mm7  
136    
137      movd eax, mm6    movq mm4, mm2
138      psubusb mm2, mm3
139    
140      ret    psubusb mm3, mm4
141      por mm2, mm3
142      lea edx,[edx+ecx]
143    
144      movq mm1,mm0
145      movq mm3,mm2
146    
147      punpcklbw mm0,mm7
148      punpckhbw mm1,mm7
149      punpcklbw mm2,mm7
150      punpckhbw mm3,mm7
151    
152      paddusw mm0,mm1
153      paddusw mm2,mm3
154    
155      paddusw mm5, mm0
156      paddusw mm6, mm2
157    %endmacro
158    
 ;===========================================================================  
 ;  
 ; uint32_t sad16bi_mmx(const uint8_t * const cur,  
 ; const uint8_t * const ref1,  
 ; const uint8_t * const ref2,  
 ; const uint32_t stride);  
 ;  
 ;===========================================================================  
159  %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );  %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
160    
161     movq mm0, [edx+%1]     movq mm0, [edx+%1]
# Line 264  Line 206 
206    
207  %endmacro  %endmacro
208    
209  align 16  %macro MEAN_16x16_MMX 0
210      movq mm0, [eax]
211      movq mm2, [eax+8]
212      lea eax, [eax+ecx]
213      movq mm1, mm0
214      movq mm3, mm2
215      punpcklbw mm0, mm7
216      punpcklbw mm2, mm7
217      punpckhbw mm1, mm7
218      punpckhbw mm3, mm7
219      paddw mm5, mm0
220      paddw mm6, mm1
221      paddw mm5, mm2
222      paddw mm6, mm3
223    %endmacro
224    
225    %macro ABS_16x16_MMX 0
226      movq mm0, [eax]
227      movq mm2, [eax+8]
228      lea eax, [eax+ecx]
229      movq mm1, mm0
230      movq mm3, mm2
231      punpcklbw mm0, mm7
232      punpcklbw mm2, mm7
233      punpckhbw mm1, mm7
234      punpckhbw mm3, mm7
235      movq mm4, mm6
236      psubusw mm4, mm0
237    
238      psubusw mm0, mm6
239      por mm0, mm4
240      movq mm4, mm6
241      psubusw mm4, mm1
242      psubusw mm1, mm6
243      por mm1, mm4
244    
245      movq mm4, mm6
246      psubusw mm4, mm2
247      psubusw mm2, mm6
248      por mm2, mm4
249      movq mm4, mm6
250      psubusw mm4, mm3
251      psubusw mm3, mm6
252      por mm3, mm4
253    
254      paddw mm0, mm1
255      paddw mm2, mm3
256      paddw mm5, mm0
257      paddw mm5, mm2
258    %endmacro
259    
260    ;=============================================================================
261    ; Code
262    ;=============================================================================
263    
264    SECTION .text
265    
266    cglobal sad16_mmx
267    cglobal sad16v_mmx
268    cglobal sad8_mmx
269    cglobal sad16bi_mmx
270    cglobal sad8bi_mmx
271    cglobal dev16_mmx
272    cglobal sse8_16bit_mmx
273    
274    ;-----------------------------------------------------------------------------
275    ;
276    ; uint32_t sad16_mmx(const uint8_t * const cur,
277    ;                                        const uint8_t * const ref,
278    ;                                        const uint32_t stride,
279    ;                                        const uint32_t best_sad);
280    ;
281    ; (early termination ignore; slows this down)
282    ;
283    ;-----------------------------------------------------------------------------
284    
285    ALIGN 16
286    sad16_mmx:
287    
288      mov eax, [esp+ 4] ; Src1
289      mov edx, [esp+ 8] ; Src2
290      mov ecx, [esp+12] ; Stride
291    
292      pxor mm6, mm6 ; accum
293      pxor mm7, mm7 ; zero
294    
295      SAD_16x16_MMX
296      SAD_16x16_MMX
297      SAD_16x16_MMX
298      SAD_16x16_MMX
299      SAD_16x16_MMX
300      SAD_16x16_MMX
301      SAD_16x16_MMX
302      SAD_16x16_MMX
303    
304      SAD_16x16_MMX
305      SAD_16x16_MMX
306      SAD_16x16_MMX
307      SAD_16x16_MMX
308      SAD_16x16_MMX
309      SAD_16x16_MMX
310      SAD_16x16_MMX
311      SAD_16x16_MMX
312    
313      pmaddwd mm6, [mmx_one] ; collapse
314      movq mm7, mm6
315      psrlq mm7, 32
316      paddd mm6, mm7
317    
318      movd eax, mm6
319    
320      ret
321    
322    ;-----------------------------------------------------------------------------
323    ;
324    ; uint32_t sad8_mmx(const uint8_t * const cur,
325    ;                                       const uint8_t * const ref,
326    ;                                       const uint32_t stride);
327    ;
328    ;-----------------------------------------------------------------------------
329    
330    ALIGN 16
331    sad8_mmx:
332    
333      mov eax, [esp+ 4] ; Src1
334      mov edx, [esp+ 8] ; Src2
335      mov ecx, [esp+12] ; Stride
336    
337      pxor mm6, mm6 ; accum
338      pxor mm7, mm7 ; zero
339    
340      SAD_8x8_MMX
341      SAD_8x8_MMX
342      SAD_8x8_MMX
343      SAD_8x8_MMX
344    
345      pmaddwd mm6, [mmx_one] ; collapse
346      movq mm7, mm6
347      psrlq mm7, 32
348      paddd mm6, mm7
349    
350      movd eax, mm6
351    
352      ret
353    
354    ;-----------------------------------------------------------------------------
355    ;
356    ; uint32_t sad16v_mmx(const uint8_t * const cur,
357    ;                                     const uint8_t * const ref,
358    ;                                         const uint32_t stride,
359    ;                                         int32_t *sad);
360    ;
361    ;-----------------------------------------------------------------------------
362    
363    ALIGN 16
364    sad16v_mmx:
365    
366      push ebx
367      push edi
368    
369      mov eax, [esp + 8 + 4] ; Src1
370      mov edx, [esp + 8 + 8] ; Src2
371      mov ecx, [esp + 8 + 12] ; Stride
372      mov ebx, [esp + 8 + 16] ; sad ptr
373    
374      pxor mm5, mm5 ; accum
375      pxor mm6, mm6 ; accum
376      pxor mm7, mm7 ; zero
377    
378      SADV_16x16_MMX
379      SADV_16x16_MMX
380      SADV_16x16_MMX
381      SADV_16x16_MMX
382      SADV_16x16_MMX
383      SADV_16x16_MMX
384      SADV_16x16_MMX
385      SADV_16x16_MMX
386    
387      pmaddwd mm5, [mmx_one] ; collapse
388      pmaddwd mm6, [mmx_one] ; collapse
389    
390      movq mm2, mm5
391      movq mm3, mm6
392    
393      psrlq mm2, 32
394      psrlq mm3, 32
395    
396      paddd mm5, mm2
397      paddd mm6, mm3
398    
399      movd [ebx], mm5
400      movd [ebx + 4], mm6
401    
402      paddd mm5, mm6
403    
404      movd edi, mm5
405    
406      pxor mm5, mm5
407      pxor mm6, mm6
408    
409      SADV_16x16_MMX
410      SADV_16x16_MMX
411      SADV_16x16_MMX
412      SADV_16x16_MMX
413      SADV_16x16_MMX
414      SADV_16x16_MMX
415      SADV_16x16_MMX
416      SADV_16x16_MMX
417    
418      pmaddwd mm5, [mmx_one] ; collapse
419      pmaddwd mm6, [mmx_one] ; collapse
420    
421      movq mm2, mm5
422      movq mm3, mm6
423    
424      psrlq mm2, 32
425      psrlq mm3, 32
426    
427      paddd mm5, mm2
428      paddd mm6, mm3
429    
430      movd [ebx + 8], mm5
431      movd [ebx + 12], mm6
432    
433      paddd mm5, mm6
434    
435      movd eax, mm5
436    
437      add eax, edi
438    
439      pop edi
440      pop ebx
441    
442      ret
443    
444    ;-----------------------------------------------------------------------------
445    ;
446    ; uint32_t sad16bi_mmx(const uint8_t * const cur,
447    ; const uint8_t * const ref1,
448    ; const uint8_t * const ref2,
449    ; const uint32_t stride);
450    ;
451    ;-----------------------------------------------------------------------------
452    
453    ALIGN 16
454  sad16bi_mmx:  sad16bi_mmx:
455     push ebx     push ebx
456     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 316  Line 502 
502    
503     movd eax, mm6     movd eax, mm6
504     pop ebx     pop ebx
505    
506     ret     ret
507    
508  ;===========================================================================  ;-----------------------------------------------------------------------------
509  ;  ;
510  ; uint32_t sad8bi_mmx(const uint8_t * const cur,  ; uint32_t sad8bi_mmx(const uint8_t * const cur,
511  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
512  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
513  ; const uint32_t stride);  ; const uint32_t stride);
514  ;  ;
515  ;===========================================================================  ;-----------------------------------------------------------------------------
516  align 16  
517    ALIGN 16
518  sad8bi_mmx:  sad8bi_mmx:
519     push ebx     push ebx
520     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 355  Line 543 
543     pop ebx     pop ebx
544     ret     ret
545    
546    ;-----------------------------------------------------------------------------
   
   
 ;===========================================================================  
547  ;  ;
548  ; uint32_t dev16_mmx(const uint8_t * const cur,  ; uint32_t dev16_mmx(const uint8_t * const cur,
549  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
550  ;  ;
551  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %macro MEAN_16x16_MMX 0  
     movq mm0, [eax]  
     movq mm2, [eax+8]  
     lea eax,[eax+ecx]  
     movq mm1, mm0  
     movq mm3, mm2  
     punpcklbw mm0,mm7  
     punpcklbw mm2,mm7  
     punpckhbw mm1,mm7  
     punpckhbw mm3,mm7  
     paddw mm5, mm0  
     paddw mm6, mm1  
     paddw mm5, mm2  
     paddw mm6, mm3  
 %endmacro  
   
 %macro ABS_16x16_MMX 0  
     movq mm0, [eax]  
     movq mm2, [eax+8]  
     lea eax,[eax+ecx]  
     movq mm1, mm0  
     movq mm3, mm2  
     punpcklbw mm0, mm7  
     punpcklbw mm2, mm7  
     punpckhbw mm1, mm7  
     punpckhbw mm3, mm7  
     movq mm4, mm6  
         psubusw mm4, mm0  
   
         psubusw mm0, mm6  
         por mm0, mm4  
         movq mm4, mm6  
         psubusw mm4, mm1  
         psubusw mm1, mm6  
         por mm1, mm4  
   
     movq mm4, mm6  
         psubusw mm4, mm2  
         psubusw mm2, mm6  
         por mm2, mm4  
         movq mm4, mm6  
         psubusw mm4, mm3  
         psubusw mm3, mm6  
         por mm3, mm4  
   
         paddw mm0, mm1  
         paddw mm2, mm3  
         paddw mm5, mm0  
         paddw mm5, mm2  
 %endmacro  
552    
553  align 16  ALIGN 16
554  dev16_mmx:  dev16_mmx:
555      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
556      mov ecx, [esp+ 8] ; Stride      mov ecx, [esp+ 8] ; Stride
# Line 485  Line 619 
619      paddd mm6, mm5      paddd mm6, mm5
620    
621      movd eax, mm6      movd eax, mm6
622    
623      ret      ret
624    
625    ;-----------------------------------------------------------------------------
626    ;
627    ; uint32_t sse8_16bit_mmx(const int16_t *b1,
628    ;                         const int16_t *b2,
629    ;                         const uint32_t stride);
630    ;
631    ;-----------------------------------------------------------------------------
632    
633    %macro ROW_SSE_MMX 2
634      movq mm0, [%1]
635      movq mm1, [%1+8]
636      psubw mm0, [%2]
637      psubw mm1, [%2+8]
638      pmaddwd mm0, mm0
639      pmaddwd mm1, mm1
640      paddd mm2, mm0
641      paddd mm2, mm1
642    %endmacro
643    
644    sse8_16bit_mmx:
645      push esi
646      push edi
647    
648      ;; Load the function params
649      mov esi, [esp+8+4]
650      mov edi, [esp+8+8]
651      mov edx, [esp+8+12]
652    
653      ;; Reset the sse accumulator
654      pxor mm2, mm2
655    
656      ;; Let's go
657      ROW_SSE_MMX esi, edi
658      lea esi, [esi+edx]
659      lea edi, [edi+edx]
660      ROW_SSE_MMX esi, edi
661      lea esi, [esi+edx]
662      lea edi, [edi+edx]
663      ROW_SSE_MMX esi, edi
664      lea esi, [esi+edx]
665      lea edi, [edi+edx]
666      ROW_SSE_MMX esi, edi
667      lea esi, [esi+edx]
668      lea edi, [edi+edx]
669      ROW_SSE_MMX esi, edi
670      lea esi, [esi+edx]
671      lea edi, [edi+edx]
672      ROW_SSE_MMX esi, edi
673      lea esi, [esi+edx]
674      lea edi, [edi+edx]
675      ROW_SSE_MMX esi, edi
676      lea esi, [esi+edx]
677      lea edi, [edi+edx]
678      ROW_SSE_MMX esi, edi
679      lea esi, [esi+edx]
680      lea edi, [edi+edx]
681    
682      ;; Finish adding each dword of the accumulator
683      movq mm3, mm2
684      psrlq mm2, 32
685      paddd mm2, mm3
686      movd eax, mm2
687    
688      ;; All done
689      pop edi
690      pop esi
691      ret

Legend:
Removed from v.430  
changed lines
  Added in v.1382

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