[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 851, Sat Feb 15 15:22:19 2003 UTC revision 1424, Mon Apr 12 15:49:56 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  ; *     This program is free software; you can redistribute it and/or modify  ; *  Copyright(C) 2001 Peter Ross <pross@xvid.org>
7  ; *     it under the terms of the GNU General Public License as published by  ; *               2002 Pascal Massimino <skal@planet-d.net>
8    ; *
9    ; *  This program is free software; you can redistribute it and/or modify it
10    ; *  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 15  Line 18 
18  ; *  ; *
19  ; *     You should have received a copy of the GNU General Public License  ; *     You should have received a copy of the GNU General Public License
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., 675 Mass Ave, Cambridge, MA 02139, USA.  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 ; *  
 ; *************************************************************************/  
   
 ;/**************************************************************************  
 ; *  
 ; *     History:  
22  ; *  ; *
23  ; * 23.07.2002  sad[16,8]bi_xmm; <pross@xvid.org>  ; * $Id: sad_mmx.asm,v 1.13 2004-04-12 15:49:56 edgomez Exp $
 ; * 04.06.2002  cleanup -Skal-  
 ; *     12.11.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
24  ; *  ; *
25  ; *************************************************************************/  ; ***************************************************************************/
26    
27  bits 32  BITS 32
28    
29  %macro cglobal 1  %macro cglobal 1
30          %ifdef PREFIX          %ifdef PREFIX
# Line 40  Line 35 
35          %endif          %endif
36  %endmacro  %endmacro
37    
38  section .data  ;=============================================================================
39    ; Read only data
40    ;=============================================================================
41    
42  align 16  %ifdef FORMAT_COFF
43  mmx_one times 4 dw 1  SECTION .rodata data
44    %else
45  section .text  SECTION .rodata data align=16
46    %endif
 cglobal  sad16_mmx  
 cglobal  sad16v_mmx  
 cglobal  sad8_mmx  
 cglobal  sad16bi_mmx  
 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    
89  align 16  %macro SAD_8x8_MMX      0
90      movq mm0, [eax]
91      movq mm1, [edx]
92    
93      movq mm2, [eax+ecx]
94      movq mm3, [edx+ecx]
95    
96      lea eax,[eax+2*ecx]
97      lea edx,[edx+2*ecx]
98    
99      movq mm4, mm0
100      psubusb mm0, mm1
101      movq mm5, mm2
102      psubusb mm2, mm3
103    
104      psubusb mm1, mm4
105      por mm0, mm1
106      psubusb mm3, mm5
107      por mm2, mm3
108    
109      movq mm1,mm0
110      movq mm3,mm2
111    
112      punpcklbw mm0,mm7
113      punpckhbw mm1,mm7
114      punpcklbw mm2,mm7
115      punpckhbw mm3,mm7
116    
117      paddusw mm0,mm1
118      paddusw mm6,mm0
119      paddusw mm2,mm3
120      paddusw mm6,mm2
121    %endmacro
122    
123    %macro SADV_16x16_MMX 0
124      movq mm0, [eax]
125      movq mm1, [edx]
126    
127      movq mm2, [eax+8]
128      movq mm3, [edx+8]
129    
130      movq mm4, mm0
131      psubusb mm0, mm1
132    
133      psubusb mm1, mm4
134      por mm0, mm1
135      lea eax,[eax+ecx]
136    
137      movq mm4, mm2
138      psubusb mm2, mm3
139    
140      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    
159    %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
160    
161      movq mm0, [edx+%1]
162      movq mm2, [ebx+%1]
163      movq mm1, mm0
164      movq mm3, mm2
165    
166    %if %2 != 0
167      add edx, ecx
168    %endif
169    
170      punpcklbw mm0, mm7
171      punpckhbw mm1, mm7
172      punpcklbw mm2, mm7
173      punpckhbw mm3, mm7
174    
175    %if %2 != 0
176      add ebx, ecx
177    %endif
178    
179      paddusw mm0, mm2              ; mm01 = ref1 + ref2
180      paddusw mm1, mm3
181      paddusw mm0, [mmx_one]        ; mm01 += 1
182      paddusw mm1, [mmx_one]
183      psrlw mm0, 1                  ; mm01 >>= 1
184      psrlw mm1, 1
185    
186      movq mm2, [eax+%1]
187      movq mm3, mm2
188      punpcklbw mm2, mm7            ; mm23 = src
189      punpckhbw mm3, mm7
190    
191    %if %2 != 0
192      add eax, ecx
193    %endif
194    
195      movq mm4, mm0
196      movq mm5, mm1
197      psubusw mm0, mm2
198      psubusw mm1, mm3
199      psubusw mm2, mm4
200      psubusw mm3, mm5
201      por mm0, mm2                  ; mm01 = ABS(mm01 - mm23)
202      por mm1, mm3
203    
204      paddusw mm6, mm0              ; mm6 += mm01
205      paddusw mm6, mm1
206    
207    %endmacro
208    
209    %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    cglobal sse8_8bit_mmx
274    
275    ;-----------------------------------------------------------------------------
276    ;
277    ; uint32_t sad16_mmx(const uint8_t * const cur,
278    ;                                        const uint8_t * const ref,
279    ;                                        const uint32_t stride,
280    ;                                        const uint32_t best_sad);
281    ;
282    ; (early termination ignore; slows this down)
283    ;
284    ;-----------------------------------------------------------------------------
285    
286    ALIGN 16
287  sad16_mmx:  sad16_mmx:
288    
289      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 135  Line 320 
320    
321      ret      ret
322    
323    ;-----------------------------------------------------------------------------
 ;===========================================================================  
324  ;  ;
325  ; uint32_t sad8_mmx(const uint8_t * const cur,  ; uint32_t sad8_mmx(const uint8_t * const cur,
326  ;                                       const uint8_t * const ref,  ;                                       const uint8_t * const ref,
327  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
328  ;  ;
329  ;===========================================================================  ;-----------------------------------------------------------------------------
330    
331  %macro SAD_8x8_MMX  0  ALIGN 16
     movq mm0, [eax]  
     movq mm1, [edx]  
   
     movq mm2, [eax+ecx]  
     movq mm3, [edx+ecx]  
   
     lea eax,[eax+2*ecx]  
     lea edx,[edx+2*ecx]  
   
     movq mm4, mm0  
     psubusb mm0, mm1  
     movq mm5, mm2  
     psubusb mm2, mm3  
   
     psubusb mm1, mm4  
     por mm0, mm1  
     psubusb mm3, mm5  
     por mm2, mm3  
   
     movq mm1,mm0  
     movq mm3,mm2  
   
     punpcklbw mm0,mm7  
     punpckhbw mm1,mm7  
     punpcklbw mm2,mm7  
     punpckhbw mm3,mm7  
   
     paddusw mm0,mm1  
     paddusw mm6,mm0  
     paddusw mm2,mm3  
     paddusw mm6,mm2  
 %endmacro  
   
 align 16  
332  sad8_mmx:  sad8_mmx:
333    
334      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 202  Line 352 
352    
353      ret      ret
354    
355    ;-----------------------------------------------------------------------------
 ;===========================================================================  
356  ;  ;
357  ; uint32_t sad16v_mmx(const uint8_t * const cur,  ; uint32_t sad16v_mmx(const uint8_t * const cur,
358  ;                                     const uint8_t * const ref,  ;                                     const uint8_t * const ref,
359  ;                                         const uint32_t stride,  ;                                         const uint32_t stride,
360  ;                                         int32_t *sad);  ;                                         int32_t *sad);
361  ;  ;
362  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %macro SADV_16x16_MMX 0  
     movq mm0, [eax]  
     movq mm1, [edx]  
   
     movq mm2, [eax+8]  
     movq mm3, [edx+8]  
   
     movq mm4, mm0  
     psubusb mm0, mm1  
363    
364      psubusb mm1, mm4  ALIGN 16
     por mm0, mm1  
     lea eax,[eax+ecx]  
   
     movq mm4, mm2  
     psubusb mm2, mm3  
   
     psubusb mm3, mm4  
     por mm2, mm3  
     lea edx,[edx+ecx]  
   
     movq mm1,mm0  
     movq mm3,mm2  
   
     punpcklbw mm0,mm7  
     punpckhbw mm1,mm7  
     punpcklbw mm2,mm7  
     punpckhbw mm3,mm7  
   
     paddusw mm0,mm1  
     paddusw mm2,mm3  
   
         paddusw mm5, mm0  
         paddusw mm6, mm2  
 %endmacro  
   
 align 16  
365  sad16v_mmx:  sad16v_mmx:
366    
367          push ebx          push ebx
# Line 326  Line 439 
439    
440          pop edi          pop edi
441      pop ebx      pop ebx
         ret  
   
442    
443      ret
444    
445  ;===========================================================================  ;-----------------------------------------------------------------------------
446  ;  ;
447  ; uint32_t sad16bi_mmx(const uint8_t * const cur,  ; uint32_t sad16bi_mmx(const uint8_t * const cur,
448  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
449  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
450  ; const uint32_t stride);  ; const uint32_t stride);
451  ;  ;
452  ;===========================================================================  ;-----------------------------------------------------------------------------
 %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );  
   
    movq mm0, [edx+%1]  
    movq mm2, [ebx+%1]  
    movq mm1, mm0  
    movq mm3, mm2  
   
 %if %2 != 0  
    add edx, ecx  
 %endif  
   
    punpcklbw mm0, mm7  
    punpckhbw mm1, mm7  
 punpcklbw mm2, mm7  
 punpckhbw mm3, mm7  
   
 %if %2 != 0  
    add ebx, ecx  
 %endif  
   
 paddusw mm0, mm2    ; mm01 = ref1 + ref2  
 paddusw mm1, mm3  
 paddusw mm0, [mmx_one] ; mm01 += 1  
 paddusw mm1, [mmx_one]  
 psrlw mm0, 1     ; mm01 >>= 1  
 psrlw mm1, 1  
453    
454     movq mm2, [eax+%1]  ALIGN 16
    movq mm3, mm2  
    punpcklbw mm2, mm7          ; mm23 = src  
    punpckhbw mm3, mm7  
   
 %if %2 != 0  
    add eax, ecx  
 %endif  
   
    movq mm4, mm0  
    movq mm5, mm1  
    psubusw mm0, mm2  
    psubusw mm1, mm3  
    psubusw mm2, mm4  
    psubusw mm3, mm5  
    por mm0, mm2                ; mm01 = ABS(mm01 - mm23)  
    por mm1, mm3  
   
    paddusw mm6,mm0             ; mm6 += mm01  
    paddusw mm6,mm1  
   
 %endmacro  
   
 align 16  
455  sad16bi_mmx:  sad16bi_mmx:
456     push ebx     push ebx
457     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 440  Line 503 
503    
504     movd eax, mm6     movd eax, mm6
505     pop ebx     pop ebx
506    
507     ret     ret
508    
509  ;===========================================================================  ;-----------------------------------------------------------------------------
510  ;  ;
511  ; uint32_t sad8bi_mmx(const uint8_t * const cur,  ; uint32_t sad8bi_mmx(const uint8_t * const cur,
512  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
513  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
514  ; const uint32_t stride);  ; const uint32_t stride);
515  ;  ;
516  ;===========================================================================  ;-----------------------------------------------------------------------------
517  align 16  
518    ALIGN 16
519  sad8bi_mmx:  sad8bi_mmx:
520     push ebx     push ebx
521     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 479  Line 544 
544     pop ebx     pop ebx
545     ret     ret
546    
547    ;-----------------------------------------------------------------------------
   
   
 ;===========================================================================  
548  ;  ;
549  ; uint32_t dev16_mmx(const uint8_t * const cur,  ; uint32_t dev16_mmx(const uint8_t * const cur,
550  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
551  ;  ;
552  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %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  
553    
554  align 16  ALIGN 16
555  dev16_mmx:  dev16_mmx:
556      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
557      mov ecx, [esp+ 8] ; Stride      mov ecx, [esp+ 8] ; Stride
# Line 609  Line 620 
620      paddd mm6, mm5      paddd mm6, mm5
621    
622      movd eax, mm6      movd eax, mm6
623    
624      ret
625    
626    ;-----------------------------------------------------------------------------
627    ;
628    ; uint32_t sse8_16bit_mmx(const int16_t *b1,
629    ;                         const int16_t *b2,
630    ;                         const uint32_t stride);
631    ;
632    ;-----------------------------------------------------------------------------
633    
634    %macro ROW_SSE_16bit_MMX 2
635      movq mm0, [%1]
636      movq mm1, [%1+8]
637      psubw mm0, [%2]
638      psubw mm1, [%2+8]
639      pmaddwd mm0, mm0
640      pmaddwd mm1, mm1
641      paddd mm2, mm0
642      paddd mm2, mm1
643    %endmacro
644    
645    sse8_16bit_mmx:
646      push esi
647      push edi
648    
649      ;; Load the function params
650      mov esi, [esp+8+4]
651      mov edi, [esp+8+8]
652      mov edx, [esp+8+12]
653    
654      ;; Reset the sse accumulator
655      pxor mm2, mm2
656    
657      ;; Let's go
658    %rep 8
659      ROW_SSE_16bit_MMX esi, edi
660      lea esi, [esi+edx]
661      lea edi, [edi+edx]
662    %endrep
663    
664      ;; Finish adding each dword of the accumulator
665      movq mm3, mm2
666      psrlq mm2, 32
667      paddd mm2, mm3
668      movd eax, mm2
669    
670      ;; All done
671      pop edi
672      pop esi
673      ret
674    
675    ;-----------------------------------------------------------------------------
676    ;
677    ; uint32_t sse8_8bit_mmx(const int8_t *b1,
678    ;                        const int8_t *b2,
679    ;                        const uint32_t stride);
680    ;
681    ;-----------------------------------------------------------------------------
682    
683    %macro ROW_SSE_8bit_MMX 2
684      movq mm0, [%1] ; load a row
685      movq mm2, [%2] ; load a row
686    
687      movq mm1, mm0  ; copy row
688      movq mm3, mm2  ; copy row
689    
690      punpcklbw mm0, mm7 ; turn the 4low elements into 16bit
691      punpckhbw mm1, mm7 ; turn the 4high elements into 16bit
692    
693      punpcklbw mm2, mm7 ; turn the 4low elements into 16bit
694      punpckhbw mm3, mm7 ; turn the 4high elements into 16bit
695    
696      psubw mm0, mm2 ; low  part of src-dst
697      psubw mm1, mm3 ; high part of src-dst
698    
699      pmaddwd mm0, mm0 ; compute the square sum
700      pmaddwd mm1, mm1 ; compute the square sum
701    
702      paddd mm6, mm0 ; add to the accumulator
703      paddd mm6, mm1 ; add to the accumulator
704    %endmacro
705    
706    sse8_8bit_mmx:
707      push esi
708      push edi
709    
710      ;; Load the function params
711      mov esi, [esp+8+4]
712      mov edi, [esp+8+8]
713      mov edx, [esp+8+12]
714    
715      ;; Reset the sse accumulator
716      pxor mm6, mm6
717    
718      ;; Used to interleave 8bit data with 0x00 values
719      pxor mm7, mm7
720    
721      ;; Let's go
722    %rep 8
723      ROW_SSE_8bit_MMX esi, edi
724      lea esi, [esi+edx]
725      lea edi, [edi+edx]
726    %endrep
727    
728      ;; Finish adding each dword of the accumulator
729      movq mm7, mm6
730      psrlq mm6, 32
731      paddd mm6, mm7
732      movd eax, mm6
733    
734      ;; All done
735      pop edi
736      pop esi
737      ret      ret

Legend:
Removed from v.851  
changed lines
  Added in v.1424

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