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

📄 mpegvideo_mmx.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * The simplest mpeg encoder (well, it was the simplest!) * Copyright (c) 2000,2001 Fabrice Bellard. * * Optimized for ia32 CPUs by Nick Kurshev <nickols_k@mail.ru> * h263, mpeg1, mpeg2 dequantizer & draw_edges by 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 "dsputil_mmx.h"#include "mpegvideo.h"#include "avcodec.h"#include "x86_cpu.h"extern uint16_t inv_zigzag_direct16[64];static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,                                  DCTELEM *block, int n, int qscale){    long level, qmul, qadd, nCoeffs;    qmul = qscale << 1;    assert(s->block_last_index[n]>=0 || s->h263_aic);    if (!s->h263_aic) {        if (n < 4)            level = block[0] * s->y_dc_scale;        else            level = block[0] * s->c_dc_scale;        qadd = (qscale - 1) | 1;    }else{        qadd = 0;        level= block[0];    }    if(s->ac_pred)        nCoeffs=63;    else        nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];//printf("%d %d  ", qmul, qadd);asm volatile(                "movd %1, %%mm6                 \n\t" //qmul                "packssdw %%mm6, %%mm6          \n\t"                "packssdw %%mm6, %%mm6          \n\t"                "movd %2, %%mm5                 \n\t" //qadd                "pxor %%mm7, %%mm7              \n\t"                "packssdw %%mm5, %%mm5          \n\t"                "packssdw %%mm5, %%mm5          \n\t"                "psubw %%mm5, %%mm7             \n\t"                "pxor %%mm4, %%mm4              \n\t"                ASMALIGN(4)                "1:                             \n\t"                "movq (%0, %3), %%mm0           \n\t"                "movq 8(%0, %3), %%mm1          \n\t"                "pmullw %%mm6, %%mm0            \n\t"                "pmullw %%mm6, %%mm1            \n\t"                "movq (%0, %3), %%mm2           \n\t"                "movq 8(%0, %3), %%mm3          \n\t"                "pcmpgtw %%mm4, %%mm2           \n\t" // block[i] < 0 ? -1 : 0                "pcmpgtw %%mm4, %%mm3           \n\t" // block[i] < 0 ? -1 : 0                "pxor %%mm2, %%mm0              \n\t"                "pxor %%mm3, %%mm1              \n\t"                "paddw %%mm7, %%mm0             \n\t"                "paddw %%mm7, %%mm1             \n\t"                "pxor %%mm0, %%mm2              \n\t"                "pxor %%mm1, %%mm3              \n\t"                "pcmpeqw %%mm7, %%mm0           \n\t" // block[i] == 0 ? -1 : 0                "pcmpeqw %%mm7, %%mm1           \n\t" // block[i] == 0 ? -1 : 0                "pandn %%mm2, %%mm0             \n\t"                "pandn %%mm3, %%mm1             \n\t"                "movq %%mm0, (%0, %3)           \n\t"                "movq %%mm1, 8(%0, %3)          \n\t"                "add $16, %3                    \n\t"                "jng 1b                         \n\t"                ::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(-nCoeffs))                : "memory"        );        block[0]= level;}static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,                                  DCTELEM *block, int n, int qscale){    long qmul, qadd, nCoeffs;    qmul = qscale << 1;    qadd = (qscale - 1) | 1;    assert(s->block_last_index[n]>=0 || s->h263_aic);    nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];//printf("%d %d  ", qmul, qadd);asm volatile(                "movd %1, %%mm6                 \n\t" //qmul                "packssdw %%mm6, %%mm6          \n\t"                "packssdw %%mm6, %%mm6          \n\t"                "movd %2, %%mm5                 \n\t" //qadd                "pxor %%mm7, %%mm7              \n\t"                "packssdw %%mm5, %%mm5          \n\t"                "packssdw %%mm5, %%mm5          \n\t"                "psubw %%mm5, %%mm7             \n\t"                "pxor %%mm4, %%mm4              \n\t"                ASMALIGN(4)                "1:                             \n\t"                "movq (%0, %3), %%mm0           \n\t"                "movq 8(%0, %3), %%mm1          \n\t"                "pmullw %%mm6, %%mm0            \n\t"                "pmullw %%mm6, %%mm1            \n\t"                "movq (%0, %3), %%mm2           \n\t"                "movq 8(%0, %3), %%mm3          \n\t"                "pcmpgtw %%mm4, %%mm2           \n\t" // block[i] < 0 ? -1 : 0                "pcmpgtw %%mm4, %%mm3           \n\t" // block[i] < 0 ? -1 : 0                "pxor %%mm2, %%mm0              \n\t"                "pxor %%mm3, %%mm1              \n\t"                "paddw %%mm7, %%mm0             \n\t"                "paddw %%mm7, %%mm1             \n\t"                "pxor %%mm0, %%mm2              \n\t"                "pxor %%mm1, %%mm3              \n\t"                "pcmpeqw %%mm7, %%mm0           \n\t" // block[i] == 0 ? -1 : 0                "pcmpeqw %%mm7, %%mm1           \n\t" // block[i] == 0 ? -1 : 0                "pandn %%mm2, %%mm0             \n\t"                "pandn %%mm3, %%mm1             \n\t"                "movq %%mm0, (%0, %3)           \n\t"                "movq %%mm1, 8(%0, %3)          \n\t"                "add $16, %3                    \n\t"                "jng 1b                         \n\t"                ::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(-nCoeffs))                : "memory"        );}/*  NK:  Note: looking at PARANOID:  "enable all paranoid tests for rounding, overflows, etc..."#ifdef PARANOID                if (level < -2048 || level > 2047)                    fprintf(stderr, "unquant error %d %d\n", i, level);#endif  We can suppose that result of two multiplications can't be greater than 0xFFFF  i.e. is 16-bit, so we use here only PMULLW instruction and can avoid  a complex multiplication.===================================================== Full formula for multiplication of 2 integer numbers which are represent as high:low words: input: value1 = high1:low1        value2 = high2:low2 output: value3 = value1*value2 value3=high3:low3 (on overflow: modulus 2^32 wrap-around) this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4 but this algorithm will compute only 0x66cb0ce4 this limited by 16-bit size of operands --------------------------------- tlow1 = high1*low2 tlow2 = high2*low1 tlow1 = tlow1 + tlow2 high3:low3 = low1*low2 high3 += tlow1*/static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,                                     DCTELEM *block, int n, int qscale){    long nCoeffs;    const uint16_t *quant_matrix;    int block0;    assert(s->block_last_index[n]>=0);    nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;    if (n < 4)        block0 = block[0] * s->y_dc_scale;    else        block0 = block[0] * s->c_dc_scale;    /* XXX: only mpeg1 */    quant_matrix = s->intra_matrix;asm volatile(                "pcmpeqw %%mm7, %%mm7           \n\t"                "psrlw $15, %%mm7               \n\t"                "movd %2, %%mm6                 \n\t"                "packssdw %%mm6, %%mm6          \n\t"                "packssdw %%mm6, %%mm6          \n\t"                "mov %3, %%"REG_a"              \n\t"                ASMALIGN(4)                "1:                             \n\t"                "movq (%0, %%"REG_a"), %%mm0    \n\t"                "movq 8(%0, %%"REG_a"), %%mm1   \n\t"                "movq (%1, %%"REG_a"), %%mm4    \n\t"                "movq 8(%1, %%"REG_a"), %%mm5   \n\t"                "pmullw %%mm6, %%mm4            \n\t" // q=qscale*quant_matrix[i]                "pmullw %%mm6, %%mm5            \n\t" // q=qscale*quant_matrix[i]                "pxor %%mm2, %%mm2              \n\t"                "pxor %%mm3, %%mm3              \n\t"                "pcmpgtw %%mm0, %%mm2           \n\t" // block[i] < 0 ? -1 : 0                "pcmpgtw %%mm1, %%mm3           \n\t" // block[i] < 0 ? -1 : 0                "pxor %%mm2, %%mm0              \n\t"                "pxor %%mm3, %%mm1              \n\t"                "psubw %%mm2, %%mm0             \n\t" // abs(block[i])                "psubw %%mm3, %%mm1             \n\t" // abs(block[i])                "pmullw %%mm4, %%mm0            \n\t" // abs(block[i])*q                "pmullw %%mm5, %%mm1            \n\t" // abs(block[i])*q                "pxor %%mm4, %%mm4              \n\t"                "pxor %%mm5, %%mm5              \n\t" // FIXME slow                "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0                "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0                "psraw $3, %%mm0                \n\t"                "psraw $3, %%mm1                \n\t"                "psubw %%mm7, %%mm0             \n\t"                "psubw %%mm7, %%mm1             \n\t"

⌨️ 快捷键说明

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