[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 1535, 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  ; *     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.15 2004-08-22 11:46:10 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
31                    %ifdef MARK_FUNCS
32                            global _%1:function
33                            %define %1 _%1:function
34                    %else
35                  global _%1                  global _%1
36                  %define %1 _%1                  %define %1 _%1
37                    %endif
38            %else
39                    %ifdef MARK_FUNCS
40                            global %1:function
41          %else          %else
42                  global %1                  global %1
43          %endif          %endif
44            %endif
45  %endmacro  %endmacro
46    
47  section .data  ;=============================================================================
48    ; Read only data
49  align 16  ;=============================================================================
 mmx_one times 4 dw 1  
50    
51  section .text  %ifdef FORMAT_COFF
52    SECTION .rodata
53  cglobal  sad16_mmx  %else
54  cglobal  sad16v_mmx  SECTION .rodata align=16
55  cglobal  sad8_mmx  %endif
 cglobal  sad16bi_mmx  
 cglobal  sad8bi_mmx  
 cglobal  dev16_mmx  
56    
57  ;===========================================================================  ALIGN 16
58  ;  mmx_one:
59  ; uint32_t sad16_mmx(const uint8_t * const cur,          times 4 dw 1
60  ;                                        const uint8_t * const ref,  
61  ;                                        const uint32_t stride,  ;=============================================================================
62  ;                                        const uint32_t best_sad);  ; Helper macros
63  ;  ;=============================================================================
 ; (early termination ignore; slows this down)  
 ;  
 ;===========================================================================  
64    
65  %macro SAD_16x16_MMX 0  %macro SAD_16x16_MMX 0
66      movq mm0, [eax]      movq mm0, [eax]
# Line 98  Line 95 
95      paddusw mm6,mm2      paddusw mm6,mm2
96  %endmacro  %endmacro
97    
98  align 16  %macro SAD_8x8_MMX      0
99      movq mm0, [eax]
100      movq mm1, [edx]
101    
102      movq mm2, [eax+ecx]
103      movq mm3, [edx+ecx]
104    
105      lea eax,[eax+2*ecx]
106      lea edx,[edx+2*ecx]
107    
108      movq mm4, mm0
109      psubusb mm0, mm1
110      movq mm5, mm2
111      psubusb mm2, mm3
112    
113      psubusb mm1, mm4
114      por mm0, mm1
115      psubusb mm3, mm5
116      por mm2, mm3
117    
118      movq mm1,mm0
119      movq mm3,mm2
120    
121      punpcklbw mm0,mm7
122      punpckhbw mm1,mm7
123      punpcklbw mm2,mm7
124      punpckhbw mm3,mm7
125    
126      paddusw mm0,mm1
127      paddusw mm6,mm0
128      paddusw mm2,mm3
129      paddusw mm6,mm2
130    %endmacro
131    
132    %macro SADV_16x16_MMX 0
133      movq mm0, [eax]
134      movq mm1, [edx]
135    
136      movq mm2, [eax+8]
137      movq mm3, [edx+8]
138    
139      movq mm4, mm0
140      psubusb mm0, mm1
141    
142      psubusb mm1, mm4
143      por mm0, mm1
144      lea eax,[eax+ecx]
145    
146      movq mm4, mm2
147      psubusb mm2, mm3
148    
149      psubusb mm3, mm4
150      por mm2, mm3
151      lea edx,[edx+ecx]
152    
153      movq mm1,mm0
154      movq mm3,mm2
155    
156      punpcklbw mm0,mm7
157      punpckhbw mm1,mm7
158      punpcklbw mm2,mm7
159      punpckhbw mm3,mm7
160    
161      paddusw mm0,mm1
162      paddusw mm2,mm3
163    
164      paddusw mm5, mm0
165      paddusw mm6, mm2
166    %endmacro
167    
168    %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
169    
170      movq mm0, [edx+%1]
171      movq mm2, [ebx+%1]
172      movq mm1, mm0
173      movq mm3, mm2
174    
175    %if %2 != 0
176      add edx, ecx
177    %endif
178    
179      punpcklbw mm0, mm7
180      punpckhbw mm1, mm7
181      punpcklbw mm2, mm7
182      punpckhbw mm3, mm7
183    
184    %if %2 != 0
185      add ebx, ecx
186    %endif
187    
188      paddusw mm0, mm2              ; mm01 = ref1 + ref2
189      paddusw mm1, mm3
190      paddusw mm0, [mmx_one]        ; mm01 += 1
191      paddusw mm1, [mmx_one]
192      psrlw mm0, 1                  ; mm01 >>= 1
193      psrlw mm1, 1
194    
195      movq mm2, [eax+%1]
196      movq mm3, mm2
197      punpcklbw mm2, mm7            ; mm23 = src
198      punpckhbw mm3, mm7
199    
200    %if %2 != 0
201      add eax, ecx
202    %endif
203    
204      movq mm4, mm0
205      movq mm5, mm1
206      psubusw mm0, mm2
207      psubusw mm1, mm3
208      psubusw mm2, mm4
209      psubusw mm3, mm5
210      por mm0, mm2                  ; mm01 = ABS(mm01 - mm23)
211      por mm1, mm3
212    
213      paddusw mm6, mm0              ; mm6 += mm01
214      paddusw mm6, mm1
215    
216    %endmacro
217    
218    %macro MEAN_16x16_MMX 0
219      movq mm0, [eax]
220      movq mm2, [eax+8]
221      lea eax, [eax+ecx]
222      movq mm1, mm0
223      movq mm3, mm2
224      punpcklbw mm0, mm7
225      punpcklbw mm2, mm7
226      punpckhbw mm1, mm7
227      punpckhbw mm3, mm7
228      paddw mm5, mm0
229      paddw mm6, mm1
230      paddw mm5, mm2
231      paddw mm6, mm3
232    %endmacro
233    
234    %macro ABS_16x16_MMX 0
235      movq mm0, [eax]
236      movq mm2, [eax+8]
237      lea eax, [eax+ecx]
238      movq mm1, mm0
239      movq mm3, mm2
240      punpcklbw mm0, mm7
241      punpcklbw mm2, mm7
242      punpckhbw mm1, mm7
243      punpckhbw mm3, mm7
244      movq mm4, mm6
245      psubusw mm4, mm0
246    
247      psubusw mm0, mm6
248      por mm0, mm4
249      movq mm4, mm6
250      psubusw mm4, mm1
251      psubusw mm1, mm6
252      por mm1, mm4
253    
254      movq mm4, mm6
255      psubusw mm4, mm2
256      psubusw mm2, mm6
257      por mm2, mm4
258      movq mm4, mm6
259      psubusw mm4, mm3
260      psubusw mm3, mm6
261      por mm3, mm4
262    
263      paddw mm0, mm1
264      paddw mm2, mm3
265      paddw mm5, mm0
266      paddw mm5, mm2
267    %endmacro
268    
269    ;=============================================================================
270    ; Code
271    ;=============================================================================
272    
273    SECTION .text
274    
275    cglobal sad16_mmx
276    cglobal sad16v_mmx
277    cglobal sad8_mmx
278    cglobal sad16bi_mmx
279    cglobal sad8bi_mmx
280    cglobal dev16_mmx
281    cglobal sse8_16bit_mmx
282    cglobal sse8_8bit_mmx
283    
284    ;-----------------------------------------------------------------------------
285    ;
286    ; uint32_t sad16_mmx(const uint8_t * const cur,
287    ;                                        const uint8_t * const ref,
288    ;                                        const uint32_t stride,
289    ;                                        const uint32_t best_sad);
290    ;
291    ; (early termination ignore; slows this down)
292    ;
293    ;-----------------------------------------------------------------------------
294    
295    ALIGN 16
296  sad16_mmx:  sad16_mmx:
297    
298      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 135  Line 329 
329    
330      ret      ret
331    
332    ;-----------------------------------------------------------------------------
 ;===========================================================================  
333  ;  ;
334  ; uint32_t sad8_mmx(const uint8_t * const cur,  ; uint32_t sad8_mmx(const uint8_t * const cur,
335  ;                                       const uint8_t * const ref,  ;                                       const uint8_t * const ref,
336  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
337  ;  ;
338  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %macro SAD_8x8_MMX  0  
     movq mm0, [eax]  
     movq mm1, [edx]  
339    
340      movq mm2, [eax+ecx]  ALIGN 16
     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  
341  sad8_mmx:  sad8_mmx:
342    
343      mov eax, [esp+ 4] ; Src1      mov eax, [esp+ 4] ; Src1
# Line 202  Line 361 
361    
362      ret      ret
363    
364    ;-----------------------------------------------------------------------------
 ;===========================================================================  
365  ;  ;
366  ; uint32_t sad16v_mmx(const uint8_t * const cur,  ; uint32_t sad16v_mmx(const uint8_t * const cur,
367  ;                                     const uint8_t * const ref,  ;                                     const uint8_t * const ref,
368  ;                                         const uint32_t stride,  ;                                         const uint32_t stride,
369  ;                                         int32_t *sad);  ;                                         int32_t *sad);
370  ;  ;
371  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %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]  
   
     movq mm1,mm0  
     movq mm3,mm2  
372    
373      punpcklbw mm0,mm7  ALIGN 16
     punpckhbw mm1,mm7  
     punpcklbw mm2,mm7  
     punpckhbw mm3,mm7  
   
     paddusw mm0,mm1  
     paddusw mm2,mm3  
   
         paddusw mm5, mm0  
         paddusw mm6, mm2  
 %endmacro  
   
 align 16  
374  sad16v_mmx:  sad16v_mmx:
375    
376          push ebx          push ebx
# Line 326  Line 448 
448    
449          pop edi          pop edi
450      pop ebx      pop ebx
         ret  
   
451    
452      ret
453    
454  ;===========================================================================  ;-----------------------------------------------------------------------------
455  ;  ;
456  ; uint32_t sad16bi_mmx(const uint8_t * const cur,  ; uint32_t sad16bi_mmx(const uint8_t * const cur,
457  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
458  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
459  ; const uint32_t stride);  ; const uint32_t stride);
460  ;  ;
461  ;===========================================================================  ;-----------------------------------------------------------------------------
 %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  
462    
463  %if %2 != 0  ALIGN 16
    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  
464  sad16bi_mmx:  sad16bi_mmx:
465     push ebx     push ebx
466     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 440  Line 512 
512    
513     movd eax, mm6     movd eax, mm6
514     pop ebx     pop ebx
515    
516     ret     ret
517    
518  ;===========================================================================  ;-----------------------------------------------------------------------------
519  ;  ;
520  ; uint32_t sad8bi_mmx(const uint8_t * const cur,  ; uint32_t sad8bi_mmx(const uint8_t * const cur,
521  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
522  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
523  ; const uint32_t stride);  ; const uint32_t stride);
524  ;  ;
525  ;===========================================================================  ;-----------------------------------------------------------------------------
526  align 16  
527    ALIGN 16
528  sad8bi_mmx:  sad8bi_mmx:
529     push ebx     push ebx
530     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 479  Line 553 
553     pop ebx     pop ebx
554     ret     ret
555    
556    ;-----------------------------------------------------------------------------
   
   
 ;===========================================================================  
557  ;  ;
558  ; uint32_t dev16_mmx(const uint8_t * const cur,  ; uint32_t dev16_mmx(const uint8_t * const cur,
559  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
560  ;  ;
561  ;===========================================================================  ;-----------------------------------------------------------------------------
562    
563  %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  
564  dev16_mmx:  dev16_mmx:
565      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
566      mov ecx, [esp+ 8] ; Stride      mov ecx, [esp+ 8] ; Stride
# Line 609  Line 629 
629      paddd mm6, mm5      paddd mm6, mm5
630    
631      movd eax, mm6      movd eax, mm6
632    
633      ret
634    
635    ;-----------------------------------------------------------------------------
636    ;
637    ; uint32_t sse8_16bit_mmx(const int16_t *b1,
638    ;                         const int16_t *b2,
639    ;                         const uint32_t stride);
640    ;
641    ;-----------------------------------------------------------------------------
642    
643    %macro ROW_SSE_16bit_MMX 2
644      movq mm0, [%1]
645      movq mm1, [%1+8]
646      psubw mm0, [%2]
647      psubw mm1, [%2+8]
648      pmaddwd mm0, mm0
649      pmaddwd mm1, mm1
650      paddd mm2, mm0
651      paddd mm2, mm1
652    %endmacro
653    
654    sse8_16bit_mmx:
655      push esi
656      push edi
657    
658      ;; Load the function params
659      mov esi, [esp+8+4]
660      mov edi, [esp+8+8]
661      mov edx, [esp+8+12]
662    
663      ;; Reset the sse accumulator
664      pxor mm2, mm2
665    
666      ;; Let's go
667    %rep 8
668      ROW_SSE_16bit_MMX esi, edi
669      lea esi, [esi+edx]
670      lea edi, [edi+edx]
671    %endrep
672    
673      ;; Finish adding each dword of the accumulator
674      movq mm3, mm2
675      psrlq mm2, 32
676      paddd mm2, mm3
677      movd eax, mm2
678    
679      ;; All done
680      pop edi
681      pop esi
682      ret
683    
684    ;-----------------------------------------------------------------------------
685    ;
686    ; uint32_t sse8_8bit_mmx(const int8_t *b1,
687    ;                        const int8_t *b2,
688    ;                        const uint32_t stride);
689    ;
690    ;-----------------------------------------------------------------------------
691    
692    %macro ROW_SSE_8bit_MMX 2
693      movq mm0, [%1] ; load a row
694      movq mm2, [%2] ; load a row
695    
696      movq mm1, mm0  ; copy row
697      movq mm3, mm2  ; copy row
698    
699      punpcklbw mm0, mm7 ; turn the 4low elements into 16bit
700      punpckhbw mm1, mm7 ; turn the 4high elements into 16bit
701    
702      punpcklbw mm2, mm7 ; turn the 4low elements into 16bit
703      punpckhbw mm3, mm7 ; turn the 4high elements into 16bit
704    
705      psubw mm0, mm2 ; low  part of src-dst
706      psubw mm1, mm3 ; high part of src-dst
707    
708      pmaddwd mm0, mm0 ; compute the square sum
709      pmaddwd mm1, mm1 ; compute the square sum
710    
711      paddd mm6, mm0 ; add to the accumulator
712      paddd mm6, mm1 ; add to the accumulator
713    %endmacro
714    
715    sse8_8bit_mmx:
716      push esi
717      push edi
718    
719      ;; Load the function params
720      mov esi, [esp+8+4]
721      mov edi, [esp+8+8]
722      mov edx, [esp+8+12]
723    
724      ;; Reset the sse accumulator
725      pxor mm6, mm6
726    
727      ;; Used to interleave 8bit data with 0x00 values
728      pxor mm7, mm7
729    
730      ;; Let's go
731    %rep 8
732      ROW_SSE_8bit_MMX esi, edi
733      lea esi, [esi+edx]
734      lea edi, [edi+edx]
735    %endrep
736    
737      ;; Finish adding each dword of the accumulator
738      movq mm7, mm6
739      psrlq mm6, 32
740      paddd mm6, mm7
741      movd eax, mm6
742    
743      ;; All done
744      pop edi
745      pop esi
746      ret      ret

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

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