[cvs] / xvidcore / src / quant / x86_asm / quantize_h263_3dne.asm Repository:
ViewVC logotype

Diff of /xvidcore/src/quant/x86_asm/quantize_h263_3dne.asm

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

revision 1.1.2.1, Tue Oct 7 13:02:35 2003 UTC revision 1.7, Tue Aug 19 09:06:48 2008 UTC
# Line 1  Line 1 
1  ;/**************************************************************************  ;/**************************************************************************
2  ; *  ; *
3  ; *  XVID MPEG-4 VIDEO CODEC  ; *  XVID MPEG-4 VIDEO CODEC
4  ; *  - mmx quantization/dequantization -  ; *  - 3dne Quantization/Dequantization -
5  ; *  ; *
6  ; *  Copyright(C) 2001-2003 XviD Team <xvid-devel@xvid.org>  ; *  Copyright(C) 2002-2003 Jaan Kalda
7  ; *  ; *
8  ; *  This program is free software ; you can redistribute it and/or modify  ; *  This program is free software ; you can redistribute it and/or modify
9  ; *  it under the terms of the GNU General Public License as published by  ; *  it under the terms of the GNU General Public License as published by
# Line 22  Line 22 
22  ; * $Id$  ; * $Id$
23  ; *  ; *
24  ; *************************************************************************/  ; *************************************************************************/
25    ;
26  ; these 3dne functions are compatible with iSSE, but are optimized specifically for  ; these 3dne functions are compatible with iSSE, but are optimized specifically for
27  ; K7 pipelines  ; K7 pipelines
 ;  
 ;------------------------------------------------------------------------------  
 ; 09.12.2002  Athlon optimizations contributed by Jaan Kalda  
 ;------------------------------------------------------------------------------  
28    
29  ; enable dequant saturate [-2048,2047], test purposes only.  ; enable dequant saturate [-2048,2047], test purposes only.
30  %define SATURATE  %define SATURATE
31    
32  ; data/text alignment  BITS 32
 %define ALIGN 16  
   
 bits 32  
   
 %ifdef FORMAT_COFF  
 section .data data  
 %else  
 section .data data align=16  
 %endif  
33    
34  %macro cglobal 1  %macro cglobal 1
35          %ifdef PREFIX          %ifdef PREFIX
36                    %ifdef MARK_FUNCS
37                            global _%1:function %1.endfunc-%1
38                            %define %1 _%1:function %1.endfunc-%1
39                    %else
40                  global _%1                  global _%1
41                  %define %1 _%1                  %define %1 _%1
42                    %endif
43            %else
44                    %ifdef MARK_FUNCS
45                            global %1:function %1.endfunc-%1
46          %else          %else
47                  global %1                  global %1
48          %endif          %endif
49            %endif
50  %endmacro  %endmacro
51    
52    ;=============================================================================
53    ; Local data
54    ;=============================================================================
55    
56    %ifdef FORMAT_COFF
57    SECTION .rodata
58    %else
59    SECTION .rodata align=16
60    %endif
61    
62  align 4  align 4
63  int_div  int_div:
64  dd 0  dd 0
65  %assign i 1  %assign i 1
66  %rep 255  %rep 255
# Line 60  Line 68 
68          %assign i i+1          %assign i i+1
69  %endrep  %endrep
70    
71  align 16  ALIGN 16
72    plus_one:
73  plus_one times 8        dw       1          times 8 dw 1
74    
75  ;===========================================================================  ;-----------------------------------------------------------------------------
 ;  
76  ; subtract by Q/2 table  ; subtract by Q/2 table
77  ;  ;-----------------------------------------------------------------------------
 ;===========================================================================  
78    
79  %macro MMX_SUB  1  ALIGN 16
80  times 4 dw %1 / 2  mmx_sub:
 %endmacro  
   
   
 align 16  
 mmx_sub  
81  %assign i 1  %assign i 1
82  %rep 31  %rep 31
83          times 4 dw i / 2          times 4 dw i / 2
# Line 84  Line 85 
85  %endrep  %endrep
86    
87    
88  ;===========================================================================  ;-----------------------------------------------------------------------------
89  ;  ;
90  ; divide by 2Q table  ; divide by 2Q table
91  ;  ;
# Line 92  Line 93 
93  ; for q=1, _pmulhw_ will overflow so it is treated seperately  ; for q=1, _pmulhw_ will overflow so it is treated seperately
94  ; (3dnow2 provides _pmulhuw_ which wont cause overflow)  ; (3dnow2 provides _pmulhuw_ which wont cause overflow)
95  ;  ;
96  ;===========================================================================  ;-----------------------------------------------------------------------------
   
 align 16  
 mmx_div  
97    
98    ALIGN 16
99    mmx_div:
100  %assign i 1  %assign i 1
101  %rep 31  %rep 31
102          times 4 dw  (1 << 16) / (i * 2) + 1          times 4 dw  (1 << 16) / (i * 2) + 1
103          %assign i i+1          %assign i i+1
104  %endrep  %endrep
105    
106  ;===========================================================================  ;-----------------------------------------------------------------------------
 ;  
107  ; add by (odd(Q) ? Q : Q - 1) table  ; add by (odd(Q) ? Q : Q - 1) table
108  ;  ;-----------------------------------------------------------------------------
 ;===========================================================================  
   
 %macro MMX_ADD  1  
 %if %1 % 2 != 0  
 times 4 dw %1  
 %else  
 times 4 dw %1 - 1  
 %endif  
 %endmacro  
   
 align 16  
 mmx_add  
109    
110    ALIGN 16
111    mmx_add:
112  %assign i 1  %assign i 1
113  %rep 31  %rep 31
114          MMX_ADD i          %if i % 2 != 0
115            times 4 dw i
116            %else
117            times 4 dw i - 1
118            %endif
119          %assign i i+1          %assign i i+1
120  %endrep  %endrep
121    
122  ;===========================================================================  ;-----------------------------------------------------------------------------
 ;  
123  ; multiple by 2Q table  ; multiple by 2Q table
124  ;  ;-----------------------------------------------------------------------------
 ;===========================================================================  
   
 %macro MMX_MUL  1  
 times 4 dw %1 * 2  
 %endmacro  
   
 align 16  
 mmx_mul  
125    
126    ALIGN 16
127    mmx_mul:
128  %assign i 1  %assign i 1
129  %rep 31  %rep 31
130          times 4 dw i * 2          times 4 dw i * 2
131          %assign i i+1          %assign i i+1
132  %endrep  %endrep
133    
134  ;===========================================================================  ;-----------------------------------------------------------------------------
 ;  
135  ; saturation limits  ; saturation limits
136  ;  ;-----------------------------------------------------------------------------
 ;===========================================================================  
137    
138  align 8  ALIGN 8
139  mmx_32768_minus_2048                            times 4 dw (32768-2048)  mmx_32768_minus_2048:
140  mmx_32767_minus_2047                            times 4 dw (32767-2047)          times 4 dw (32768-2048)
141    mmx_32767_minus_2047:
142            times 4 dw (32767-2047)
143    
144  align 16  ALIGN 16
145  mmx_2047 times 4 dw 2047  mmx_2047:
146            times 4 dw 2047
147    
148  align 8  ALIGN 8
149  mmzero dd 0, 0  mmzero:
150  int2047 dd 2047          dd 0, 0
151  int_2048 dd -2048  int2047:
152            dd 2047
153    int_2048:
154            dd -2048
155    
156  section .text  ;=============================================================================
157    ; Code
158    ;=============================================================================
159    
160    SECTION .text
161    
162  ;===========================================================================  
163    ;-----------------------------------------------------------------------------
164  ;  ;
165  ; void quant_intra_3dne(int16_t * coeff,  ; uint32_t quant_h263_intra_3dne(int16_t * coeff,
166  ;                                       const int16_t const * data,  ;                                       const int16_t const * data,
167  ;                                       const uint32_t quant,  ;                                       const uint32_t quant,
168  ;                                       const uint32_t dcscalar);  ;                                const uint32_t dcscalar,
169    ;                                const uint16_t *mpeg_matrices);
170  ;  ;
171  ;===========================================================================  ;-----------------------------------------------------------------------------
172  ;This is Athlon-optimized code (ca 70 clk per call)  ;This is Athlon-optimized code (ca 70 clk per call)
 ;Optimized by Jaan, 30 Nov 2002  
173    
174  %macro quant_intra1  1  %macro quant_intra1  1
   
175          psubw   mm1, mm0        ;A3          psubw   mm1, mm0        ;A3
176          psubw   mm3, mm2        ;B3          psubw   mm3, mm2        ;B3
177  %if (%1)  %if (%1)
# Line 186  Line 179 
179          psubw   mm7, mm6        ;D8          psubw   mm7, mm6        ;D8
180  %endif  %endif
181    
182  align 8  ALIGN 8
183          db      0Fh, 6Fh, 64h, 21h, (%1 * 32 +16)       ;movq   mm4, [ecx + %1 * 32 +16+32]     ;C1          db      0Fh, 6Fh, 64h, 21h, (%1 * 32 +16)       ;movq   mm4, [ecx + %1 * 32 +16+32]     ;C1
184          pmaxsw  mm1, mm0        ;A4          pmaxsw  mm1, mm0        ;A4
185          db      0Fh, 6Fh, 74h, 21h, (%1 * 32 +24)       ;movq   mm6, [ecx + %1 * 32 +24+32]     ;D1          db      0Fh, 6Fh, 74h, 21h, (%1 * 32 +24)       ;movq   mm6, [ecx + %1 * 32 +24+32]     ;D1
# Line 260  Line 253 
253          psubw   mm7, mm6        ;D8          psubw   mm7, mm6        ;D8
254  %endif  %endif
255    
256  align 8  ALIGN 8
257          db      0Fh, 6Fh, 64h, 21h, (%1 * 32 +16)       ;movq   mm4, [ecx + %1 * 32 +16+32]     ;C1          db      0Fh, 6Fh, 64h, 21h, (%1 * 32 +16)       ;movq   mm4, [ecx + %1 * 32 +16+32]     ;C1
258          pmaxsw  mm1, mm0        ;A4          pmaxsw  mm1, mm0        ;A4
259          db      0Fh, 6Fh, 74h, 21h, (%1 * 32 +24)       ;movq   mm6, [ecx + %1 * 32 +24+32]     ;D1          db      0Fh, 6Fh, 74h, 21h, (%1 * 32 +24)       ;movq   mm6, [ecx + %1 * 32 +24+32]     ;D1
# Line 327  Line 320 
320  %endmacro  %endmacro
321    
322    
323  align ALIGN  ALIGN 16
324  cglobal quant_h263_intra_3dne  cglobal quant_h263_intra_3dne
325  quant_h263_intra_3dne:  quant_h263_intra_3dne:
326    
# Line 379  Line 372 
372          movq    [edx + 3 * 32 + 16], mm5        ;C9          movq    [edx + 3 * 32 + 16], mm5        ;C9
373          movq    [edx + 3 * 32 + 24], mm7        ;D9          movq    [edx + 3 * 32 + 24], mm7        ;D9
374    
375      xor eax, eax
376          ret          ret
377    
378          align 16  ALIGN 16
379    
380  .q1loop  .q1loop
381  quant_intra1 0  quant_intra1 0
# Line 402  Line 396 
396    
397  quant_intra1 3  quant_intra1 3
398          psubw   mm5, mm4                        ;C8          psubw   mm5, mm4                        ;C8
399          mov     esi, [dword esp + 12]           ; pop back the register value    mov esi, [esp + 12]         ; pop back the register value
400          mov     edi, [esp + 4]                  ; pop back the register value          mov     edi, [esp + 4]                  ; pop back the register value
401          sar     eax, 16          sar     eax, 16
402          lea     ebx, [byte eax + 1]             ; workaround for eax < 0          lea     ebx, [byte eax + 1]             ; workaround for eax < 0
# Line 414  Line 408 
408          movq    [edx + 3 * 32 + 16], mm5        ;C9          movq    [edx + 3 * 32 + 16], mm5        ;C9
409          movq    [edx + 3 * 32 + 24], mm7        ;D9          movq    [edx + 3 * 32 + 24], mm7        ;D9
410    
411      xor eax, eax
412          ret          ret
413    .endfunc
414    
415    
416    
417    
418  ;===========================================================================  ;-----------------------------------------------------------------------------
419  ;  ;
420  ; uint32_t quant_inter_3dne(int16_t * coeff,  ; uint32_t quant_h263_inter_3dne(int16_t * coeff,
421  ;                                       const int16_t const * data,  ;                                       const int16_t const * data,
422  ;                                       const uint32_t quant);  ;                                const uint32_t quant,
423    ;                                const uint16_t *mpeg_matrices);
424  ;  ;
425  ;===========================================================================  ;-----------------------------------------------------------------------------
426  ;This is Athlon-optimized code (ca 90 clk per call)  ;This is Athlon-optimized code (ca 90 clk per call)
427  ;Optimized by Jaan, 30 Nov 2002  ;Optimized by Jaan, 30 Nov 2002
428    
# Line 500  Line 497 
497          movq    [edx + %1*16+8], mm4          movq    [edx + %1*16+8], mm4
498  %endmacro  %endmacro
499    
500  align ALIGN  ALIGN 16
501  cglobal quant_h263_inter_3dne  cglobal quant_h263_inter_3dne
502  quant_h263_inter_3dne:  quant_h263_inter_3dne:
503          mov     edx, [esp  + 4]         ; coeff          mov     edx, [esp  + 4]         ; coeff
# Line 517  Line 514 
514          lea     eax, [mmzero]          lea     eax, [mmzero]
515          jz      near .q1loop          jz      near .q1loop
516          cmp     esp, esp          cmp     esp, esp
517  align 8  ALIGN 8
518          movq    mm3, [ecx + 120]        ;B1          movq    mm3, [ecx + 120]        ;B1
519          pxor    mm4, mm4                ;B2          pxor    mm4, mm4                ;B2
520          psubw   mm4, mm3                ;B3          psubw   mm4, mm3                ;B3
# Line 548  Line 545 
545    
546          ret          ret
547    
548  align ALIGN  ALIGN 16
549  .q1loop  .q1loop
550          movq mm6, [byte ebx]          movq mm6, [byte ebx]
551    
# Line 570  Line 567 
567          pop ebx          pop ebx
568    
569          ret          ret
570    .endfunc
571    
572  ;===========================================================================  ;-----------------------------------------------------------------------------
573  ;  ;
574  ; void dequant_intra_3dne(int16_t *data,  ; uint32_t dequant_h263_intra_3dne(int16_t *data,
575  ;                                       const int16_t const *coeff,  ;                                       const int16_t const *coeff,
576  ;                                       const uint32_t quant,  ;                                       const uint32_t quant,
577  ;                                       const uint32_t dcscalar);  ;                                  const uint32_t dcscalar,
578    ;                                  const uint16_t *mpeg_matrices);
579  ;  ;
580  ;===========================================================================  ;-----------------------------------------------------------------------------
581    
582    ; this is the same as dequant_inter_3dne, except that we're    ; this is the same as dequant_inter_3dne, except that we're
583    ; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster)    ; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster)
# Line 604  Line 603 
603          movq    mm4, [esi]              ;C1 ;0          movq    mm4, [esi]              ;C1 ;0
604          mov     esp, esp          mov     esp, esp
605          pcmpeqw mm6, [ecx+%1*24]        ;A6 (c ==0) ? -1 : 0 (1st)          pcmpeqw mm6, [ecx+%1*24]        ;A6 (c ==0) ? -1 : 0 (1st)
606  align 4  ALIGN 4
607          psraw   mm1, 15                 ; sign(c)       ;A7 (2nd)          psraw   mm1, 15                 ; sign(c)       ;A7 (2nd)
608  %if (%1)  %if (%1)
609          movq    [edx+%1*24+16-24], mm5  ; C14 (7th) 2later          movq    [edx+%1*24+16-24], mm5  ; C14 (7th) 2later
# Line 650  Line 649 
649  %endmacro  %endmacro
650    
651    
652  align ALIGN  ALIGN 16
653  cglobal dequant_h263_intra_3dne  cglobal dequant_h263_intra_3dne
654  dequant_h263_intra_3dne:  dequant_h263_intra_3dne:
655          mov     ecx, [esp+ 8]                   ; coeff          mov     ecx, [esp+ 8]                   ; coeff
# Line 677  Line 676 
676          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)
677          mov     edx, [esp+ 4+16]                ; data          mov     edx, [esp+ 4+16]                ; data
678    
679  align 8  ALIGN 8
680          dequant 0          dequant 0
681    
682          cmp     ebp, -2048          cmp     ebp, -2048
# Line 717  Line 716 
716          pxor    mm3, mm2                ;B13 (6th+)          pxor    mm3, mm2                ;B13 (6th+)
717          movq    [edx+4*24+8], mm3       ;B14 (7th)          movq    [edx+4*24+8], mm3       ;B14 (7th)
718          mov     [edx], ax          mov     [edx], ax
719    
720      xor eax, eax
721          ret          ret
722    .endfunc
723    
724  ;===========================================================================  ;-----------------------------------------------------------------------------
725  ;  ;
726  ; void dequant_inter_3dne(int16_t * data,  ; uint32_t dequant_h263_inter_3dne(int16_t * data,
727  ;                                       const int16_t * const coeff,  ;                                       const int16_t * const coeff,
728  ;                                       const uint32_t quant);  ;                                  const uint32_t quant,
729    ;                                  const uint16_t *mpeg_matrices);
730  ;  ;
731  ;===========================================================================  ;-----------------------------------------------------------------------------
732    
733  ; this is the same as dequant_inter_3dne,  ; this is the same as dequant_inter_3dne,
734  ; except that we're saturating using 'pminsw' (saves 2 cycles/loop)  ; except that we're saturating using 'pminsw' (saves 2 cycles/loop)
735  ;This is Athlon-optimized code (ca 100 clk per call)  ;This is Athlon-optimized code (ca 100 clk per call)
 ;Optimized by Jaan, 30 Nov 2002  
736    
737  align ALIGN  ALIGN 16
738  cglobal dequant_h263_inter_3dne  cglobal dequant_h263_inter_3dne
739  dequant_h263_inter_3dne:  dequant_h263_inter_3dne:
740          mov     ecx, [esp+ 8]                   ; coeff          mov     ecx, [esp+ 8]                   ; coeff
# Line 753  Line 755 
755          pmaxsw  mm2, mm3                        ;|c|            ;B4 (2nd)          pmaxsw  mm2, mm3                        ;|c|            ;B4 (2nd)
756          pmullw  mm2, [edi]                      ;*= 2Q          ;B8 (3rd+)          pmullw  mm2, [edi]                      ;*= 2Q          ;B8 (3rd+)
757          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)
758          mov     edx, [dword esp+ 4+12]          ; data    mov edx, [esp+ 4+12]        ; data
759    
760  align 8  ALIGN 8
761    
762          dequant 0          dequant 0
763          dequant 1          dequant 1
# Line 778  Line 780 
780          pxor    mm3, mm2                ;B13 (6th+)          pxor    mm3, mm2                ;B13 (6th+)
781          movq    [edx+4*24+8], mm3       ;B14 (7th)          movq    [edx+4*24+8], mm3       ;B14 (7th)
782    
783      xor eax, eax
784          ret          ret
785    .endfunc
786    
787    
788    %ifidn __OUTPUT_FORMAT__,elf
789    section ".note.GNU-stack" noalloc noexec nowrite progbits
790    %endif
791    

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.7

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