dsputil_mmx_qns.h

Go to the documentation of this file.
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 /* This header intentionally has no multiple inclusion guards. It is meant to
00026  * be included multiple times and generates different code depending on the
00027  * value of certain #defines. */
00028 
00029 #define MAX_ABS (512 >> (SCALE_OFFSET>0 ? SCALE_OFFSET : 0))
00030 
00031 static int DEF(try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale)
00032 {
00033     x86_reg i=0;
00034 
00035     assert(FFABS(scale) < MAX_ABS);
00036     scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT;
00037 
00038     SET_RND(mm6);
00039     asm volatile(
00040         "pxor %%mm7, %%mm7              \n\t"
00041         "movd  %4, %%mm5                \n\t"
00042         "punpcklwd %%mm5, %%mm5         \n\t"
00043         "punpcklwd %%mm5, %%mm5         \n\t"
00044         ASMALIGN(4)
00045         "1:                             \n\t"
00046         "movq  (%1, %0), %%mm0          \n\t"
00047         "movq  8(%1, %0), %%mm1         \n\t"
00048         PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6)
00049         "paddw (%2, %0), %%mm0          \n\t"
00050         "paddw 8(%2, %0), %%mm1         \n\t"
00051         "psraw $6, %%mm0                \n\t"
00052         "psraw $6, %%mm1                \n\t"
00053         "pmullw (%3, %0), %%mm0         \n\t"
00054         "pmullw 8(%3, %0), %%mm1        \n\t"
00055         "pmaddwd %%mm0, %%mm0           \n\t"
00056         "pmaddwd %%mm1, %%mm1           \n\t"
00057         "paddd %%mm1, %%mm0             \n\t"
00058         "psrld $4, %%mm0                \n\t"
00059         "paddd %%mm0, %%mm7             \n\t"
00060         "add $16, %0                    \n\t"
00061         "cmp $128, %0                   \n\t" //FIXME optimize & bench
00062         " jb 1b                         \n\t"
00063         PHADDD(%%mm7, %%mm6)
00064         "psrld $2, %%mm7                \n\t"
00065         "movd %%mm7, %0                 \n\t"
00066 
00067         : "+r" (i)
00068         : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
00069     );
00070     return i;
00071 }
00072 
00073 static void DEF(add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale)
00074 {
00075     x86_reg i=0;
00076 
00077     if(FFABS(scale) < MAX_ABS){
00078         scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT;
00079         SET_RND(mm6);
00080         asm volatile(
00081                 "movd  %3, %%mm5        \n\t"
00082                 "punpcklwd %%mm5, %%mm5 \n\t"
00083                 "punpcklwd %%mm5, %%mm5 \n\t"
00084                 ASMALIGN(4)
00085                 "1:                     \n\t"
00086                 "movq  (%1, %0), %%mm0  \n\t"
00087                 "movq  8(%1, %0), %%mm1 \n\t"
00088                 PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6)
00089                 "paddw (%2, %0), %%mm0  \n\t"
00090                 "paddw 8(%2, %0), %%mm1 \n\t"
00091                 "movq %%mm0, (%2, %0)   \n\t"
00092                 "movq %%mm1, 8(%2, %0)  \n\t"
00093                 "add $16, %0            \n\t"
00094                 "cmp $128, %0           \n\t" // FIXME optimize & bench
00095                 " jb 1b                 \n\t"
00096 
00097                 : "+r" (i)
00098                 : "r"(basis), "r"(rem), "g"(scale)
00099         );
00100     }else{
00101         for(i=0; i<8*8; i++){
00102             rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
00103         }
00104     }
00105 }

Generated on Fri Jan 9 14:44:26 2009 for libextractor by  doxygen 1.5.1