1 |
; Originally provided by Intel at AP-922 |
;/***************************************************************************** |
2 |
; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm |
; * |
3 |
; (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) |
; * XVID MPEG-4 VIDEO CODEC |
4 |
; but in a limited edition. |
; * mmx version - inverse discrete cosine transformation |
5 |
; New macro implements a column part for precise iDCT |
; * |
6 |
; The routine precision now satisfies IEEE standard 1180-1990. |
; * Initial version provided by Intel at AppNote AP-922 |
7 |
; |
; * Copyright (C) 1999 Intel Corporation, |
8 |
; Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru> |
; * |
9 |
; Rounding trick Copyright (c) 2000 Michel Lespinasse <walken@zoy.org> |
; * Modifications |
10 |
; |
; * Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru> |
11 |
; http://www.elecard.com/peter/idct.html |
; * Copyright (c) 2000 Michel Lespinasse <walken@zoy.org> |
12 |
; http://www.linuxvideo.org/mpeg2dec/ |
; * |
13 |
; |
; * ported to NASM and some minor changes |
14 |
|
; * Copyright (C) 2001 Peter Ross <pross@xvid.org> |
15 |
|
; * |
16 |
|
; * This program is an implementation of a part of one or more MPEG-4 |
17 |
|
; * Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
18 |
|
; * to use this software module in hardware or software products are |
19 |
|
; * advised that its use may infringe existing patents or copyrights, and |
20 |
|
; * any such use would be at such party's own risk. The original |
21 |
|
; * developer of this software module and his/her company, and subsequent |
22 |
|
; * editors and their companies, will have no liability for use of this |
23 |
|
; * software or modifications or derivatives thereof. |
24 |
|
; * |
25 |
|
; * This program is free software; you can redistribute it and/or modify |
26 |
|
; * it under the terms of the GNU General Public License as published by |
27 |
|
; * the Free Software Foundation; either version 2 of the License, or |
28 |
|
; * (at your option) any later version. |
29 |
|
; * |
30 |
|
; * This program is distributed in the hope that it will be useful, |
31 |
|
; * but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 |
|
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
33 |
|
; * GNU General Public License for more details. |
34 |
|
; * |
35 |
|
; * You should have received a copy of the GNU General Public License |
36 |
|
; * along with this program; if not, write to the Free Software |
37 |
|
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
38 |
|
; * |
39 |
|
; *************************************************************************/ |
40 |
|
|
41 |
;============================================================================= |
;============================================================================= |
42 |
; |
; |
43 |
; These examples contain code fragments for first stage iDCT 8x8 |
; These examples contain code fragments for first stage iDCT 8x8 |
44 |
; (for rows) and first stage DCT 8x8 (for columns) |
; (for rows) and first stage DCT 8x8 (for columns) |
45 |
; |
; |
46 |
;============================================================================= |
;============================================================================= |
|
; |
|
|
; 04.11.2001 nasm conversion; peter ross <pross@cs.rmit.edu.au> |
|
|
; |
|
47 |
|
|
48 |
bits 32 |
bits 32 |
49 |
|
|
68 |
%define SHIFT_FRW_ROW BITS_FRW_ACC + 17 |
%define SHIFT_FRW_ROW BITS_FRW_ACC + 17 |
69 |
%define RND_FRW_ROW 262144 * (BITS_FRW_ACC - 1) ; 1 << (SHIFT_FRW_ROW-1) |
%define RND_FRW_ROW 262144 * (BITS_FRW_ACC - 1) ; 1 << (SHIFT_FRW_ROW-1) |
70 |
|
|
71 |
|
%ifdef FORMAT_COFF |
72 |
section .data |
section .data data |
73 |
|
%else |
74 |
|
section .data data align=16 |
75 |
|
%endif |
76 |
|
|
77 |
align 16 |
align 16 |
78 |
|
|
780 |
DCT_8_INV_COL_4 eax+8, eax+8 |
DCT_8_INV_COL_4 eax+8, eax+8 |
781 |
|
|
782 |
ret |
ret |
783 |
|
|
784 |
|
;============================================================================= |
785 |
|
; The code below this line is for SSE2-equipped processors |
786 |
|
; By Dmitry Rozhdestvensky |
787 |
|
;============================================================================= |
788 |
|
|
789 |
|
section .data |
790 |
|
|
791 |
|
align 16 |
792 |
|
|
793 |
|
tab_i_04_s2 dw 16384, 21407, 16384, 8867 ; movq-> w05 w04 w01 w00 |
794 |
|
dw 16384, -8867, 16384, -21407 ; w13 w12 w09 w08 |
795 |
|
dw 16384, 8867, -16384, -21407 ; w07 w06 w03 w02 |
796 |
|
dw -16384, 21407, 16384, -8867 ; w15 w14 w11 w10 |
797 |
|
dw 22725, 19266, 19266, -4520 ; w21 w20 w17 w16 |
798 |
|
dw 12873, -22725, 4520, -12873 ; w29 w28 w25 w24 |
799 |
|
dw 12873, 4520, -22725, -12873 ; w23 w22 w19 w18 |
800 |
|
dw 4520, 19266, 19266, -22725 ; w31 w30 w27 w26 |
801 |
|
|
802 |
|
; Table for rows 1,7 - constants are multiplied by cos_1_16 |
803 |
|
|
804 |
|
tab_i_17_s2 dw 22725, 29692, 22725, 12299 ; movq-> w05 w04 w01 w00 |
805 |
|
dw 22725, -12299, 22725, -29692 ; w13 w12 w09 w08 |
806 |
|
dw 22725, 12299, -22725, -29692 ; w07 w06 w03 w02 |
807 |
|
dw -22725, 29692, 22725, -12299 ; w15 w14 w11 w10 |
808 |
|
dw 31521, 26722, 26722, -6270 ; w21 w20 w17 w16 |
809 |
|
dw 17855, -31521, 6270, -17855 ; w29 w28 w25 w24 |
810 |
|
dw 17855, 6270, -31521, -17855 ; w23 w22 w19 w18 |
811 |
|
dw 6270, 26722, 26722, -31521 ; w31 w30 w27 w26 |
812 |
|
|
813 |
|
; Table for rows 2,6 - constants are multiplied by cos_2_16 |
814 |
|
|
815 |
|
tab_i_26_s2 dw 21407, 27969, 21407, 11585 ; movq-> w05 w04 w01 w00 |
816 |
|
dw 21407, -11585, 21407, -27969 ; w13 w12 w09 w08 |
817 |
|
dw 21407, 11585, -21407, -27969 ; w07 w06 w03 w02 |
818 |
|
dw -21407, 27969, 21407, -11585 ; w15 w14 w11 w10 |
819 |
|
dw 29692, 25172, 25172, -5906 ; w21 w20 w17 w16 |
820 |
|
dw 16819, -29692, 5906, -16819 ; w29 w28 w25 w24 |
821 |
|
dw 16819, 5906, -29692, -16819 ; w23 w22 w19 w18 |
822 |
|
dw 5906, 25172, 25172, -29692 ; w31 w30 w27 w26 |
823 |
|
|
824 |
|
; Table for rows 3,5 - constants are multiplied by cos_3_16 |
825 |
|
|
826 |
|
tab_i_35_s2 dw 19266, 25172, 19266, 10426 ; movq-> w05 w04 w01 w00 |
827 |
|
dw 19266, -10426, 19266, -25172 ; w13 w12 w09 w08 |
828 |
|
dw 19266, 10426, -19266, -25172 ; w07 w06 w03 w02 |
829 |
|
dw -19266, 25172, 19266, -10426 ; w15 w14 w11 w10 |
830 |
|
dw 26722, 22654, 22654, -5315 ; w21 w20 w17 w16 |
831 |
|
dw 15137, -26722, 5315, -15137 ; w29 w28 w25 w24 |
832 |
|
dw 15137, 5315, -26722, -15137 ; w23 w22 w19 w18 |
833 |
|
dw 5315, 22654, 22654, -26722 ; w31 w30 w27 w26 |
834 |
|
|
835 |
|
%if SHIFT_INV_ROW == 12 ; assume SHIFT_INV_ROW == 12 |
836 |
|
rounder_2_0 dd 65536, 65536 |
837 |
|
dd 65536, 65536 |
838 |
|
rounder_2_4 dd 0, 0 |
839 |
|
dd 0, 0 |
840 |
|
rounder_2_1 dd 7195, 7195 |
841 |
|
dd 7195, 7195 |
842 |
|
rounder_2_7 dd 1024, 1024 |
843 |
|
dd 1024, 1024 |
844 |
|
rounder_2_2 dd 4520, 4520 |
845 |
|
dd 4520, 4520 |
846 |
|
rounder_2_6 dd 1024, 1024 |
847 |
|
dd 1024, 1024 |
848 |
|
rounder_2_3 dd 2407, 2407 |
849 |
|
dd 2407, 2407 |
850 |
|
rounder_2_5 dd 240, 240 |
851 |
|
dd 240, 240 |
852 |
|
|
853 |
|
%elif SHIFT_INV_ROW == 11 ; assume SHIFT_INV_ROW == 11 |
854 |
|
rounder_2_0 dd 65536, 65536 |
855 |
|
dd 65536, 65536 |
856 |
|
rounder_2_4 dd 0, 0 |
857 |
|
dd 0, 0 |
858 |
|
rounder_2_1 dd 3597, 3597 |
859 |
|
dd 3597, 3597 |
860 |
|
rounder_2_7 dd 512, 512 |
861 |
|
dd 512, 512 |
862 |
|
rounder_2_2 dd 2260, 2260 |
863 |
|
dd 2260, 2260 |
864 |
|
rounder_2_6 dd 512, 512 |
865 |
|
dd 512, 512 |
866 |
|
rounder_2_3 dd 1203, 1203 |
867 |
|
dd 1203, 1203 |
868 |
|
rounder_2_5 dd 120, 120 |
869 |
|
dd 120, 120 |
870 |
|
%else |
871 |
|
|
872 |
|
%error invalid _SHIFT_INV_ROW_ |
873 |
|
|
874 |
|
%endif |
875 |
|
|
876 |
|
tg_1_16_2 dw 13036, 13036, 13036, 13036 ; tg * (2<<16) + 0.5 |
877 |
|
dw 13036, 13036, 13036, 13036 |
878 |
|
tg_2_16_2 dw 27146, 27146, 27146, 27146 ; tg * (2<<16) + 0.5 |
879 |
|
dw 27146, 27146, 27146, 27146 |
880 |
|
tg_3_16_2 dw -21746, -21746, -21746, -21746 ; tg * (2<<16) + 0.5 |
881 |
|
dw -21746, -21746, -21746, -21746 |
882 |
|
ocos_4_16_2 dw 23170, 23170, 23170, 23170 ; cos * (2<<15) + 0.5 |
883 |
|
dw 23170, 23170, 23170, 23170 |
884 |
|
|
885 |
|
%macro DCT_8_INV_ROW_1_sse2 4 |
886 |
|
|
887 |
|
pshufhw xmm1,[%1],11011000b ;x 75643210 |
888 |
|
pshuflw xmm1,xmm1,11011000b ;x 75643120 |
889 |
|
pshufd xmm0,xmm1,00000000b ;x 20202020 |
890 |
|
pmaddwd xmm0,[%3] ;w 13 12 9 8 5410 |
891 |
|
;a 3210 first part |
892 |
|
|
893 |
|
pshufd xmm2,xmm1,10101010b ;x 64646464 |
894 |
|
pmaddwd xmm2,[%3+16] ;w 15 14 11 10 7632 |
895 |
|
;a 3210 second part |
896 |
|
|
897 |
|
paddd xmm2,xmm0 ;a 3210 ready |
898 |
|
paddd xmm2,[%4] ;must be 4 dwords long, not 2 as for sse1 |
899 |
|
movdqa xmm5,xmm2 |
900 |
|
|
901 |
|
pshufd xmm3,xmm1,01010101b ;x 31313131 |
902 |
|
pmaddwd xmm3,[%3+32] ;w 29 28 25 24 21 20 17 16 |
903 |
|
;b 3210 first part |
904 |
|
|
905 |
|
pshufd xmm4,xmm1,11111111b ;x 75757575 |
906 |
|
pmaddwd xmm4,[%3+48] ;w 31 30 27 26 23 22 19 18 |
907 |
|
;b 3210 second part |
908 |
|
paddd xmm3,xmm4 ;b 3210 ready |
909 |
|
|
910 |
|
paddd xmm2,xmm3 ;will be y 3210 |
911 |
|
psubd xmm5,xmm3 ;will be y 4567 |
912 |
|
psrad xmm2,SHIFT_INV_ROW |
913 |
|
psrad xmm5,SHIFT_INV_ROW |
914 |
|
packssdw xmm2,xmm5 ;y 45673210 |
915 |
|
pshufhw xmm6,xmm2,00011011b ;y 76543210 |
916 |
|
movdqa [%2],xmm6 |
917 |
|
|
918 |
|
%endmacro |
919 |
|
|
920 |
|
%macro DCT_8_INV_COL_4_sse2 2 |
921 |
|
|
922 |
|
movdqa xmm0,[%1+16*0] ;x0 (all columns) |
923 |
|
movdqa xmm2,[%1+16*4] ;x4 |
924 |
|
movdqa xmm1,xmm0 |
925 |
|
|
926 |
|
movdqa xmm4,[%1+16*2] ;x2 |
927 |
|
movdqa xmm5,[%1+16*6] ;x6 |
928 |
|
movdqa xmm6,[tg_2_16_2] |
929 |
|
movdqa xmm7,xmm6 |
930 |
|
|
931 |
|
paddsw xmm0,xmm2 ;u04=x0+x4 |
932 |
|
psubsw xmm1,xmm2 ;v04=x0-x4 |
933 |
|
movdqa xmm3,xmm0 |
934 |
|
movdqa xmm2,xmm1 |
935 |
|
|
936 |
|
pmulhw xmm6,xmm4 |
937 |
|
pmulhw xmm7,xmm5 |
938 |
|
psubsw xmm6,xmm5 ;v26=x2*T2-x6 |
939 |
|
paddsw xmm7,xmm4 ;u26=x6*T2+x2 |
940 |
|
|
941 |
|
paddsw xmm1,xmm6 ;a1=v04+v26 |
942 |
|
paddsw xmm0,xmm7 ;a0=u04+u26 |
943 |
|
psubsw xmm2,xmm6 ;a2=v04-v26 |
944 |
|
psubsw xmm3,xmm7 ;a3=u04-u26 |
945 |
|
|
946 |
|
movdqa [%2+16*0],xmm0 ;store a3-a0 to |
947 |
|
movdqa [%2+16*6],xmm1 ;free registers |
948 |
|
movdqa [%2+16*2],xmm2 |
949 |
|
movdqa [%2+16*4],xmm3 |
950 |
|
|
951 |
|
movdqa xmm0,[%1+16*1] ;x1 |
952 |
|
movdqa xmm1,[%1+16*7] ;x7 |
953 |
|
movdqa xmm2,[tg_1_16_2] |
954 |
|
movdqa xmm3,xmm2 |
955 |
|
|
956 |
|
movdqa xmm4,[%1+16*3] ;x3 |
957 |
|
movdqa xmm5,[%1+16*5] ;x5 |
958 |
|
movdqa xmm6,[tg_3_16_2] |
959 |
|
movdqa xmm7,xmm6 |
960 |
|
|
961 |
|
pmulhw xmm2,xmm0 |
962 |
|
pmulhw xmm3,xmm1 |
963 |
|
psubsw xmm2,xmm1 ;v17=x1*T1-x7 |
964 |
|
paddsw xmm3,xmm0 ;u17=x7*T1+x1 |
965 |
|
movdqa xmm0,xmm3 ;u17 |
966 |
|
movdqa xmm1,xmm2 ;v17 |
967 |
|
|
968 |
|
pmulhw xmm6,xmm4 ;x3*(t3-1) |
969 |
|
pmulhw xmm7,xmm5 ;x5*(t3-1) |
970 |
|
paddsw xmm6,xmm4 |
971 |
|
paddsw xmm7,xmm5 |
972 |
|
psubsw xmm6,xmm5 ;v35=x3*T3-x5 |
973 |
|
paddsw xmm7,xmm4 ;u35=x5*T3+x3 |
974 |
|
|
975 |
|
movdqa xmm4,[ocos_4_16_2] |
976 |
|
|
977 |
|
paddsw xmm0,xmm7 ;b0=u17+u35 |
978 |
|
psubsw xmm1,xmm6 ;b3=v17-v35 |
979 |
|
psubsw xmm3,xmm7 ;u12=u17-v35 |
980 |
|
paddsw xmm2,xmm6 ;v12=v17+v35 |
981 |
|
|
982 |
|
movdqa xmm5,xmm3 |
983 |
|
paddsw xmm3,xmm2 ;tb1 |
984 |
|
psubsw xmm5,xmm2 ;tb2 |
985 |
|
pmulhw xmm5,xmm4 |
986 |
|
pmulhw xmm4,xmm3 |
987 |
|
paddsw xmm5,xmm5 |
988 |
|
paddsw xmm4,xmm4 |
989 |
|
|
990 |
|
movdqa xmm6,[%2+16*0] ;a0 |
991 |
|
movdqa xmm7,xmm6 |
992 |
|
movdqa xmm2,[%2+16*4] ;a3 |
993 |
|
movdqa xmm3,xmm2 |
994 |
|
|
995 |
|
paddsw xmm6,xmm0 |
996 |
|
psubsw xmm7,xmm0 |
997 |
|
psraw xmm6,SHIFT_INV_COL ;y0=a0+b0 |
998 |
|
psraw xmm7,SHIFT_INV_COL ;y7=a0-b0 |
999 |
|
movdqa [%2+16*0],xmm6 |
1000 |
|
movdqa [%2+16*7],xmm7 |
1001 |
|
|
1002 |
|
paddsw xmm2,xmm1 |
1003 |
|
psubsw xmm3,xmm1 |
1004 |
|
psraw xmm2,SHIFT_INV_COL ;y3=a3+b3 |
1005 |
|
psraw xmm3,SHIFT_INV_COL ;y4=a3-b3 |
1006 |
|
movdqa [%2+16*3],xmm2 |
1007 |
|
movdqa [%2+16*4],xmm3 |
1008 |
|
|
1009 |
|
movdqa xmm0,[%2+16*6] ;a1 |
1010 |
|
movdqa xmm1,xmm0 |
1011 |
|
movdqa xmm6,[%2+16*2] ;a2 |
1012 |
|
movdqa xmm7,xmm6 |
1013 |
|
|
1014 |
|
|
1015 |
|
paddsw xmm0,xmm4 |
1016 |
|
psubsw xmm1,xmm4 |
1017 |
|
psraw xmm0,SHIFT_INV_COL ;y1=a1+b1 |
1018 |
|
psraw xmm1,SHIFT_INV_COL ;y6=a1-b1 |
1019 |
|
movdqa [%2+16*1],xmm0 |
1020 |
|
movdqa [%2+16*6],xmm1 |
1021 |
|
|
1022 |
|
paddsw xmm6,xmm5 |
1023 |
|
psubsw xmm7,xmm5 |
1024 |
|
psraw xmm6,SHIFT_INV_COL ;y2=a2+b2 |
1025 |
|
psraw xmm7,SHIFT_INV_COL ;y5=a2-b2 |
1026 |
|
movdqa [%2+16*2],xmm6 |
1027 |
|
movdqa [%2+16*5],xmm7 |
1028 |
|
|
1029 |
|
%endmacro |
1030 |
|
|
1031 |
|
section .text |
1032 |
|
|
1033 |
|
align 16 |
1034 |
|
cglobal idct_sse2 |
1035 |
|
idct_sse2 |
1036 |
|
|
1037 |
|
mov eax, dword [esp + 4] |
1038 |
|
|
1039 |
|
DCT_8_INV_ROW_1_sse2 eax+0, eax+0, tab_i_04_s2, rounder_2_0 |
1040 |
|
DCT_8_INV_ROW_1_sse2 eax+16, eax+16, tab_i_17_s2, rounder_2_1 |
1041 |
|
DCT_8_INV_ROW_1_sse2 eax+32, eax+32, tab_i_26_s2, rounder_2_2 |
1042 |
|
DCT_8_INV_ROW_1_sse2 eax+48, eax+48, tab_i_35_s2, rounder_2_3 |
1043 |
|
DCT_8_INV_ROW_1_sse2 eax+64, eax+64, tab_i_04_s2, rounder_2_4 |
1044 |
|
DCT_8_INV_ROW_1_sse2 eax+80, eax+80, tab_i_35_s2, rounder_2_5 |
1045 |
|
DCT_8_INV_ROW_1_sse2 eax+96, eax+96, tab_i_26_s2, rounder_2_6 |
1046 |
|
DCT_8_INV_ROW_1_sse2 eax+112, eax+112, tab_i_17_s2, rounder_2_7 |
1047 |
|
|
1048 |
|
DCT_8_INV_COL_4_sse2 eax, eax |
1049 |
|
;DCT_8_INV_COL_4 eax+8, eax+8 |
1050 |
|
|
1051 |
|
ret |