[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.4, 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 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
38                            %define %1 _%1:function
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
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  ;  ;-----------------------------------------------------------------------------
 ;===========================================================================  
   
 %macro MMX_SUB  1  
 times 4 dw %1 / 2  
 %endmacro  
   
78    
79  align 16  ALIGN 16
80  mmx_sub  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
139    mmx_32768_minus_2048:
140            times 4 dw (32768-2048)
141    mmx_32767_minus_2047:
142            times 4 dw (32767-2047)
143    
144  align 8  ALIGN 16
145  mmx_32768_minus_2048                            times 4 dw (32768-2048)  mmx_2047:
146  mmx_32767_minus_2047                            times 4 dw (32767-2047)          times 4 dw 2047
147    
148  align 16  ALIGN 8
149  mmx_2047 times 4 dw 2047  mmzero:
150            dd 0, 0
151    int2047:
152            dd 2047
153    int_2048:
154            dd -2048
155    
156  align 8  ;=============================================================================
157  mmzero dd 0, 0  ; Code
158  int2047 dd 2047  ;=============================================================================
 int_2048 dd -2048  
159    
160  section .text  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 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    
414    
415    
416    
417  ;===========================================================================  ;-----------------------------------------------------------------------------
418  ;  ;
419  ; uint32_t quant_inter_3dne(int16_t * coeff,  ; uint32_t quant_h263_inter_3dne(int16_t * coeff,
420  ;                                       const int16_t const * data,  ;                                       const int16_t const * data,
421  ;                                       const uint32_t quant);  ;                                const uint32_t quant,
422    ;                                const uint16_t *mpeg_matrices);
423  ;  ;
424  ;===========================================================================  ;-----------------------------------------------------------------------------
425  ;This is Athlon-optimized code (ca 90 clk per call)  ;This is Athlon-optimized code (ca 90 clk per call)
426  ;Optimized by Jaan, 30 Nov 2002  ;Optimized by Jaan, 30 Nov 2002
427    
# Line 500  Line 496 
496          movq    [edx + %1*16+8], mm4          movq    [edx + %1*16+8], mm4
497  %endmacro  %endmacro
498    
499  align ALIGN  ALIGN 16
500  cglobal quant_h263_inter_3dne  cglobal quant_h263_inter_3dne
501  quant_h263_inter_3dne:  quant_h263_inter_3dne:
502          mov     edx, [esp  + 4]         ; coeff          mov     edx, [esp  + 4]         ; coeff
# Line 517  Line 513 
513          lea     eax, [mmzero]          lea     eax, [mmzero]
514          jz      near .q1loop          jz      near .q1loop
515          cmp     esp, esp          cmp     esp, esp
516  align 8  ALIGN 8
517          movq    mm3, [ecx + 120]        ;B1          movq    mm3, [ecx + 120]        ;B1
518          pxor    mm4, mm4                ;B2          pxor    mm4, mm4                ;B2
519          psubw   mm4, mm3                ;B3          psubw   mm4, mm3                ;B3
# Line 548  Line 544 
544    
545          ret          ret
546    
547  align ALIGN  ALIGN 16
548  .q1loop  .q1loop
549          movq mm6, [byte ebx]          movq mm6, [byte ebx]
550    
# Line 571  Line 567 
567    
568          ret          ret
569    
570  ;===========================================================================  ;-----------------------------------------------------------------------------
571  ;  ;
572  ; void dequant_intra_3dne(int16_t *data,  ; uint32_t dequant_h263_intra_3dne(int16_t *data,
573  ;                                       const int16_t const *coeff,  ;                                       const int16_t const *coeff,
574  ;                                       const uint32_t quant,  ;                                       const uint32_t quant,
575  ;                                       const uint32_t dcscalar);  ;                                  const uint32_t dcscalar,
576    ;                                  const uint16_t *mpeg_matrices);
577  ;  ;
578  ;===========================================================================  ;-----------------------------------------------------------------------------
579    
580    ; this is the same as dequant_inter_3dne, except that we're    ; this is the same as dequant_inter_3dne, except that we're
581    ; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster)    ; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster)
# Line 604  Line 601 
601          movq    mm4, [esi]              ;C1 ;0          movq    mm4, [esi]              ;C1 ;0
602          mov     esp, esp          mov     esp, esp
603          pcmpeqw mm6, [ecx+%1*24]        ;A6 (c ==0) ? -1 : 0 (1st)          pcmpeqw mm6, [ecx+%1*24]        ;A6 (c ==0) ? -1 : 0 (1st)
604  align 4  ALIGN 4
605          psraw   mm1, 15                 ; sign(c)       ;A7 (2nd)          psraw   mm1, 15                 ; sign(c)       ;A7 (2nd)
606  %if (%1)  %if (%1)
607          movq    [edx+%1*24+16-24], mm5  ; C14 (7th) 2later          movq    [edx+%1*24+16-24], mm5  ; C14 (7th) 2later
# Line 650  Line 647 
647  %endmacro  %endmacro
648    
649    
650  align ALIGN  ALIGN 16
651  cglobal dequant_h263_intra_3dne  cglobal dequant_h263_intra_3dne
652  dequant_h263_intra_3dne:  dequant_h263_intra_3dne:
653          mov     ecx, [esp+ 8]                   ; coeff          mov     ecx, [esp+ 8]                   ; coeff
# Line 677  Line 674 
674          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)
675          mov     edx, [esp+ 4+16]                ; data          mov     edx, [esp+ 4+16]                ; data
676    
677  align 8  ALIGN 8
678          dequant 0          dequant 0
679    
680          cmp     ebp, -2048          cmp     ebp, -2048
# Line 717  Line 714 
714          pxor    mm3, mm2                ;B13 (6th+)          pxor    mm3, mm2                ;B13 (6th+)
715          movq    [edx+4*24+8], mm3       ;B14 (7th)          movq    [edx+4*24+8], mm3       ;B14 (7th)
716          mov     [edx], ax          mov     [edx], ax
717    
718      xor eax, eax
719          ret          ret
720    
721  ;===========================================================================  ;-----------------------------------------------------------------------------
722  ;  ;
723  ; void dequant_inter_3dne(int16_t * data,  ; uint32_t dequant_h263_inter_3dne(int16_t * data,
724  ;                                       const int16_t * const coeff,  ;                                       const int16_t * const coeff,
725  ;                                       const uint32_t quant);  ;                                  const uint32_t quant,
726    ;                                  const uint16_t *mpeg_matrices);
727  ;  ;
728  ;===========================================================================  ;-----------------------------------------------------------------------------
729    
730  ; this is the same as dequant_inter_3dne,  ; this is the same as dequant_inter_3dne,
731  ; except that we're saturating using 'pminsw' (saves 2 cycles/loop)  ; except that we're saturating using 'pminsw' (saves 2 cycles/loop)
732  ;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  
733    
734  align ALIGN  ALIGN 16
735  cglobal dequant_h263_inter_3dne  cglobal dequant_h263_inter_3dne
736  dequant_h263_inter_3dne:  dequant_h263_inter_3dne:
737          mov     ecx, [esp+ 8]                   ; coeff          mov     ecx, [esp+ 8]                   ; coeff
# Line 755  Line 754 
754          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)          psraw   mm3, 15                         ; sign(c)       ;B7 (2nd)
755          mov     edx, [dword esp+ 4+12]          ; data          mov     edx, [dword esp+ 4+12]          ; data
756    
757  align 8  ALIGN 8
758    
759          dequant 0          dequant 0
760          dequant 1          dequant 1
# Line 778  Line 777 
777          pxor    mm3, mm2                ;B13 (6th+)          pxor    mm3, mm2                ;B13 (6th+)
778          movq    [edx+4*24+8], mm3       ;B14 (7th)          movq    [edx+4*24+8], mm3       ;B14 (7th)
779    
780      xor eax, eax
781          ret          ret

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

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