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 |
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 |
39 |
global %1 |
global %1 |
40 |
%endif |
%endif |
41 |
%endmacro |
%endmacro |
42 |
|
|
43 |
|
;============================================================================= |
44 |
|
; Local data |
45 |
|
;============================================================================= |
46 |
|
|
47 |
|
%ifdef FORMAT_COFF |
48 |
|
SECTION .rodata |
49 |
|
%else |
50 |
|
SECTION .rodata align=16 |
51 |
|
%endif |
52 |
|
|
53 |
align 4 |
align 4 |
54 |
int_div |
int_div: |
55 |
dd 0 |
dd 0 |
56 |
%assign i 1 |
%assign i 1 |
57 |
%rep 255 |
%rep 255 |
59 |
%assign i i+1 |
%assign i i+1 |
60 |
%endrep |
%endrep |
61 |
|
|
62 |
align 16 |
ALIGN 16 |
63 |
|
plus_one: |
64 |
plus_one times 8 dw 1 |
times 8 dw 1 |
65 |
|
|
66 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
67 |
; subtract by Q/2 table |
; subtract by Q/2 table |
68 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
69 |
|
|
70 |
%macro MMX_SUB 1 |
ALIGN 16 |
71 |
times 4 dw %1 / 2 |
mmx_sub: |
|
%endmacro |
|
|
|
|
|
|
|
|
align 16 |
|
|
mmx_sub |
|
72 |
%assign i 1 |
%assign i 1 |
73 |
%rep 31 |
%rep 31 |
74 |
times 4 dw i / 2 |
times 4 dw i / 2 |
76 |
%endrep |
%endrep |
77 |
|
|
78 |
|
|
79 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
80 |
; |
; |
81 |
; divide by 2Q table |
; divide by 2Q table |
82 |
; |
; |
84 |
; for q=1, _pmulhw_ will overflow so it is treated seperately |
; for q=1, _pmulhw_ will overflow so it is treated seperately |
85 |
; (3dnow2 provides _pmulhuw_ which wont cause overflow) |
; (3dnow2 provides _pmulhuw_ which wont cause overflow) |
86 |
; |
; |
87 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
|
|
|
align 16 |
|
|
mmx_div |
|
88 |
|
|
89 |
|
ALIGN 16 |
90 |
|
mmx_div: |
91 |
%assign i 1 |
%assign i 1 |
92 |
%rep 31 |
%rep 31 |
93 |
times 4 dw (1 << 16) / (i * 2) + 1 |
times 4 dw (1 << 16) / (i * 2) + 1 |
94 |
%assign i i+1 |
%assign i i+1 |
95 |
%endrep |
%endrep |
96 |
|
|
97 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
98 |
; add by (odd(Q) ? Q : Q - 1) table |
; add by (odd(Q) ? Q : Q - 1) table |
99 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
|
|
|
|
%macro MMX_ADD 1 |
|
|
%if %1 % 2 != 0 |
|
|
times 4 dw %1 |
|
|
%else |
|
|
times 4 dw %1 - 1 |
|
|
%endif |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
|
mmx_add |
|
100 |
|
|
101 |
|
ALIGN 16 |
102 |
|
mmx_add: |
103 |
%assign i 1 |
%assign i 1 |
104 |
%rep 31 |
%rep 31 |
105 |
MMX_ADD i |
%if i % 2 != 0 |
106 |
|
times 4 dw i |
107 |
|
%else |
108 |
|
times 4 dw i - 1 |
109 |
|
%endif |
110 |
%assign i i+1 |
%assign i i+1 |
111 |
%endrep |
%endrep |
112 |
|
|
113 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
114 |
; multiple by 2Q table |
; multiple by 2Q table |
115 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
|
|
|
|
%macro MMX_MUL 1 |
|
|
times 4 dw %1 * 2 |
|
|
%endmacro |
|
|
|
|
|
align 16 |
|
|
mmx_mul |
|
116 |
|
|
117 |
|
ALIGN 16 |
118 |
|
mmx_mul: |
119 |
%assign i 1 |
%assign i 1 |
120 |
%rep 31 |
%rep 31 |
121 |
times 4 dw i * 2 |
times 4 dw i * 2 |
122 |
%assign i i+1 |
%assign i i+1 |
123 |
%endrep |
%endrep |
124 |
|
|
125 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
|
; |
|
126 |
; saturation limits |
; saturation limits |
127 |
; |
;----------------------------------------------------------------------------- |
|
;=========================================================================== |
|
128 |
|
|
129 |
align 8 |
ALIGN 8 |
130 |
mmx_32768_minus_2048 times 4 dw (32768-2048) |
mmx_32768_minus_2048: |
131 |
mmx_32767_minus_2047 times 4 dw (32767-2047) |
times 4 dw (32768-2048) |
132 |
|
mmx_32767_minus_2047: |
133 |
|
times 4 dw (32767-2047) |
134 |
|
|
135 |
align 16 |
ALIGN 16 |
136 |
mmx_2047 times 4 dw 2047 |
mmx_2047: |
137 |
|
times 4 dw 2047 |
138 |
|
|
139 |
align 8 |
ALIGN 8 |
140 |
mmzero dd 0, 0 |
mmzero: |
141 |
int2047 dd 2047 |
dd 0, 0 |
142 |
int_2048 dd -2048 |
int2047: |
143 |
|
dd 2047 |
144 |
|
int_2048: |
145 |
|
dd -2048 |
146 |
|
|
147 |
section .text |
;============================================================================= |
148 |
|
; Code |
149 |
|
;============================================================================= |
150 |
|
|
151 |
|
SECTION .text |
152 |
|
|
153 |
;=========================================================================== |
|
154 |
|
;----------------------------------------------------------------------------- |
155 |
; |
; |
156 |
; void quant_intra_3dne(int16_t * coeff, |
; uint32_t quant_h263_intra_3dne(int16_t * coeff, |
157 |
; const int16_t const * data, |
; const int16_t const * data, |
158 |
; const uint32_t quant, |
; const uint32_t quant, |
159 |
; const uint32_t dcscalar); |
; const uint32_t dcscalar, |
160 |
|
; const uint16_t *mpeg_matrices); |
161 |
; |
; |
162 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
163 |
;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 |
|
164 |
|
|
165 |
%macro quant_intra1 1 |
%macro quant_intra1 1 |
|
|
|
166 |
psubw mm1, mm0 ;A3 |
psubw mm1, mm0 ;A3 |
167 |
psubw mm3, mm2 ;B3 |
psubw mm3, mm2 ;B3 |
168 |
%if (%1) |
%if (%1) |
170 |
psubw mm7, mm6 ;D8 |
psubw mm7, mm6 ;D8 |
171 |
%endif |
%endif |
172 |
|
|
173 |
align 8 |
ALIGN 8 |
174 |
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 |
175 |
pmaxsw mm1, mm0 ;A4 |
pmaxsw mm1, mm0 ;A4 |
176 |
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 |
244 |
psubw mm7, mm6 ;D8 |
psubw mm7, mm6 ;D8 |
245 |
%endif |
%endif |
246 |
|
|
247 |
align 8 |
ALIGN 8 |
248 |
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 |
249 |
pmaxsw mm1, mm0 ;A4 |
pmaxsw mm1, mm0 ;A4 |
250 |
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 |
311 |
%endmacro |
%endmacro |
312 |
|
|
313 |
|
|
314 |
align ALIGN |
ALIGN 16 |
315 |
cglobal quant_h263_intra_3dne |
cglobal quant_h263_intra_3dne |
316 |
quant_h263_intra_3dne: |
quant_h263_intra_3dne: |
317 |
|
|
363 |
movq [edx + 3 * 32 + 16], mm5 ;C9 |
movq [edx + 3 * 32 + 16], mm5 ;C9 |
364 |
movq [edx + 3 * 32 + 24], mm7 ;D9 |
movq [edx + 3 * 32 + 24], mm7 ;D9 |
365 |
|
|
366 |
|
xor eax, eax |
367 |
ret |
ret |
368 |
|
|
369 |
align 16 |
ALIGN 16 |
370 |
|
|
371 |
.q1loop |
.q1loop |
372 |
quant_intra1 0 |
quant_intra1 0 |
399 |
movq [edx + 3 * 32 + 16], mm5 ;C9 |
movq [edx + 3 * 32 + 16], mm5 ;C9 |
400 |
movq [edx + 3 * 32 + 24], mm7 ;D9 |
movq [edx + 3 * 32 + 24], mm7 ;D9 |
401 |
|
|
402 |
|
xor eax, eax |
403 |
ret |
ret |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
409 |
; |
; |
410 |
; uint32_t quant_inter_3dne(int16_t * coeff, |
; uint32_t quant_h263_inter_3dne(int16_t * coeff, |
411 |
; const int16_t const * data, |
; const int16_t const * data, |
412 |
; const uint32_t quant); |
; const uint32_t quant, |
413 |
|
; const uint16_t *mpeg_matrices); |
414 |
; |
; |
415 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
416 |
;This is Athlon-optimized code (ca 90 clk per call) |
;This is Athlon-optimized code (ca 90 clk per call) |
417 |
;Optimized by Jaan, 30 Nov 2002 |
;Optimized by Jaan, 30 Nov 2002 |
418 |
|
|
487 |
movq [edx + %1*16+8], mm4 |
movq [edx + %1*16+8], mm4 |
488 |
%endmacro |
%endmacro |
489 |
|
|
490 |
align ALIGN |
ALIGN 16 |
491 |
cglobal quant_h263_inter_3dne |
cglobal quant_h263_inter_3dne |
492 |
quant_h263_inter_3dne: |
quant_h263_inter_3dne: |
493 |
mov edx, [esp + 4] ; coeff |
mov edx, [esp + 4] ; coeff |
504 |
lea eax, [mmzero] |
lea eax, [mmzero] |
505 |
jz near .q1loop |
jz near .q1loop |
506 |
cmp esp, esp |
cmp esp, esp |
507 |
align 8 |
ALIGN 8 |
508 |
movq mm3, [ecx + 120] ;B1 |
movq mm3, [ecx + 120] ;B1 |
509 |
pxor mm4, mm4 ;B2 |
pxor mm4, mm4 ;B2 |
510 |
psubw mm4, mm3 ;B3 |
psubw mm4, mm3 ;B3 |
535 |
|
|
536 |
ret |
ret |
537 |
|
|
538 |
align ALIGN |
ALIGN 16 |
539 |
.q1loop |
.q1loop |
540 |
movq mm6, [byte ebx] |
movq mm6, [byte ebx] |
541 |
|
|
558 |
|
|
559 |
ret |
ret |
560 |
|
|
561 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
562 |
; |
; |
563 |
; void dequant_intra_3dne(int16_t *data, |
; uint32_t dequant_h263_intra_3dne(int16_t *data, |
564 |
; const int16_t const *coeff, |
; const int16_t const *coeff, |
565 |
; const uint32_t quant, |
; const uint32_t quant, |
566 |
; const uint32_t dcscalar); |
; const uint32_t dcscalar, |
567 |
|
; const uint16_t *mpeg_matrices); |
568 |
; |
; |
569 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
570 |
|
|
571 |
; this is the same as dequant_inter_3dne, except that we're |
; this is the same as dequant_inter_3dne, except that we're |
572 |
; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster) |
; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster) |
592 |
movq mm4, [esi] ;C1 ;0 |
movq mm4, [esi] ;C1 ;0 |
593 |
mov esp, esp |
mov esp, esp |
594 |
pcmpeqw mm6, [ecx+%1*24] ;A6 (c ==0) ? -1 : 0 (1st) |
pcmpeqw mm6, [ecx+%1*24] ;A6 (c ==0) ? -1 : 0 (1st) |
595 |
align 4 |
ALIGN 4 |
596 |
psraw mm1, 15 ; sign(c) ;A7 (2nd) |
psraw mm1, 15 ; sign(c) ;A7 (2nd) |
597 |
%if (%1) |
%if (%1) |
598 |
movq [edx+%1*24+16-24], mm5 ; C14 (7th) 2later |
movq [edx+%1*24+16-24], mm5 ; C14 (7th) 2later |
638 |
%endmacro |
%endmacro |
639 |
|
|
640 |
|
|
641 |
align ALIGN |
ALIGN 16 |
642 |
cglobal dequant_h263_intra_3dne |
cglobal dequant_h263_intra_3dne |
643 |
dequant_h263_intra_3dne: |
dequant_h263_intra_3dne: |
644 |
mov ecx, [esp+ 8] ; coeff |
mov ecx, [esp+ 8] ; coeff |
665 |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
666 |
mov edx, [esp+ 4+16] ; data |
mov edx, [esp+ 4+16] ; data |
667 |
|
|
668 |
align 8 |
ALIGN 8 |
669 |
dequant 0 |
dequant 0 |
670 |
|
|
671 |
cmp ebp, -2048 |
cmp ebp, -2048 |
705 |
pxor mm3, mm2 ;B13 (6th+) |
pxor mm3, mm2 ;B13 (6th+) |
706 |
movq [edx+4*24+8], mm3 ;B14 (7th) |
movq [edx+4*24+8], mm3 ;B14 (7th) |
707 |
mov [edx], ax |
mov [edx], ax |
708 |
|
|
709 |
|
xor eax, eax |
710 |
ret |
ret |
711 |
|
|
712 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
713 |
; |
; |
714 |
; void dequant_inter_3dne(int16_t * data, |
; uint32_t dequant_h263_inter_3dne(int16_t * data, |
715 |
; const int16_t * const coeff, |
; const int16_t * const coeff, |
716 |
; const uint32_t quant); |
; const uint32_t quant, |
717 |
|
; const uint16_t *mpeg_matrices); |
718 |
; |
; |
719 |
;=========================================================================== |
;----------------------------------------------------------------------------- |
720 |
|
|
721 |
; this is the same as dequant_inter_3dne, |
; this is the same as dequant_inter_3dne, |
722 |
; except that we're saturating using 'pminsw' (saves 2 cycles/loop) |
; except that we're saturating using 'pminsw' (saves 2 cycles/loop) |
723 |
;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 |
|
724 |
|
|
725 |
align ALIGN |
ALIGN 16 |
726 |
cglobal dequant_h263_inter_3dne |
cglobal dequant_h263_inter_3dne |
727 |
dequant_h263_inter_3dne: |
dequant_h263_inter_3dne: |
728 |
mov ecx, [esp+ 8] ; coeff |
mov ecx, [esp+ 8] ; coeff |
745 |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
psraw mm3, 15 ; sign(c) ;B7 (2nd) |
746 |
mov edx, [dword esp+ 4+12] ; data |
mov edx, [dword esp+ 4+12] ; data |
747 |
|
|
748 |
align 8 |
ALIGN 8 |
749 |
|
|
750 |
dequant 0 |
dequant 0 |
751 |
dequant 1 |
dequant 1 |
768 |
pxor mm3, mm2 ;B13 (6th+) |
pxor mm3, mm2 ;B13 (6th+) |
769 |
movq [edx+4*24+8], mm3 ;B14 (7th) |
movq [edx+4*24+8], mm3 ;B14 (7th) |
770 |
|
|
771 |
|
xor eax, eax |
772 |
ret |
ret |