19 |
; * along with this program ; if not, write to the Free Software |
; * along with this program ; if not, write to the Free Software |
20 |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
; * |
; * |
22 |
; * $Id: quantize_h263_3dne.asm,v 1.1.2.2 2003-10-09 18:50:22 edgomez Exp $ |
; * $Id: quantize_h263_3dne.asm,v 1.1.2.3 2003-10-28 22:23:03 edgomez Exp $ |
23 |
; * |
; * |
24 |
; *************************************************************************/ |
; *************************************************************************/ |
25 |
; |
; |
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 |
40 |
%endif |
%endif |
41 |
%endmacro |
%endmacro |
42 |
|
|
43 |
;*************************************************************************** |
;============================================================================= |
44 |
; Local data |
; Local data |
45 |
;*************************************************************************** |
;============================================================================= |
46 |
|
|
47 |
%ifdef FORMAT_COFF |
SECTION .rodata |
|
section .data data |
|
|
%else |
|
|
section .data data align=16 |
|
|
%endif |
|
48 |
|
|
49 |
align 4 |
align 4 |
50 |
int_div: |
int_div: |
55 |
%assign i i+1 |
%assign i i+1 |
56 |
%endrep |
%endrep |
57 |
|
|
58 |
align 16 |
ALIGN 16 |
59 |
plus_one: |
plus_one: |
60 |
times 8 dw 1 |
times 8 dw 1 |
61 |
|
|
62 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
63 |
; subtract by Q/2 table |
; subtract by Q/2 table |
64 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
65 |
|
|
66 |
align 16 |
ALIGN 16 |
67 |
mmx_sub: |
mmx_sub: |
68 |
%assign i 1 |
%assign i 1 |
69 |
%rep 31 |
%rep 31 |
72 |
%endrep |
%endrep |
73 |
|
|
74 |
|
|
75 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
76 |
; |
; |
77 |
; divide by 2Q table |
; divide by 2Q table |
78 |
; |
; |
80 |
; for q=1, _pmulhw_ will overflow so it is treated seperately |
; for q=1, _pmulhw_ will overflow so it is treated seperately |
81 |
; (3dnow2 provides _pmulhuw_ which wont cause overflow) |
; (3dnow2 provides _pmulhuw_ which wont cause overflow) |
82 |
; |
; |
83 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
84 |
|
|
85 |
align 16 |
ALIGN 16 |
86 |
mmx_div: |
mmx_div: |
87 |
%assign i 1 |
%assign i 1 |
88 |
%rep 31 |
%rep 31 |
90 |
%assign i i+1 |
%assign i i+1 |
91 |
%endrep |
%endrep |
92 |
|
|
93 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
94 |
; add by (odd(Q) ? Q : Q - 1) table |
; add by (odd(Q) ? Q : Q - 1) table |
95 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
96 |
|
|
97 |
align 16 |
ALIGN 16 |
98 |
mmx_add: |
mmx_add: |
99 |
%assign i 1 |
%assign i 1 |
100 |
%rep 31 |
%rep 31 |
106 |
%assign i i+1 |
%assign i i+1 |
107 |
%endrep |
%endrep |
108 |
|
|
109 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
110 |
; multiple by 2Q table |
; multiple by 2Q table |
111 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
112 |
|
|
113 |
align 16 |
ALIGN 16 |
114 |
mmx_mul: |
mmx_mul: |
115 |
%assign i 1 |
%assign i 1 |
116 |
%rep 31 |
%rep 31 |
118 |
%assign i i+1 |
%assign i i+1 |
119 |
%endrep |
%endrep |
120 |
|
|
121 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
122 |
; saturation limits |
; saturation limits |
123 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
124 |
|
|
125 |
align 8 |
ALIGN 8 |
126 |
mmx_32768_minus_2048: |
mmx_32768_minus_2048: |
127 |
times 4 dw (32768-2048) |
times 4 dw (32768-2048) |
128 |
mmx_32767_minus_2047: |
mmx_32767_minus_2047: |
129 |
times 4 dw (32767-2047) |
times 4 dw (32767-2047) |
130 |
|
|
131 |
align 16 |
ALIGN 16 |
132 |
mmx_2047: |
mmx_2047: |
133 |
times 4 dw 2047 |
times 4 dw 2047 |
134 |
|
|
135 |
align 8 |
ALIGN 8 |
136 |
mmzero: |
mmzero: |
137 |
dd 0, 0 |
dd 0, 0 |
138 |
int2047: |
int2047: |
140 |
int_2048: |
int_2048: |
141 |
dd -2048 |
dd -2048 |
142 |
|
|
143 |
;*************************************************************************** |
;============================================================================= |
144 |
; Code |
; Code |
145 |
;*************************************************************************** |
;============================================================================= |
146 |
|
|
147 |
section .text |
SECTION .text |
148 |
|
|
149 |
|
|
150 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
151 |
; |
; |
152 |
; uint32_t quant_h263_intra_3dne(int16_t * coeff, |
; uint32_t quant_h263_intra_3dne(int16_t * coeff, |
153 |
; const int16_t const * data, |
; const int16_t const * data, |
154 |
; const uint32_t quant, |
; const uint32_t quant, |
155 |
; const uint32_t dcscalar); |
; const uint32_t dcscalar); |
156 |
; |
; |
157 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
158 |
;This is Athlon-optimized code (ca 70 clk per call) |
;This is Athlon-optimized code (ca 70 clk per call) |
159 |
|
|
160 |
%macro quant_intra1 1 |
%macro quant_intra1 1 |
|
|
|
161 |
psubw mm1, mm0 ;A3 |
psubw mm1, mm0 ;A3 |
162 |
psubw mm3, mm2 ;B3 |
psubw mm3, mm2 ;B3 |
163 |
%if (%1) |
%if (%1) |
165 |
psubw mm7, mm6 ;D8 |
psubw mm7, mm6 ;D8 |
166 |
%endif |
%endif |
167 |
|
|
168 |
align 8 |
ALIGN 8 |
169 |
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 |
170 |
pmaxsw mm1, mm0 ;A4 |
pmaxsw mm1, mm0 ;A4 |
171 |
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 |
239 |
psubw mm7, mm6 ;D8 |
psubw mm7, mm6 ;D8 |
240 |
%endif |
%endif |
241 |
|
|
242 |
align 8 |
ALIGN 8 |
243 |
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 |
244 |
pmaxsw mm1, mm0 ;A4 |
pmaxsw mm1, mm0 ;A4 |
245 |
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 |
306 |
%endmacro |
%endmacro |
307 |
|
|
308 |
|
|
309 |
align ALIGN |
ALIGN 16 |
310 |
cglobal quant_h263_intra_3dne |
cglobal quant_h263_intra_3dne |
311 |
quant_h263_intra_3dne: |
quant_h263_intra_3dne: |
312 |
|
|
361 |
xor eax, eax |
xor eax, eax |
362 |
ret |
ret |
363 |
|
|
364 |
align 16 |
ALIGN 16 |
365 |
|
|
366 |
.q1loop |
.q1loop |
367 |
quant_intra1 0 |
quant_intra1 0 |
400 |
|
|
401 |
|
|
402 |
|
|
403 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
404 |
; |
; |
405 |
; uint32_t quant_h263_inter_3dne(int16_t * coeff, |
; uint32_t quant_h263_inter_3dne(int16_t * coeff, |
406 |
; const int16_t const * data, |
; const int16_t const * data, |
407 |
; const uint32_t quant); |
; const uint32_t quant); |
408 |
; |
; |
409 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
410 |
;This is Athlon-optimized code (ca 90 clk per call) |
;This is Athlon-optimized code (ca 90 clk per call) |
411 |
;Optimized by Jaan, 30 Nov 2002 |
;Optimized by Jaan, 30 Nov 2002 |
412 |
|
|
481 |
movq [edx + %1*16+8], mm4 |
movq [edx + %1*16+8], mm4 |
482 |
%endmacro |
%endmacro |
483 |
|
|
484 |
align ALIGN |
ALIGN 16 |
485 |
cglobal quant_h263_inter_3dne |
cglobal quant_h263_inter_3dne |
486 |
quant_h263_inter_3dne: |
quant_h263_inter_3dne: |
487 |
mov edx, [esp + 4] ; coeff |
mov edx, [esp + 4] ; coeff |
498 |
lea eax, [mmzero] |
lea eax, [mmzero] |
499 |
jz near .q1loop |
jz near .q1loop |
500 |
cmp esp, esp |
cmp esp, esp |
501 |
align 8 |
ALIGN 8 |
502 |
movq mm3, [ecx + 120] ;B1 |
movq mm3, [ecx + 120] ;B1 |
503 |
pxor mm4, mm4 ;B2 |
pxor mm4, mm4 ;B2 |
504 |
psubw mm4, mm3 ;B3 |
psubw mm4, mm3 ;B3 |
529 |
|
|
530 |
ret |
ret |
531 |
|
|
532 |
align ALIGN |
ALIGN 16 |
533 |
.q1loop |
.q1loop |
534 |
movq mm6, [byte ebx] |
movq mm6, [byte ebx] |
535 |
|
|
552 |
|
|
553 |
ret |
ret |
554 |
|
|
555 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
556 |
; |
; |
557 |
; uint32_t dequant_h263_intra_3dne(int16_t *data, |
; uint32_t dequant_h263_intra_3dne(int16_t *data, |
558 |
; const int16_t const *coeff, |
; const int16_t const *coeff, |
559 |
; const uint32_t quant, |
; const uint32_t quant, |
560 |
; const uint32_t dcscalar); |
; const uint32_t dcscalar); |
561 |
; |
; |
562 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
563 |
|
|
564 |
; this is the same as dequant_inter_3dne, except that we're |
; this is the same as dequant_inter_3dne, except that we're |
565 |
; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster) |
; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster) |
585 |
movq mm4, [esi] ;C1 ;0 |
movq mm4, [esi] ;C1 ;0 |
586 |
mov esp, esp |
mov esp, esp |
587 |
pcmpeqw mm6, [ecx+%1*24] ;A6 (c ==0) ? -1 : 0 (1st) |
pcmpeqw mm6, [ecx+%1*24] ;A6 (c ==0) ? -1 : 0 (1st) |
588 |
align 4 |
ALIGN 4 |
589 |
psraw mm1, 15 ; sign(c) ;A7 (2nd) |
psraw mm1, 15 ; sign(c) ;A7 (2nd) |
590 |
%if (%1) |
%if (%1) |
591 |
movq [edx+%1*24+16-24], mm5 ; C14 (7th) 2later |
movq [edx+%1*24+16-24], mm5 ; C14 (7th) 2later |
631 |
%endmacro |
%endmacro |
632 |
|
|
633 |
|
|
634 |
align ALIGN |
ALIGN 16 |
635 |
cglobal dequant_h263_intra_3dne |
cglobal dequant_h263_intra_3dne |
636 |
dequant_h263_intra_3dne: |
dequant_h263_intra_3dne: |
637 |
mov ecx, [esp+ 8] ; coeff |
mov ecx, [esp+ 8] ; coeff |
658 |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
659 |
mov edx, [esp+ 4+16] ; data |
mov edx, [esp+ 4+16] ; data |
660 |
|
|
661 |
align 8 |
ALIGN 8 |
662 |
dequant 0 |
dequant 0 |
663 |
|
|
664 |
cmp ebp, -2048 |
cmp ebp, -2048 |
702 |
xor eax, eax |
xor eax, eax |
703 |
ret |
ret |
704 |
|
|
705 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
706 |
; |
; |
707 |
; uint32_t dequant_h263_inter_3dne(int16_t * data, |
; uint32_t dequant_h263_inter_3dne(int16_t * data, |
708 |
; const int16_t * const coeff, |
; const int16_t * const coeff, |
709 |
; const uint32_t quant); |
; const uint32_t quant); |
710 |
; |
; |
711 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
712 |
|
|
713 |
; this is the same as dequant_inter_3dne, |
; this is the same as dequant_inter_3dne, |
714 |
; except that we're saturating using 'pminsw' (saves 2 cycles/loop) |
; except that we're saturating using 'pminsw' (saves 2 cycles/loop) |
715 |
; This is Athlon-optimized code (ca 100 clk per call) |
; This is Athlon-optimized code (ca 100 clk per call) |
716 |
|
|
717 |
align ALIGN |
ALIGN 16 |
718 |
cglobal dequant_h263_inter_3dne |
cglobal dequant_h263_inter_3dne |
719 |
dequant_h263_inter_3dne: |
dequant_h263_inter_3dne: |
720 |
mov ecx, [esp+ 8] ; coeff |
mov ecx, [esp+ 8] ; coeff |
737 |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
738 |
mov edx, [dword esp+ 4+12] ; data |
mov edx, [dword esp+ 4+12] ; data |
739 |
|
|
740 |
align 8 |
ALIGN 8 |
741 |
|
|
742 |
dequant 0 |
dequant 0 |
743 |
dequant 1 |
dequant 1 |