2002-10-28 02:34:08 +02:00
|
|
|
/*
|
|
|
|
* FFT/MDCT transform with SSE optimizations
|
2008-08-12 03:33:34 +03:00
|
|
|
* Copyright (c) 2008 Loren Merritt
|
2002-10-28 02:34:08 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-10-28 02:34:08 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-10-28 02:34:08 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-10-28 02:34:08 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-10-28 02:34:08 +02:00
|
|
|
*/
|
2008-05-09 14:56:36 +03:00
|
|
|
|
|
|
|
#include "libavutil/x86_cpu.h"
|
|
|
|
#include "libavcodec/dsputil.h"
|
2009-09-16 00:14:14 +03:00
|
|
|
#include "fft.h"
|
2002-10-28 02:34:08 +02:00
|
|
|
|
2010-01-22 05:25:11 +02:00
|
|
|
DECLARE_ALIGNED(16, static const int, m1m1m1m1)[4] =
|
2006-09-21 19:37:39 +03:00
|
|
|
{ 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
|
|
|
|
|
2008-08-12 03:26:58 +03:00
|
|
|
void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
|
|
|
|
void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
|
2002-10-28 02:34:08 +02:00
|
|
|
|
2004-03-13 23:43:24 +02:00
|
|
|
void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
|
2002-10-28 02:34:08 +02:00
|
|
|
{
|
2008-08-12 03:26:58 +03:00
|
|
|
int n = 1 << s->nbits;
|
|
|
|
|
|
|
|
ff_fft_dispatch_interleave_sse(z, s->nbits);
|
|
|
|
|
|
|
|
if(n <= 16) {
|
|
|
|
x86_reg i = -8*n;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2008-08-12 03:26:58 +03:00
|
|
|
"1: \n"
|
|
|
|
"movaps (%0,%1), %%xmm0 \n"
|
|
|
|
"movaps %%xmm0, %%xmm1 \n"
|
|
|
|
"unpcklps 16(%0,%1), %%xmm0 \n"
|
|
|
|
"unpckhps 16(%0,%1), %%xmm1 \n"
|
|
|
|
"movaps %%xmm0, (%0,%1) \n"
|
|
|
|
"movaps %%xmm1, 16(%0,%1) \n"
|
|
|
|
"add $32, %0 \n"
|
|
|
|
"jl 1b \n"
|
|
|
|
:"+r"(i)
|
|
|
|
:"r"(z+n)
|
|
|
|
:"memory"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-10-28 02:34:08 +02:00
|
|
|
|
2008-08-12 03:26:58 +03:00
|
|
|
void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
|
|
|
|
{
|
|
|
|
int n = 1 << s->nbits;
|
|
|
|
int i;
|
|
|
|
for(i=0; i<n; i+=2) {
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2008-08-12 03:26:58 +03:00
|
|
|
"movaps %2, %%xmm0 \n"
|
|
|
|
"movlps %%xmm0, %0 \n"
|
|
|
|
"movhps %%xmm0, %1 \n"
|
|
|
|
:"=m"(s->tmp_buf[s->revtab[i]]),
|
|
|
|
"=m"(s->tmp_buf[s->revtab[i+1]])
|
|
|
|
:"m"(z[i])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
|
2002-10-28 02:34:08 +02:00
|
|
|
}
|
2003-01-07 19:41:43 +02:00
|
|
|
|
2009-09-20 20:30:20 +03:00
|
|
|
void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
|
2006-09-21 19:37:39 +03:00
|
|
|
{
|
2008-08-12 03:33:34 +03:00
|
|
|
av_unused x86_reg i, j, k, l;
|
2009-09-20 20:30:20 +03:00
|
|
|
long n = 1 << s->mdct_bits;
|
2008-08-12 03:33:34 +03:00
|
|
|
long n2 = n >> 1;
|
|
|
|
long n4 = n >> 2;
|
|
|
|
long n8 = n >> 3;
|
2009-09-20 20:30:20 +03:00
|
|
|
const uint16_t *revtab = s->revtab + n8;
|
2006-09-21 19:37:39 +03:00
|
|
|
const FFTSample *tcos = s->tcos;
|
|
|
|
const FFTSample *tsin = s->tsin;
|
2008-08-12 03:33:34 +03:00
|
|
|
FFTComplex *z = (FFTComplex *)output;
|
2006-09-21 19:37:39 +03:00
|
|
|
|
|
|
|
/* pre rotation */
|
2008-08-12 03:33:34 +03:00
|
|
|
for(k=n8-2; k>=0; k-=2) {
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2008-08-12 03:33:34 +03:00
|
|
|
"movaps (%2,%1,2), %%xmm0 \n" // { z[k].re, z[k].im, z[k+1].re, z[k+1].im }
|
|
|
|
"movaps -16(%2,%0,2), %%xmm1 \n" // { z[-k-2].re, z[-k-2].im, z[-k-1].re, z[-k-1].im }
|
|
|
|
"movaps %%xmm0, %%xmm2 \n"
|
|
|
|
"shufps $0x88, %%xmm1, %%xmm0 \n" // { z[k].re, z[k+1].re, z[-k-2].re, z[-k-1].re }
|
|
|
|
"shufps $0x77, %%xmm2, %%xmm1 \n" // { z[-k-1].im, z[-k-2].im, z[k+1].im, z[k].im }
|
|
|
|
"movlps (%3,%1), %%xmm4 \n"
|
|
|
|
"movlps (%4,%1), %%xmm5 \n"
|
|
|
|
"movhps -8(%3,%0), %%xmm4 \n" // { cos[k], cos[k+1], cos[-k-2], cos[-k-1] }
|
|
|
|
"movhps -8(%4,%0), %%xmm5 \n" // { sin[k], sin[k+1], sin[-k-2], sin[-k-1] }
|
|
|
|
"movaps %%xmm0, %%xmm2 \n"
|
|
|
|
"movaps %%xmm1, %%xmm3 \n"
|
|
|
|
"mulps %%xmm5, %%xmm0 \n" // re*sin
|
|
|
|
"mulps %%xmm4, %%xmm1 \n" // im*cos
|
|
|
|
"mulps %%xmm4, %%xmm2 \n" // re*cos
|
|
|
|
"mulps %%xmm5, %%xmm3 \n" // im*sin
|
|
|
|
"subps %%xmm0, %%xmm1 \n" // -> re
|
|
|
|
"addps %%xmm3, %%xmm2 \n" // -> im
|
|
|
|
"movaps %%xmm1, %%xmm0 \n"
|
|
|
|
"unpcklps %%xmm2, %%xmm1 \n" // { z[k], z[k+1] }
|
|
|
|
"unpckhps %%xmm2, %%xmm0 \n" // { z[-k-2], z[-k-1] }
|
|
|
|
::"r"(-4*k), "r"(4*k),
|
|
|
|
"r"(input+n4), "r"(tcos+n8), "r"(tsin+n8)
|
2006-09-21 19:37:39 +03:00
|
|
|
);
|
2009-01-14 01:44:16 +02:00
|
|
|
#if ARCH_X86_64
|
2008-08-12 03:33:34 +03:00
|
|
|
// if we have enough regs, don't let gcc make the luts latency-bound
|
|
|
|
// but if not, latency is faster than spilling
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__("movlps %%xmm0, %0 \n"
|
2008-08-12 03:33:34 +03:00
|
|
|
"movhps %%xmm0, %1 \n"
|
|
|
|
"movlps %%xmm1, %2 \n"
|
|
|
|
"movhps %%xmm1, %3 \n"
|
|
|
|
:"=m"(z[revtab[-k-2]]),
|
|
|
|
"=m"(z[revtab[-k-1]]),
|
|
|
|
"=m"(z[revtab[ k ]]),
|
|
|
|
"=m"(z[revtab[ k+1]])
|
2006-09-21 19:37:39 +03:00
|
|
|
);
|
2008-08-12 03:33:34 +03:00
|
|
|
#else
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__("movlps %%xmm0, %0" :"=m"(z[revtab[-k-2]]));
|
|
|
|
__asm__("movhps %%xmm0, %0" :"=m"(z[revtab[-k-1]]));
|
|
|
|
__asm__("movlps %%xmm1, %0" :"=m"(z[revtab[ k ]]));
|
|
|
|
__asm__("movhps %%xmm1, %0" :"=m"(z[revtab[ k+1]]));
|
2007-05-13 19:32:32 +03:00
|
|
|
#endif
|
2006-09-21 19:37:39 +03:00
|
|
|
}
|
2008-07-13 18:03:58 +03:00
|
|
|
|
2009-09-20 20:30:20 +03:00
|
|
|
ff_fft_dispatch_sse(z, s->nbits);
|
2008-07-13 18:03:58 +03:00
|
|
|
|
2008-08-12 03:33:34 +03:00
|
|
|
/* post rotation + reinterleave + reorder */
|
2008-07-13 18:03:58 +03:00
|
|
|
|
2008-08-12 03:33:34 +03:00
|
|
|
#define CMUL(j,xmm0,xmm1)\
|
|
|
|
"movaps (%2,"#j",2), %%xmm6 \n"\
|
|
|
|
"movaps 16(%2,"#j",2), "#xmm0"\n"\
|
|
|
|
"movaps %%xmm6, "#xmm1"\n"\
|
|
|
|
"movaps "#xmm0",%%xmm7 \n"\
|
|
|
|
"mulps (%3,"#j"), %%xmm6 \n"\
|
|
|
|
"mulps (%4,"#j"), "#xmm0"\n"\
|
|
|
|
"mulps (%4,"#j"), "#xmm1"\n"\
|
|
|
|
"mulps (%3,"#j"), %%xmm7 \n"\
|
|
|
|
"subps %%xmm6, "#xmm0"\n"\
|
|
|
|
"addps %%xmm7, "#xmm1"\n"
|
2006-09-21 19:37:39 +03:00
|
|
|
|
2008-08-12 03:33:34 +03:00
|
|
|
j = -n2;
|
|
|
|
k = n2-16;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2008-08-12 03:33:34 +03:00
|
|
|
"1: \n"
|
|
|
|
CMUL(%0, %%xmm0, %%xmm1)
|
|
|
|
CMUL(%1, %%xmm4, %%xmm5)
|
|
|
|
"shufps $0x1b, %%xmm1, %%xmm1 \n"
|
|
|
|
"shufps $0x1b, %%xmm5, %%xmm5 \n"
|
|
|
|
"movaps %%xmm4, %%xmm6 \n"
|
|
|
|
"unpckhps %%xmm1, %%xmm4 \n"
|
|
|
|
"unpcklps %%xmm1, %%xmm6 \n"
|
|
|
|
"movaps %%xmm0, %%xmm2 \n"
|
|
|
|
"unpcklps %%xmm5, %%xmm0 \n"
|
|
|
|
"unpckhps %%xmm5, %%xmm2 \n"
|
|
|
|
"movaps %%xmm6, (%2,%1,2) \n"
|
|
|
|
"movaps %%xmm4, 16(%2,%1,2) \n"
|
|
|
|
"movaps %%xmm0, (%2,%0,2) \n"
|
|
|
|
"movaps %%xmm2, 16(%2,%0,2) \n"
|
|
|
|
"sub $16, %1 \n"
|
|
|
|
"add $16, %0 \n"
|
|
|
|
"jl 1b \n"
|
|
|
|
:"+&r"(j), "+&r"(k)
|
|
|
|
:"r"(z+n8), "r"(tcos+n8), "r"(tsin+n8)
|
2006-09-21 19:37:39 +03:00
|
|
|
:"memory"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-09-20 20:30:20 +03:00
|
|
|
void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
|
2008-07-13 18:03:58 +03:00
|
|
|
{
|
|
|
|
x86_reg j, k;
|
2009-09-20 20:30:20 +03:00
|
|
|
long n = 1 << s->mdct_bits;
|
2008-08-12 03:33:34 +03:00
|
|
|
long n4 = n >> 2;
|
2008-07-13 18:03:58 +03:00
|
|
|
|
2008-08-12 03:33:34 +03:00
|
|
|
ff_imdct_half_sse(s, output+n4, input);
|
2008-07-13 18:03:58 +03:00
|
|
|
|
|
|
|
j = -n;
|
|
|
|
k = n-16;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2008-08-12 03:33:34 +03:00
|
|
|
"movaps %4, %%xmm7 \n"
|
|
|
|
"1: \n"
|
|
|
|
"movaps (%2,%1), %%xmm0 \n"
|
|
|
|
"movaps (%3,%0), %%xmm1 \n"
|
|
|
|
"shufps $0x1b, %%xmm0, %%xmm0 \n"
|
|
|
|
"shufps $0x1b, %%xmm1, %%xmm1 \n"
|
|
|
|
"xorps %%xmm7, %%xmm0 \n"
|
|
|
|
"movaps %%xmm1, (%3,%1) \n"
|
|
|
|
"movaps %%xmm0, (%2,%0) \n"
|
|
|
|
"sub $16, %1 \n"
|
|
|
|
"add $16, %0 \n"
|
|
|
|
"jl 1b \n"
|
2008-07-13 18:03:58 +03:00
|
|
|
:"+r"(j), "+r"(k)
|
2008-08-12 03:33:34 +03:00
|
|
|
:"r"(output+n4), "r"(output+n4*3),
|
|
|
|
"m"(*m1m1m1m1)
|
2008-07-13 18:03:58 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|