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