Libav
|
00001 /* 00002 * DSP utils : QNS functions are compiled 3 times for mmx/3dnow/ssse3 00003 * Copyright (c) 2004 Michael Niedermayer 00004 * 00005 * MMX optimization by Michael Niedermayer <michaelni@gmx.at> 00006 * 3DNow! and SSSE3 optimization by Zuxy Meng <zuxy.meng@gmail.com> 00007 * 00008 * This file is part of FFmpeg. 00009 * 00010 * FFmpeg is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * FFmpeg is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with FFmpeg; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 */ 00024 00025 #define MAX_ABS (512 >> (SCALE_OFFSET>0 ? SCALE_OFFSET : 0)) 00026 00027 static int DEF(try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale) 00028 { 00029 x86_reg i=0; 00030 00031 assert(FFABS(scale) < MAX_ABS); 00032 scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT; 00033 00034 SET_RND(mm6); 00035 __asm__ volatile( 00036 "pxor %%mm7, %%mm7 \n\t" 00037 "movd %4, %%mm5 \n\t" 00038 "punpcklwd %%mm5, %%mm5 \n\t" 00039 "punpcklwd %%mm5, %%mm5 \n\t" 00040 ASMALIGN(4) 00041 "1: \n\t" 00042 "movq (%1, %0), %%mm0 \n\t" 00043 "movq 8(%1, %0), %%mm1 \n\t" 00044 PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6) 00045 "paddw (%2, %0), %%mm0 \n\t" 00046 "paddw 8(%2, %0), %%mm1 \n\t" 00047 "psraw $6, %%mm0 \n\t" 00048 "psraw $6, %%mm1 \n\t" 00049 "pmullw (%3, %0), %%mm0 \n\t" 00050 "pmullw 8(%3, %0), %%mm1 \n\t" 00051 "pmaddwd %%mm0, %%mm0 \n\t" 00052 "pmaddwd %%mm1, %%mm1 \n\t" 00053 "paddd %%mm1, %%mm0 \n\t" 00054 "psrld $4, %%mm0 \n\t" 00055 "paddd %%mm0, %%mm7 \n\t" 00056 "add $16, %0 \n\t" 00057 "cmp $128, %0 \n\t" //FIXME optimize & bench 00058 " jb 1b \n\t" 00059 PHADDD(%%mm7, %%mm6) 00060 "psrld $2, %%mm7 \n\t" 00061 "movd %%mm7, %0 \n\t" 00062 00063 : "+r" (i) 00064 : "r"(basis), "r"(rem), "r"(weight), "g"(scale) 00065 ); 00066 return i; 00067 } 00068 00069 static void DEF(add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale) 00070 { 00071 x86_reg i=0; 00072 00073 if(FFABS(scale) < MAX_ABS){ 00074 scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT; 00075 SET_RND(mm6); 00076 __asm__ volatile( 00077 "movd %3, %%mm5 \n\t" 00078 "punpcklwd %%mm5, %%mm5 \n\t" 00079 "punpcklwd %%mm5, %%mm5 \n\t" 00080 ASMALIGN(4) 00081 "1: \n\t" 00082 "movq (%1, %0), %%mm0 \n\t" 00083 "movq 8(%1, %0), %%mm1 \n\t" 00084 PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6) 00085 "paddw (%2, %0), %%mm0 \n\t" 00086 "paddw 8(%2, %0), %%mm1 \n\t" 00087 "movq %%mm0, (%2, %0) \n\t" 00088 "movq %%mm1, 8(%2, %0) \n\t" 00089 "add $16, %0 \n\t" 00090 "cmp $128, %0 \n\t" // FIXME optimize & bench 00091 " jb 1b \n\t" 00092 00093 : "+r" (i) 00094 : "r"(basis), "r"(rem), "g"(scale) 00095 ); 00096 }else{ 00097 for(i=0; i<8*8; i++){ 00098 rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT); 00099 } 00100 } 00101 }