[svn] / branches / release-1_2-branch / xvidcore / src / motion / x86_asm / sad_sse2.asm Repository:
ViewVC logotype

Diff of /branches/release-1_2-branch/xvidcore/src/motion/x86_asm/sad_sse2.asm

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

trunk/xvidcore/src/motion/x86_asm/sad_sse2.asm revision 430, Fri Sep 6 16:59:47 2002 UTC branches/release-1_2-branch/xvidcore/src/motion/x86_asm/sad_sse2.asm revision 1838, Mon Dec 1 17:27:03 2008 UTC
# Line 1  Line 1 
1  ;/*****************************************************************************  ;/****************************************************************************
2  ; *  ; *
3  ; *  XVID MPEG-4 VIDEO CODEC  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *  sse2 sum of absolute difference  ; *  - SSE2 optimized SAD operators -
5  ; *  ; *
6  ; *  Copyright(C) 2002 Michael Militzer  ; *  Copyright(C) 2003 Pascal Massimino <skal@planet-d.net>
 ; *  Copyright(C) 2002 Dmitry Rozhdestvensky  
7  ; *  ; *
 ; *  This program is an implementation of a part of one or more MPEG-4  
 ; *  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.  
8  ; *  ; *
9  ; *  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
10  ; *  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
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 29  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_sse2.asm,v 1.16.2.1 2008-12-01 17:27:03 Isibaar Exp $
24    ; *
25  bits 32  ; ***************************************************************************/
26    
27  %macro cglobal 1  %include "nasm.inc"
         %ifdef PREFIX  
                 global _%1  
                 %define %1 _%1  
         %else  
                 global %1  
         %endif  
 %endmacro  
28    
29  %define sad_debug 0 ;1=unaligned 2=ref unaligned 3=aligned 0=autodetect  ;=============================================================================
30  %define dev_debug 2 ;1=unaligned 2=aligned 0=autodetect  ; Read only data
31  %define test_stride_alignment 0 ;test stride for alignment while autodetect  ;=============================================================================
 %define early_return 0 ;use early return in sad  
32    
33  section .data  DATA
34    
35  align 64  ALIGN SECTION_ALIGN
 buffer  times 4*8 dd 0   ;8 128-bit words  
36  zero    times 4   dd 0  zero    times 4   dd 0
37    
38  section .text  ;=============================================================================
39    ; Code
40    ;=============================================================================
41    
42    SECTION .rotext align=SECTION_ALIGN
43    
44  cglobal  sad16_sse2  cglobal  sad16_sse2
45  cglobal  dev16_sse2  cglobal  dev16_sse2
46    
47  ;===========================================================================  cglobal  sad16_sse3
48  ;               General macros for SSE2 code  cglobal  dev16_sse3
 ;===========================================================================  
   
 %macro load_stride 1  
                 mov     ecx,%1  
                 add     ecx,ecx  
                 mov     edx,ecx  
                 add     ecx,%1          ;stride*3  
                 add     edx,edx         ;stride*4  
 %endmacro  
   
 %macro sad8lines 1  
   
                 psadbw  xmm0,[%1]  
                 psadbw  xmm1,[%1+ebx]  
                 psadbw  xmm2,[%1+ebx*2]  
                 psadbw  xmm3,[%1+ecx]  
   
                 add     %1,edx  
   
                 psadbw  xmm4,[%1]  
                 psadbw  xmm5,[%1+ebx]  
                 psadbw  xmm6,[%1+ebx*2]  
                 psadbw  xmm7,[%1+ecx]  
   
                 add     %1,edx  
 %endmacro  
   
 %macro after_sad 1 ; Summarizes 0th and 4th words of all xmm registers  
   
                 paddusw xmm0,xmm1  
                 paddusw xmm2,xmm3  
                 paddusw xmm4,xmm5  
                 paddusw xmm6,xmm7  
   
                 paddusw xmm0,xmm2  
                 paddusw xmm4,xmm6  
   
                 paddusw xmm4,xmm0  
                 pshufd  xmm5,xmm4,11111110b  
                 paddusw xmm5,xmm4  
49    
50                  pextrw  %1,xmm5,0       ;less latency then movd  ;-----------------------------------------------------------------------------
51  %endmacro  ; uint32_t sad16_sse2 (const uint8_t * const cur, <- assumed aligned!
   
 %macro restore 1  ;restores used registers  
   
 %if %1=1  
                 pop ebp  
 %endif  
                 pop edi  
                 pop esi  
                 pop ebx  
 %endmacro  
   
 ;===========================================================================  
 ;  
 ; uint32_t sad16_sse2 (const uint8_t * const cur,  
52  ;                                       const uint8_t * const ref,  ;                                       const uint8_t * const ref,
53  ;                                       const uint32_t stride,  ;                                       const uint32_t stride,
54  ;                                       const uint32_t best_sad);  ;                      const uint32_t /*ignored*/);
55  ;  ;-----------------------------------------------------------------------------
 ;  
 ;===========================================================================  
   
 align 16  
 sad16_sse2  
                 push    ebx  
                 push    esi  
                 push    edi  
   
                 mov     ebx,[esp + 3*4 + 12]    ;stride  
   
 %if sad_debug<>0  
                 mov     edi,[esp + 3*4 + 4]  
                 mov     esi,[esp + 3*4 + 8]  
 %endif  
   
 %if sad_debug=1  
                 jmp     sad16_sse2_ul  
 %endif  
 %if sad_debug=2  
                 jmp     sad16_sse2_semial  
 %endif  
 %if sad_debug=3  
                 jmp     sad16_sse2_al  
 %endif  
   
 %if test_stride_alignment<>0  
                 test    ebx,15  
                 jnz     sad16_sse2_ul  
 %endif  
                 mov     edi,[esp + 3*4 + 4]     ;cur (most likely aligned)  
   
                 test    edi,15  
                 cmovz   esi,[esp + 3*4 + 8]     ;load esi if edi is aligned  
                 cmovnz  esi,edi                 ;move to esi and load edi  
                 cmovnz  edi,[esp + 3*4 + 8]     ;if not  
                 jnz     esi_unaligned  
   
                 test    esi,15  
                 jnz     near sad16_sse2_semial  
                 jmp     sad16_sse2_al  
56    
 esi_unaligned:  test    edi,15  
                 jnz     near sad16_sse2_ul  
                 jmp     sad16_sse2_semial  
57    
58  ;===========================================================================  %macro SAD_16x16_SSE2 1
59  ;       Branch requires 16-byte alignment of esi and edi and stride    %1  xmm0, [TMP1]
60  ;===========================================================================    %1  xmm1, [TMP1+TMP0]
61      lea TMP1,[TMP1+2*TMP0]
62  %macro sad16x8_al 1    movdqa  xmm2, [_EAX]
63      movdqa  xmm3, [_EAX+TMP0]
64                  movdqa  xmm0,[esi]    lea _EAX,[_EAX+2*TMP0]
65                  movdqa  xmm1,[esi+ebx]    psadbw  xmm0, xmm2
66                  movdqa  xmm2,[esi+ebx*2]    paddusw xmm6,xmm0
67                  movdqa  xmm3,[esi+ecx]    psadbw  xmm1, xmm3
68      paddusw xmm6,xmm1
69                  add     esi,edx  %endmacro
70    
71                  movdqa  xmm4,[esi]  %macro SAD16_SSE2_SSE3 1
72                  movdqa  xmm5,[esi+ebx]    PUSH_XMM6_XMM7
73                  movdqa  xmm6,[esi+ebx*2]    mov _EAX, prm1 ; cur (assumed aligned)
74                  movdqa  xmm7,[esi+ecx]    mov TMP1, prm2 ; ref
75      mov TMP0, prm3 ; stride
76                  add     esi,edx  
77      pxor xmm6, xmm6 ; accum
78                  sad8lines edi  
79      SAD_16x16_SSE2 %1
80                  after_sad %1    SAD_16x16_SSE2 %1
81      SAD_16x16_SSE2 %1
82  %endmacro    SAD_16x16_SSE2 %1
83      SAD_16x16_SSE2 %1
84  align 16    SAD_16x16_SSE2 %1
85  sad16_sse2_al    SAD_16x16_SSE2 %1
86      SAD_16x16_SSE2 %1
87                  load_stride ebx  
88      pshufd  xmm5, xmm6, 00000010b
89                  sad16x8_al eax    paddusw xmm6, xmm5
90      pextrw  eax, xmm6, 0
 %if early_return=1  
                 cmp     eax,[esp + 3*4 + 16]    ;best_sad  
                 jg      continue_al  
 %endif  
   
                 sad16x8_al ebx  
   
                 add     eax,ebx  
   
 continue_al:    restore 0  
91    
92      POP_XMM6_XMM7
93                  ret                  ret
   
 ;===========================================================================  
 ;       Branch requires 16-byte alignment of the edi and stride only  
 ;===========================================================================  
   
 %macro sad16x8_semial 1  
   
                 movdqu  xmm0,[esi]  
                 movdqu  xmm1,[esi+ebx]  
                 movdqu  xmm2,[esi+ebx*2]  
                 movdqu  xmm3,[esi+ecx]  
   
                 add     esi,edx  
   
                 movdqu  xmm4,[esi]  
                 movdqu  xmm5,[esi+ebx]  
                 movdqu  xmm6,[esi+ebx*2]  
                 movdqu  xmm7,[esi+ecx]  
   
                 add     esi,edx  
   
                 sad8lines edi  
   
                 after_sad %1  
   
94  %endmacro  %endmacro
95    
96  align 16  ALIGN SECTION_ALIGN
97  sad16_sse2_semial  sad16_sse2:
98      SAD16_SSE2_SSE3 movdqu
99                  load_stride ebx  ENDFUNC
100    
101                  sad16x8_semial eax  
102    ALIGN SECTION_ALIGN
103  %if early_return=1  sad16_sse3:
104                  cmp     eax,[esp + 3*4 + 16]    ;best_sad    SAD16_SSE2_SSE3 lddqu
105                  jg      cont_semial  ENDFUNC
106  %endif  
107    
108                  sad16x8_semial ebx  ;-----------------------------------------------------------------------------
109    ; uint32_t dev16_sse2(const uint8_t * const cur, const uint32_t stride);
110                  add     eax,ebx  ;-----------------------------------------------------------------------------
111    
112  cont_semial:    restore 0  %macro MEAN_16x16_SSE2 1  ; _EAX: src, TMP0:stride, mm7: zero or mean => mm6: result
113      %1 xmm0, [_EAX]
114                  ret    %1 xmm1, [_EAX+TMP0]
115      lea _EAX, [_EAX+2*TMP0]    ; + 2*stride
116      psadbw xmm0, xmm7
117  ;===========================================================================    paddusw xmm6, xmm0
118  ;               Branch does not require alignment, even stride    psadbw xmm1, xmm7
119  ;===========================================================================    paddusw xmm6, xmm1
   
 %macro sad16x4_ul 1  
   
                 movdqu  xmm0,[esi]  
                 movdqu  xmm1,[esi+ebx]  
                 movdqu  xmm2,[esi+ebx*2]  
                 movdqu  xmm3,[esi+ecx]  
   
                 add     esi,edx  
   
                 movdqu  xmm4,[edi]  
                 movdqu  xmm5,[edi+ebx]  
                 movdqu  xmm6,[edi+ebx*2]  
                 movdqu  xmm7,[edi+ecx]  
   
                 add     edi,edx  
   
                 psadbw  xmm4,xmm0  
                 psadbw  xmm5,xmm1  
                 psadbw  xmm6,xmm2  
                 psadbw  xmm7,xmm3  
   
                 paddusw xmm4,xmm5  
                 paddusw xmm6,xmm7  
   
                 paddusw xmm4,xmm6  
                 pshufd  xmm7,xmm4,11111110b  
                 paddusw xmm7,xmm4  
   
                 pextrw  %1,xmm7,0  
 %endmacro  
   
   
 align 16  
 sad16_sse2_ul  
   
                 load_stride ebx  
   
                 push ebp  
   
                 sad16x4_ul eax  
   
 %if early_return=1  
                 cmp     eax,[esp + 4*4 + 16]    ;best_sad  
                 jg      continue_ul  
 %endif  
   
                 sad16x4_ul ebp  
                 add     eax,ebp  
   
 %if early_return=1  
                 cmp     eax,[esp + 4*4 + 16]    ;best_sad  
                 jg      continue_ul  
 %endif  
   
                 sad16x4_ul ebp  
                 add     eax,ebp  
   
 %if early_return=1  
                 cmp     eax,[esp + 4*4 + 16]    ;best_sad  
                 jg      continue_ul  
 %endif  
   
                 sad16x4_ul ebp  
                 add     eax,ebp  
   
 continue_ul:    restore 1  
   
                 ret  
   
 ;===========================================================================  
 ;  
 ; uint32_t dev16_sse2(const uint8_t * const cur,  
 ;                                       const uint32_t stride);  
 ;  
 ; experimental!  
 ;  
 ;===========================================================================  
   
 align 16  
 dev16_sse2  
   
                 push    ebx  
                 push    esi  
                 push    edi  
                 push    ebp  
   
                 mov     esi, [esp + 4*4 + 4]      ; cur  
                 mov     ebx, [esp + 4*4 + 8]      ; stride  
                 mov     edi, buffer  
   
 %if dev_debug=1  
                 jmp     dev16_sse2_ul  
 %endif  
   
 %if dev_debug=2  
                 jmp     dev16_sse2_al  
 %endif  
   
                 test    esi,15  
                 jnz     near dev16_sse2_ul  
   
 %if test_stride_alignment=1  
                 test    ebx,15  
                 jnz     dev16_sse2_ul  
 %endif  
   
                 mov     edi,esi  
                 jmp     dev16_sse2_al  
   
 ;===========================================================================  
 ;               Branch requires alignment of both the cur and stride  
 ;===========================================================================  
   
 %macro make_mean 0  
                 add     eax,ebp         ;mean 16-bit  
                 mov     al,ah           ;eax= {0 0 mean/256 mean/256}  
                 mov     ebp,eax  
                 shl     ebp,16  
                 or      eax,ebp  
120  %endmacro  %endmacro
121    
 %macro sad_mean16x8_al 3        ;destination,0=zero,1=mean from eax,source  
   
 %if %2=0  
                 pxor    xmm0,xmm0  
 %else  
                 movd    xmm0,eax  
                 pshufd  xmm0,xmm0,0  
 %endif  
                 movdqa  xmm1,xmm0  
                 movdqa  xmm2,xmm0  
                 movdqa  xmm3,xmm0  
                 movdqa  xmm4,xmm0  
                 movdqa  xmm5,xmm0  
                 movdqa  xmm6,xmm0  
                 movdqa  xmm7,xmm0  
   
                 sad8lines %3  
122    
123                  after_sad %1  %macro MEAN16_SSE2_SSE3 1
124      PUSH_XMM6_XMM7
125      mov _EAX, prm1   ; src
126      mov TMP0, prm2   ; stride
127    
128  %endmacro    pxor xmm6, xmm6     ; accum
129      pxor xmm7, xmm7     ; zero
130    
131  align 16    MEAN_16x16_SSE2 %1
132  dev16_sse2_al    MEAN_16x16_SSE2 %1
133      MEAN_16x16_SSE2 %1
134      MEAN_16x16_SSE2 %1
135    
136                  load_stride ebx    MEAN_16x16_SSE2 %1
137      MEAN_16x16_SSE2 %1
138      MEAN_16x16_SSE2 %1
139      MEAN_16x16_SSE2 %1
140    
141                  sad_mean16x8_al eax,0,esi    mov _EAX, prm1       ; src again
                 sad_mean16x8_al ebp,0,esi  
142    
143                  make_mean    pshufd   xmm7, xmm6, 10b
144      paddusw  xmm7, xmm6
145      pxor     xmm6, xmm6     ; zero accum
146      psrlw    xmm7, 8        ; => Mean
147      pshuflw  xmm7, xmm7, 0  ; replicate Mean
148      packuswb xmm7, xmm7
149      pshufd   xmm7, xmm7, 00000000b
150    
151                  sad_mean16x8_al ebp,1,edi    MEAN_16x16_SSE2 %1
152                  sad_mean16x8_al eax,1,edi    MEAN_16x16_SSE2 %1
153      MEAN_16x16_SSE2 %1
154      MEAN_16x16_SSE2 %1
155    
156                  add eax,ebp    MEAN_16x16_SSE2 %1
157      MEAN_16x16_SSE2 %1
158      MEAN_16x16_SSE2 %1
159      MEAN_16x16_SSE2 %1
160    
161                  restore 1    pshufd   xmm7, xmm6, 10b
162      paddusw  xmm7, xmm6
163      pextrw eax, xmm7, 0
164    
165      POP_XMM6_XMM7
166                  ret                  ret
   
 ;===========================================================================  
 ;               Branch does not require alignment  
 ;===========================================================================  
   
 %macro sad_mean16x8_ul 2  
   
                 pxor    xmm7,xmm7  
   
                 movdqu  xmm0,[%1]  
                 movdqu  xmm1,[%1+ebx]  
                 movdqu  xmm2,[%1+ebx*2]  
                 movdqu  xmm3,[%1+ecx]  
   
                 add     %1,edx  
   
                 movdqa  [buffer+16*0],xmm0  
                 movdqa  [buffer+16*1],xmm1  
                 movdqa  [buffer+16*2],xmm2  
                 movdqa  [buffer+16*3],xmm3  
   
                 movdqu  xmm4,[%1]  
                 movdqu  xmm5,[%1+ebx]  
                 movdqu  xmm6,[%1+ebx*2]  
                 movdqa  [buffer+16*4],xmm4  
                 movdqa  [buffer+16*5],xmm5  
                 movdqa  [buffer+16*6],xmm6  
   
                 psadbw  xmm0,xmm7  
                 psadbw  xmm1,xmm7  
                 psadbw  xmm2,xmm7  
                 psadbw  xmm3,xmm7  
                 psadbw  xmm4,xmm7  
                 psadbw  xmm5,xmm7  
                 psadbw  xmm6,xmm7  
   
                 movdqu  xmm7,[%1+ecx]  
                 movdqa  [buffer+16*7],xmm7  
                 psadbw  xmm7,[zero]  
   
                 add     %1,edx  
   
                 after_sad %2  
167  %endmacro  %endmacro
168    
169  align 16  ALIGN SECTION_ALIGN
170  dev16_sse2_ul  dev16_sse2:
171      MEAN16_SSE2_SSE3 movdqu
172                  load_stride ebx  ENDFUNC
173    
174                  sad_mean16x8_ul esi,eax  ALIGN SECTION_ALIGN
175                  sad_mean16x8_ul esi,ebp  dev16_sse3:
176      MEAN16_SSE2_SSE3 lddqu
177                  make_mean  ENDFUNC
178    
                 sad_mean16x8_al ebp,1,edi  
                 sad_mean16x8_al eax,1,edi  
179    
180                  add     eax,ebp  %ifidn __OUTPUT_FORMAT__,elf
181    section ".note.GNU-stack" noalloc noexec nowrite progbits
182                  restore 1  %endif
183    
                 ret  

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

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