• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/x86/mpegvideo_mmx_template.c

Go to the documentation of this file.
00001 /*
00002  * MPEG video MMX templates
00003  *
00004  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #undef MMREG_WIDTH
00024 #undef MM
00025 #undef MOVQ
00026 #undef SPREADW
00027 #undef PMAXW
00028 #undef PMAX
00029 #undef SAVE_SIGN
00030 #undef RESTORE_SIGN
00031 
00032 #if HAVE_SSE2
00033 #define MMREG_WIDTH "16"
00034 #define MM "%%xmm"
00035 #define MOVQ "movdqa"
00036 #define SPREADW(a) \
00037             "pshuflw $0, "a", "a"       \n\t"\
00038             "punpcklwd "a", "a"         \n\t"
00039 #define PMAXW(a,b) "pmaxsw "a", "b"     \n\t"
00040 #define PMAX(a,b) \
00041             "movhlps "a", "b"           \n\t"\
00042             PMAXW(b, a)\
00043             "pshuflw $0x0E, "a", "b"    \n\t"\
00044             PMAXW(b, a)\
00045             "pshuflw $0x01, "a", "b"    \n\t"\
00046             PMAXW(b, a)
00047 #else
00048 #define MMREG_WIDTH "8"
00049 #define MM "%%mm"
00050 #define MOVQ "movq"
00051 #if HAVE_MMX2
00052 #define SPREADW(a) "pshufw $0, "a", "a" \n\t"
00053 #define PMAXW(a,b) "pmaxsw "a", "b"     \n\t"
00054 #define PMAX(a,b) \
00055             "pshufw $0x0E, "a", "b"     \n\t"\
00056             PMAXW(b, a)\
00057             "pshufw $0x01, "a", "b"     \n\t"\
00058             PMAXW(b, a)
00059 #else
00060 #define SPREADW(a) \
00061             "punpcklwd "a", "a"         \n\t"\
00062             "punpcklwd "a", "a"         \n\t"
00063 #define PMAXW(a,b) \
00064             "psubusw "a", "b"           \n\t"\
00065             "paddw "a", "b"             \n\t"
00066 #define PMAX(a,b)  \
00067             "movq "a", "b"              \n\t"\
00068             "psrlq $32, "a"             \n\t"\
00069             PMAXW(b, a)\
00070             "movq "a", "b"              \n\t"\
00071             "psrlq $16, "a"             \n\t"\
00072             PMAXW(b, a)
00073 
00074 #endif
00075 #endif
00076 
00077 #if HAVE_SSSE3
00078 #define SAVE_SIGN(a,b) \
00079             "movdqa "b", "a"            \n\t"\
00080             "pabsw  "b", "b"            \n\t"
00081 #define RESTORE_SIGN(a,b) \
00082             "psignw "a", "b"            \n\t"
00083 #else
00084 #define SAVE_SIGN(a,b) \
00085             "pxor "a", "a"              \n\t"\
00086             "pcmpgtw "b", "a"           \n\t" /* block[i] <= 0 ? 0xFF : 0x00 */\
00087             "pxor "a", "b"              \n\t"\
00088             "psubw "a", "b"             \n\t" /* ABS(block[i]) */
00089 #define RESTORE_SIGN(a,b) \
00090             "pxor "a", "b"              \n\t"\
00091             "psubw "a", "b"             \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
00092 #endif
00093 
00094 static int RENAME(dct_quantize)(MpegEncContext *s,
00095                             DCTELEM *block, int n,
00096                             int qscale, int *overflow)
00097 {
00098     x86_reg last_non_zero_p1;
00099     int level=0, q; //=0 is because gcc says uninitialized ...
00100     const uint16_t *qmat, *bias;
00101     LOCAL_ALIGNED_16(int16_t, temp_block, [64]);
00102 
00103     assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
00104 
00105     //s->fdct (block);
00106     RENAMEl(ff_fdct) (block); //cannot be anything else ...
00107 
00108     if(s->dct_error_sum)
00109         s->denoise_dct(s, block);
00110 
00111     if (s->mb_intra) {
00112         int dummy;
00113         if (n < 4)
00114             q = s->y_dc_scale;
00115         else
00116             q = s->c_dc_scale;
00117         /* note: block[0] is assumed to be positive */
00118         if (!s->h263_aic) {
00119         __asm__ volatile (
00120                 "mul %%ecx                \n\t"
00121                 : "=d" (level), "=a"(dummy)
00122                 : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1])
00123         );
00124         } else
00125             /* For AIC we skip quant/dequant of INTRADC */
00126             level = (block[0] + 4)>>3;
00127 
00128         block[0]=0; //avoid fake overflow
00129 //        temp_block[0] = (block[0] + (q >> 1)) / q;
00130         last_non_zero_p1 = 1;
00131         bias = s->q_intra_matrix16[qscale][1];
00132         qmat = s->q_intra_matrix16[qscale][0];
00133     } else {
00134         last_non_zero_p1 = 0;
00135         bias = s->q_inter_matrix16[qscale][1];
00136         qmat = s->q_inter_matrix16[qscale][0];
00137     }
00138 
00139     if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){
00140 
00141         __asm__ volatile(
00142             "movd %%"REG_a", "MM"3              \n\t" // last_non_zero_p1
00143             SPREADW(MM"3")
00144             "pxor "MM"7, "MM"7                  \n\t" // 0
00145             "pxor "MM"4, "MM"4                  \n\t" // 0
00146             MOVQ" (%2), "MM"5                   \n\t" // qmat[0]
00147             "pxor "MM"6, "MM"6                  \n\t"
00148             "psubw (%3), "MM"6                  \n\t" // -bias[0]
00149             "mov $-128, %%"REG_a"               \n\t"
00150             ".p2align 4                         \n\t"
00151             "1:                                 \n\t"
00152             MOVQ" (%1, %%"REG_a"), "MM"0        \n\t" // block[i]
00153             SAVE_SIGN(MM"1", MM"0")                   // ABS(block[i])
00154             "psubusw "MM"6, "MM"0               \n\t" // ABS(block[i]) + bias[0]
00155             "pmulhw "MM"5, "MM"0                \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
00156             "por "MM"0, "MM"4                   \n\t"
00157             RESTORE_SIGN(MM"1", MM"0")                // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
00158             MOVQ" "MM"0, (%5, %%"REG_a")        \n\t"
00159             "pcmpeqw "MM"7, "MM"0               \n\t" // out==0 ? 0xFF : 0x00
00160             MOVQ" (%4, %%"REG_a"), "MM"1        \n\t"
00161             MOVQ" "MM"7, (%1, %%"REG_a")        \n\t" // 0
00162             "pandn "MM"1, "MM"0                 \n\t"
00163             PMAXW(MM"0", MM"3")
00164             "add $"MMREG_WIDTH", %%"REG_a"      \n\t"
00165             " js 1b                             \n\t"
00166             PMAX(MM"3", MM"0")
00167             "movd "MM"3, %%"REG_a"              \n\t"
00168             "movzb %%al, %%"REG_a"              \n\t" // last_non_zero_p1
00169             : "+a" (last_non_zero_p1)
00170             : "r" (block+64), "r" (qmat), "r" (bias),
00171               "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
00172               XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00173                                 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
00174         );
00175     }else{ // FMT_H263
00176         __asm__ volatile(
00177             "movd %%"REG_a", "MM"3              \n\t" // last_non_zero_p1
00178             SPREADW(MM"3")
00179             "pxor "MM"7, "MM"7                  \n\t" // 0
00180             "pxor "MM"4, "MM"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>"4                  \n\t" // 0
00>