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

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

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

revision 652, Sun Nov 17 00:35:33 2002 UTC revision 1540, Sun Aug 29 10:02:38 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  ; *  Copyright(C) 2002 Peter Ross <pross@xvid.org>  ; *  Copyright(C) 2001 Peter Ross <pross@xvid.org>
7    ; *               2002 Pascal Massimino <skal@planet-d.net>
8  ; *  ; *
9  ; *  This file is part of XviD, a free MPEG-4 video encoder/decoder  ; *  This program is free software; you can redistribute it and/or modify it
 ; *  
 ; *  XviD is free software; you can redistribute it and/or modify it  
10  ; *  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.
# Line 21  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  ; *  Under section 8 of the GNU General Public License, the copyright  ; * $Id: sad_mmx.asm,v 1.16 2004-08-29 10:02:38 edgomez Exp $
 ; *  holders of XVID explicitly forbid distribution in the following  
 ; *  countries:  
 ; *  
 ; *    - Japan  
 ; *    - United States of America  
 ; *  
 ; *  Linking XviD statically or dynamically with other modules is making a  
 ; *  combined work based on XviD.  Thus, the terms and conditions of the  
 ; *  GNU General Public License cover the whole combination.  
 ; *  
 ; *  As a special exception, the copyright holders of XviD give you  
 ; *  permission to link XviD with independent modules that communicate with  
 ; *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
 ; *  license terms of these independent modules, and to copy and distribute  
 ; *  the resulting combined work under terms of your choice, provided that  
 ; *  every copy of the combined work is accompanied by a complete copy of  
 ; *  the source code of XviD (the version of XviD used to produce the  
 ; *  combined work), being distributed under the terms of the GNU General  
 ; *  Public License plus this exception.  An independent module is a module  
 ; *  which is not derived from or based on XviD.  
24  ; *  ; *
25  ; *  Note that people who make modified versions of XviD are not obligated  ; ***************************************************************************/
 ; *  to grant this special exception for their modified versions; it is  
 ; *  their choice whether to do so.  The GNU General Public License gives  
 ; *  permission to release a modified version without this exception; this  
 ; *  exception also makes it possible to release a modified version which  
 ; *  carries forward this exception.  
 ; *  
 ; * $Id: sad_mmx.asm,v 1.10 2002-11-17 00:32:06 edgomez Exp $  
 ; *  
 ; ****************************************************************************/  
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 %1.endfunc-%1
33                            %define %1 _%1:function %1.endfunc-%1
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 %1.endfunc-%1
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    ;=============================================================================
50    
51  align 16  %ifdef FORMAT_COFF
52  mmx_one times 4 dw 1  SECTION .rodata
53    %else
54    SECTION .rodata align=16
55    %endif
56    
57  section .text  ALIGN 16
58    mmx_one:
59  cglobal  sad16_mmx          times 4 dw 1
60  cglobal  sad8_mmx  
61  cglobal  sad16bi_mmx  ;=============================================================================
62  cglobal  sad8bi_mmx  ; Helper macros
63  cglobal  dev16_mmx  ;=============================================================================
   
 ;===========================================================================  
 ;  
 ; uint32_t sad16_mmx(const uint8_t * const cur,  
 ;                                        const uint8_t * const ref,  
 ;                                        const uint32_t stride,  
 ;                                        const uint32_t best_sad);  
 ;  
 ; (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 122  Line 95 
95      paddusw mm6,mm2      paddusw mm6,mm2
96  %endmacro  %endmacro
97    
 align 16  
 sad16_mmx:  
   
     mov eax, [esp+ 4] ; Src1  
     mov edx, [esp+ 8] ; Src2  
     mov ecx, [esp+12] ; Stride  
   
     pxor mm6, mm6 ; accum  
     pxor mm7, mm7 ; zero  
   
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
   
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
     SAD_16x16_MMX  
   
     pmaddwd mm6, [mmx_one] ; collapse  
     movq mm7, mm6  
     psrlq mm7, 32  
     paddd mm6, mm7  
   
     movd eax, mm6  
   
     ret  
   
   
 ;===========================================================================  
 ;  
 ; uint32_t sad8_mmx(const uint8_t * const cur,  
 ;                                       const uint8_t * const ref,  
 ;                                       const uint32_t stride);  
 ;  
 ;===========================================================================  
   
98  %macro SAD_8x8_MMX  0  %macro SAD_8x8_MMX  0
99      movq mm0, [eax]      movq mm0, [eax]
100      movq mm1, [edx]      movq mm1, [edx]
# Line 202  Line 129 
129      paddusw mm6,mm2      paddusw mm6,mm2
130  %endmacro  %endmacro
131    
132  align 16  %macro SADV_16x16_MMX 0
133  sad8_mmx:    movq mm0, [eax]
134      movq mm1, [edx]
     mov eax, [esp+ 4] ; Src1  
     mov edx, [esp+ 8] ; Src2  
     mov ecx, [esp+12] ; Stride  
135    
136      pxor mm6, mm6 ; accum    movq mm2, [eax+8]
137      pxor mm7, mm7 ; zero    movq mm3, [edx+8]
138    
139      SAD_8x8_MMX    movq mm4, mm0
140      SAD_8x8_MMX    psubusb mm0, mm1
     SAD_8x8_MMX  
     SAD_8x8_MMX  
141    
142      pmaddwd mm6, [mmx_one] ; collapse    psubusb mm1, mm4
143      movq mm7, mm6    por mm0, mm1
144      psrlq mm7, 32    lea eax,[eax+ecx]
     paddd mm6, mm7  
145    
146      movd eax, mm6    movq mm4, mm2
147      psubusb mm2, mm3
148    
149      ret    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    
 ;===========================================================================  
 ;  
 ; uint32_t sad16bi_mmx(const uint8_t * const cur,  
 ; const uint8_t * const ref1,  
 ; const uint8_t * const ref2,  
 ; const uint32_t stride);  
 ;  
 ;===========================================================================  
168  %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );  %macro SADBI_16x16_MMX 2    ; SADBI_16x16_MMX( int_ptr_offset, bool_increment_ptr );
169    
170     movq mm0, [edx+%1]     movq mm0, [edx+%1]
# Line 288  Line 215 
215    
216  %endmacro  %endmacro
217    
218  align 16  %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:
297    
298      mov eax, [esp+ 4] ; Src1
299      mov edx, [esp+ 8] ; Src2
300      mov ecx, [esp+12] ; Stride
301    
302      pxor mm6, mm6 ; accum
303      pxor mm7, mm7 ; zero
304    
305      SAD_16x16_MMX
306      SAD_16x16_MMX
307      SAD_16x16_MMX
308      SAD_16x16_MMX
309      SAD_16x16_MMX
310      SAD_16x16_MMX
311      SAD_16x16_MMX
312      SAD_16x16_MMX
313    
314      SAD_16x16_MMX
315      SAD_16x16_MMX
316      SAD_16x16_MMX
317      SAD_16x16_MMX
318      SAD_16x16_MMX
319      SAD_16x16_MMX
320      SAD_16x16_MMX
321      SAD_16x16_MMX
322    
323      pmaddwd mm6, [mmx_one] ; collapse
324      movq mm7, mm6
325      psrlq mm7, 32
326      paddd mm6, mm7
327    
328      movd eax, mm6
329    
330      ret
331    .endfunc
332    
333    ;-----------------------------------------------------------------------------
334    ;
335    ; uint32_t sad8_mmx(const uint8_t * const cur,
336    ;                                       const uint8_t * const ref,
337    ;                                       const uint32_t stride);
338    ;
339    ;-----------------------------------------------------------------------------
340    
341    ALIGN 16
342    sad8_mmx:
343    
344      mov eax, [esp+ 4] ; Src1
345      mov edx, [esp+ 8] ; Src2
346      mov ecx, [esp+12] ; Stride
347    
348      pxor mm6, mm6 ; accum
349      pxor mm7, mm7 ; zero
350    
351      SAD_8x8_MMX
352      SAD_8x8_MMX
353      SAD_8x8_MMX
354      SAD_8x8_MMX
355    
356      pmaddwd mm6, [mmx_one] ; collapse
357      movq mm7, mm6
358      psrlq mm7, 32
359      paddd mm6, mm7
360    
361      movd eax, mm6
362    
363      ret
364    .endfunc
365    
366    ;-----------------------------------------------------------------------------
367    ;
368    ; uint32_t sad16v_mmx(const uint8_t * const cur,
369    ;                                     const uint8_t * const ref,
370    ;                                         const uint32_t stride,
371    ;                                         int32_t *sad);
372    ;
373    ;-----------------------------------------------------------------------------
374    
375    ALIGN 16
376    sad16v_mmx:
377    
378      push ebx
379      push edi
380    
381      mov eax, [esp + 8 + 4] ; Src1
382      mov edx, [esp + 8 + 8] ; Src2
383      mov ecx, [esp + 8 + 12] ; Stride
384      mov ebx, [esp + 8 + 16] ; sad ptr
385    
386      pxor mm5, mm5 ; accum
387      pxor mm6, mm6 ; accum
388      pxor mm7, mm7 ; zero
389    
390      SADV_16x16_MMX
391      SADV_16x16_MMX
392      SADV_16x16_MMX
393      SADV_16x16_MMX
394      SADV_16x16_MMX
395      SADV_16x16_MMX
396      SADV_16x16_MMX
397      SADV_16x16_MMX
398    
399      pmaddwd mm5, [mmx_one] ; collapse
400      pmaddwd mm6, [mmx_one] ; collapse
401    
402      movq mm2, mm5
403      movq mm3, mm6
404    
405      psrlq mm2, 32
406      psrlq mm3, 32
407    
408      paddd mm5, mm2
409      paddd mm6, mm3
410    
411      movd [ebx], mm5
412      movd [ebx + 4], mm6
413    
414      paddd mm5, mm6
415    
416      movd edi, mm5
417    
418      pxor mm5, mm5
419      pxor mm6, mm6
420    
421      SADV_16x16_MMX
422      SADV_16x16_MMX
423      SADV_16x16_MMX
424      SADV_16x16_MMX
425      SADV_16x16_MMX
426      SADV_16x16_MMX
427      SADV_16x16_MMX
428      SADV_16x16_MMX
429    
430      pmaddwd mm5, [mmx_one] ; collapse
431      pmaddwd mm6, [mmx_one] ; collapse
432    
433      movq mm2, mm5
434      movq mm3, mm6
435    
436      psrlq mm2, 32
437      psrlq mm3, 32
438    
439      paddd mm5, mm2
440      paddd mm6, mm3
441    
442      movd [ebx + 8], mm5
443      movd [ebx + 12], mm6
444    
445      paddd mm5, mm6
446    
447      movd eax, mm5
448    
449      add eax, edi
450    
451      pop edi
452      pop ebx
453    
454      ret
455    .endfunc
456    
457    ;-----------------------------------------------------------------------------
458    ;
459    ; uint32_t sad16bi_mmx(const uint8_t * const cur,
460    ; const uint8_t * const ref1,
461    ; const uint8_t * const ref2,
462    ; const uint32_t stride);
463    ;
464    ;-----------------------------------------------------------------------------
465    
466    ALIGN 16
467  sad16bi_mmx:  sad16bi_mmx:
468     push ebx     push ebx
469     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 340  Line 515 
515    
516     movd eax, mm6     movd eax, mm6
517     pop ebx     pop ebx
518    
519     ret     ret
520    .endfunc
521    
522  ;===========================================================================  ;-----------------------------------------------------------------------------
523  ;  ;
524  ; uint32_t sad8bi_mmx(const uint8_t * const cur,  ; uint32_t sad8bi_mmx(const uint8_t * const cur,
525  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
526  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
527  ; const uint32_t stride);  ; const uint32_t stride);
528  ;  ;
529  ;===========================================================================  ;-----------------------------------------------------------------------------
530  align 16  
531    ALIGN 16
532  sad8bi_mmx:  sad8bi_mmx:
533     push ebx     push ebx
534     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 378  Line 556 
556     movd eax, mm6     movd eax, mm6
557     pop ebx     pop ebx
558     ret     ret
559    .endfunc
560    
561    ;-----------------------------------------------------------------------------
   
   
 ;===========================================================================  
562  ;  ;
563  ; uint32_t dev16_mmx(const uint8_t * const cur,  ; uint32_t dev16_mmx(const uint8_t * const cur,
564  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
565  ;  ;
566  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %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  
567    
568  align 16  ALIGN 16
569  dev16_mmx:  dev16_mmx:
570      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
571      mov ecx, [esp+ 8] ; Stride      mov ecx, [esp+ 8] ; Stride
# Line 509  Line 634 
634      paddd mm6, mm5      paddd mm6, mm5
635    
636      movd eax, mm6      movd eax, mm6
637    
638      ret
639    .endfunc
640    
641    ;-----------------------------------------------------------------------------
642    ;
643    ; uint32_t sse8_16bit_mmx(const int16_t *b1,
644    ;                         const int16_t *b2,
645    ;                         const uint32_t stride);
646    ;
647    ;-----------------------------------------------------------------------------
648    
649    %macro ROW_SSE_16bit_MMX 2
650      movq mm0, [%1]
651      movq mm1, [%1+8]
652      psubw mm0, [%2]
653      psubw mm1, [%2+8]
654      pmaddwd mm0, mm0
655      pmaddwd mm1, mm1
656      paddd mm2, mm0
657      paddd mm2, mm1
658    %endmacro
659    
660    sse8_16bit_mmx:
661      push esi
662      push edi
663    
664      ;; Load the function params
665      mov esi, [esp+8+4]
666      mov edi, [esp+8+8]
667      mov edx, [esp+8+12]
668    
669      ;; Reset the sse accumulator
670      pxor mm2, mm2
671    
672      ;; Let's go
673    %rep 8
674      ROW_SSE_16bit_MMX esi, edi
675      lea esi, [esi+edx]
676      lea edi, [edi+edx]
677    %endrep
678    
679      ;; Finish adding each dword of the accumulator
680      movq mm3, mm2
681      psrlq mm2, 32
682      paddd mm2, mm3
683      movd eax, mm2
684    
685      ;; All done
686      pop edi
687      pop esi
688      ret
689    .endfunc
690    
691    ;-----------------------------------------------------------------------------
692    ;
693    ; uint32_t sse8_8bit_mmx(const int8_t *b1,
694    ;                        const int8_t *b2,
695    ;                        const uint32_t stride);
696    ;
697    ;-----------------------------------------------------------------------------
698    
699    %macro ROW_SSE_8bit_MMX 2
700      movq mm0, [%1] ; load a row
701      movq mm2, [%2] ; load a row
702    
703      movq mm1, mm0  ; copy row
704      movq mm3, mm2  ; copy row
705    
706      punpcklbw mm0, mm7 ; turn the 4low elements into 16bit
707      punpckhbw mm1, mm7 ; turn the 4high elements into 16bit
708    
709      punpcklbw mm2, mm7 ; turn the 4low elements into 16bit
710      punpckhbw mm3, mm7 ; turn the 4high elements into 16bit
711    
712      psubw mm0, mm2 ; low  part of src-dst
713      psubw mm1, mm3 ; high part of src-dst
714    
715      pmaddwd mm0, mm0 ; compute the square sum
716      pmaddwd mm1, mm1 ; compute the square sum
717    
718      paddd mm6, mm0 ; add to the accumulator
719      paddd mm6, mm1 ; add to the accumulator
720    %endmacro
721    
722    sse8_8bit_mmx:
723      push esi
724      push edi
725    
726      ;; Load the function params
727      mov esi, [esp+8+4]
728      mov edi, [esp+8+8]
729      mov edx, [esp+8+12]
730    
731      ;; Reset the sse accumulator
732      pxor mm6, mm6
733    
734      ;; Used to interleave 8bit data with 0x00 values
735      pxor mm7, mm7
736    
737      ;; Let's go
738    %rep 8
739      ROW_SSE_8bit_MMX esi, edi
740      lea esi, [esi+edx]
741      lea edi, [edi+edx]
742    %endrep
743    
744      ;; Finish adding each dword of the accumulator
745      movq mm7, mm6
746      psrlq mm6, 32
747      paddd mm6, mm7
748      movd eax, mm6
749    
750      ;; All done
751      pop edi
752      pop esi
753      ret      ret
754    .endfunc
755    

Legend:
Removed from v.652  
changed lines
  Added in v.1540

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