1 |
;/************************************************************************** |
;/***************************************************************************** |
2 |
; * |
; * |
3 |
; * XVID MPEG-4 VIDEO CODEC |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; * mmx quantization/dequantization |
; * mmx optimized quantization/dequantization |
5 |
|
; * |
6 |
|
; * Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 |
|
; * Copyright(C) 2002 Michael Militzer <michael@xvid.org> |
8 |
|
; * Copyright(C) 2002 Pascal Massimino <skal@planet-d.net> |
9 |
; * |
; * |
10 |
; * This program is an implementation of a part of one or more MPEG-4 |
; * This program is an implementation of a part of one or more MPEG-4 |
11 |
; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
28 |
; * |
; * |
29 |
; * You should have received a copy of the GNU General Public License |
; * You should have received a copy of the GNU General Public License |
30 |
; * along with this program; if not, write to the Free Software |
; * along with this program; if not, write to the Free Software |
31 |
; * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
; * |
|
|
; *************************************************************************/ |
|
|
|
|
|
;/************************************************************************** |
|
|
; * |
|
|
; * History: |
|
|
; * |
|
|
; * 14.06.2002 mmx+xmm dequant_* funcs revamped -Skal- |
|
|
; * 24.02.2002 sse2 quant_intra / dequant_intra (have to use movdqu ???) |
|
|
; * 17.04.2002 sse2 quant_inter / dequant_inter |
|
|
; * 26.12.2001 minor bug fixes, dequant saturate, further optimization |
|
|
; * 19.11.2001 quant_inter_mmx now returns sum of abs. coefficient values |
|
|
; * 04.11.2001 nasm version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
32 |
; * |
; * |
33 |
; *************************************************************************/ |
; *************************************************************************/ |
34 |
|
|
252 |
; |
; |
253 |
;=========================================================================== |
;=========================================================================== |
254 |
|
|
255 |
align 8 |
align 16 |
256 |
mmx_32768_minus_2048 times 4 dw (32768-2048) |
sse2_2047 times 8 dw 2047 |
|
mmx_32767_minus_2047 times 4 dw (32767-2047) |
|
257 |
|
|
258 |
align 16 |
align 16 |
259 |
mmx_2047 times 4 dw 2047 |
mmx_2047 times 4 dw 2047 |
260 |
|
|
261 |
align 16 |
align 8 |
262 |
sse2_pos_2047 times 8 dw 2047 |
mmx_32768_minus_2048 times 4 dw (32768-2048) |
263 |
sse2_neg_2048 times 8 dw -2048 |
mmx_32767_minus_2047 times 4 dw (32767-2047) |
264 |
|
|
265 |
|
|
266 |
section .text |
section .text |
845 |
|
|
846 |
ret |
ret |
847 |
|
|
848 |
|
|
849 |
;=========================================================================== |
;=========================================================================== |
850 |
; |
; |
851 |
; void dequant_intra_sse2(int16_t *data, |
; void dequant_intra_sse2(int16_t *data, |
854 |
; const uint32_t dcscalar); |
; const uint32_t dcscalar); |
855 |
; |
; |
856 |
;=========================================================================== |
;=========================================================================== |
857 |
|
align ALIGN |
|
align 16 |
|
858 |
cglobal dequant_intra_sse2 |
cglobal dequant_intra_sse2 |
859 |
dequant_intra_sse2: |
dequant_intra_sse2: |
860 |
|
mov edx, [esp+ 4] ; data |
861 |
push esi |
mov ecx, [esp+ 8] ; coeff |
862 |
push edi |
mov eax, [esp+12] ; quant |
|
|
|
|
mov edi, [esp + 8 + 4] ; data |
|
|
mov esi, [esp + 8 + 8] ; coeff |
|
|
mov eax, [esp + 8 + 12] ; quant |
|
|
|
|
863 |
movq mm6, [mmx_add + eax*8 - 8] |
movq mm6, [mmx_add + eax*8 - 8] |
864 |
movq mm7, [mmx_mul + eax*8 - 8] |
movq mm7, [mmx_mul + eax*8 - 8] |
865 |
movq2dq xmm6, mm6 |
movq2dq xmm6, mm6 |
866 |
movq2dq xmm7, mm7 |
movq2dq xmm7, mm7 |
867 |
movlhps xmm6, xmm6 |
movlhps xmm6, xmm6 |
868 |
movlhps xmm7, xmm7 |
movlhps xmm7, xmm7 |
869 |
|
mov eax, -16 |
870 |
|
|
871 |
xor eax, eax |
align ALIGN |
872 |
|
.loop |
873 |
align 16 |
movdqa xmm0, [ecx + 8*16 + 8*eax] ; c = coeff[i] |
874 |
.das2_loop |
movdqa xmm3, [ecx + 8*16 + 8*eax+ 16] |
|
movdqa xmm0, [esi + eax*8] |
|
|
movdqa xmm3, [esi + eax*8 + 16] |
|
875 |
pxor xmm1, xmm1 |
pxor xmm1, xmm1 |
876 |
pxor xmm4, xmm4 |
pxor xmm4, xmm4 |
877 |
pcmpgtw xmm1, xmm0 |
pcmpgtw xmm1, xmm0 ; sign(c) |
878 |
pcmpgtw xmm4, xmm3 |
pcmpgtw xmm4, xmm3 |
879 |
pxor xmm2, xmm2 |
pxor xmm2, xmm2 |
880 |
pxor xmm5, xmm5 |
pxor xmm5, xmm5 |
881 |
pcmpeqw xmm2, xmm0 |
pcmpeqw xmm2, xmm0 ; c is zero |
882 |
pcmpeqw xmm5, xmm3 |
pcmpeqw xmm5, xmm3 |
883 |
pandn xmm2, xmm6 |
pandn xmm2, xmm6 ; offset = isZero ? 0 : quant_add |
884 |
pandn xmm5, xmm6 |
pandn xmm5, xmm6 |
885 |
pxor xmm0, xmm1 |
pxor xmm0, xmm1 ; negate if negative |
886 |
pxor xmm3, xmm4 |
pxor xmm3, xmm4 |
887 |
psubw xmm0, xmm1 |
psubw xmm0, xmm1 |
888 |
psubw xmm3, xmm4 |
psubw xmm3, xmm4 |
889 |
pmullw xmm0, xmm7 |
pmullw xmm0, xmm7 ; *= 2Q |
890 |
pmullw xmm3, xmm7 |
pmullw xmm3, xmm7 |
891 |
paddw xmm0, xmm2 |
paddw xmm0, xmm2 ; + offset |
892 |
paddw xmm3, xmm5 |
paddw xmm3, xmm5 |
893 |
pxor xmm0, xmm1 |
paddw xmm0, xmm1 ; negate back |
894 |
pxor xmm3, xmm4 |
paddw xmm3, xmm4 |
|
psubw xmm0, xmm1 |
|
|
psubw xmm3, xmm4 |
|
895 |
|
|
896 |
%ifdef SATURATE |
; saturates to +2047 |
897 |
movdqu xmm2, [sse2_pos_2047] |
movdqa xmm2, [sse2_2047] |
|
movdqu xmm4, [sse2_neg_2048] |
|
898 |
pminsw xmm0, xmm2 |
pminsw xmm0, xmm2 |
|
pminsw xmm3, xmm2 |
|
|
pmaxsw xmm0, xmm4 |
|
|
pmaxsw xmm3, xmm4 |
|
|
%endif |
|
|
|
|
|
movdqa [edi + eax*8], xmm0 |
|
|
movdqa [edi + eax*8 + 16], xmm3 |
|
|
|
|
899 |
add eax, 4 |
add eax, 4 |
900 |
cmp eax, 16 |
pminsw xmm3, xmm2 |
|
jnz near .das2_loop |
|
901 |
|
|
902 |
mov ax, [esi] ; ax = data[0] |
pxor xmm0, xmm1 |
903 |
imul ax, [esp + 8 + 16] ; eax = data[0] * dcscalar |
pxor xmm3, xmm4 |
904 |
|
movdqa [edx + 8*16 - 8*4 + 8*eax], xmm0 |
905 |
|
movdqa [edx + 8*16 - 8*4 + 8*eax + 16], xmm3 |
906 |
|
jnz near .loop |
907 |
|
|
908 |
%ifdef SATURATE |
; deal with DC |
909 |
cmp ax, -2048 |
movd mm0, [ecx] |
910 |
jl .das2_set_n2048 |
pmullw mm0, [esp+16] ; dcscalar |
911 |
cmp ax, 2047 |
movq mm2, [mmx_32767_minus_2047] |
912 |
jg .das2_set_2047 |
paddsw mm0, mm2 |
913 |
%endif |
psubsw mm0, mm2 |
914 |
mov [edi], ax |
movq mm2, [mmx_32768_minus_2048] |
915 |
|
psubsw mm0, mm2 |
916 |
|
paddsw mm0, mm2 |
917 |
|
movd eax, mm0 |
918 |
|
mov [edx], ax |
919 |
|
|
|
pop edi |
|
|
pop esi |
|
920 |
ret |
ret |
921 |
|
|
|
%ifdef SATURATE |
|
|
align 16 |
|
|
.das2_set_n2048 |
|
|
mov word [edi], -2048 |
|
|
pop edi |
|
|
pop esi |
|
|
ret |
|
922 |
|
|
923 |
align 16 |
|
|
.das2_set_2047 |
|
|
mov word [edi], 2047 |
|
|
pop edi |
|
|
pop esi |
|
|
ret |
|
|
%endif |
|
924 |
|
|
925 |
;=========================================================================== |
;=========================================================================== |
926 |
; |
; |
1050 |
; const uint32_t quant); |
; const uint32_t quant); |
1051 |
; |
; |
1052 |
;=========================================================================== |
;=========================================================================== |
1053 |
|
align ALIGN |
|
align 16 |
|
1054 |
cglobal dequant_inter_sse2 |
cglobal dequant_inter_sse2 |
1055 |
dequant_inter_sse2 |
dequant_inter_sse2 |
1056 |
|
mov edx, [esp + 4] ; data |
1057 |
push esi |
mov ecx, [esp + 8] ; coeff |
1058 |
push edi |
mov eax, [esp + 12] ; quant |
|
|
|
|
mov edi, [esp + 8 + 4] ; data |
|
|
mov esi, [esp + 8 + 8] ; coeff |
|
|
mov eax, [esp + 8 + 12] ; quant |
|
1059 |
movq mm6, [mmx_add + eax * 8 - 8] |
movq mm6, [mmx_add + eax * 8 - 8] |
1060 |
movq mm7, [mmx_mul + eax * 8 - 8] |
movq mm7, [mmx_mul + eax * 8 - 8] |
|
|
|
1061 |
movq2dq xmm6, mm6 |
movq2dq xmm6, mm6 |
1062 |
movq2dq xmm7, mm7 |
movq2dq xmm7, mm7 |
1063 |
movlhps xmm6, xmm6 |
movlhps xmm6, xmm6 |
1064 |
movlhps xmm7, xmm7 |
movlhps xmm7, xmm7 |
1065 |
|
mov eax, -16 |
1066 |
|
|
1067 |
xor eax, eax |
align ALIGN |
1068 |
|
.loop |
1069 |
|
movdqa xmm0, [ecx + 8*16 + 8*eax] ; c = coeff[i] |
1070 |
|
movdqa xmm3, [ecx + 8*16 + 8*eax + 16] |
1071 |
|
|
|
align 16 |
|
|
.des2_loop |
|
|
movdqa xmm0, [esi + eax*8] ; xmm0 = [coeff] |
|
|
movdqa xmm3, [esi + eax*8 + 16] |
|
1072 |
pxor xmm1, xmm1 |
pxor xmm1, xmm1 |
1073 |
pxor xmm4, xmm4 |
pxor xmm4, xmm4 |
1074 |
pcmpgtw xmm1, xmm0 |
pcmpgtw xmm1, xmm0 ; sign(c) |
1075 |
pcmpgtw xmm4, xmm3 |
pcmpgtw xmm4, xmm3 |
1076 |
pxor xmm2, xmm2 |
pxor xmm2, xmm2 |
1077 |
pxor xmm5, xmm5 |
pxor xmm5, xmm5 |
1078 |
pcmpeqw xmm2, xmm0 |
pcmpeqw xmm2, xmm0 ; c is zero |
1079 |
pcmpeqw xmm5, xmm3 |
pcmpeqw xmm5, xmm3 |
1080 |
pandn xmm2, xmm6 |
pandn xmm2, xmm6 |
1081 |
pandn xmm5, xmm6 |
pandn xmm5, xmm6 |
1082 |
pxor xmm0, xmm1 |
pxor xmm0, xmm1 ; negate if negative |
1083 |
pxor xmm3, xmm4 |
pxor xmm3, xmm4 |
1084 |
psubw xmm0, xmm1 |
psubw xmm0, xmm1 |
1085 |
psubw xmm3, xmm4 |
psubw xmm3, xmm4 |
1086 |
pmullw xmm0, xmm7 |
pmullw xmm0, xmm7 ; *= 2Q |
1087 |
pmullw xmm3, xmm7 |
pmullw xmm3, xmm7 |
1088 |
paddw xmm0, xmm2 |
paddw xmm0, xmm2 ; + offset |
1089 |
paddw xmm3, xmm5 |
paddw xmm3, xmm5 |
|
pxor xmm0, xmm1 |
|
|
pxor xmm3, xmm4 |
|
|
psubw xmm0, xmm1 |
|
|
psubw xmm3, xmm4 |
|
1090 |
|
|
1091 |
%ifdef SATURATE |
paddw xmm0, xmm1 ; start restoring sign |
1092 |
movdqu xmm2, [sse2_pos_2047] |
paddw xmm3, xmm4 |
|
movdqu xmm4, [sse2_neg_2048] |
|
|
pminsw xmm0, xmm2 |
|
|
pminsw xmm3, xmm2 |
|
|
pmaxsw xmm0, xmm4 |
|
|
pmaxsw xmm3, xmm4 |
|
|
%endif |
|
|
|
|
|
movdqa [edi + eax*8], xmm0 |
|
|
movdqa [edi + eax*8 + 16], xmm3 |
|
1093 |
|
|
1094 |
|
; saturates to +2047 |
1095 |
|
movdqa xmm2, [sse2_2047] |
1096 |
|
pminsw xmm0, xmm2 |
1097 |
add eax, 4 |
add eax, 4 |
1098 |
cmp eax, 16 |
pminsw xmm3, xmm2 |
|
jnz near .des2_loop |
|
1099 |
|
|
1100 |
pop edi |
pxor xmm0, xmm1 ; finish restoring sign |
1101 |
pop esi |
pxor xmm3, xmm4 |
1102 |
|
movdqa [edx + 8*16 - 8*4 + 8*eax], xmm0 |
1103 |
|
movdqa [edx + 8*16 - 8*4 + 8*eax + 16], xmm3 |
1104 |
|
jnz near .loop |
1105 |
|
|
1106 |
ret |
ret |