Statistics
| Branch: | Revision:

ffmpeg / libavcodec / x86 / fft_sse.c @ 7160bb71

History | View | Annotate | Download (2.89 KB)

1 bb6f5690 Fabrice Bellard
/*
2
 * FFT/MDCT transform with SSE optimizations
3 46803f4f Loren Merritt
 * Copyright (c) 2008 Loren Merritt
4 bb6f5690 Fabrice Bellard
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 bb6f5690 Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 bb6f5690 Fabrice Bellard
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 bb6f5690 Fabrice Bellard
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 bb6f5690 Fabrice Bellard
 */
21 245976da Diego Biurrun
22
#include "libavutil/x86_cpu.h"
23
#include "libavcodec/dsputil.h"
24 f4863213 Måns Rullgård
#include "fft.h"
25 bb6f5690 Fabrice Bellard
26 c6727809 Måns Rullgård
DECLARE_ALIGNED(16, static const int, m1m1m1m1)[4] =
27 ebbafcb4 Loren Merritt
    { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
28
29 5d0ddd1a Loren Merritt
void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
30
void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
31 bb6f5690 Fabrice Bellard
32 68951ecf Gildas Bazin
void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
33 bb6f5690 Fabrice Bellard
{
34 5d0ddd1a Loren Merritt
    int n = 1 << s->nbits;
35
36
    ff_fft_dispatch_interleave_sse(z, s->nbits);
37
38
    if(n <= 16) {
39
        x86_reg i = -8*n;
40 be449fca Diego Pettenò
        __asm__ volatile(
41 5d0ddd1a Loren Merritt
            "1: \n"
42
            "movaps     (%0,%1), %%xmm0 \n"
43
            "movaps      %%xmm0, %%xmm1 \n"
44
            "unpcklps 16(%0,%1), %%xmm0 \n"
45
            "unpckhps 16(%0,%1), %%xmm1 \n"
46
            "movaps      %%xmm0,   (%0,%1) \n"
47
            "movaps      %%xmm1, 16(%0,%1) \n"
48
            "add $32, %0 \n"
49
            "jl 1b \n"
50
            :"+r"(i)
51
            :"r"(z+n)
52
            :"memory"
53
        );
54
    }
55
}
56 bb6f5690 Fabrice Bellard
57 5d0ddd1a Loren Merritt
void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
58
{
59
    int n = 1 << s->nbits;
60
    int i;
61
    for(i=0; i<n; i+=2) {
62 be449fca Diego Pettenò
        __asm__ volatile(
63 5d0ddd1a Loren Merritt
            "movaps %2, %%xmm0 \n"
64
            "movlps %%xmm0, %0 \n"
65
            "movhps %%xmm0, %1 \n"
66
            :"=m"(s->tmp_buf[s->revtab[i]]),
67
             "=m"(s->tmp_buf[s->revtab[i+1]])
68
            :"m"(z[i])
69
        );
70
    }
71
    memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
72 bb6f5690 Fabrice Bellard
}
73 e1958604 Fabrice Bellard
74 01b22147 Måns Rullgård
void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
75 b9fa3208 Loren Merritt
{
76
    x86_reg j, k;
77 cb4f1246 Alex Converse
    long n = s->mdct_size;
78 46803f4f Loren Merritt
    long n4 = n >> 2;
79 b9fa3208 Loren Merritt
80 46803f4f Loren Merritt
    ff_imdct_half_sse(s, output+n4, input);
81 b9fa3208 Loren Merritt
82
    j = -n;
83
    k = n-16;
84 be449fca Diego Pettenò
    __asm__ volatile(
85 46803f4f Loren Merritt
        "movaps %4, %%xmm7 \n"
86
        "1: \n"
87
        "movaps       (%2,%1), %%xmm0 \n"
88
        "movaps       (%3,%0), %%xmm1 \n"
89
        "shufps $0x1b, %%xmm0, %%xmm0 \n"
90
        "shufps $0x1b, %%xmm1, %%xmm1 \n"
91
        "xorps         %%xmm7, %%xmm0 \n"
92
        "movaps        %%xmm1, (%3,%1) \n"
93
        "movaps        %%xmm0, (%2,%0) \n"
94
        "sub $16, %1 \n"
95
        "add $16, %0 \n"
96
        "jl 1b \n"
97 b9fa3208 Loren Merritt
        :"+r"(j), "+r"(k)
98 46803f4f Loren Merritt
        :"r"(output+n4), "r"(output+n4*3),
99
         "m"(*m1m1m1m1)
100 b9fa3208 Loren Merritt
    );
101
}