2
* FFT/MDCT transform with SSE optimizations
3
* Copyright (c) 2002 Fabrice Bellard.
5
* This file is part of FFmpeg.
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.
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.
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
23
static const int p1p1p1m1[4] __attribute__((aligned(16))) =
26
static const int p1p1m1p1[4] __attribute__((aligned(16))) =
29
static const int p1p1m1m1[4] __attribute__((aligned(16))) =
30
{ 0, 0, 1 << 31, 1 << 31 };
32
static const int p1m1p1m1[4] __attribute__((aligned(16))) =
33
{ 0, 1 << 31, 0, 1 << 31 };
35
static const int m1m1m1m1[4] __attribute__((aligned(16))) =
36
{ 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
39
static void print_v4sf(const char *str, __m128 a)
41
float *p = (float *)&a;
42
printf("%s: %f %f %f %f\n",
43
str, p[0], p[1], p[2], p[3]);
47
/* XXX: handle reverse case */
48
void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
56
"movaps %0, %%xmm4 \n\t"
57
"movaps %1, %%xmm5 \n\t"
59
"m"(*(s->inverse ? p1p1m1p1 : p1p1p1m1))
66
/* do the pass 0 butterfly */
67
"movaps (%0,%1), %%xmm0 \n\t"
68
"movaps %%xmm0, %%xmm1 \n\t"
69
"shufps $0x4E, %%xmm0, %%xmm0 \n\t"
70
"xorps %%xmm4, %%xmm1 \n\t"
71
"addps %%xmm1, %%xmm0 \n\t"
72
"movaps 16(%0,%1), %%xmm2 \n\t"
73
"movaps %%xmm2, %%xmm3 \n\t"
74
"shufps $0x4E, %%xmm2, %%xmm2 \n\t"
75
"xorps %%xmm4, %%xmm3 \n\t"
76
"addps %%xmm3, %%xmm2 \n\t"
77
/* multiply third by -i */
78
/* by toggling the sign bit */
79
"shufps $0xB4, %%xmm2, %%xmm2 \n\t"
80
"xorps %%xmm5, %%xmm2 \n\t"
81
/* do the pass 1 butterfly */
82
"movaps %%xmm0, %%xmm1 \n\t"
83
"addps %%xmm2, %%xmm0 \n\t"
84
"subps %%xmm2, %%xmm1 \n\t"
85
"movaps %%xmm0, (%0,%1) \n\t"
86
"movaps %%xmm1, 16(%0,%1) \n\t"
93
nblocks = 1 << (ln-3);
104
"movaps (%2,%0), %%xmm1 \n\t"
105
"movaps (%1,%0), %%xmm0 \n\t"
106
"movaps 16(%2,%0), %%xmm5 \n\t"
107
"movaps 16(%1,%0), %%xmm4 \n\t"
108
"movaps %%xmm1, %%xmm2 \n\t"
109
"movaps %%xmm5, %%xmm6 \n\t"
110
"shufps $0xA0, %%xmm1, %%xmm1 \n\t"
111
"shufps $0xF5, %%xmm2, %%xmm2 \n\t"
112
"shufps $0xA0, %%xmm5, %%xmm5 \n\t"
113
"shufps $0xF5, %%xmm6, %%xmm6 \n\t"
114
"mulps (%3,%0,2), %%xmm1 \n\t" // cre*re cim*re
115
"mulps 16(%3,%0,2), %%xmm2 \n\t" // -cim*im cre*im
116
"mulps 32(%3,%0,2), %%xmm5 \n\t" // cre*re cim*re
117
"mulps 48(%3,%0,2), %%xmm6 \n\t" // -cim*im cre*im
118
"addps %%xmm2, %%xmm1 \n\t"
119
"addps %%xmm6, %%xmm5 \n\t"
120
"movaps %%xmm0, %%xmm3 \n\t"
121
"movaps %%xmm4, %%xmm7 \n\t"
122
"addps %%xmm1, %%xmm0 \n\t"
123
"subps %%xmm1, %%xmm3 \n\t"
124
"addps %%xmm5, %%xmm4 \n\t"
125
"subps %%xmm5, %%xmm7 \n\t"
126
"movaps %%xmm0, (%1,%0) \n\t"
127
"movaps %%xmm3, (%2,%0) \n\t"
128
"movaps %%xmm4, 16(%1,%0) \n\t"
129
"movaps %%xmm7, 16(%2,%0) \n\t"
132
:"r"(p), "r"(p + nloops), "r"(cptr)
139
} while (nblocks != 0);
142
void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output,
143
const FFTSample *input, FFTSample *tmp)
145
long k, n8, n4, n2, n;
146
const uint16_t *revtab = s->fft.revtab;
147
const FFTSample *tcos = s->tcos;
148
const FFTSample *tsin = s->tsin;
149
const FFTSample *in1, *in2;
150
FFTComplex *z = (FFTComplex *)tmp;
158
asm volatile ("movaps %0, %%xmm8\n\t"::"m"(*p1m1p1m1));
159
#define P1M1P1M1 "%%xmm8"
161
#define P1M1P1M1 "%4"
166
in2 = input + n2 - 4;
168
/* Complex multiplication */
169
for (k = 0; k < n4; k += 4) {
171
"movaps %0, %%xmm0 \n\t" // xmm0 = r0 X r1 X : in2
172
"movaps %1, %%xmm3 \n\t" // xmm3 = X i1 X i0: in1
173
"movaps -16+1*%0, %%xmm4 \n\t" // xmm4 = r0 X r1 X : in2
174
"movaps 16+1*%1, %%xmm7 \n\t" // xmm7 = X i1 X i0: in1
175
"movlps %2, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos
176
"movlps %3, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin
177
"movlps 8+1*%2, %%xmm5 \n\t" // xmm5 = X X R1 R0: tcos
178
"movlps 8+1*%3, %%xmm6 \n\t" // xmm6 = X X I1 I0: tsin
179
"shufps $95, %%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0
180
"shufps $160,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0
181
"shufps $95, %%xmm4, %%xmm4 \n\t" // xmm4 = r1 r1 r0 r0
182
"shufps $160,%%xmm7, %%xmm7 \n\t" // xmm7 = i1 i1 i0 i0
183
"unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0
184
"unpcklps %%xmm6, %%xmm5 \n\t" // xmm5 = I1 R1 I0 R0
185
"movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0
186
"movaps %%xmm5, %%xmm6 \n\t" // xmm6 = I1 R1 I0 R0
187
"xorps "P1M1P1M1", %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0
188
"xorps "P1M1P1M1", %%xmm6 \n\t" // xmm6 = -I1 R1 -I0 R0
189
"mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR
190
"mulps %%xmm5, %%xmm4 \n\t" // xmm4 = rI rR rI rR
191
"shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0
192
"shufps $177,%%xmm6, %%xmm6 \n\t" // xmm6 = R1 -I1 R0 -I0
193
"mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii
194
"mulps %%xmm6, %%xmm7 \n\t" // xmm7 = Ri -Ii Ri -Ii
195
"addps %%xmm3, %%xmm0 \n\t" // xmm0 = result
196
"addps %%xmm7, %%xmm4 \n\t" // xmm4 = result
197
::"m"(in2[-2*k]), "m"(in1[2*k]),
198
"m"(tcos[k]), "m"(tsin[k])
203
/* Should be in the same block, hack for gcc2.95 & gcc3 */
205
"movlps %%xmm0, %0 \n\t"
206
"movhps %%xmm0, %1 \n\t"
207
"movlps %%xmm4, %2 \n\t"
208
"movhps %%xmm4, %3 \n\t"
209
:"=m"(z[revtab[k]]), "=m"(z[revtab[k + 1]]),
210
"=m"(z[revtab[k + 2]]), "=m"(z[revtab[k + 3]])
214
ff_fft_calc_sse(&s->fft, z);
218
#define P1M1P1M1 "%3"
221
/* post rotation + reordering */
222
for (k = 0; k < n4; k += 4) {
224
"movaps %0, %%xmm0 \n\t" // xmm0 = i1 r1 i0 r0: z
225
"movaps 16+1*%0, %%xmm4 \n\t" // xmm4 = i1 r1 i0 r0: z
226
"movlps %1, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos
227
"movlps 8+1*%1, %%xmm5 \n\t" // xmm5 = X X R1 R0: tcos
228
"movaps %%xmm0, %%xmm3 \n\t" // xmm3 = i1 r1 i0 r0
229
"movaps %%xmm4, %%xmm7 \n\t" // xmm7 = i1 r1 i0 r0
230
"movlps %2, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin
231
"movlps 8+1*%2, %%xmm6 \n\t" // xmm6 = X X I1 I0: tsin
232
"shufps $160,%%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0
233
"shufps $245,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0
234
"shufps $160,%%xmm4, %%xmm4 \n\t" // xmm4 = r1 r1 r0 r0
235
"shufps $245,%%xmm7, %%xmm7 \n\t" // xmm7 = i1 i1 i0 i0
236
"unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0
237
"unpcklps %%xmm6, %%xmm5 \n\t" // xmm5 = I1 R1 I0 R0
238
"movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0
239
"movaps %%xmm5, %%xmm6 \n\t" // xmm6 = I1 R1 I0 R0
240
"xorps "P1M1P1M1", %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0
241
"mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR
242
"xorps "P1M1P1M1", %%xmm6 \n\t" // xmm6 = -I1 R1 -I0 R0
243
"mulps %%xmm5, %%xmm4 \n\t" // xmm4 = rI rR rI rR
244
"shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0
245
"shufps $177,%%xmm6, %%xmm6 \n\t" // xmm6 = R1 -I1 R0 -I0
246
"mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii
247
"mulps %%xmm6, %%xmm7 \n\t" // xmm7 = Ri -Ii Ri -Ii
248
"addps %%xmm3, %%xmm0 \n\t" // xmm0 = result
249
"addps %%xmm7, %%xmm4 \n\t" // xmm4 = result
250
"movaps %%xmm0, %0 \n\t"
251
"movaps %%xmm4, 16+1*%0\n\t"
253
:"m"(tcos[k]), "m"(tsin[k])
272
asm volatile("movaps %0, %%xmm7 \n\t"::"m"(*m1m1m1m1));
275
"movaps -16(%4,%0), %%xmm1 \n\t" // xmm1 = 4 5 6 7 = z[-2-k]
277
"movaps (%4,%0), %%xmm0 \n\t" // xmm0 = 0 1 2 3 = z[k]
278
"xorps %%xmm7, %%xmm0 \n\t" // xmm0 = -0 -1 -2 -3
279
"movaps %%xmm0, %%xmm2 \n\t" // xmm2 = -0 -1 -2 -3
280
"shufps $141,%%xmm1, %%xmm0 \n\t" // xmm0 = -1 -3 4 6
281
"shufps $216,%%xmm1, %%xmm2 \n\t" // xmm2 = -0 -2 5 7
282
"shufps $156,%%xmm0, %%xmm0 \n\t" // xmm0 = -1 6 -3 4 !
283
"shufps $156,%%xmm2, %%xmm2 \n\t" // xmm2 = -0 7 -2 5 !
284
"movaps %%xmm0, (%1,%0) \n\t" // output[2*k]
285
"movaps %%xmm2, (%2,%0) \n\t" // output[n2+2*k]
287
"shufps $27, %%xmm0, %%xmm0 \n\t" // xmm0 = 4 -3 6 -1
288
"xorps %%xmm7, %%xmm0 \n\t" // xmm0 = -4 3 -6 1 !
289
"shufps $27, %%xmm2, %%xmm2 \n\t" // xmm2 = 5 -2 7 -0 !
290
"movaps %%xmm0, -16(%2,%0) \n\t" // output[n2-4-2*k]
291
"movaps %%xmm2, -16(%3,%0) \n\t" // output[n-4-2*k]
295
:"r"(output), "r"(output+n2), "r"(output+n), "r"(z+n8)