]> git.sesse.net Git - ffmpeg/blob - libavcodec/i386/fft_sse.c
ff_fft_calc_3dn/3dn2/sse: convert intrinsics to inline asm.
[ffmpeg] / libavcodec / i386 / fft_sse.c
1 /*
2  * FFT/MDCT transform with SSE optimizations
3  * Copyright (c) 2002 Fabrice Bellard.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 #include "../dsputil.h"
20
21 static const int p1p1p1m1[4] __attribute__((aligned(16))) =
22     { 0, 0, 0, 1 << 31 };
23
24 static const int p1p1m1p1[4] __attribute__((aligned(16))) =
25     { 0, 0, 1 << 31, 0 };
26
27 static const int p1p1m1m1[4] __attribute__((aligned(16))) =
28     { 0, 0, 1 << 31, 1 << 31 };
29
30 #if 0
31 static void print_v4sf(const char *str, __m128 a)
32 {
33     float *p = (float *)&a;
34     printf("%s: %f %f %f %f\n",
35            str, p[0], p[1], p[2], p[3]);
36 }
37 #endif
38
39 /* XXX: handle reverse case */
40 void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
41 {
42     int ln = s->nbits;
43     long i, j;
44     long nblocks, nloops;
45     FFTComplex *p, *cptr;
46
47     asm volatile(
48         "movaps %0, %%xmm4 \n\t"
49         "movaps %1, %%xmm5 \n\t"
50         ::"m"(*p1p1m1m1),
51           "m"(*(s->inverse ? p1p1m1p1 : p1p1p1m1))
52     );
53
54     i = 8 << ln;
55     asm volatile(
56         "1: \n\t"
57         "sub $32, %0 \n\t"
58         /* do the pass 0 butterfly */
59         "movaps   (%0,%1), %%xmm0 \n\t"
60         "movaps    %%xmm0, %%xmm1 \n\t"
61         "shufps     $0x4E, %%xmm0, %%xmm0 \n\t"
62         "xorps     %%xmm4, %%xmm1 \n\t"
63         "addps     %%xmm1, %%xmm0 \n\t"
64         "movaps 16(%0,%1), %%xmm2 \n\t"
65         "movaps    %%xmm2, %%xmm3 \n\t"
66         "shufps     $0x4E, %%xmm2, %%xmm2 \n\t"
67         "xorps     %%xmm4, %%xmm3 \n\t"
68         "addps     %%xmm3, %%xmm2 \n\t"
69         /* multiply third by -i */
70         /* by toggling the sign bit */
71         "shufps     $0xB4, %%xmm2, %%xmm2 \n\t"
72         "xorps     %%xmm5, %%xmm2 \n\t"
73         /* do the pass 1 butterfly */
74         "movaps    %%xmm0, %%xmm1 \n\t"
75         "addps     %%xmm2, %%xmm0 \n\t"
76         "subps     %%xmm2, %%xmm1 \n\t"
77         "movaps    %%xmm0,   (%0,%1) \n\t"
78         "movaps    %%xmm1, 16(%0,%1) \n\t"
79         "jg 1b \n\t"
80         :"+r"(i)
81         :"r"(z)
82     );
83     /* pass 2 .. ln-1 */
84
85     nblocks = 1 << (ln-3);
86     nloops = 1 << 2;
87     cptr = s->exptab1;
88     do {
89         p = z;
90         j = nblocks;
91         do {
92             i = nloops*8;
93             asm volatile(
94                 "1: \n\t"
95                 "sub $16, %0 \n\t"
96                 "movaps    (%2,%0), %%xmm1 \n\t"
97                 "movaps    (%1,%0), %%xmm0 \n\t"
98                 "movaps     %%xmm1, %%xmm2 \n\t"
99                 "shufps      $0xA0, %%xmm1, %%xmm1 \n\t"
100                 "shufps      $0xF5, %%xmm2, %%xmm2 \n\t"
101                 "mulps   (%3,%0,2), %%xmm1 \n\t" //  cre*re cim*re
102                 "mulps 16(%3,%0,2), %%xmm2 \n\t" // -cim*im cre*im
103                 "addps      %%xmm2, %%xmm1 \n\t"
104                 "movaps     %%xmm0, %%xmm3 \n\t"
105                 "addps      %%xmm1, %%xmm0 \n\t"
106                 "subps      %%xmm1, %%xmm3 \n\t"
107                 "movaps     %%xmm0, (%1,%0) \n\t"
108                 "movaps     %%xmm3, (%2,%0) \n\t"
109                 "jg 1b \n\t"
110                 :"+r"(i)
111                 :"r"(p), "r"(p + nloops), "r"(cptr)
112             );
113             p += nloops*2;
114         } while (--j);
115         cptr += nloops*2;
116         nblocks >>= 1;
117         nloops <<= 1;
118     } while (nblocks != 0);
119 }
120