[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 430, Fri Sep 6 16:59:47 2002 UTC revision 1519, Sat Jul 24 11:46:08 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 program is an implementation of a part of one or more MPEG-4  ; *  This program is free software; you can redistribute it and/or modify it
10  ; *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  ; *  under the terms of the GNU General Public License as published by
 ; *  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.  
 ; *  
 ; *  This program is free software; you can redistribute it and/or modify  
 ; *  it 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 28  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_mmx.asm,v 1.14 2004-07-24 11:46:08 edgomez Exp $
24    ; *
25    ; ***************************************************************************/
26    
27  bits 32  BITS 32
28    
29  %macro cglobal 1  %macro cglobal 1
30          %ifdef PREFIX          %ifdef PREFIX
# Line 41  Line 35 
35          %endif          %endif
36  %endmacro  %endmacro
37    
38  section .data  ;=============================================================================
39    ; Read only data
40  align 16  ;=============================================================================
 mmx_one times 4 dw 1  
41    
42  section .text  %ifdef FORMAT_COFF
43    SECTION .rodata
44  cglobal  sad16_mmx  %else
45  cglobal  sad8_mmx  SECTION .rodata align=16
46  cglobal  sad16bi_mmx  %endif
 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    
 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);  
 ;  
 ;===========================================================================  
   
89  %macro SAD_8x8_MMX  0  %macro SAD_8x8_MMX  0
90      movq mm0, [eax]      movq mm0, [eax]
91      movq mm1, [edx]      movq mm1, [edx]
# Line 178  Line 120 
120      paddusw mm6,mm2      paddusw mm6,mm2
121  %endmacro  %endmacro
122    
123  align 16  %macro SADV_16x16_MMX 0
124  sad8_mmx:    movq mm0, [eax]
125      movq mm1, [edx]
     mov eax, [esp+ 4] ; Src1  
     mov edx, [esp+ 8] ; Src2  
     mov ecx, [esp+12] ; Stride  
126    
127      pxor mm6, mm6 ; accum    movq mm2, [eax+8]
128      pxor mm7, mm7 ; zero    movq mm3, [edx+8]
129    
130      SAD_8x8_MMX    movq mm4, mm0
131      SAD_8x8_MMX    psubusb mm0, mm1
     SAD_8x8_MMX  
     SAD_8x8_MMX  
132    
133      pmaddwd mm6, [mmx_one] ; collapse    psubusb mm1, mm4
134      movq mm7, mm6    por mm0, mm1
135      psrlq mm7, 32    lea eax,[eax+ecx]
     paddd mm6, mm7  
136    
137      movd eax, mm6    movq mm4, mm2
138      psubusb mm2, mm3
139    
140      ret    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    
 ;===========================================================================  
 ;  
 ; uint32_t sad16bi_mmx(const uint8_t * const cur,  
 ; const uint8_t * const ref1,  
 ; const uint8_t * const ref2,  
 ; const uint32_t stride);  
 ;  
 ;===========================================================================  
159  %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 );
160    
161     movq mm0, [edx+%1]     movq mm0, [edx+%1]
# Line 264  Line 206 
206    
207  %endmacro  %endmacro
208    
209  align 16  %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    cglobal sse8_8bit_mmx
274    
275    ;-----------------------------------------------------------------------------
276    ;
277    ; uint32_t sad16_mmx(const uint8_t * const cur,
278    ;                                        const uint8_t * const ref,
279    ;                                        const uint32_t stride,
280    ;                                        const uint32_t best_sad);
281    ;
282    ; (early termination ignore; slows this down)
283    ;
284    ;-----------------------------------------------------------------------------
285    
286    ALIGN 16
287    sad16_mmx:
288    
289      mov eax, [esp+ 4] ; Src1
290      mov edx, [esp+ 8] ; Src2
291      mov ecx, [esp+12] ; Stride
292    
293      pxor mm6, mm6 ; accum
294      pxor mm7, mm7 ; zero
295    
296      SAD_16x16_MMX
297      SAD_16x16_MMX
298      SAD_16x16_MMX
299      SAD_16x16_MMX
300      SAD_16x16_MMX
301      SAD_16x16_MMX
302      SAD_16x16_MMX
303      SAD_16x16_MMX
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      pmaddwd mm6, [mmx_one] ; collapse
315      movq mm7, mm6
316      psrlq mm7, 32
317      paddd mm6, mm7
318    
319      movd eax, mm6
320    
321      ret
322    
323    ;-----------------------------------------------------------------------------
324    ;
325    ; uint32_t sad8_mmx(const uint8_t * const cur,
326    ;                                       const uint8_t * const ref,
327    ;                                       const uint32_t stride);
328    ;
329    ;-----------------------------------------------------------------------------
330    
331    ALIGN 16
332    sad8_mmx:
333    
334      mov eax, [esp+ 4] ; Src1
335      mov edx, [esp+ 8] ; Src2
336      mov ecx, [esp+12] ; Stride
337    
338      pxor mm6, mm6 ; accum
339      pxor mm7, mm7 ; zero
340    
341      SAD_8x8_MMX
342      SAD_8x8_MMX
343      SAD_8x8_MMX
344      SAD_8x8_MMX
345    
346      pmaddwd mm6, [mmx_one] ; collapse
347      movq mm7, mm6
348      psrlq mm7, 32
349      paddd mm6, mm7
350    
351      movd eax, mm6
352    
353      ret
354    
355    ;-----------------------------------------------------------------------------
356    ;
357    ; uint32_t sad16v_mmx(const uint8_t * const cur,
358    ;                                     const uint8_t * const ref,
359    ;                                         const uint32_t stride,
360    ;                                         int32_t *sad);
361    ;
362    ;-----------------------------------------------------------------------------
363    
364    ALIGN 16
365    sad16v_mmx:
366    
367      push ebx
368      push edi
369    
370      mov eax, [esp + 8 + 4] ; Src1
371      mov edx, [esp + 8 + 8] ; Src2
372      mov ecx, [esp + 8 + 12] ; Stride
373      mov ebx, [esp + 8 + 16] ; sad ptr
374    
375      pxor mm5, mm5 ; accum
376      pxor mm6, mm6 ; accum
377      pxor mm7, mm7 ; zero
378    
379      SADV_16x16_MMX
380      SADV_16x16_MMX
381      SADV_16x16_MMX
382      SADV_16x16_MMX
383      SADV_16x16_MMX
384      SADV_16x16_MMX
385      SADV_16x16_MMX
386      SADV_16x16_MMX
387    
388      pmaddwd mm5, [mmx_one] ; collapse
389      pmaddwd mm6, [mmx_one] ; collapse
390    
391      movq mm2, mm5
392      movq mm3, mm6
393    
394      psrlq mm2, 32
395      psrlq mm3, 32
396    
397      paddd mm5, mm2
398      paddd mm6, mm3
399    
400      movd [ebx], mm5
401      movd [ebx + 4], mm6
402    
403      paddd mm5, mm6
404    
405      movd edi, mm5
406    
407      pxor mm5, mm5
408      pxor mm6, mm6
409    
410      SADV_16x16_MMX
411      SADV_16x16_MMX
412      SADV_16x16_MMX
413      SADV_16x16_MMX
414      SADV_16x16_MMX
415      SADV_16x16_MMX
416      SADV_16x16_MMX
417      SADV_16x16_MMX
418    
419      pmaddwd mm5, [mmx_one] ; collapse
420      pmaddwd mm6, [mmx_one] ; collapse
421    
422      movq mm2, mm5
423      movq mm3, mm6
424    
425      psrlq mm2, 32
426      psrlq mm3, 32
427    
428      paddd mm5, mm2
429      paddd mm6, mm3
430    
431      movd [ebx + 8], mm5
432      movd [ebx + 12], mm6
433    
434      paddd mm5, mm6
435    
436      movd eax, mm5
437    
438      add eax, edi
439    
440      pop edi
441      pop ebx
442    
443      ret
444    
445    ;-----------------------------------------------------------------------------
446    ;
447    ; uint32_t sad16bi_mmx(const uint8_t * const cur,
448    ; const uint8_t * const ref1,
449    ; const uint8_t * const ref2,
450    ; const uint32_t stride);
451    ;
452    ;-----------------------------------------------------------------------------
453    
454    ALIGN 16
455  sad16bi_mmx:  sad16bi_mmx:
456     push ebx     push ebx
457     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 316  Line 503 
503    
504     movd eax, mm6     movd eax, mm6
505     pop ebx     pop ebx
506    
507     ret     ret
508    
509  ;===========================================================================  ;-----------------------------------------------------------------------------
510  ;  ;
511  ; uint32_t sad8bi_mmx(const uint8_t * const cur,  ; uint32_t sad8bi_mmx(const uint8_t * const cur,
512  ; const uint8_t * const ref1,  ; const uint8_t * const ref1,
513  ; const uint8_t * const ref2,  ; const uint8_t * const ref2,
514  ; const uint32_t stride);  ; const uint32_t stride);
515  ;  ;
516  ;===========================================================================  ;-----------------------------------------------------------------------------
517  align 16  
518    ALIGN 16
519  sad8bi_mmx:  sad8bi_mmx:
520     push ebx     push ebx
521     mov eax, [esp+4+ 4] ; Src     mov eax, [esp+4+ 4] ; Src
# Line 355  Line 544 
544     pop ebx     pop ebx
545     ret     ret
546    
547    ;-----------------------------------------------------------------------------
   
   
 ;===========================================================================  
548  ;  ;
549  ; uint32_t dev16_mmx(const uint8_t * const cur,  ; uint32_t dev16_mmx(const uint8_t * const cur,
550  ;                                       const uint32_t stride);  ;                                       const uint32_t stride);
551  ;  ;
552  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 %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  
553    
554  align 16  ALIGN 16
555  dev16_mmx:  dev16_mmx:
556      mov eax, [esp+ 4] ; Src      mov eax, [esp+ 4] ; Src
557      mov ecx, [esp+ 8] ; Stride      mov ecx, [esp+ 8] ; Stride
# Line 485  Line 620 
620      paddd mm6, mm5      paddd mm6, mm5
621    
622      movd eax, mm6      movd eax, mm6
623    
624      ret
625    
626    ;-----------------------------------------------------------------------------
627    ;
628    ; uint32_t sse8_16bit_mmx(const int16_t *b1,
629    ;                         const int16_t *b2,
630    ;                         const uint32_t stride);
631    ;
632    ;-----------------------------------------------------------------------------
633    
634    %macro ROW_SSE_16bit_MMX 2
635      movq mm0, [%1]
636      movq mm1, [%1+8]
637      psubw mm0, [%2]
638      psubw mm1, [%2+8]
639      pmaddwd mm0, mm0
640      pmaddwd mm1, mm1
641      paddd mm2, mm0
642      paddd mm2, mm1
643    %endmacro
644    
645    sse8_16bit_mmx:
646      push esi
647      push edi
648    
649      ;; Load the function params
650      mov esi, [esp+8+4]
651      mov edi, [esp+8+8]
652      mov edx, [esp+8+12]
653    
654      ;; Reset the sse accumulator
655      pxor mm2, mm2
656    
657      ;; Let's go
658    %rep 8
659      ROW_SSE_16bit_MMX esi, edi
660      lea esi, [esi+edx]
661      lea edi, [edi+edx]
662    %endrep
663    
664      ;; Finish adding each dword of the accumulator
665      movq mm3, mm2
666      psrlq mm2, 32
667      paddd mm2, mm3
668      movd eax, mm2
669    
670      ;; All done
671      pop edi
672      pop esi
673      ret      ret
674    
675    ;-----------------------------------------------------------------------------
676    ;
677    ; uint32_t sse8_8bit_mmx(const int8_t *b1,
678    ;                        const int8_t *b2,
679    ;                        const uint32_t stride);
680    ;
681    ;-----------------------------------------------------------------------------
682    
683    %macro ROW_SSE_8bit_MMX 2
684      movq mm0, [%1] ; load a row
685      movq mm2, [%2] ; load a row
686    
687      movq mm1, mm0  ; copy row
688      movq mm3, mm2  ; copy row
689    
690      punpcklbw mm0, mm7 ; turn the 4low elements into 16bit
691      punpckhbw mm1, mm7 ; turn the 4high elements into 16bit
692    
693      punpcklbw mm2, mm7 ; turn the 4low elements into 16bit
694      punpckhbw mm3, mm7 ; turn the 4high elements into 16bit
695    
696      psubw mm0, mm2 ; low  part of src-dst
697      psubw mm1, mm3 ; high part of src-dst
698    
699      pmaddwd mm0, mm0 ; compute the square sum
700      pmaddwd mm1, mm1 ; compute the square sum
701    
702      paddd mm6, mm0 ; add to the accumulator
703      paddd mm6, mm1 ; add to the accumulator
704    %endmacro
705    
706    sse8_8bit_mmx:
707      push esi
708      push edi
709    
710      ;; Load the function params
711      mov esi, [esp+8+4]
712      mov edi, [esp+8+8]
713      mov edx, [esp+8+12]
714    
715      ;; Reset the sse accumulator
716      pxor mm6, mm6
717    
718      ;; Used to interleave 8bit data with 0x00 values
719      pxor mm7, mm7
720    
721      ;; Let's go
722    %rep 8
723      ROW_SSE_8bit_MMX esi, edi
724      lea esi, [esi+edx]
725      lea edi, [edi+edx]
726    %endrep
727    
728      ;; Finish adding each dword of the accumulator
729      movq mm7, mm6
730      psrlq mm6, 32
731      paddd mm6, mm7
732      movd eax, mm6
733    
734      ;; All done
735      pop edi
736      pop esi
737      ret

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

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