⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idct_mmx_xvid.c

📁 tcpmp播放器的flv插件
💻 C
📖 第 1 页 / 共 2 页
字号:
///****************************************************************************// *// *  XVID MPEG-4 VIDEO CODEC// *  - MMX and XMM forward discrete cosine transform -// *// *  Copyright(C) 2001 Peter Ross <pross@xvid.org>// *// *  This program is free software; you can redistribute it and/or modify it// *  under the terms of the GNU General Public License as published by// *  the Free Software Foundation; either version 2 of the License, or// *  (at your option) any later version.// *// *  This program is distributed in the hope that it will be useful,// *  but WITHOUT ANY WARRANTY; without even the implied warranty of// *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// *  GNU General Public License for more details.// *// *  You should have received a copy of the GNU General Public License// *  along with this program; if not, write to the Free Software// *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA// *// * $Id: idct_mmx_xvid.c,v 1.2 2005/09/10 19:03:37 michael Exp $// *// ***************************************************************************/// ****************************************************************************//// Originally provided by Intel at AP-922// http://developer.intel.com/vtune/cbts/strmsimd/922down.htm// (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)// but in a limited edition.// New macro implements a column part for precise iDCT// The routine precision now satisfies IEEE standard 1180-1990.//// Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru>// Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org>//// http://www.elecard.com/peter/idct.html// http://www.linuxvideo.org/mpeg2dec///// ***************************************************************************///// These examples contain code fragments for first stage iDCT 8x8// (for rows) and first stage DCT 8x8 (for columns)//// conversion to gcc syntax by michael niedermayer#include <inttypes.h>#include "../avcodec.h"//=============================================================================// Macros and other preprocessor constants//=============================================================================#define BITS_INV_ACC    5                              // 4 or 5 for IEEE#define SHIFT_INV_ROW   (16 - BITS_INV_ACC) //11#define SHIFT_INV_COL   (1 + BITS_INV_ACC) //6#define RND_INV_ROW     (1024 * (6 - BITS_INV_ACC))#define RND_INV_COL     (16 * (BITS_INV_ACC - 3))#define RND_INV_CORR    (RND_INV_COL - 1)#define BITS_FRW_ACC    3                              // 2 or 3 for accuracy#define SHIFT_FRW_COL   BITS_FRW_ACC#define SHIFT_FRW_ROW   (BITS_FRW_ACC + 17)#define RND_FRW_ROW     (262144*(BITS_FRW_ACC - 1))//-----------------------------------------------------------------------------// Various memory constants (trigonometric values or rounding values)//-----------------------------------------------------------------------------static const int16_t tg_1_16[4*4] attribute_used __attribute__ ((aligned(8))) = {   13036,13036,13036,13036,        // tg * (2<<16) + 0.5  27146,27146,27146,27146,        // tg * (2<<16) + 0.5  -21746,-21746,-21746,-21746,    // tg * (2<<16) + 0.5  23170,23170,23170,23170};       // cos * (2<<15) + 0.5static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) = {   65536,65536,  3597,3597,  2260,2260,  1203,1203,  0,0,  120,120,  512,512,  512,512};//-----------------------------------------------------------------------------//// The first stage iDCT 8x8 - inverse DCTs of rows////-----------------------------------------------------------------------------// The 8-point inverse DCT direct algorithm//-----------------------------------------------------------------------------//// static const short w[32] = {//       FIX(cos_4_16),  FIX(cos_2_16),  FIX(cos_4_16),  FIX(cos_6_16),//       FIX(cos_4_16),  FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16),//       FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16),  FIX(cos_2_16),//       FIX(cos_4_16), -FIX(cos_2_16),  FIX(cos_4_16), -FIX(cos_6_16),//       FIX(cos_1_16),  FIX(cos_3_16),  FIX(cos_5_16),  FIX(cos_7_16),//       FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16),//       FIX(cos_5_16), -FIX(cos_1_16),  FIX(cos_7_16),  FIX(cos_3_16),//       FIX(cos_7_16), -FIX(cos_5_16),  FIX(cos_3_16), -FIX(cos_1_16) };//// #define DCT_8_INV_ROW(x, y)// {//       int a0, a1, a2, a3, b0, b1, b2, b3;////       a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3];//       a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7];//       a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11];//       a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15];//       b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19];//       b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23];//       b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27];//       b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31];////       y[0] = SHIFT_ROUND ( a0 + b0 );//       y[1] = SHIFT_ROUND ( a1 + b1 );//       y[2] = SHIFT_ROUND ( a2 + b2 );//       y[3] = SHIFT_ROUND ( a3 + b3 );//       y[4] = SHIFT_ROUND ( a3 - b3 );//       y[5] = SHIFT_ROUND ( a2 - b2 );//       y[6] = SHIFT_ROUND ( a1 - b1 );//       y[7] = SHIFT_ROUND ( a0 - b0 );// }////-----------------------------------------------------------------------------//// In this implementation the outputs of the iDCT-1D are multiplied//       for rows 0,4 - by cos_4_16,//       for rows 1,7 - by cos_1_16,//       for rows 2,6 - by cos_2_16,//       for rows 3,5 - by cos_3_16// and are shifted to the left for better accuracy//// For the constants used,//       FIX(float_const) = (short) (float_const * (1<<15) + 0.5)////-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Tables for mmx processors//-----------------------------------------------------------------------------// Table for rows 0,4 - constants are multiplied by cos_4_16static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8))) = {   16384,16384,16384,-16384,       // movq-> w06 w04 w02 w00  21407,8867,8867,-21407,         // w07 w05 w03 w01  16384,-16384,16384,16384,       // w14 w12 w10 w08  -8867,21407,-21407,-8867,       // w15 w13 w11 w09  22725,12873,19266,-22725,       // w22 w20 w18 w16  19266,4520,-4520,-12873,        // w23 w21 w19 w17  12873,4520,4520,19266,          // w30 w28 w26 w24  -22725,19266,-12873,-22725,     // w31 w29 w27 w25// Table for rows 1,7 - constants are multiplied by cos_1_16  22725,22725,22725,-22725,       // movq-> w06 w04 w02 w00  29692,12299,12299,-29692,       // w07 w05 w03 w01  22725,-22725,22725,22725,       // w14 w12 w10 w08  -12299,29692,-29692,-12299,     // w15 w13 w11 w09  31521,17855,26722,-31521,       // w22 w20 w18 w16  26722,6270,-6270,-17855,        // w23 w21 w19 w17  17855,6270,6270,26722,          // w30 w28 w26 w24  -31521,26722,-17855,-31521,     // w31 w29 w27 w25// Table for rows 2,6 - constants are multiplied by cos_2_16  21407,21407,21407,-21407,       // movq-> w06 w04 w02 w00  27969,11585,11585,-27969,       // w07 w05 w03 w01  21407,-21407,21407,21407,       // w14 w12 w10 w08  -11585,27969,-27969,-11585,     // w15 w13 w11 w09  29692,16819,25172,-29692,       // w22 w20 w18 w16  25172,5906,-5906,-16819,        // w23 w21 w19 w17  16819,5906,5906,25172,          // w30 w28 w26 w24  -29692,25172,-16819,-29692,     // w31 w29 w27 w25// Table for rows 3,5 - constants are multiplied by cos_3_16  19266,19266,19266,-19266,       // movq-> w06 w04 w02 w00  25172,10426,10426,-25172,       // w07 w05 w03 w01  19266,-19266,19266,19266,       // w14 w12 w10 w08  -10426,25172,-25172,-10426,     // w15 w13 w11 w09  26722,15137,22654,-26722,       // w22 w20 w18 w16  22654,5315,-5315,-15137,        // w23 w21 w19 w17  15137,5315,5315,22654,          // w30 w28 w26 w24  -26722,22654,-15137,-26722,     // w31 w29 w27 w25};//-----------------------------------------------------------------------------// Tables for xmm processors//-----------------------------------------------------------------------------// %3 for rows 0,4 - constants are multiplied by cos_4_16static const int16_t tab_i_04_xmm[32*4] attribute_used __attribute__ ((aligned(8))) = {   16384,21407,16384,8867,      // movq-> w05 w04 w01 w00  16384,8867,-16384,-21407,    // w07 w06 w03 w02  16384,-8867,16384,-21407,    // w13 w12 w09 w08  -16384,21407,16384,-8867,    // w15 w14 w11 w10  22725,19266,19266,-4520,     // w21 w20 w17 w16  12873,4520,-22725,-12873,    // w23 w22 w19 w18  12873,-22725,4520,-12873,    // w29 w28 w25 w24  4520,19266,19266,-22725,     // w31 w30 w27 w26// %3 for rows 1,7 - constants are multiplied by cos_1_16  22725,29692,22725,12299,     // movq-> w05 w04 w01 w00  22725,12299,-22725,-29692,   // w07 w06 w03 w02  22725,-12299,22725,-29692,   // w13 w12 w09 w08  -22725,29692,22725,-12299,   // w15 w14 w11 w10  31521,26722,26722,-6270,     // w21 w20 w17 w16  17855,6270,-31521,-17855,    // w23 w22 w19 w18  17855,-31521,6270,-17855,    // w29 w28 w25 w24  6270,26722,26722,-31521,     // w31 w30 w27 w26// %3 for rows 2,6 - constants are multiplied by cos_2_16  21407,27969,21407,11585,     // movq-> w05 w04 w01 w00  21407,11585,-21407,-27969,   // w07 w06 w03 w02  21407,-11585,21407,-27969,   // w13 w12 w09 w08  -21407,27969,21407,-11585,   // w15 w14 w11 w10  29692,25172,25172,-5906,     // w21 w20 w17 w16  16819,5906,-29692,-16819,    // w23 w22 w19 w18  16819,-29692,5906,-16819,    // w29 w28 w25 w24  5906,25172,25172,-29692,     // w31 w30 w27 w26// %3 for rows 3,5 - constants are multiplied by cos_3_16  19266,25172,19266,10426,     // movq-> w05 w04 w01 w00  19266,10426,-19266,-25172,   // w07 w06 w03 w02  19266,-10426,19266,-25172,   // w13 w12 w09 w08  -19266,25172,19266,-10426,   // w15 w14 w11 w10  26722,22654,22654,-5315,     // w21 w20 w17 w16  15137,5315,-26722,-15137,    // w23 w22 w19 w18  15137,-26722,5315,-15137,    // w29 w28 w25 w24  5315,22654,22654,-26722,     // w31 w30 w27 w26};//=============================================================================// Helper macros for the code//=============================================================================//-----------------------------------------------------------------------------// DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER//-----------------------------------------------------------------------------#define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\  "movq " #A1 ",%%mm0              \n\t"/* 0 ; x3 x2 x1 x0*/\  "movq 8+" #A1 ",%%mm1            \n\t"/* 1 ; x7 x6 x5 x4*/\  "movq %%mm0,%%mm2            \n\t"/* 2  ; x3 x2 x1 x0*/\  "movq " #A3 ",%%mm3              \n\t"/* 3 ; w06 w04 w02 w00*/\  "punpcklwd %%mm1,%%mm0       \n\t"/* x5 x1 x4 x0*/\  "movq %%mm0,%%mm5            \n\t"/* 5 ; x5 x1 x4 x0*/\  "punpckldq %%mm0,%%mm0       \n\t"/* x4 x0 x4 x0*/\  "movq 8+" #A3 ",%%mm4            \n\t"/* 4 ; w07 w05 w03 w01*/\  "punpckhwd %%mm1,%%mm2       \n\t"/* 1 ; x7 x3 x6 x2*/\  "pmaddwd %%mm0,%%mm3         \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\  "movq %%mm2,%%mm6            \n\t"/* 6 ; x7 x3 x6 x2*/\  "movq 32+" #A3 ",%%mm1           \n\t"/* 1 ; w22 w20 w18 w16*/\  "punpckldq %%mm2,%%mm2       \n\t"/* x6 x2 x6 x2*/\  "pmaddwd %%mm2,%%mm4         \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\  "punpckhdq %%mm5,%%mm5       \n\t"/* x5 x1 x5 x1*/\  "pmaddwd 16+" #A3 ",%%mm0        \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\  "punpckhdq %%mm6,%%mm6       \n\t"/* x7 x3 x7 x3*/\  "movq 40+" #A3 ",%%mm7           \n\t"/* 7 ; w23 w21 w19 w17*/\  "pmaddwd %%mm5,%%mm1         \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\  "paddd " #A4 ",%%mm3             \n\t"/* +%4*/\  "pmaddwd %%mm6,%%mm7         \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\  "pmaddwd 24+" #A3 ",%%mm2        \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\  "paddd %%mm4,%%mm3           \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\  "pmaddwd 48+" #A3 ",%%mm5        \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\  "movq %%mm3,%%mm4            \n\t"/* 4 ; a1 a0*/\  "pmaddwd 56+" #A3 ",%%mm6        \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\  "paddd %%mm7,%%mm1           \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\  "paddd " #A4 ",%%mm0             \n\t"/* +%4*/\  "psubd %%mm1,%%mm3           \n\t"/* a1-b1 a0-b0*/\

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -