• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • 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 "libavutil/cpu.h"
00024 #include "libavcodec/lpc.h"
00025 
00026 static void lpc_apply_welch_window_sse2(const int32_t *data, int len,
00027                                         double *w_data)
00028 {
00029     double c = 2.0 / (len-1.0);
00030     int n2 = len>>1;
00031     x86_reg i = -n2*sizeof(int32_t);
00032     x86_reg j =  n2*sizeof(int32_t);
00033     __asm__ volatile(
00034         "movsd   %4,     %%xmm7                \n\t"
00035         "movapd  "MANGLE(ff_pd_1)", %%xmm6     \n\t"
00036         "movapd  "MANGLE(ff_pd_2)", %%xmm5     \n\t"
00037         "movlhps %%xmm7, %%xmm7                \n\t"
00038         "subpd   %%xmm5, %%xmm7                \n\t"
00039         "addsd   %%xmm6, %%xmm7                \n\t"
00040         "test    $1,     %5                    \n\t"
00041         "jz      2f                            \n\t"
00042 #define WELCH(MOVPD, offset)\
00043         "1:                                    \n\t"\
00044         "movapd   %%xmm7,  %%xmm1              \n\t"\
00045         "mulpd    %%xmm1,  %%xmm1              \n\t"\
00046         "movapd   %%xmm6,  %%xmm0              \n\t"\
00047         "subpd    %%xmm1,  %%xmm0              \n\t"\
00048         "pshufd   $0x4e,   %%xmm0, %%xmm1      \n\t"\
00049         "cvtpi2pd (%3,%0), %%xmm2              \n\t"\
00050         "cvtpi2pd "#offset"*4(%3,%1), %%xmm3   \n\t"\
00051         "mulpd    %%xmm0,  %%xmm2              \n\t"\
00052         "mulpd    %%xmm1,  %%xmm3              \n\t"\
00053         "movapd   %%xmm2, (%2,%0,2)            \n\t"\
00054         MOVPD"    %%xmm3, "#offset"*8(%2,%1,2) \n\t"\
00055         "subpd    %%xmm5,  %%xmm7              \n\t"\
00056         "sub      $8,      %1                  \n\t"\
00057         "add      $8,      %0                  \n\t"\
00058         "jl 1b                                 \n\t"\
00059 
00060         WELCH("movupd", -1)
00061         "jmp 3f                                \n\t"
00062         "2:                                    \n\t"
00063         WELCH("movapd", -2)
00064         "3:                                    \n\t"
00065         :"+&r"(i), "+&r"(j)
00066         :"r"(w_data+n2), "r"(data+n2), "m"(c), "r"(len)
00067          XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
00068                                     "%xmm5", "%xmm6", "%xmm7")
00069     );
00070 #undef WELCH
00071 }
00072 
00073 static void lpc_compute_autocorr_sse2(const double *data, int len, int lag,
00074                                       double *autoc)
00075 {
00076     int j;
00077 
00078     if((x86_reg)data & 15)
00079         data++;
00080 
00081     for(j=0; j<lag; j+=2){
00082         x86_reg i = -len*sizeof(double);
00083         if(j == lag-2) {
00084             __asm__ volatile(
00085                 "movsd    "MANGLE(ff_pd_1)", %%xmm0 \n\t"
00086                 "movsd    "MANGLE(ff_pd_1)", %%xmm1 \n\t"
00087                 "movsd    "MANGLE(ff_pd_1)", %%xmm2 \n\t"
00088                 "1:                                 \n\t"
00089                 "movapd   (%2,%0), %%xmm3           \n\t"
00090                 "movupd -8(%3,%0), %%xmm4           \n\t"
00091                 "movapd   (%3,%0), %%xmm5           \n\t"
00092                 "mulpd     %%xmm3, %%xmm4           \n\t"
00093                 "mulpd     %%xmm3, %%xmm5           \n\t"
00094                 "mulpd -16(%3,%0), %%xmm3           \n\t"
00095                 "addpd     %%xmm4, %%xmm1           \n\t"
00096                 "addpd     %%xmm5, %%xmm0           \n\t"
00097                 "addpd     %%xmm3, %%xmm2           \n\t"
00098                 "add       $16,    %0               \n\t"
00099                 "jl 1b                              \n\t"
00100                 "movhlps   %%xmm0, %%xmm3           \n\t"
00101                 "movhlps   %%xmm1, %%xmm4           \n\t"
00102                 "movhlps   %%xmm2, %%xmm5           \n\t"
00103                 "addsd     %%xmm3, %%xmm0           \n\t"
00104                 "addsd     %%xmm4, %%xmm1           \n\t"
00105                 "addsd     %%xmm5, %%xmm2           \n\t"
00106                 "movsd     %%xmm0,   (%1)           \n\t"
00107                 "movsd     %%xmm1,  8(%1)           \n\t"
00108                 "movsd     %%xmm2, 16(%1)           \n\t"
00109                 :"+&r"(i)
00110                 :"r"(autoc+j), "r"(data+len), "r"(data+len-j)
00111                 :"memory"
00112             );
00113         } else {
00114             __asm__ volatile(
00115                 "movsd    "MANGLE(ff_pd_1)", %%xmm0 \n\t"
00116                 "movsd    "MANGLE(ff_pd_1)", %%xmm1 \n\t"
00117                 "1:                                 \n\t"
00118                 "movapd   (%3,%0), %%xmm3           \n\t"
00119                 "movupd -8(%4,%0), %%xmm4           \n\t"
00120                 "mulpd     %%xmm3, %%xmm4           \n\t"
00121                 "mulpd    (%4,%0), %%xmm3           \n\t"
00122                 "addpd     %%xmm4, %%xmm1           \n\t"
00123                 "addpd     %%xmm3, %%xmm0           \n\t"
00124                 "add       $16,    %0               \n\t"
00125                 "jl 1b                              \n\t"
00126                 "movhlps   %%xmm0, %%xmm3           \n\t"
00127                 "movhlps   %%xmm1, %%xmm4           \n\t"
00128                 "addsd     %%xmm3, %%xmm0           \n\t"
00129                 "addsd     %%xmm4, %%xmm1           \n\t"
00130                 "movsd     %%xmm0, %1               \n\t"
00131                 "movsd     %%xmm1, %2               \n\t"
00132                 :"+&r"(i), "=m"(autoc[j]), "=m"(autoc[j+1])
00133                 :"r"(data+len), "r"(data+len-j)
00134             );
00135         }
00136     }
00137 }
00138 
00139 av_cold void ff_lpc_init_x86(LPCContext *c)
00140 {
00141     int mm_flags = av_get_cpu_flags();
00142 
00143     if (mm_flags & (AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW)) {
00144         c->lpc_apply_welch_window = lpc_apply_welch_window_sse2;
00145         c->lpc_compute_autocorr   = lpc_compute_autocorr_sse2;
00146     }
00147 }

Generated on Fri Feb 22 2013 07:24:30 for FFmpeg by  doxygen 1.7.1