[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 262, Sun Jul 7 09:45:40 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  ; *     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
 ; *  
 ; *************************************************************************/  
   
 ;/**************************************************************************  
22  ; *  ; *
23  ; *     History:  ; * $Id: sad_mmx.asm,v 1.16 2004-08-29 10:02:38 edgomez Exp $
24  ; *  ; *
25  ; * 23.07.2002  sad[16,8]bi_xmm; <pross@xvid.org>  ; ***************************************************************************/
 ; * 04.06.2002  cleanup -Skal-  
 ; *     12.11.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
 ; *  
 ; *************************************************************************/  
26    
27  bits 32  BITS 32
28    
29  %macro cglobal 1  %macro cglobal 1
30            %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  align 16  ;=============================================================================
 mmx_one times 4 dw 1  
   
 section .text  
50    
51  cglobal  sad16_mmx  %ifdef FORMAT_COFF
52  cglobal  sad8_mmx  SECTION .rodata
53  cglobal  sad16bi_mmx  %else
54  cglobal  sad8bi_mmx  SECTION .rodata align=16
55  cglobal  dev16_mmx  %endif
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  ; (early termination ignore; slows this down)  ; Helper macros
63  ;  ;=============================================================================
 ;===========================================================================  
64    
65  %macro SAD_16x16_MMX 0  %macro SAD_16x16_MMX 0
66      movq mm0, [eax]      movq mm0, [eax]
# Line 94  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 174  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]
135    
136      mov eax, [esp+ 4] ; Src1    movq mm2, [eax+8]
137      mov edx, [esp+ 8] ; Src2    movq mm3, [edx+8]
     mov ecx, [esp+12] ; Stride  
138    
139      pxor mm6, mm6 ; accum    movq mm4, mm0
140      pxor mm7, mm7 ; zero    psubusb mm0, mm1
141    
142      SAD_8x8_MMX    psubusb mm1, mm4
143      SAD_8x8_MMX    por mm0, mm1
144      SAD_8x8_MMX    lea eax,[eax+ecx]
     SAD_8x8_MMX  
145    
146      pmaddwd mm6, [mmx_one] ; collapse    movq mm4, mm2
147      movq mm7, mm6    psubusb mm2, mm3
     psrlq mm7, 32  
     paddd mm6, mm7  
148    
149      movd eax, mm6    psubusb mm3, mm4
150      por mm2, mm3
151      lea edx,[edx+ecx]
152    
153      ret    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  ; uint32_t sad16bi_mmx(const uint8_t * const cur,  %endif
178  ; const uint8_t * const ref1,  
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]      movq mm0, [eax]
220      movq mm2, [eax+8]      movq mm2, [eax+8]
221      lea eax,[eax+ecx]      lea eax,[eax+ecx]
# Line 256  Line 266 
266          paddw mm5, mm2          paddw mm5, mm2
267  %endmacro  %endmacro
268    
269  align 16  ;=============================================================================
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:
468      push ebx
469      mov eax, [esp+4+ 4] ; Src
470      mov edx, [esp+4+ 8] ; Ref1
471      mov ebx, [esp+4+12] ; Ref2
472      mov ecx, [esp+4+16] ; Stride
473    
474      pxor mm6, mm6 ; accum2
475      pxor mm7, mm7
476    .Loop
477      SADBI_16x16_MMX 0, 0
478      SADBI_16x16_MMX 8, 1
479      SADBI_16x16_MMX 0, 0
480      SADBI_16x16_MMX 8, 1
481      SADBI_16x16_MMX 0, 0
482      SADBI_16x16_MMX 8, 1
483      SADBI_16x16_MMX 0, 0
484      SADBI_16x16_MMX 8, 1
485      SADBI_16x16_MMX 0, 0
486      SADBI_16x16_MMX 8, 1
487      SADBI_16x16_MMX 0, 0
488      SADBI_16x16_MMX 8, 1
489      SADBI_16x16_MMX 0, 0
490      SADBI_16x16_MMX 8, 1
491      SADBI_16x16_MMX 0, 0
492      SADBI_16x16_MMX 8, 1
493    
494      SADBI_16x16_MMX 0, 0
495      SADBI_16x16_MMX 8, 1
496      SADBI_16x16_MMX 0, 0
497      SADBI_16x16_MMX 8, 1
498      SADBI_16x16_MMX 0, 0
499      SADBI_16x16_MMX 8, 1
500      SADBI_16x16_MMX 0, 0
501      SADBI_16x16_MMX 8, 1
502      SADBI_16x16_MMX 0, 0
503      SADBI_16x16_MMX 8, 1
504      SADBI_16x16_MMX 0, 0
505      SADBI_16x16_MMX 8, 1
506      SADBI_16x16_MMX 0, 0
507      SADBI_16x16_MMX 8, 1
508      SADBI_16x16_MMX 0, 0
509      SADBI_16x16_MMX 8, 1
510    
511      pmaddwd mm6, [mmx_one] ; collapse
512      movq mm7, mm6
513      psrlq mm7, 32
514      paddd mm6, mm7
515    
516      movd eax, mm6
517      pop ebx
518    
519      ret
520    .endfunc
521    
522    ;-----------------------------------------------------------------------------
523    ;
524    ; uint32_t sad8bi_mmx(const uint8_t * const cur,
525    ; const uint8_t * const ref1,
526    ; const uint8_t * const ref2,
527    ; const uint32_t stride);
528    ;
529    ;-----------------------------------------------------------------------------
530    
531    ALIGN 16
532    sad8bi_mmx:
533      push ebx
534      mov eax, [esp+4+ 4] ; Src
535      mov edx, [esp+4+ 8] ; Ref1
536      mov ebx, [esp+4+12] ; Ref2
537      mov ecx, [esp+4+16] ; Stride
538    
539      pxor mm6, mm6 ; accum2
540      pxor mm7, mm7
541    .Loop
542      SADBI_16x16_MMX 0, 1
543      SADBI_16x16_MMX 0, 1
544      SADBI_16x16_MMX 0, 1
545      SADBI_16x16_MMX 0, 1
546      SADBI_16x16_MMX 0, 1
547      SADBI_16x16_MMX 0, 1
548      SADBI_16x16_MMX 0, 1
549      SADBI_16x16_MMX 0, 1
550    
551      pmaddwd mm6, [mmx_one] ; collapse
552      movq mm7, mm6
553      psrlq mm7, 32
554      paddd mm6, mm7
555    
556      movd eax, mm6
557      pop ebx
558      ret
559    .endfunc
560    
561    ;-----------------------------------------------------------------------------
562    ;
563    ; uint32_t dev16_mmx(const uint8_t * const cur,
564    ;                                       const uint32_t stride);
565    ;
566    ;-----------------------------------------------------------------------------
567    
568    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 325  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      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
754    .endfunc
755    

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

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