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

📄 simple_idct_mmx.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Simple IDCT MMX * * Copyright (c) 2001, 2002 Michael Niedermayer <michaelni@gmx.at> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include "dsputil.h"#include "simple_idct.h"/*23170.47500622725.26082621406.72761719265.54587016384.00000012872.8261988866.9569054520.335430*/#define C0 23170 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define C1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define C2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define C3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#if 0#define C4 16384 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#else#define C4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5#endif#define C5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define C6 8867  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define C7 4520  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5#define ROW_SHIFT 11#define COL_SHIFT 20 // 6DECLARE_ASM_CONST(8, uint64_t, wm1010)= 0xFFFF0000FFFF0000ULL;DECLARE_ASM_CONST(8, uint64_t, d40000)= 0x0000000000040000ULL;DECLARE_ALIGNED(8, static const int16_t, coeffs[])= {        1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0,//        1<<(COL_SHIFT-1), 0, 1<<(COL_SHIFT-1), 0,//        0, 1<<(COL_SHIFT-1-16), 0, 1<<(COL_SHIFT-1-16),        1<<(ROW_SHIFT-1), 1, 1<<(ROW_SHIFT-1), 0,        // the 1 = ((1<<(COL_SHIFT-1))/C4)<<ROW_SHIFT :)//        0, 0, 0, 0,//        0, 0, 0, 0, C4,  C4,  C4,  C4, C4, -C4,  C4, -C4, C2,  C6,  C2,  C6, C6, -C2,  C6, -C2, C1,  C3,  C1,  C3, C5,  C7,  C5,  C7, C3, -C7,  C3, -C7,-C1, -C5, -C1, -C5, C5, -C1,  C5, -C1, C7,  C3,  C7,  C3, C7, -C5,  C7, -C5, C3, -C1,  C3, -C1};#if 0static void unused_var_killer(){        int a= wm1010 + d40000;        temp[0]=a;}static void inline idctCol (int16_t * col, int16_t *input){#undef C0#undef C1#undef C2#undef C3#undef C4#undef C5#undef C6#undef C7        int a0, a1, a2, a3, b0, b1, b2, b3;        const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C6 = 8867;  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C7 = 4520;  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5/*        if( !(col[8*1] | col[8*2] |col[8*3] |col[8*4] |col[8*5] |col[8*6] | col[8*7])) {                col[8*0] = col[8*1] = col[8*2] = col[8*3] = col[8*4] =                        col[8*5] = col[8*6] = col[8*7] = col[8*0]<<3;                return;        }*/col[8*0] = input[8*0 + 0];col[8*1] = input[8*2 + 0];col[8*2] = input[8*0 + 1];col[8*3] = input[8*2 + 1];col[8*4] = input[8*4 + 0];col[8*5] = input[8*6 + 0];col[8*6] = input[8*4 + 1];col[8*7] = input[8*6 + 1];        a0 = C4*col[8*0] + C2*col[8*2] + C4*col[8*4] + C6*col[8*6] + (1<<(COL_SHIFT-1));        a1 = C4*col[8*0] + C6*col[8*2] - C4*col[8*4] - C2*col[8*6] + (1<<(COL_SHIFT-1));        a2 = C4*col[8*0] - C6*col[8*2] - C4*col[8*4] + C2*col[8*6] + (1<<(COL_SHIFT-1));        a3 = C4*col[8*0] - C2*col[8*2] + C4*col[8*4] - C6*col[8*6] + (1<<(COL_SHIFT-1));        b0 = C1*col[8*1] + C3*col[8*3] + C5*col[8*5] + C7*col[8*7];        b1 = C3*col[8*1] - C7*col[8*3] - C1*col[8*5] - C5*col[8*7];        b2 = C5*col[8*1] - C1*col[8*3] + C7*col[8*5] + C3*col[8*7];        b3 = C7*col[8*1] - C5*col[8*3] + C3*col[8*5] - C1*col[8*7];        col[8*0] = (a0 + b0) >> COL_SHIFT;        col[8*1] = (a1 + b1) >> COL_SHIFT;        col[8*2] = (a2 + b2) >> COL_SHIFT;        col[8*3] = (a3 + b3) >> COL_SHIFT;        col[8*4] = (a3 - b3) >> COL_SHIFT;        col[8*5] = (a2 - b2) >> COL_SHIFT;        col[8*6] = (a1 - b1) >> COL_SHIFT;        col[8*7] = (a0 - b0) >> COL_SHIFT;}static void inline idctRow (int16_t * output, int16_t * input){        int16_t row[8];        int a0, a1, a2, a3, b0, b1, b2, b3;        const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C6 = 8867;  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5        const int C7 = 4520;  //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5row[0] = input[0];row[2] = input[1];row[4] = input[4];row[6] = input[5];row[1] = input[8];row[3] = input[9];row[5] = input[12];row[7] = input[13];        if( !(row[1] | row[2] |row[3] |row[4] |row[5] |row[6] | row[7]) ) {                row[0] = row[1] = row[2] = row[3] = row[4] =                        row[5] = row[6] = row[7] = row[0]<<3;        output[0]  = row[0];        output[2]  = row[1];        output[4]  = row[2];        output[6]  = row[3];        output[8]  = row[4];        output[10] = row[5];        output[12] = row[6];        output[14] = row[7];                return;        }        a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + (1<<(ROW_SHIFT-1));        a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + (1<<(ROW_SHIFT-1));        a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + (1<<(ROW_SHIFT-1));        a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + (1<<(ROW_SHIFT-1));        b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];        b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];        b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];        b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];        row[0] = (a0 + b0) >> ROW_SHIFT;        row[1] = (a1 + b1) >> ROW_SHIFT;        row[2] = (a2 + b2) >> ROW_SHIFT;        row[3] = (a3 + b3) >> ROW_SHIFT;        row[4] = (a3 - b3) >> ROW_SHIFT;        row[5] = (a2 - b2) >> ROW_SHIFT;        row[6] = (a1 - b1) >> ROW_SHIFT;        row[7] = (a0 - b0) >> ROW_SHIFT;        output[0]  = row[0];        output[2]  = row[1];        output[4]  = row[2];        output[6]  = row[3];        output[8]  = row[4];        output[10] = row[5];        output[12] = row[6];        output[14] = row[7];}#endifstatic inline void idct(int16_t *block){        DECLARE_ALIGNED(8, int64_t, align_tmp[16]);        int16_t * const temp= (int16_t*)align_tmp;        asm volatile(#if 0 //Alternative, simpler variant#define ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \        "movq " #src0 ", %%mm0          \n\t" /* R4     R0      r4      r0 */\        "movq " #src4 ", %%mm1          \n\t" /* R6     R2      r6      r2 */\        "movq " #src1 ", %%mm2          \n\t" /* R3     R1      r3      r1 */\        "movq " #src5 ", %%mm3          \n\t" /* R7     R5      r7      r5 */\        "movq 16(%2), %%mm4             \n\t" /* C4     C4      C4      C4 */\        "pmaddwd %%mm0, %%mm4           \n\t" /* C4R4+C4R0      C4r4+C4r0 */\        "movq 24(%2), %%mm5             \n\t" /* -C4    C4      -C4     C4 */\        "pmaddwd %%mm5, %%mm0           \n\t" /* -C4R4+C4R0     -C4r4+C4r0 */\        "movq 32(%2), %%mm5             \n\t" /* C6     C2      C6      C2 */\        "pmaddwd %%mm1, %%mm5           \n\t" /* C6R6+C2R2      C6r6+C2r2 */\        "movq 40(%2), %%mm6             \n\t" /* -C2    C6      -C2     C6 */\

⌨️ 快捷键说明

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