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

libavcodec/x86/lpc_mmx.c

Go to the documentation of this file.
00001 /*
00002  * MMX optimized LPC DSP utils
00003  * Copyright (c) 2007 Loren Merritt
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavutil/x86_cpu.h"
00023 #include "dsputil_mmx.h"
00024 
00025 static void apply_welch_window_sse2(const int32_t *data, int len, double *w_data)
00026 {
00027     double c = 2.0 / (len-1.0);
00028     int n2 = len>>1;
00029     x86_reg i = -n2*sizeof(int32_t);
00030     x86_reg j =  n2*sizeof(int32_t);
00031     __asm__ volatile(
00032         "movsd   %0,     %%xmm7                \n\t"
00033         "movapd  "MANGLE(ff_pd_1)", %%xmm6     \n\t"
00034         "movapd  "MANGLE(ff_pd_2)", %%xmm5     \n\t"
00035         "movlhps %%xmm7, %%xmm7                \n\t"
00036         "subpd   %%xmm5, %%xmm7                \n\t"
00037         "addsd   %%xmm6, %%xmm7                \n\t"
00038         ::"m"(c)
00039     );
00040 #define WELCH(MOVPD, offset)\
00041     __asm__ volatile(\
00042         "1:                                    \n\t"\
00043         "movapd   %%xmm7,  %%xmm1              \n\t"\
00044         "mulpd    %%xmm1,  %%xmm1              \n\t"\
00045         "movapd   %%xmm6,  %%xmm0              \n\t"\
00046         "subpd    %%xmm1,  %%xmm0              \n\t"\
00047         "pshufd   $0x4e,   %%xmm0, %%xmm1      \n\t"\
00048         "cvtpi2pd (%3,%0), %%xmm2              \n\t"\
00049         "cvtpi2pd "#offset"*4(%3,%1), %%xmm3   \n\t"\
00050         "mulpd    %%xmm0,  %%xmm2              \n\t"\
00051         "mulpd    %%xmm1,  %%xmm3              \n\t"\
00052         "movapd   %%xmm2, (%2,%0,2)            \n\t"\
00053         MOVPD"    %%xmm3, "#offset"*8(%2,%1,2) \n\t"\
00054         "subpd    %%xmm5,  %%xmm7              \n\t"\
00055         "sub      $8,      %1                  \n\t"\
00056         "add      $8,      %0                  \n\t"\
00057         "jl 1b                                 \n\t"\
00058         :"+&r"(i), "+&r"(j)\
00059         :"r"(w_data+n2), "r"(data+n2)\
00060     );
00061     if(len&1)
00062         WELCH("movupd", -1)
00063     else
00064         WELCH("movapd", -2)
00065 #undef WELCH
00066 }
00067 
00068 void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag,
00069                                    double *autoc)
00070 {
00071     double tmp[len + lag + 2];
00072     double *data1 = tmp + lag;
00073     int j;
00074 
00075     if((x86_reg)data1 & 15)
00076         data1++;
00077 
00078     apply_welch_window_sse2(data, len, data1);
00079 
00080     for(j=0; j<lag; j++)
00081         data1[j-lag]= 0.0;
00082     data1[len] = 0.0;
00083 
00084     for(j=0; j<lag; j+=2){
00085         x86_reg i = -len*sizeof(double);
00086         if(j == lag-2) {
00087             __asm__ volatile(
00088                 "movsd    "MANGLE(ff_pd_1)", %%xmm0 \n\t"
00089                 "movsd    "MANGLE(ff_pd_1)", %%xmm1 \n\t"
00090                 "movsd    "MANGLE(ff_pd_1)", %%xmm2 \n\t"
00091                 "1:                                 \n\t"
00092                 "movapd   (%2,%0), %%xmm3           \n\t"
00093                 "movupd -8(%3,%0), %%xmm4           \n\t"
00094                 "movapd   (%3,%0), %%xmm5           \n\t"
00095                 "mulpd     %%xmm3, %%xmm4           \n\t"
00096                 "mulpd     %%xmm3, %%xmm5           \n\t"
00097                 "mulpd -16(%3,%0), %%xmm3           \n\t"
00098                 "addpd     %%xmm4, %%xmm1           \n\t"
00099                 "addpd     %%xmm5, %%xmm0           \n\t"
00100                 "addpd     %%xmm3, %%xmm2           \n\t"
00101                 "add       $16,    %0               \n\t"
00102                 "jl 1b                              \n\t"
00103                 "movhlps   %%xmm0, %%xmm3           \n\t"
00104                 "movhlps   %%xmm1, %%xmm4           \n\t"
00105                 "movhlps   %%xmm2, %%xmm5           \n\t"
00106                 "addsd     %%xmm3, %%xmm0           \n\t"
00107                 "addsd     %%xmm4, %%xmm1           \n\t"
00108                 "addsd     %%xmm5, %%xmm2           \n\t"
00109                 "movsd     %%xmm0,   (%1)           \n\t"
00110                 "movsd     %%xmm1,  8(%1)           \n\t"
00111                 "movsd     %%xmm2, 16(%1)           \n\t"
00112                 :"+&r"(i)
00113                 :"r"(autoc+j), "r"(data1+len), "r"(data1+len-j)
00114                 :"memory"
00115             );
00116         } else {
00117             __asm__ volatile(
00118                 "movsd    "MANGLE(ff_pd_1)", %%xmm0 \n\t"
00119                 "movsd    "MANGLE(ff_pd_1)", %%xmm1 \n\t"
00120                 "1:                                 \n\t"
00121                 "movapd   (%3,%0), %%xmm3           \n\t"
00122                 "movupd -8(%4,%0), %%xmm4           \n\t"
00123                 "mulpd     %%xmm3, %%xmm4           \n\t"
00124                 "mulpd    (%4,%0), %%xmm3           \n\t"
00125                 "addpd     %%xmm4, %%xmm1           \n\t"
00126                 "addpd     %%xmm3, %%xmm0           \n\t"
00127                 "add       $16,    %0               \n\t"
00128                 "jl 1b                              \n\t"
00129                 "movhlps   %%xmm0, %%xmm3           \n\t"
00130                 "movhlps   %%xmm1, %%xmm4           \n\t"
00131                 "addsd     %%xmm3, %%xmm0           \n\t"
00132                 "addsd     %%xmm4, %%xmm1           \n\t"
00133                 "movsd     %%xmm0, %1               \n\t"
00134                 "movsd     %%xmm1, %2               \n\t"
00135                 :"+&r"(i), "=m"(autoc[j]), "=m"(autoc[j+1])
00136                 :"r"(data1+len), "r"(data1+len-j)
00137             );
00138         }
00139     }
00140 }

Generated on Fri Sep 16 2011 17:17:46 for FFmpeg by  doxygen 1.7.1