[cvs] / xvidcore / src / motion / x86_asm / sad_3dne.asm Repository:
ViewVC logotype

Diff of /xvidcore/src/motion/x86_asm/sad_3dne.asm

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

revision 1.2, Sat Feb 15 15:22:19 2003 UTC revision 1.5, Sun Aug 22 11:46:10 2004 UTC
# Line 1  Line 1 
1  ;/**************************************************************************  ;/****************************************************************************
2  ; *  ; *
3  ; *     XVID MPEG-4 VIDEO CODEC  ; *     XVID MPEG-4 VIDEO CODEC
4  ; *     xmm sum of absolute difference  ; *  - K7 optimized SAD operators -
5  ; *  ; *
6  ; *     This program is an implementation of a part of one or more MPEG-4  ; *  Copyright(C) 2002 Jaan Kalda
 ; *     Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
 ; *     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.  
7  ; *  ; *
8  ; *     This program is free software; you can redistribute it and/or modify  ; *  This program is free software; you can redistribute it and/or modify it
9  ; *     it under the terms of the GNU General Public License as published by  ; *  under the terms of the GNU General Public License as published by
10  ; *     the Free Software Foundation; either version 2 of the License, or  ; *     the Free Software Foundation; either version 2 of the License, or
11  ; *     (at your option) any later version.  ; *     (at your option) any later version.
12  ; *  ; *
# Line 24  Line 17 
17  ; *  ; *
18  ; *     You should have received a copy of the GNU General Public License  ; *     You should have received a copy of the GNU General Public License
19  ; *     along with this program; if not, write to the Free Software  ; *     along with this program; if not, write to the Free Software
20  ; *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  ; *  ; *
22  ; *************************************************************************/  ; * $Id$
23  ;  ; *
24  ; these 3dne functions are compatible with iSSE, but are optimized specifically for  ; ***************************************************************************/
 ; K7 pipelines  
 ;  
 ;------------------------------------------------------------------------------  
 ; 09.12.2002  Athlon optimizations contributed by Jaan Kalda  
 ;------------------------------------------------------------------------------  
25    
26  bits 32  ; these 3dne functions are compatible with iSSE, but are optimized specifically
27    ; for K7 pipelines
28    
29    BITS 32
30    
31  %macro cglobal 1  %macro cglobal 1
32          %ifdef PREFIX          %ifdef PREFIX
33                    %ifdef MARK_FUNCS
34                            global _%1:function
35                            %define %1 _%1:function
36                    %else
37                  global _%1                  global _%1
38                  %define %1 _%1                  %define %1 _%1
39                    %endif
40            %else
41                    %ifdef MARK_FUNCS
42                            global %1:function
43          %else          %else
44                  global %1                  global %1
45          %endif          %endif
46            %endif
47  %endmacro  %endmacro
48    
49    ;=============================================================================
50    ; Read only data
51    ;=============================================================================
52    
53  %ifdef FORMAT_COFF  %ifdef FORMAT_COFF
54  section .data data  SECTION .rodata
55  %else  %else
56  section .data data align=16  SECTION .rodata align=16
57  %endif  %endif
58    
59  align 16  ALIGN 16
60  mmx_one times 4 dw 1  mmx_one:
61            times 4 dw 1
62  section .text  
63    ;=============================================================================
64    ; Helper macros
65    ;=============================================================================
66    
67  cglobal  sad16_3dne          ;; %1 block number (0..4)
 cglobal  sad8_3dne  
 cglobal  sad16bi_3dne  
 cglobal  sad8bi_3dne  
 cglobal  dev16_3dne  
   
 ;===========================================================================  
 ;  
 ; uint32_t sad16_3dne(const uint8_t * const cur,  
 ;                                       const uint8_t * const ref,  
 ;                                       const uint32_t stride,  
 ;                                       const uint32_t best_sad);  
 ;  
 ;===========================================================================  
 ; optimization: 21% faster  
68  %macro SAD_16x16_SSE 1  %macro SAD_16x16_SSE 1
69      movq mm7, [eax]      movq mm7, [eax]
70      movq mm6, [eax+8]      movq mm6, [eax+8]
# Line 107  Line 100 
100      paddd mm1,mm3      paddd mm1,mm3
101  %endmacro  %endmacro
102    
103  align 16  %macro SADBI_16x16_SSE0 0
104  sad16_3dne:    movq mm2, [edx]
105      movq mm3, [edx+8]
106    
107      movq mm5, [byte eax]
108      movq mm6, [eax+8]
109      pavgb mm2, [byte ebx]
110      pavgb mm3, [ebx+8]
111    
112      add edx, ecx
113      psadbw mm5, mm2
114      psadbw mm6, mm3
115    
116      add eax, ecx
117      add ebx, ecx
118      movq mm2, [byte edx]
119    
120      movq mm3, [edx+8]
121      movq mm0, [byte eax]
122    
123      movq mm1, [eax+8]
124      pavgb mm2, [byte ebx]
125    
126      pavgb mm3, [ebx+8]
127      add edx, ecx
128      add eax, ecx
129    
130      add ebx, ecx
131      psadbw mm0, mm2
132      psadbw mm1, mm3
133    
134    %endmacro
135    
136    %macro SADBI_16x16_SSE 0
137      movq mm2, [byte edx]
138      movq mm3, [edx+8]
139      paddusw mm5, mm0
140      paddusw mm6, mm1
141      movq mm0, [eax]
142      movq mm1, [eax+8]
143      pavgb mm2, [ebx]
144      pavgb mm3, [ebx+8]
145      add edx, ecx
146      add eax, ecx
147      add ebx, ecx
148      psadbw mm0, mm2
149      psadbw mm1, mm3
150    %endmacro
151    
152    %macro SADBI_8x8_3dne 0
153      movq mm2, [edx]
154      movq mm3, [edx+ecx]
155      pavgb mm2, [eax]
156      pavgb mm3, [eax+ecx]
157      lea edx, [edx+2*ecx]
158      lea eax, [eax+2*ecx]
159      paddusw mm5, mm0
160      paddusw mm6, mm1
161      movq mm0, [ebx]
162      movq mm1, [ebx+ecx]
163      lea ebx, [ebx+2*ecx]
164      psadbw mm0, mm2
165      psadbw mm1, mm3
166    %endmacro
167    
168    %macro ABS_16x16_SSE 1
169    %if (%1 == 0)
170      movq mm7, [eax]
171      psadbw mm7, mm4
172      mov esi, esi
173      movq mm6, [eax+8]
174      movq mm5, [eax+ecx]
175      movq mm3, [eax+ecx+8]
176      psadbw mm6, mm4
177    
178      movq mm2, [byte eax+2*ecx]
179      psadbw mm5, mm4
180      movq mm1, [eax+2*ecx+8]
181      psadbw mm3, mm4
182    
183      movq mm0, [dword eax+edx]
184      psadbw mm2, mm4
185      add eax, edx
186      psadbw mm1, mm4
187    %endif
188    %if (%1 == 1)
189      psadbw mm0, mm4
190      paddd mm7, mm0
191      movq mm0, [eax+8]
192      psadbw mm0, mm4
193      paddd mm6, mm0
194    
195      movq mm0, [byte eax+ecx]
196      psadbw mm0, mm4
197    
198      paddd mm5, mm0
199      movq mm0, [eax+ecx+8]
200    
201      psadbw mm0, mm4
202      paddd mm3, mm0
203      movq mm0, [eax+2*ecx]
204      psadbw mm0, mm4
205      paddd mm2, mm0
206    
207      movq mm0, [eax+2*ecx+8]
208      add eax, edx
209      psadbw mm0, mm4
210      paddd mm1, mm0
211      movq mm0, [eax]
212    %endif
213    %if (%1 == 2)
214      psadbw mm0, mm4
215      paddd mm7, mm0
216      movq mm0, [eax+8]
217      psadbw mm0, mm4
218      paddd mm6, mm0
219    %endif
220    %endmacro
221    
222    ;=============================================================================
223    ; Code
224    ;=============================================================================
225    
226    SECTION .text
227    
228    cglobal sad16_3dne
229    cglobal sad8_3dne
230    cglobal sad16bi_3dne
231    cglobal sad8bi_3dne
232    cglobal dev16_3dne
233    
234    ;-----------------------------------------------------------------------------
235    ;
236    ; uint32_t sad16_3dne(const uint8_t * const cur,
237    ;                     const uint8_t * const ref,
238    ;                     const uint32_t stride,
239    ;                     const uint32_t best_sad);
240    ;
241    ;-----------------------------------------------------------------------------
242    
243    ; optimization: 21% faster
244    
245    ALIGN 16
246    sad16_3dne:
247      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
248      mov edx, [esp+ 8] ; Src2      mov edx, [esp+ 8] ; Src2
249      mov ecx, [esp+12] ; Stride      mov ecx, [esp+12] ; Stride
250      push ebx      push ebx
251      lea ebx,[2*ecx+ecx]      lea ebx,[2*ecx+ecx]
252    
253      SAD_16x16_SSE 0      SAD_16x16_SSE 0
254      SAD_16x16_SSE 1      SAD_16x16_SSE 1
255      SAD_16x16_SSE 2      SAD_16x16_SSE 2
256      SAD_16x16_SSE 3      SAD_16x16_SSE 3
257    
258      mov ecx,[esp]      mov ecx,[esp]
259      add ecx,[esp+4]      add ecx,[esp+4]
260      add ecx,[esp+8]      add ecx,[esp+8]
# Line 127  Line 263 
263      add esp,byte 4+12      add esp,byte 4+12
264      movd eax, mm1      movd eax, mm1
265      add eax,ecx      add eax,ecx
266    
267      ret      ret
268    
269    
270  ;===========================================================================  ;-----------------------------------------------------------------------------
271  ;  ;
272  ; uint32_t sad8_3dne(const uint8_t * const cur,  ; uint32_t sad8_3dne(const uint8_t * const cur,
273  ;                                       const uint8_t * const ref,  ;                                       const uint8_t * const ref,
274  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
275  ;  ;
276  ;===========================================================================  ;-----------------------------------------------------------------------------
277  align 16  
278    ALIGN 16
279  sad8_3dne:  sad8_3dne:
280    
281      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 183  Line 321 
321      ret      ret
322    
323    
324  ;===========================================================================  ;-----------------------------------------------------------------------------
325  ;  ;
326  ; uint32_t sad16bi_3dne(const uint8_t * const cur,  ; uint32_t sad16bi_3dne(const uint8_t * const cur,
327  ;                                       const uint8_t * const ref1,  ;                                       const uint8_t * const ref1,
328  ;                                       const uint8_t * const ref2,  ;                                       const uint8_t * const ref2,
329  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
330  ;  ;
331  ;===========================================================================  ;-----------------------------------------------------------------------------
332  ;optimization: 14% faster  ;optimization: 14% faster
 %macro SADBI_16x16_SSE0 0  
     movq mm2, [edx]  
     movq mm3, [edx+8]  
   
     movq mm5, [byte eax]  
     movq mm6, [eax+8]  
     pavgb mm2, [byte ebx]  
     pavgb mm3, [ebx+8]  
   
     add edx, ecx  
     psadbw mm5, mm2  
     psadbw mm6, mm3  
   
     add eax, ecx  
     add ebx, ecx  
     movq mm2, [byte edx]  
   
     movq mm3, [edx+8]  
     movq mm0, [byte eax]  
333    
334      movq mm1, [eax+8]  ALIGN 16
     pavgb mm2, [byte ebx]  
   
     pavgb mm3, [ebx+8]  
     add edx, ecx  
     add eax, ecx  
   
     add ebx, ecx  
     psadbw mm0, mm2  
     psadbw mm1, mm3  
   
 %endmacro  
 %macro SADBI_16x16_SSE 0  
     movq mm2, [byte edx]  
     movq mm3, [edx+8]  
     paddusw mm5,mm0  
     paddusw mm6,mm1  
     movq mm0, [eax]  
     movq mm1, [eax+8]  
     pavgb mm2, [ebx]  
     pavgb mm3, [ebx+8]  
     add edx, ecx  
     add eax, ecx  
     add ebx, ecx  
     psadbw mm0, mm2  
     psadbw mm1, mm3  
 %endmacro  
   
 align 16  
335  sad16bi_3dne:  sad16bi_3dne:
336      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
337      mov edx, [esp+ 8] ; Ref1      mov edx, [esp+ 8] ; Ref1
# Line 270  Line 361 
361      pop ebx      pop ebx
362      paddusw mm6,mm5      paddusw mm6,mm5
363      movd eax, mm6      movd eax, mm6
364    
365      ret      ret
366  ;===========================================================================  
367    ;-----------------------------------------------------------------------------
368  ;  ;
369  ; uint32_t sad8bi_3dne(const uint8_t * const cur,  ; uint32_t sad8bi_3dne(const uint8_t * const cur,
370  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
371  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
372  ; const uint32_t stride);  ; const uint32_t stride);
373  ;  ;
374  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %macro SADBI_8x8_3dne 0  
    movq mm2, [edx]  
    movq mm3, [edx+ecx]  
    pavgb mm2, [eax]  
    pavgb mm3, [eax+ecx]  
    lea edx, [edx+2*ecx]  
    lea eax, [eax+2*ecx]  
    paddusw mm5,mm0  
    paddusw mm6,mm1  
    movq mm0, [ebx]  
    movq mm1, [ebx+ecx]  
    lea ebx, [ebx+2*ecx]  
    psadbw mm0, mm2  
    psadbw mm1, mm3  
 %endmacro  
375    
376  align 16  ALIGN 16
377  sad8bi_3dne:  sad8bi_3dne:
378     mov eax, [esp+12] ; Ref2     mov eax, [esp+12] ; Ref2
379     mov edx, [esp+ 8] ; Ref1     mov edx, [esp+ 8] ; Ref1
# Line 359  Line 436 
436     mov ebx,[esp]     mov ebx,[esp]
437     add esp,byte 4     add esp,byte 4
438     movd eax, mm6     movd eax, mm6
439    
440     ret     ret
441    
442    
# Line 369  Line 447 
447  ;  ;
448  ;===========================================================================  ;===========================================================================
449  ; optimization: 25 % faster  ; optimization: 25 % faster
 %macro ABS_16x16_SSE 1  
 %if (%1 == 0)  
     movq mm7, [eax]  
     psadbw mm7, mm4  
     mov esi,esi  
     movq mm6, [eax+8]  
     movq mm5, [eax+ecx]  
     movq mm3, [eax+ecx+8]  
     psadbw mm6, mm4  
   
     movq mm2, [byte eax+2*ecx]  
     psadbw mm5, mm4  
     movq mm1, [eax+2*ecx+8]  
     psadbw mm3, mm4  
   
     movq mm0, [dword eax+edx]  
     psadbw mm2, mm4  
     add eax,edx  
     psadbw mm1, mm4  
 %endif  
 %if (%1 == 1)  
     psadbw mm0, mm4  
     paddd mm7, mm0  
     movq mm0, [eax+8]  
     psadbw mm0, mm4  
     paddd mm6, mm0  
450    
451      movq mm0, [byte eax+ecx]  ALIGN 16
     psadbw mm0, mm4  
   
     paddd mm5, mm0  
     movq mm0, [eax+ecx+8]  
   
     psadbw mm0, mm4  
     paddd mm3, mm0  
     movq mm0, [eax+2*ecx]  
     psadbw mm0, mm4  
     paddd mm2, mm0  
   
     movq mm0, [eax+2*ecx+8]  
     add eax,edx  
     psadbw mm0, mm4  
     paddd mm1, mm0  
     movq mm0, [eax]  
 %endif  
 %if (%1 == 2)  
     psadbw mm0, mm4  
     paddd mm7, mm0  
     movq mm0, [eax+8]  
     psadbw mm0, mm4  
     paddd mm6, mm0  
 %endif  
 %endmacro  
   
 align 16  
452  dev16_3dne:  dev16_3dne:
453    
454      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
# Line 431  Line 456 
456      lea edx,[ecx+2*ecx]      lea edx,[ecx+2*ecx]
457    
458      pxor mm4, mm4      pxor mm4, mm4
459  align 8  
460    ALIGN 8
461      ABS_16x16_SSE 0      ABS_16x16_SSE 0
462      ABS_16x16_SSE 1      ABS_16x16_SSE 1
463      ABS_16x16_SSE 1      ABS_16x16_SSE 1
464      ABS_16x16_SSE 1      ABS_16x16_SSE 1
465      ABS_16x16_SSE 1      ABS_16x16_SSE 1
466    
467      paddd mm1, mm2      paddd mm1, mm2
468      paddd mm3, mm5      paddd mm3, mm5
469    
470      ABS_16x16_SSE 2      ABS_16x16_SSE 2
471    
472      paddd mm7, mm6      paddd mm7, mm6
473      paddd mm1, mm3      paddd mm1, mm3
474      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
475      paddd mm7,mm1      paddd mm7,mm1
476      punpcklbw mm7,mm7 ;xxyyaazz      punpcklbw mm7,mm7 ;xxyyaazz
477          pshufw mm4,mm7,055h    pshufw mm4, mm7, 055h     ; mm4 contains the mean
478      ; mm4 contains the mean  
479    
480      pxor mm1, mm1      pxor mm1, mm1
481    
482      ABS_16x16_SSE 0      ABS_16x16_SSE 0
# Line 454  Line 484 
484      ABS_16x16_SSE 1      ABS_16x16_SSE 1
485      ABS_16x16_SSE 1      ABS_16x16_SSE 1
486      ABS_16x16_SSE 1      ABS_16x16_SSE 1
487    
488      paddd mm1, mm2      paddd mm1, mm2
489      paddd mm3, mm5      paddd mm3, mm5
490    
491      ABS_16x16_SSE 2      ABS_16x16_SSE 2
492    
493      paddd mm7, mm6      paddd mm7, mm6
494      paddd mm1, mm3      paddd mm1, mm3
495      paddd mm7,mm1      paddd mm7,mm1
496      movd eax, mm7      movd eax, mm7
497    
498      ret      ret

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

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