00001 /* 00002 * XVID MPEG-4 VIDEO CODEC 00003 * - MMX and XMM forward discrete cosine transform - 00004 * 00005 * Copyright(C) 2001 Peter Ross <pross@xvid.org> 00006 * 00007 * Originally provided by Intel at AP-922 00008 * http://developer.intel.com/vtune/cbts/strmsimd/922down.htm 00009 * (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) 00010 * but in a limited edition. 00011 * New macro implements a column part for precise iDCT 00012 * The routine precision now satisfies IEEE standard 1180-1990. 00013 * 00014 * Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru> 00015 * Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org> 00016 * 00017 * http://www.elecard.com/peter/idct.html 00018 * http://www.linuxvideo.org/mpeg2dec/ 00019 * 00020 * These examples contain code fragments for first stage iDCT 8x8 00021 * (for rows) and first stage DCT 8x8 (for columns) 00022 * 00023 * conversion to gcc syntax by Michael Niedermayer 00024 * 00025 * This file is part of FFmpeg. 00026 * 00027 * FFmpeg is free software; you can redistribute it and/or 00028 * modify it under the terms of the GNU Lesser General Public 00029 * License as published by the Free Software Foundation; either 00030 * version 2.1 of the License, or (at your option) any later version. 00031 * 00032 * FFmpeg is distributed in the hope that it will be useful, 00033 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00034 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00035 * Lesser General Public License for more details. 00036 * 00037 * You should have received a copy of the GNU Lesser General Public License 00038 * along with FFmpeg; if not, write to the Free Software Foundation, 00039 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00040 */ 00041 00042 #include <inttypes.h> 00043 #include "libavcodec/avcodec.h" 00044 #include "idct_xvid.h" 00045 00046 //============================================================================= 00047 // Macros and other preprocessor constants 00048 //============================================================================= 00049 00050 #define BITS_INV_ACC 5 // 4 or 5 for IEEE 00051 #define SHIFT_INV_ROW (16 - BITS_INV_ACC) //11 00052 #define SHIFT_INV_COL (1 + BITS_INV_ACC) //6 00053 #define RND_INV_ROW (1024 * (6 - BITS_INV_ACC)) 00054 #define RND_INV_COL (16 * (BITS_INV_ACC - 3)) 00055 #define RND_INV_CORR (RND_INV_COL - 1) 00056 00057 #define BITS_FRW_ACC 3 // 2 or 3 for accuracy 00058 #define SHIFT_FRW_COL BITS_FRW_ACC 00059 #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17) 00060 #define RND_FRW_ROW (262144*(BITS_FRW_ACC - 1)) 00061 00062 00063 //----------------------------------------------------------------------------- 00064 // Various memory constants (trigonometric values or rounding values) 00065 //----------------------------------------------------------------------------- 00066 00067 00068 DECLARE_ALIGNED(8, static const int16_t, tg_1_16)[4*4] = { 00069 13036,13036,13036,13036, // tg * (2<<16) + 0.5 00070 27146,27146,27146,27146, // tg * (2<<16) + 0.5 00071 -21746,-21746,-21746,-21746, // tg * (2<<16) + 0.5 00072 23170,23170,23170,23170}; // cos * (2<<15) + 0.5 00073 00074 DECLARE_ALIGNED(8, static const int32_t, rounder_0)[2*8] = { 00075 65536,65536, 00076 3597,3597, 00077 2260,2260, 00078 1203,1203, 00079 0,0, 00080 120,120, 00081 512,512, 00082 512,512}; 00083 00084 //----------------------------------------------------------------------------- 00085 // 00086 // The first stage iDCT 8x8 - inverse DCTs of rows 00087 // 00088 //----------------------------------------------------------------------------- 00089 // The 8-point inverse DCT direct algorithm 00090 //----------------------------------------------------------------------------- 00091 // 00092 // static const short w[32] = { 00093 // FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16), 00094 // FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16), 00095 // FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16), 00096 // FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16), 00097 // FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16), 00098 // FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16), 00099 // FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16), 00100 // FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) }; 00101 // 00102 // #define DCT_8_INV_ROW(x, y) 00103 // { 00104 // int a0, a1, a2, a3, b0, b1, b2, b3; 00105 // 00106 // a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3]; 00107 // a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7]; 00108 // a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11]; 00109 // a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15]; 00110 // b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19]; 00111 // b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23]; 00112 // b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27]; 00113 // b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31]; 00114 // 00115 // y[0] = SHIFT_ROUND ( a0 + b0 ); 00116 // y[1] = SHIFT_ROUND ( a1 + b1 ); 00117 // y[2] = SHIFT_ROUND ( a2 + b2 ); 00118 // y[3] = SHIFT_ROUND ( a3 + b3 ); 00119 // y[4] = SHIFT_ROUND ( a3 - b3 ); 00120 // y[5] = SHIFT_ROUND ( a2 - b2 ); 00121 // y[6] = SHIFT_ROUND ( a1 - b1 ); 00122 // y[7] = SHIFT_ROUND ( a0 - b0 ); 00123 // } 00124 // 00125 //----------------------------------------------------------------------------- 00126 // 00127 // In this implementation the outputs of the iDCT-1D are multiplied 00128 // for rows 0,4 - by cos_4_16, 00129 // for rows 1,7 - by cos_1_16, 00130 // for rows 2,6 - by cos_2_16, 00131 // for rows 3,5 - by cos_3_16 00132 // and are shifted to the left for better accuracy 00133 // 00134 // For the constants used, 00135 // FIX(float_const) = (short) (float_const * (1<<15) + 0.5) 00136 // 00137 //----------------------------------------------------------------------------- 00138 00139 //----------------------------------------------------------------------------- 00140 // Tables for mmx processors 00141 //----------------------------------------------------------------------------- 00142 00143 // Table for rows 0,4 - constants are multiplied by cos_4_16 00144 DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx)[32*4] = { 00145 16384,16384,16384,-16384, // movq-> w06 w04 w02 w00 00146 21407,8867,8867,-21407, // w07 w05 w03 w01 00147 16384,-16384,16384,16384, // w14 w12 w10 w08 00148 -8867,21407,-21407,-8867, // w15 w13 w11 w09 00149 22725,12873,19266,-22725, // w22 w20 w18 w16 00150 19266,4520,-4520,-12873, // w23 w21 w19 w17 00151 12873,4520,4520,19266, // w30 w28 w26 w24 00152 -22725,19266,-12873,-22725, // w31 w29 w27 w25 00153 // Table for rows 1,7 - constants are multiplied by cos_1_16 00154 22725,22725,22725,-22725, // movq-> w06 w04 w02 w00 00155 29692,12299,12299,-29692, // w07 w05 w03 w01 00156 22725,-22725,22725,22725, // w14 w12 w10 w08 00157 -12299,29692,-29692,-12299, // w15 w13 w11 w09 00158 31521,17855,26722,-31521, // w22 w20 w18 w16 00159 26722,6270,-6270,-17855, // w23 w21 w19 w17 00160 17855,6270,6270,26722, // w30 w28 w26 w24 00161 -31521,26722,-17855,-31521, // w31 w29 w27 w25 00162 // Table for rows 2,6 - constants are multiplied by cos_2_16 00163 21407,21407,21407,-21407, // movq-> w06 w04 w02 w00 00164 27969,11585,11585,-27969, // w07 w05 w03 w01 00165 21407,-21407,21407,21407, // w14 w12 w10 w08 00166 -11585,27969,-27969,-11585, // w15 w13 w11 w09 00167 29692,16819,25172,-29692, // w22 w20 w18 w16 00168 25172,5906,-5906,-16819, // w23 w21 w19 w17 00169 16819,5906,5906,25172, // w30 w28 w26 w24 00170 -29692,25172,-16819,-29692, // w31 w29 w27 w25 00171 // Table for rows 3,5 - constants are multiplied by cos_3_16 00172 19266,19266,19266,-19266, // movq-> w06 w04 w02 w00 00173 25172,10426,10426,-25172, // w07 w05 w03 w01 00174 19266,-19266,19266,19266, // w14 w12 w10 w08 00175 -10426,25172,-25172,-10426, // w15 w13 w11 w09 00176 26722,15137,22654,-26722, // w22 w20 w18 w16 00177 22654,5315,-5315,-15137, // w23 w21 w19 w17 00178 15137,5315,5315,22654, // w30 w28 w26 w24 00179 -26722,22654,-15137,-26722, // w31 w29 w27 w25 00180 }; 00181 //----------------------------------------------------------------------------- 00182 // Tables for xmm processors 00183 //----------------------------------------------------------------------------- 00184 00185 // %3 for rows 0,4 - constants are multiplied by cos_4_16 00186 DECLARE_ALIGNED(8, static const int16_t, tab_i_04_xmm)[32*4] = { 00187 16384,21407,16384,8867, // movq-> w05 w04 w01 w00 00188 16384,8867,-16384,-21407, // w07 w06 w03 w02 00189 16384,-8867,16384,-21407, // w13 w12 w09 w08 00190 -16384,21407,16384,-8867, // w15 w14 w11 w10 00191 22725,19266,19266,-4520, // w21 w20 w17 w16 00192 12873,4520,-22725,-12873, // w23 w22 w19 w18 00193 12873,-22725,4520,-12873, // w29 w28 w25 w24 00194 4520,19266,19266,-22725, // w31 w30 w27 w26 00195 // %3 for rows 1,7 - constants are multiplied by cos_1_16 00196 22725,29692,22725,12299, // movq-> w05 w04 w01 w00 00197 22725,12299,-22725,-29692, // w07 w06 w03 w02 00198 22725,-12299,22725,-29692, // w13 w12 w09 w08 00199 -22725,29692,22725,-12299, // w15 w14 w11 w10 00200 31521,26722,26722,-6270, // w21 w20 w17 w16 00201 17855,6270,-31521,-17855, // w23 w22 w19 w18 00202 17855,-31521,6270,-17855, // w29 w28 w25 w24 00203 6270,26722,26722,-31521, // w31 w30 w27 w26 00204 // %3 for rows 2,6 - constants are multiplied by cos_2_16 00205 21407,27969,21407,11585, // movq-> w05 w04 w01 w00 00206 21407,11585,-21407,-27969, // w07 w06 w03 w02 00207 21407,-11585,21407,-27969, // w13 w12 w09 w08 00208 -21407,27969,21407,-11585, // w15 w14 w11 w10 00209 29692,25172,25172,-5906, // w21 w20 w17 w16 00210 16819,5906,-29692,-16819, // w23 w22 w19 w18 00211 16819,-29692,5906,-16819, // w29 w28 w25 w24 00212 5906,25172,25172,-29692, // w31 w30 w27 w26 00213 // %3 for rows 3,5 - constants are multiplied by cos_3_16 00214 19266,25172,19266,10426, // movq-> w05 w04 w01 w00 00215 19266,10426,-19266,-25172, // w07 w06 w03 w02 00216 19266,-10426,19266,-25172, // w13 w12 w09 w08 00217 -19266,25172,19266,-10426, // w15 w14 w11 w10 00218 26722,22654,22654,-5315, // w21 w20 w17 w16 00219 15137,5315,-26722,-15137, // w23 w22 w19 w18 00220 15137,-26722,5315,-15137, // w29 w28 w25 w24 00221 5315,22654,22654,-26722, // w31 w30 w27 w26 00222 }; 00223 //============================================================================= 00224 // Helper macros for the code 00225 //============================================================================= 00226 00227 //----------------------------------------------------------------------------- 00228 // DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER 00229 //----------------------------------------------------------------------------- 00230 00231 #define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\ 00232 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\ 00233 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\ 00234 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\ 00235 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w06 w04 w02 w00*/\ 00236 "punpcklwd %%mm1,%%mm0 \n\t"/* x5 x1 x4 x0*/\ 00237 "movq %%mm0,%%mm5 \n\t"/* 5 ; x5 x1 x4 x0*/\ 00238 "punpckldq %%mm0,%%mm0 \n\t"/* x4 x0 x4 x0*/\ 00239 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w05 w03 w01*/\ 00240 "punpckhwd %%mm1,%%mm2 \n\t"/* 1 ; x7 x3 x6 x2*/\ 00241 "pmaddwd %%mm0,%%mm3 \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\ 00242 "movq %%mm2,%%mm6 \n\t"/* 6 ; x7 x3 x6 x2*/\ 00243 "movq 32+" #A3 ",%%mm1 \n\t"/* 1 ; w22 w20 w18 w16*/\ 00244 "punpckldq %%mm2,%%mm2 \n\t"/* x6 x2 x6 x2*/\ 00245 "pmaddwd %%mm2,%%mm4 \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\ 00246 "punpckhdq %%mm5,%%mm5 \n\t"/* x5 x1 x5 x1*/\ 00247 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\ 00248 "punpckhdq %%mm6,%%mm6 \n\t"/* x7 x3 x7 x3*/\ 00249 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w21 w19 w17*/\ 00250 "pmaddwd %%mm5,%%mm1 \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\ 00251 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\ 00252 "pmaddwd %%mm6,%%mm7 \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\ 00253 "pmaddwd 24+" #A3 ",%%mm2 \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\ 00254 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\ 00255 "pmaddwd 48+" #A3 ",%%mm5 \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\ 00256 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\ 00257 "pmaddwd 56+" #A3 ",%%mm6 \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\ 00258 "paddd %%mm7,%%mm1 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\ 00259 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\ 00260 "psubd %%mm1,%%mm3 \n\t"/* a1-b1 a0-b0*/\ 00261 "psrad $11,%%mm3 \n\t"/* y6=a1-b1 y7=a0-b0*/\ 00262 "paddd %%mm4,%%mm1 \n\t"/* 4 ; a1+b1 a0+b0*/\ 00263 "paddd %%mm2,%%mm0 \n\t"/* 2 ; a3=sum(even3) a2=sum(even2)*/\ 00264 "psrad $11,%%mm1 \n\t"/* y1=a1+b1 y0=a0+b0*/\ 00265 "paddd %%mm6,%%mm5 \n\t"/* 6 ; b3=sum(odd3) b2=sum(odd2)*/\ 00266 "movq %%mm0,%%mm4 \n\t"/* 4 ; a3 a2*/\ 00267 "paddd %%mm5,%%mm0 \n\t"/* a3+b3 a2+b2*/\ 00268 "psubd %%mm5,%%mm4 \n\t"/* 5 ; a3-b3 a2-b2*/\ 00269 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\ 00270 "psrad $11,%%mm4 \n\t"/* y4=a3-b3 y5=a2-b2*/\ 00271 "packssdw %%mm0,%%mm1 \n\t"/* 0 ; y3 y2 y1 y0*/\ 00272 "packssdw %%mm3,%%mm4 \n\t"/* 3 ; y6 y7 y4 y5*/\ 00273 "movq %%mm4,%%mm7 \n\t"/* 7 ; y6 y7 y4 y5*/\ 00274 "psrld $16,%%mm4 \n\t"/* 0 y6 0 y4*/\ 00275 "pslld $16,%%mm7 \n\t"/* y7 0 y5 0*/\ 00276 "movq %%mm1," #A2 " \n\t"/* 1 ; save y3 y2 y1 y0*/\ 00277 "por %%mm4,%%mm7 \n\t"/* 4 ; y7 y6 y5 y4*/\ 00278 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\ 00279 00280 00281 //----------------------------------------------------------------------------- 00282 // DCT_8_INV_ROW_XMM( INP, OUT, TABLE, ROUNDER 00283 //----------------------------------------------------------------------------- 00284 00285 #define DCT_8_INV_ROW_XMM(A1,A2,A3,A4)\ 00286 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\ 00287 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\ 00288 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\ 00289 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w05 w04 w01 w00*/\ 00290 "pshufw $0x88,%%mm0,%%mm0 \n\t"/* x2 x0 x2 x0*/\ 00291 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w06 w03 w02*/\ 00292 "movq %%mm1,%%mm5 \n\t"/* 5 ; x7 x6 x5 x4*/\ 00293 "pmaddwd %%mm0,%%mm3 \n\t"/* x2*w05+x0*w04 x2*w01+x0*w00*/\ 00294 "movq 32+" #A3 ",%%mm6 \n\t"/* 6 ; w21 w20 w17 w16*/\ 00295 "pshufw $0x88,%%mm1,%%mm1 \n\t"/* x6 x4 x6 x4*/\ 00296 "pmaddwd %%mm1,%%mm4 \n\t"/* x6*w07+x4*w06 x6*w03+x4*w02*/\ 00297 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w22 w19 w18*/\ 00298 "pshufw $0xdd,%%mm2,%%mm2 \n\t"/* x3 x1 x3 x1*/\ 00299 "pmaddwd %%mm2,%%mm6 \n\t"/* x3*w21+x1*w20 x3*w17+x1*w16*/\ 00300 "pshufw $0xdd,%%mm5,%%mm5 \n\t"/* x7 x5 x7 x5*/\ 00301 "pmaddwd %%mm5,%%mm7 \n\t"/* x7*w23+x5*w22 x7*w19+x5*w18*/\ 00302 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\ 00303 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x2*w13+x0*w12 x2*w09+x0*w08*/\ 00304 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\ 00305 "pmaddwd 24+" #A3 ",%%mm1 \n\t"/* x6*w15+x4*w14 x6*w11+x4*w10*/\ 00306 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\ 00307 "pmaddwd 48+" #A3 ",%%mm2 \n\t"/* x3*w29+x1*w28 x3*w25+x1*w24*/\ 00308 "paddd %%mm7,%%mm6 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\ 00309 "pmaddwd 56+" #A3 ",%%mm5 \n\t"/* x7*w31+x5*w30 x7*w27+x5*w26*/\ 00310 "paddd %%mm6,%%mm3 \n\t"/* a1+b1 a0+b0*/\ 00311 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\ 00312 "psrad $11,%%mm3 \n\t"/* y1=a1+b1 y0=a0+b0*/\ 00313 "paddd %%mm1,%%mm0 \n\t"/* 1 ; a3=sum(even3) a2=sum(even2)*/\ 00314 "psubd %%mm6,%%mm4 \n\t"/* 6 ; a1-b1 a0-b0*/\ 00315 "movq %%mm0,%%mm7 \n\t"/* 7 ; a3 a2*/\ 00316 "paddd %%mm5,%%mm2 \n\t"/* 5 ; b3=sum(odd3) b2=sum(odd2)*/\ 00317 "paddd %%mm2,%%mm0 \n\t"/* a3+b3 a2+b2*/\ 00318 "psrad $11,%%mm4 \n\t"/* y6=a1-b1 y7=a0-b0*/\ 00319 "psubd %%mm2,%%mm7 \n\t"/* 2 ; a3-b3 a2-b2*/\ 00320 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\ 00321 "psrad $11,%%mm7 \n\t"/* y4=a3-b3 y5=a2-b2*/\ 00322 "packssdw %%mm0,%%mm3 \n\t"/* 0 ; y3 y2 y1 y0*/\ 00323 "packssdw %%mm4,%%mm7 \n\t"/* 4 ; y6 y7 y4 y5*/\ 00324 "movq %%mm3, " #A2 " \n\t"/* 3 ; save y3 y2 y1 y0*/\ 00325 "pshufw $0xb1,%%mm7,%%mm7 \n\t"/* y7 y6 y5 y4*/\ 00326 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\ 00327 00328 00329 //----------------------------------------------------------------------------- 00330 // 00331 // The first stage DCT 8x8 - forward DCTs of columns 00332 // 00333 // The %2puts are multiplied 00334 // for rows 0,4 - on cos_4_16, 00335 // for rows 1,7 - on cos_1_16, 00336 // for rows 2,6 - on cos_2_16, 00337 // for rows 3,5 - on cos_3_16 00338 // and are shifted to the left for rise of accuracy 00339 // 00340 //----------------------------------------------------------------------------- 00341 // 00342 // The 8-point scaled forward DCT algorithm (26a8m) 00343 // 00344 //----------------------------------------------------------------------------- 00345 // 00346 // #define DCT_8_FRW_COL(x, y) 00347 //{ 00348 // short t0, t1, t2, t3, t4, t5, t6, t7; 00349 // short tp03, tm03, tp12, tm12, tp65, tm65; 00350 // short tp465, tm465, tp765, tm765; 00351 // 00352 // t0 = LEFT_SHIFT ( x[0] + x[7] ); 00353 // t1 = LEFT_SHIFT ( x[1] + x[6] ); 00354 // t2 = LEFT_SHIFT ( x[2] + x[5] ); 00355 // t3 = LEFT_SHIFT ( x[3] + x[4] ); 00356 // t4 = LEFT_SHIFT ( x[3] - x[4] ); 00357 // t5 = LEFT_SHIFT ( x[2] - x[5] ); 00358 // t6 = LEFT_SHIFT ( x[1] - x[6] ); 00359 // t7 = LEFT_SHIFT ( x[0] - x[7] ); 00360 // 00361 // tp03 = t0 + t3; 00362 // tm03 = t0 - t3; 00363 // tp12 = t1 + t2; 00364 // tm12 = t1 - t2; 00365 // 00366 // y[0] = tp03 + tp12; 00367 // y[4] = tp03 - tp12; 00368 // 00369 // y[2] = tm03 + tm12 * tg_2_16; 00370 // y[6] = tm03 * tg_2_16 - tm12; 00371 // 00372 // tp65 =(t6 +t5 )*cos_4_16; 00373 // tm65 =(t6 -t5 )*cos_4_16; 00374 // 00375 // tp765 = t7 + tp65; 00376 // tm765 = t7 - tp65; 00377 // tp465 = t4 + tm65; 00378 // tm465 = t4 - tm65; 00379 // 00380 // y[1] = tp765 + tp465 * tg_1_16; 00381 // y[7] = tp765 * tg_1_16 - tp465; 00382 // y[5] = tm765 * tg_3_16 + tm465; 00383 // y[3] = tm765 - tm465 * tg_3_16; 00384 //} 00385 // 00386 //----------------------------------------------------------------------------- 00387 00388 //----------------------------------------------------------------------------- 00389 // DCT_8_INV_COL_4 INP,OUT 00390 //----------------------------------------------------------------------------- 00391 00392 #define DCT_8_INV_COL(A1,A2)\ 00393 "movq 2*8(%3),%%mm0\n\t"\ 00394 "movq 16*3+" #A1 ",%%mm3\n\t"\ 00395 "movq %%mm0,%%mm1 \n\t"/* tg_3_16*/\ 00396 "movq 16*5+" #A1 ",%%mm5\n\t"\ 00397 "pmulhw %%mm3,%%mm0 \n\t"/* x3*(tg_3_16-1)*/\ 00398 "movq (%3),%%mm4\n\t"\ 00399 "pmulhw %%mm5,%%mm1 \n\t"/* x5*(tg_3_16-1)*/\ 00400 "movq 16*7+" #A1 ",%%mm7\n\t"\ 00401 "movq %%mm4,%%mm2 \n\t"/* tg_1_16*/\ 00402 "movq 16*1+" #A1 ",%%mm6\n\t"\ 00403 "pmulhw %%mm7,%%mm4 \n\t"/* x7*tg_1_16*/\ 00404 "paddsw %%mm3,%%mm0 \n\t"/* x3*tg_3_16*/\ 00405 "pmulhw %%mm6,%%mm2 \n\t"/* x1*tg_1_16*/\ 00406 "paddsw %%mm3,%%mm1 \n\t"/* x3+x5*(tg_3_16-1)*/\ 00407 "psubsw %%mm5,%%mm0 \n\t"/* x3*tg_3_16-x5 = tm35*/\ 00408 "movq 3*8(%3),%%mm3\n\t"\ 00409 "paddsw %%mm5,%%mm1 \n\t"/* x3+x5*tg_3_16 = tp35*/\ 00410 "paddsw %%mm6,%%mm4 \n\t"/* x1+tg_1_16*x7 = tp17*/\ 00411 "psubsw %%mm7,%%mm2 \n\t"/* x1*tg_1_16-x7 = tm17*/\ 00412 "movq %%mm4,%%mm5 \n\t"/* tp17*/\ 00413 "movq %%mm2,%%mm6 \n\t"/* tm17*/\ 00414 "paddsw %%mm1,%%mm5 \n\t"/* tp17+tp35 = b0*/\ 00415 "psubsw %%mm0,%%mm6 \n\t"/* tm17-tm35 = b3*/\ 00416 "psubsw %%mm1,%%mm4 \n\t"/* tp17-tp35 = t1*/\ 00417 "paddsw %%mm0,%%mm2 \n\t"/* tm17+tm35 = t2*/\ 00418 "movq 1*8(%3),%%mm7\n\t"\ 00419 "movq %%mm4,%%mm1 \n\t"/* t1*/\ 00420 "movq %%mm5,3*16 +" #A2 "\n\t"/* save b0*/\ 00421 "paddsw %%mm2,%%mm1 \n\t"/* t1+t2*/\ 00422 "movq %%mm6,5*16 +" #A2 "\n\t"/* save b3*/\ 00423 "psubsw %%mm2,%%mm4 \n\t"/* t1-t2*/\ 00424 "movq 2*16+" #A1 ",%%mm5\n\t"\ 00425 "movq %%mm7,%%mm0 \n\t"/* tg_2_16*/\ 00426 "movq 6*16+" #A1 ",%%mm6\n\t"\ 00427 "pmulhw %%mm5,%%mm0 \n\t"/* x2*tg_2_16*/\ 00428 "pmulhw %%mm6,%%mm7 \n\t"/* x6*tg_2_16*/\ 00429 "pmulhw %%mm3,%%mm1 \n\t"/* ocos_4_16*(t1+t2) = b1/2*/\ 00430 "movq 0*16+" #A1 ",%%mm2\n\t"\ 00431 "pmulhw %%mm3,%%mm4 \n\t"/* ocos_4_16*(t1-t2) = b2/2*/\ 00432 "psubsw %%mm6,%%mm0 \n\t"/* t2*tg_2_16-x6 = tm26*/\ 00433 "movq %%mm2,%%mm3 \n\t"/* x0*/\ 00434 "movq 4*16+" #A1 ",%%mm6\n\t"\ 00435 "paddsw %%mm5,%%mm7 \n\t"/* x2+x6*tg_2_16 = tp26*/\ 00436 "paddsw %%mm6,%%mm2 \n\t"/* x0+x4 = tp04*/\ 00437 "psubsw %%mm6,%%mm3 \n\t"/* x0-x4 = tm04*/\ 00438 "movq %%mm2,%%mm5 \n\t"/* tp04*/\ 00439 "movq %%mm3,%%mm6 \n\t"/* tm04*/\ 00440 "psubsw %%mm7,%%mm2 \n\t"/* tp04-tp26 = a3*/\ 00441 "paddsw %%mm0,%%mm3 \n\t"/* tm04+tm26 = a1*/\ 00442 "paddsw %%mm1,%%mm1 \n\t"/* b1*/\ 00443 "paddsw %%mm4,%%mm4 \n\t"/* b2*/\ 00444 "paddsw %%mm7,%%mm5 \n\t"/* tp04+tp26 = a0*/\ 00445 "psubsw %%mm0,%%mm6 \n\t"/* tm04-tm26 = a2*/\ 00446 "movq %%mm3,%%mm7 \n\t"/* a1*/\ 00447 "movq %%mm6,%%mm0 \n\t"/* a2*/\ 00448 "paddsw %%mm1,%%mm3 \n\t"/* a1+b1*/\ 00449 "paddsw %%mm4,%%mm6 \n\t"/* a2+b2*/\ 00450 "psraw $6,%%mm3 \n\t"/* dst1*/\ 00451 "psubsw %%mm1,%%mm7 \n\t"/* a1-b1*/\ 00452 "psraw $6,%%mm6 \n\t"/* dst2*/\ 00453 "psubsw %%mm4,%%mm0 \n\t"/* a2-b2*/\ 00454 "movq 3*16+" #A2 ",%%mm1 \n\t"/* load b0*/\ 00455 "psraw $6,%%mm7 \n\t"/* dst6*/\ 00456 "movq %%mm5,%%mm4 \n\t"/* a0*/\ 00457 "psraw $6,%%mm0 \n\t"/* dst5*/\ 00458 "movq %%mm3,1*16+" #A2 "\n\t"\ 00459 "paddsw %%mm1,%%mm5 \n\t"/* a0+b0*/\ 00460 "movq %%mm6,2*16+" #A2 "\n\t"\ 00461 "psubsw %%mm1,%%mm4 \n\t"/* a0-b0*/\ 00462 "movq 5*16+" #A2 ",%%mm3 \n\t"/* load b3*/\ 00463 "psraw $6,%%mm5 \n\t"/* dst0*/\ 00464 "movq %%mm2,%%mm6 \n\t"/* a3*/\ 00465 "psraw $6,%%mm4 \n\t"/* dst7*/\ 00466 "movq %%mm0,5*16+" #A2 "\n\t"\ 00467 "paddsw %%mm3,%%mm2 \n\t"/* a3+b3*/\ 00468 "movq %%mm7,6*16+" #A2 "\n\t"\ 00469 "psubsw %%mm3,%%mm6 \n\t"/* a3-b3*/\ 00470 "movq %%mm5,0*16+" #A2 "\n\t"\ 00471 "psraw $6,%%mm2 \n\t"/* dst3*/\ 00472 "movq %%mm4,7*16+" #A2 "\n\t"\ 00473 "psraw $6,%%mm6 \n\t"/* dst4*/\ 00474 "movq %%mm2,3*16+" #A2 "\n\t"\ 00475 "movq %%mm6,4*16+" #A2 "\n\t" 00476 00477 //============================================================================= 00478 // Code 00479 //============================================================================= 00480 00481 //----------------------------------------------------------------------------- 00482 // void idct_mmx(uint16_t block[64]); 00483 //----------------------------------------------------------------------------- 00484 00485 00486 void ff_idct_xvid_mmx(short *block){ 00487 __asm__ volatile( 00488 //# Process each row 00489 DCT_8_INV_ROW_MMX(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1)) 00490 DCT_8_INV_ROW_MMX(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1)) 00491 DCT_8_INV_ROW_MMX(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1)) 00492 DCT_8_INV_ROW_MMX(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1)) 00493 DCT_8_INV_ROW_MMX(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1)) 00494 DCT_8_INV_ROW_MMX(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1)) 00495 DCT_8_INV_ROW_MMX(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1)) 00496 DCT_8_INV_ROW_MMX(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1)) 00497 00498 //# Process the columns (4 at a time) 00499 DCT_8_INV_COL(0(%0), 0(%0)) 00500 DCT_8_INV_COL(8(%0), 8(%0)) 00501 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_mmx), "r"(tg_1_16)); 00502 } 00503 00504 //----------------------------------------------------------------------------- 00505 // void idct_xmm(uint16_t block[64]); 00506 //----------------------------------------------------------------------------- 00507 00508 00509 void ff_idct_xvid_mmx2(short *block){ 00510 __asm__ volatile( 00511 //# Process each row 00512 DCT_8_INV_ROW_XMM(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1)) 00513 DCT_8_INV_ROW_XMM(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1)) 00514 DCT_8_INV_ROW_XMM(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1)) 00515 DCT_8_INV_ROW_XMM(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1)) 00516 DCT_8_INV_ROW_XMM(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1)) 00517 DCT_8_INV_ROW_XMM(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1)) 00518 DCT_8_INV_ROW_XMM(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1)) 00519 DCT_8_INV_ROW_XMM(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1)) 00520 00521 //# Process the columns (4 at a time) 00522 DCT_8_INV_COL(0(%0), 0(%0)) 00523 DCT_8_INV_COL(8(%0), 8(%0)) 00524 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm), "r"(tg_1_16)); 00525 } 00526