]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/fft_sse.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / x86 / fft_sse.c
1 /*
2  * FFT/MDCT transform with SSE optimizations
3  * Copyright (c) 2008 Loren Merritt
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/x86_cpu.h"
23 #include "libavcodec/dsputil.h"
24 #include "fft.h"
25
26 DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] =
27     { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
28
29 void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
30 void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
31 void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits);
32
33 void ff_fft_calc_avx(FFTContext *s, FFTComplex *z)
34 {
35     ff_fft_dispatch_interleave_avx(z, s->nbits);
36 }
37
38 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
39 {
40     int n = 1 << s->nbits;
41
42     ff_fft_dispatch_interleave_sse(z, s->nbits);
43
44     if(n <= 16) {
45         x86_reg i = -8*n;
46         __asm__ volatile(
47             "1: \n"
48             "movaps     (%0,%1), %%xmm0 \n"
49             "movaps      %%xmm0, %%xmm1 \n"
50             "unpcklps 16(%0,%1), %%xmm0 \n"
51             "unpckhps 16(%0,%1), %%xmm1 \n"
52             "movaps      %%xmm0,   (%0,%1) \n"
53             "movaps      %%xmm1, 16(%0,%1) \n"
54             "add $32, %0 \n"
55             "jl 1b \n"
56             :"+r"(i)
57             :"r"(z+n)
58             :"memory"
59         );
60     }
61 }
62
63 void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
64 {
65     int n = 1 << s->nbits;
66     int i;
67     for(i=0; i<n; i+=2) {
68         __asm__ volatile(
69             "movaps %2, %%xmm0 \n"
70             "movlps %%xmm0, %0 \n"
71             "movhps %%xmm0, %1 \n"
72             :"=m"(s->tmp_buf[s->revtab[i]]),
73              "=m"(s->tmp_buf[s->revtab[i+1]])
74             :"m"(z[i])
75         );
76     }
77     memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
78 }
79
80 void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
81 {
82     x86_reg j, k;
83     long n = s->mdct_size;
84     long n4 = n >> 2;
85
86     s->imdct_half(s, output + n4, input);
87
88     j = -n;
89     k = n-16;
90     __asm__ volatile(
91         "movaps "MANGLE(ff_m1m1m1m1)", %%xmm7 \n"
92         "1: \n"
93         "movaps       (%2,%1), %%xmm0 \n"
94         "movaps       (%3,%0), %%xmm1 \n"
95         "shufps $0x1b, %%xmm0, %%xmm0 \n"
96         "shufps $0x1b, %%xmm1, %%xmm1 \n"
97         "xorps         %%xmm7, %%xmm0 \n"
98         "movaps        %%xmm1, (%3,%1) \n"
99         "movaps        %%xmm0, (%2,%0) \n"
100         "sub $16, %1 \n"
101         "add $16, %0 \n"
102         "jl 1b \n"
103         :"+r"(j), "+r"(k)
104         :"r"(output+n4), "r"(output+n4*3)
105         XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm7")
106     );
107 }
108