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 |
|
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 |
; Local data |
54 |
;*************************************************************************** |
;============================================================================= |
55 |
|
|
56 |
%ifdef FORMAT_COFF |
%ifdef FORMAT_COFF |
57 |
section .data data |
SECTION .rodata |
58 |
%else |
%else |
59 |
section .data data align=16 |
SECTION .rodata align=16 |
60 |
%endif |
%endif |
61 |
|
|
62 |
align 4 |
align 4 |
68 |
%assign i i+1 |
%assign i i+1 |
69 |
%endrep |
%endrep |
70 |
|
|
71 |
align 16 |
ALIGN 16 |
72 |
plus_one: |
plus_one: |
73 |
times 8 dw 1 |
times 8 dw 1 |
74 |
|
|
75 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
76 |
; subtract by Q/2 table |
; subtract by Q/2 table |
77 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
78 |
|
|
79 |
align 16 |
ALIGN 16 |
80 |
mmx_sub: |
mmx_sub: |
81 |
%assign i 1 |
%assign i 1 |
82 |
%rep 31 |
%rep 31 |
85 |
%endrep |
%endrep |
86 |
|
|
87 |
|
|
88 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
89 |
; |
; |
90 |
; divide by 2Q table |
; divide by 2Q table |
91 |
; |
; |
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 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
97 |
|
|
98 |
align 16 |
ALIGN 16 |
99 |
mmx_div: |
mmx_div: |
100 |
%assign i 1 |
%assign i 1 |
101 |
%rep 31 |
%rep 31 |
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 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
109 |
|
|
110 |
align 16 |
ALIGN 16 |
111 |
mmx_add: |
mmx_add: |
112 |
%assign i 1 |
%assign i 1 |
113 |
%rep 31 |
%rep 31 |
119 |
%assign i i+1 |
%assign i i+1 |
120 |
%endrep |
%endrep |
121 |
|
|
122 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
123 |
; multiple by 2Q table |
; multiple by 2Q table |
124 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
125 |
|
|
126 |
align 16 |
ALIGN 16 |
127 |
mmx_mul: |
mmx_mul: |
128 |
%assign i 1 |
%assign i 1 |
129 |
%rep 31 |
%rep 31 |
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: |
mmx_32768_minus_2048: |
140 |
times 4 dw (32768-2048) |
times 4 dw (32768-2048) |
141 |
mmx_32767_minus_2047: |
mmx_32767_minus_2047: |
142 |
times 4 dw (32767-2047) |
times 4 dw (32767-2047) |
143 |
|
|
144 |
align 16 |
ALIGN 16 |
145 |
mmx_2047: |
mmx_2047: |
146 |
times 4 dw 2047 |
times 4 dw 2047 |
147 |
|
|
148 |
align 8 |
ALIGN 8 |
149 |
mmzero: |
mmzero: |
150 |
dd 0, 0 |
dd 0, 0 |
151 |
int2047: |
int2047: |
153 |
int_2048: |
int_2048: |
154 |
dd -2048 |
dd -2048 |
155 |
|
|
156 |
;*************************************************************************** |
;============================================================================= |
157 |
; Code |
; Code |
158 |
;*************************************************************************** |
;============================================================================= |
159 |
|
|
160 |
section .text |
SECTION .text |
161 |
|
|
162 |
|
|
163 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
164 |
; |
; |
165 |
; uint32_t quant_h263_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) |
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) |
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 |
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 |
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 |
|
|
375 |
xor eax, eax |
xor eax, eax |
376 |
ret |
ret |
377 |
|
|
378 |
align 16 |
ALIGN 16 |
379 |
|
|
380 |
.q1loop |
.q1loop |
381 |
quant_intra1 0 |
quant_intra1 0 |
410 |
|
|
411 |
xor eax, eax |
xor eax, eax |
412 |
ret |
ret |
413 |
|
.endfunc |
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
419 |
; |
; |
420 |
; uint32_t quant_h263_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 |
|
|
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 |
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 |
545 |
|
|
546 |
ret |
ret |
547 |
|
|
548 |
align ALIGN |
ALIGN 16 |
549 |
.q1loop |
.q1loop |
550 |
movq mm6, [byte ebx] |
movq mm6, [byte ebx] |
551 |
|
|
567 |
pop ebx |
pop ebx |
568 |
|
|
569 |
ret |
ret |
570 |
|
.endfunc |
571 |
|
|
572 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
573 |
; |
; |
574 |
; uint32_t dequant_h263_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) |
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 |
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 |
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 |
719 |
|
|
720 |
xor eax, eax |
xor eax, eax |
721 |
ret |
ret |
722 |
|
.endfunc |
723 |
|
|
724 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
725 |
; |
; |
726 |
; uint32_t dequant_h263_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) |
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 |
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, [dword esp+ 4+12] ; data |
759 |
|
|
760 |
align 8 |
ALIGN 8 |
761 |
|
|
762 |
dequant 0 |
dequant 0 |
763 |
dequant 1 |
dequant 1 |
782 |
|
|
783 |
xor eax, eax |
xor eax, eax |
784 |
ret |
ret |
785 |
|
.endfunc |
786 |
|
|