[svn] / tags / release-0_9_2 / xvidcore / src / dct / x86_asm / idct_mmx.asm Repository:
ViewVC logotype

Diff of /tags/release-0_9_2/xvidcore/src/dct/x86_asm/idct_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3, Fri Mar 8 02:46:11 2002 UTC revision 649, Sat Nov 16 23:51:58 2002 UTC
# Line 1  Line 1 
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 file is part of XviD, a free MPEG-4 video encoder/decoder
17    ; *
18    ; *  XviD is free software; you can redistribute it and/or modify it
19    ; *  under the terms of the GNU General Public License as published by
20    ; *  the Free Software Foundation; either version 2 of the License, or
21    ; *  (at your option) any later version.
22    ; *
23    ; *  This program is distributed in the hope that it will be useful,
24    ; *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25    ; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26    ; *  GNU General Public License for more details.
27    ; *
28    ; *  You should have received a copy of the GNU General Public License
29    ; *  along with this program; if not, write to the Free Software
30    ; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
31    ; *
32    ; *  Under section 8 of the GNU General Public License, the copyright
33    ; *  holders of XVID explicitly forbid distribution in the following
34    ; *  countries:
35    ; *
36    ; *    - Japan
37    ; *    - United States of America
38    ; *
39    ; *  Linking XviD statically or dynamically with other modules is making a
40    ; *  combined work based on XviD.  Thus, the terms and conditions of the
41    ; *  GNU General Public License cover the whole combination.
42    ; *
43    ; *  As a special exception, the copyright holders of XviD give you
44    ; *  permission to link XviD with independent modules that communicate with
45    ; *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the
46    ; *  license terms of these independent modules, and to copy and distribute
47    ; *  the resulting combined work under terms of your choice, provided that
48    ; *  every copy of the combined work is accompanied by a complete copy of
49    ; *  the source code of XviD (the version of XviD used to produce the
50    ; *  combined work), being distributed under the terms of the GNU General
51    ; *  Public License plus this exception.  An independent module is a module
52    ; *  which is not derived from or based on XviD.
53    ; *
54    ; *  Note that people who make modified versions of XviD are not obligated
55    ; *  to grant this special exception for their modified versions; it is
56    ; *  their choice whether to do so.  The GNU General Public License gives
57    ; *  permission to release a modified version without this exception; this
58    ; *  exception also makes it possible to release a modified version which
59    ; *  carries forward this exception.
60    ; *
61    ; * $Id: idct_mmx.asm,v 1.5 2002-11-16 23:51:58 edgomez Exp $
62    ; *
63    ; *************************************************************************/
64    
65  ;=============================================================================  ;=============================================================================
66  ;  ;
67  ; These examples contain code fragments for first stage iDCT 8x8  ; These examples contain code fragments for first stage iDCT 8x8
68  ; (for rows) and first stage DCT 8x8 (for columns)  ; (for rows) and first stage DCT 8x8 (for columns)
69  ;  ;
70  ;=============================================================================  ;=============================================================================
 ;  
 ; 04.11.2001  nasm conversion; peter ross <pross@cs.rmit.edu.au>  
 ;  
71    
72  bits 32  bits 32
73    
# Line 44  Line 92 
92  %define SHIFT_FRW_ROW   BITS_FRW_ACC + 17  %define SHIFT_FRW_ROW   BITS_FRW_ACC + 17
93  %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)
94    
95    %ifdef FORMAT_COFF
96  section .data  section .data data
97    %else
98    section .data data align=16
99    %endif
100    
101  align 16  align 16
102    
# Line 753  Line 804 
804          DCT_8_INV_COL_4 eax+8, eax+8          DCT_8_INV_COL_4 eax+8, eax+8
805    
806          ret          ret
807    
808    ;=============================================================================
809    ;         The code below this line is for SSE2-equipped processors
810    ;         By Dmitry Rozhdestvensky
811    ;=============================================================================
812    
813    section .data
814    
815    align 16
816    
817    tab_i_04_s2 dw 16384, 21407, 16384, 8867 ; movq-> w05 w04 w01 w00
818                    dw 16384, -8867, 16384, -21407 ; w13 w12 w09 w08
819                    dw 16384, 8867, -16384, -21407 ; w07 w06 w03 w02
820                    dw -16384, 21407, 16384, -8867 ; w15 w14 w11 w10
821                    dw 22725, 19266, 19266, -4520 ; w21 w20 w17 w16
822                    dw 12873, -22725, 4520, -12873 ; w29 w28 w25 w24
823                    dw 12873, 4520, -22725, -12873 ; w23 w22 w19 w18
824                    dw 4520, 19266, 19266, -22725 ; w31 w30 w27 w26
825    
826    ; Table for rows 1,7 - constants are multiplied by cos_1_16
827    
828    tab_i_17_s2     dw 22725, 29692, 22725, 12299 ; movq-> w05 w04 w01 w00
829                    dw 22725, -12299, 22725, -29692 ; w13 w12 w09 w08
830                    dw 22725, 12299, -22725, -29692 ; w07 w06 w03 w02
831                    dw -22725, 29692, 22725, -12299 ; w15 w14 w11 w10
832                    dw 31521, 26722, 26722, -6270 ; w21 w20 w17 w16
833                    dw 17855, -31521, 6270, -17855 ; w29 w28 w25 w24
834                    dw 17855, 6270, -31521, -17855 ; w23 w22 w19 w18
835                    dw 6270, 26722, 26722, -31521 ; w31 w30 w27 w26
836    
837    ; Table for rows 2,6 - constants are multiplied by cos_2_16
838    
839    tab_i_26_s2     dw 21407, 27969, 21407, 11585 ; movq-> w05 w04 w01 w00
840                    dw 21407, -11585, 21407, -27969 ; w13 w12 w09 w08
841                    dw 21407, 11585, -21407, -27969 ; w07 w06 w03 w02
842                    dw -21407, 27969, 21407, -11585 ; w15 w14 w11 w10
843                    dw 29692, 25172, 25172, -5906 ; w21 w20 w17 w16
844                    dw 16819, -29692, 5906, -16819 ; w29 w28 w25 w24
845                    dw 16819, 5906, -29692, -16819 ; w23 w22 w19 w18
846                    dw 5906, 25172, 25172, -29692 ; w31 w30 w27 w26
847    
848    ; Table for rows 3,5 - constants are multiplied by cos_3_16
849    
850    tab_i_35_s2     dw 19266, 25172, 19266, 10426 ; movq-> w05 w04 w01 w00
851                    dw 19266, -10426, 19266, -25172 ; w13 w12 w09 w08
852                    dw 19266, 10426, -19266, -25172 ; w07 w06 w03 w02
853                    dw -19266, 25172, 19266, -10426 ; w15 w14 w11 w10
854                    dw 26722, 22654, 22654, -5315 ; w21 w20 w17 w16
855                    dw 15137, -26722, 5315, -15137 ; w29 w28 w25 w24
856                    dw 15137, 5315, -26722, -15137 ; w23 w22 w19 w18
857                    dw 5315, 22654, 22654, -26722 ; w31 w30 w27 w26
858    
859    %if SHIFT_INV_ROW == 12   ; assume SHIFT_INV_ROW == 12
860    rounder_2_0      dd  65536, 65536
861                     dd  65536, 65536
862    rounder_2_4      dd      0,     0
863                     dd      0,     0
864    rounder_2_1      dd   7195,  7195
865                     dd   7195,  7195
866    rounder_2_7      dd   1024,  1024
867                     dd   1024,  1024
868    rounder_2_2      dd   4520,  4520
869                     dd   4520,  4520
870    rounder_2_6      dd   1024,  1024
871                     dd   1024,  1024
872    rounder_2_3      dd   2407,  2407
873                     dd   2407,  2407
874    rounder_2_5      dd    240,   240
875                     dd    240,   240
876    
877    %elif SHIFT_INV_ROW == 11   ; assume SHIFT_INV_ROW == 11
878    rounder_2_0      dd  65536, 65536
879                     dd  65536, 65536
880    rounder_2_4      dd      0,     0
881                     dd      0,     0
882    rounder_2_1      dd   3597,  3597
883                     dd   3597,  3597
884    rounder_2_7      dd    512,   512
885                     dd    512,   512
886    rounder_2_2      dd   2260,  2260
887                     dd   2260,  2260
888    rounder_2_6      dd    512,   512
889                     dd    512,   512
890    rounder_2_3      dd   1203,  1203
891                     dd   1203,  1203
892    rounder_2_5      dd    120,   120
893                     dd    120,   120
894    %else
895    
896    %error invalid _SHIFT_INV_ROW_
897    
898    %endif
899    
900      tg_1_16_2     dw  13036,  13036,  13036,  13036       ; tg * (2<<16) + 0.5
901                    dw  13036,  13036,  13036,  13036
902      tg_2_16_2     dw  27146,  27146,  27146,  27146       ; tg * (2<<16) + 0.5
903                    dw  27146,  27146,  27146,  27146
904      tg_3_16_2     dw -21746, -21746, -21746, -21746       ; tg * (2<<16) + 0.5
905                    dw -21746, -21746, -21746, -21746
906    ocos_4_16_2     dw  23170,  23170,  23170,  23170       ; cos * (2<<15) + 0.5
907                    dw  23170,  23170,  23170,  23170
908    
909    %macro DCT_8_INV_ROW_1_sse2  4
910    
911            pshufhw         xmm1,[%1],11011000b     ;x 75643210
912            pshuflw         xmm1,xmm1,11011000b     ;x 75643120
913            pshufd          xmm0,xmm1,00000000b     ;x 20202020
914            pmaddwd         xmm0,[%3]               ;w 13 12 9 8 5410
915                                                            ;a 3210 first part
916    
917            pshufd          xmm2,xmm1,10101010b     ;x 64646464
918            pmaddwd         xmm2,[%3+16]            ;w 15 14 11 10 7632
919                                                            ;a 3210 second part
920    
921            paddd           xmm2,xmm0                       ;a 3210 ready
922            paddd           xmm2,[%4]               ;must be 4 dwords long, not 2 as for sse1
923            movdqa          xmm5,xmm2
924    
925            pshufd          xmm3,xmm1,01010101b     ;x 31313131
926            pmaddwd         xmm3,[%3+32]            ;w 29 28 25 24 21 20 17 16
927                                                            ;b 3210 first part
928    
929            pshufd          xmm4,xmm1,11111111b     ;x 75757575
930            pmaddwd         xmm4,[%3+48]            ;w 31 30 27 26 23 22 19 18
931                                                           ;b 3210 second part
932            paddd           xmm3,xmm4                       ;b 3210 ready
933    
934            paddd           xmm2,xmm3                       ;will be y 3210
935            psubd           xmm5,xmm3                       ;will be y 4567
936            psrad           xmm2,SHIFT_INV_ROW
937            psrad           xmm5,SHIFT_INV_ROW
938            packssdw        xmm2,xmm5                      ;y 45673210
939            pshufhw         xmm6,xmm2,00011011b     ;y 76543210
940            movdqa          [%2],xmm6
941    
942    %endmacro
943    
944    %macro DCT_8_INV_COL_4_sse2          2
945    
946            movdqa          xmm0,[%1+16*0]          ;x0 (all columns)
947            movdqa          xmm2,[%1+16*4]          ;x4
948            movdqa          xmm1,xmm0
949    
950            movdqa          xmm4,[%1+16*2]          ;x2
951            movdqa          xmm5,[%1+16*6]          ;x6
952            movdqa          xmm6,[tg_2_16_2]
953            movdqa          xmm7,xmm6
954    
955            paddsw          xmm0,xmm2                       ;u04=x0+x4
956            psubsw          xmm1,xmm2                       ;v04=x0-x4
957            movdqa          xmm3,xmm0
958            movdqa          xmm2,xmm1
959    
960            pmulhw          xmm6,xmm4
961            pmulhw          xmm7,xmm5
962            psubsw          xmm6,xmm5                       ;v26=x2*T2-x6
963            paddsw          xmm7,xmm4                       ;u26=x6*T2+x2
964    
965            paddsw          xmm1,xmm6                       ;a1=v04+v26
966            paddsw          xmm0,xmm7                       ;a0=u04+u26
967            psubsw          xmm2,xmm6                       ;a2=v04-v26
968            psubsw          xmm3,xmm7                       ;a3=u04-u26
969    
970            movdqa          [%2+16*0],xmm0          ;store a3-a0 to
971            movdqa          [%2+16*6],xmm1          ;free registers
972            movdqa          [%2+16*2],xmm2
973            movdqa          [%2+16*4],xmm3
974    
975            movdqa          xmm0,[%1+16*1]          ;x1
976            movdqa          xmm1,[%1+16*7]          ;x7
977            movdqa          xmm2,[tg_1_16_2]
978            movdqa          xmm3,xmm2
979    
980            movdqa          xmm4,[%1+16*3]          ;x3
981            movdqa          xmm5,[%1+16*5]          ;x5
982            movdqa          xmm6,[tg_3_16_2]
983            movdqa          xmm7,xmm6
984    
985            pmulhw          xmm2,xmm0
986            pmulhw          xmm3,xmm1
987            psubsw          xmm2,xmm1                       ;v17=x1*T1-x7
988            paddsw          xmm3,xmm0                       ;u17=x7*T1+x1
989            movdqa          xmm0,xmm3                       ;u17
990            movdqa          xmm1,xmm2                       ;v17
991    
992            pmulhw          xmm6,xmm4                       ;x3*(t3-1)
993            pmulhw          xmm7,xmm5                       ;x5*(t3-1)
994            paddsw          xmm6,xmm4
995            paddsw          xmm7,xmm5
996            psubsw          xmm6,xmm5                       ;v35=x3*T3-x5
997            paddsw          xmm7,xmm4                       ;u35=x5*T3+x3
998    
999            movdqa          xmm4,[ocos_4_16_2]
1000    
1001            paddsw          xmm0,xmm7                       ;b0=u17+u35
1002            psubsw          xmm1,xmm6                       ;b3=v17-v35
1003            psubsw          xmm3,xmm7                       ;u12=u17-v35
1004            paddsw          xmm2,xmm6                       ;v12=v17+v35
1005    
1006            movdqa          xmm5,xmm3
1007            paddsw          xmm3,xmm2                       ;tb1
1008            psubsw          xmm5,xmm2                       ;tb2
1009            pmulhw          xmm5,xmm4
1010            pmulhw          xmm4,xmm3
1011            paddsw          xmm5,xmm5
1012            paddsw          xmm4,xmm4
1013    
1014            movdqa          xmm6,[%2+16*0]          ;a0
1015            movdqa          xmm7,xmm6
1016            movdqa          xmm2,[%2+16*4]          ;a3
1017            movdqa          xmm3,xmm2
1018    
1019            paddsw          xmm6,xmm0
1020            psubsw          xmm7,xmm0
1021            psraw           xmm6,SHIFT_INV_COL      ;y0=a0+b0
1022            psraw           xmm7,SHIFT_INV_COL      ;y7=a0-b0
1023            movdqa          [%2+16*0],xmm6
1024            movdqa          [%2+16*7],xmm7
1025    
1026            paddsw          xmm2,xmm1
1027            psubsw          xmm3,xmm1
1028            psraw           xmm2,SHIFT_INV_COL      ;y3=a3+b3
1029            psraw           xmm3,SHIFT_INV_COL      ;y4=a3-b3
1030            movdqa          [%2+16*3],xmm2
1031            movdqa          [%2+16*4],xmm3
1032    
1033            movdqa          xmm0,[%2+16*6]          ;a1
1034            movdqa          xmm1,xmm0
1035            movdqa          xmm6,[%2+16*2]          ;a2
1036            movdqa          xmm7,xmm6
1037    
1038    
1039            paddsw          xmm0,xmm4
1040            psubsw          xmm1,xmm4
1041            psraw           xmm0,SHIFT_INV_COL      ;y1=a1+b1
1042            psraw           xmm1,SHIFT_INV_COL      ;y6=a1-b1
1043            movdqa          [%2+16*1],xmm0
1044            movdqa          [%2+16*6],xmm1
1045    
1046            paddsw          xmm6,xmm5
1047            psubsw          xmm7,xmm5
1048            psraw           xmm6,SHIFT_INV_COL      ;y2=a2+b2
1049            psraw           xmm7,SHIFT_INV_COL      ;y5=a2-b2
1050            movdqa          [%2+16*2],xmm6
1051            movdqa          [%2+16*5],xmm7
1052    
1053    %endmacro
1054    
1055    section .text
1056    
1057    align 16
1058    cglobal idct_sse2
1059    idct_sse2
1060    
1061            mov eax, dword [esp + 4]
1062    
1063            DCT_8_INV_ROW_1_sse2 eax+0, eax+0, tab_i_04_s2, rounder_2_0
1064            DCT_8_INV_ROW_1_sse2 eax+16, eax+16, tab_i_17_s2, rounder_2_1
1065            DCT_8_INV_ROW_1_sse2 eax+32, eax+32, tab_i_26_s2, rounder_2_2
1066            DCT_8_INV_ROW_1_sse2 eax+48, eax+48, tab_i_35_s2, rounder_2_3
1067            DCT_8_INV_ROW_1_sse2 eax+64, eax+64, tab_i_04_s2, rounder_2_4
1068            DCT_8_INV_ROW_1_sse2 eax+80, eax+80, tab_i_35_s2, rounder_2_5
1069            DCT_8_INV_ROW_1_sse2 eax+96, eax+96, tab_i_26_s2, rounder_2_6
1070            DCT_8_INV_ROW_1_sse2 eax+112, eax+112, tab_i_17_s2, rounder_2_7
1071    
1072            DCT_8_INV_COL_4_sse2 eax, eax
1073            ;DCT_8_INV_COL_4 eax+8, eax+8
1074    
1075            ret

Legend:
Removed from v.3  
changed lines
  Added in v.649

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4