[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 1381, Thu Mar 18 16:11:28 2004 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  ; *     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.12 2004-03-22 22:36:24 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    
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:  sad16_mmx:
287    
288      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 135  Line 319 
319    
320      ret      ret
321    
322    ;-----------------------------------------------------------------------------
 ;===========================================================================  
323  ;  ;
324  ; uint32_t sad8_mmx(const uint8_t * const cur,  ; uint32_t sad8_mmx(const uint8_t * const cur,
325  ;                                       const uint8_t * const ref,  ;                                       const uint8_t * const ref,
326  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
327  ;  ;
328  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %macro SAD_8x8_MMX  0  
     movq mm0, [eax]  
     movq mm1, [edx]  
   
     movq mm2, [eax+ecx]  
     movq mm3, [edx+ecx]  
329    
330      lea eax,[eax+2*ecx]  ALIGN 16
     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  
331  sad8_mmx:  sad8_mmx:
332    
333      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 202  Line 351 
351    
352      ret      ret
353    
354    ;-----------------------------------------------------------------------------
 ;===========================================================================  
355  ;  ;
356  ; uint32_t sad16v_mmx(const uint8_t * const cur,  ; uint32_t sad16v_mmx(const uint8_t * const cur,
357  ;                                     const uint8_t * const ref,  ;                                     const uint8_t * const ref,
358  ;                                         const uint32_t stride,  ;                                         const uint32_t stride,
359  ;                                         int32_t *sad);  ;                                         int32_t *sad);
360  ;  ;
361  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %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  
   
     psubusb mm1, mm4  
     por mm0, mm1  
     lea eax,[eax+ecx]  
   
     movq mm4, mm2  
     psubusb mm2, mm3  
   
     psubusb mm3, mm4  
     por mm2, mm3  
     lea edx,[edx+ecx]  
362    
363      movq mm1,mm0  ALIGN 16
     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  
364  sad16v_mmx:  sad16v_mmx:
365    
366          push ebx          push ebx
# Line 326  Line 438 
438    
439          pop edi          pop edi
440      pop ebx      pop ebx
         ret  
   
441    
442      ret
443    
444  ;===========================================================================  ;-----------------------------------------------------------------------------
445  ;  ;
446  ; uint32_t sad16bi_mmx(const uint8_t * const cur,  ; uint32_t sad16bi_mmx(const uint8_t * const cur,
447  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
448  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
449  ; const uint32_t stride);  ; const uint32_t stride);
450  ;  ;
451  ;===========================================================================  ;-----------------------------------------------------------------------------
 %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );  
452    
453     movq mm0, [edx+%1]  ALIGN 16
    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  
   
    movq mm2, [eax+%1]  
    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  
454  sad16bi_mmx:  sad16bi_mmx:
455     push ebx     push ebx
456     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 440  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 479  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  ;===========================================================================  ;-----------------------------------------------------------------------------
552    
553  %macro MEAN_16x16_MMX 0  ALIGN 16
     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  
   
 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 609  Line 619 
619      paddd mm6, mm5      paddd mm6, mm5
620    
621      movd eax, mm6      movd eax, mm6
622    
623      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      ret

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

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