2 * FFT/MDCT transform with Extended 3DNow! optimizations
3 * Copyright (c) 2006 Zuxy MENG Jie, Loren Merritt
4 * Based on fft_sse.c copyright (c) 2002 Fabrice Bellard.
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "../dsputil.h"
24 static const int p1m1[2] __attribute__((aligned(8))) =
27 static const int m1p1[2] __attribute__((aligned(8))) =
30 void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z)
38 /* FEMMS is not a must here but recommended by AMD */
41 ::"m"(*(s->inverse ? m1p1 : p1m1))
48 "movq (%0,%1), %%mm0 \n\t"
49 "movq 16(%0,%1), %%mm1 \n\t"
50 "movq 8(%0,%1), %%mm2 \n\t"
51 "movq 24(%0,%1), %%mm3 \n\t"
52 "movq %%mm0, %%mm4 \n\t"
53 "movq %%mm1, %%mm5 \n\t"
54 "pfadd %%mm2, %%mm0 \n\t"
55 "pfadd %%mm3, %%mm1 \n\t"
56 "pfsub %%mm2, %%mm4 \n\t"
57 "pfsub %%mm3, %%mm5 \n\t"
58 "movq %%mm0, %%mm2 \n\t"
59 "pswapd %%mm5, %%mm5 \n\t"
60 "movq %%mm4, %%mm3 \n\t"
61 "pxor %%mm7, %%mm5 \n\t"
62 "pfadd %%mm1, %%mm0 \n\t"
63 "pfadd %%mm5, %%mm4 \n\t"
64 "pfsub %%mm1, %%mm2 \n\t"
65 "pfsub %%mm5, %%mm3 \n\t"
66 "movq %%mm0, (%0,%1) \n\t"
67 "movq %%mm4, 8(%0,%1) \n\t"
68 "movq %%mm2, 16(%0,%1) \n\t"
69 "movq %%mm3, 24(%0,%1) \n\t"
76 nblocks = 1 << (ln-3);
87 "movq (%1,%0), %%mm0 \n\t"
88 "movq 8(%1,%0), %%mm1 \n\t"
89 "movq (%2,%0), %%mm2 \n\t"
90 "movq 8(%2,%0), %%mm3 \n\t"
91 "movq (%3,%0,2), %%mm4 \n\t"
92 "movq 8(%3,%0,2), %%mm5 \n\t"
93 "pswapd %%mm4, %%mm6 \n\t" // no need for cptr[2] & cptr[3]
94 "pswapd %%mm5, %%mm7 \n\t"
95 "pfmul %%mm2, %%mm4 \n\t" // cre*re cim*im
96 "pfmul %%mm3, %%mm5 \n\t"
97 "pfmul %%mm2, %%mm6 \n\t" // cim*re cre*im
98 "pfmul %%mm3, %%mm7 \n\t"
99 "pfpnacc %%mm6, %%mm4 \n\t" // cre*re-cim*im cim*re+cre*im
100 "pfpnacc %%mm7, %%mm5 \n\t"
101 "movq %%mm0, %%mm2 \n\t"
102 "movq %%mm1, %%mm3 \n\t"
103 "pfadd %%mm4, %%mm0 \n\t"
104 "pfadd %%mm5, %%mm1 \n\t"
105 "pfsub %%mm4, %%mm2 \n\t"
106 "pfsub %%mm5, %%mm3 \n\t"
107 "movq %%mm0, (%1,%0) \n\t"
108 "movq %%mm1, 8(%1,%0) \n\t"
109 "movq %%mm2, (%2,%0) \n\t"
110 "movq %%mm3, 8(%2,%0) \n\t"
113 :"r"(p), "r"(p + nloops), "r"(cptr)
120 } while (nblocks != 0);
121 asm volatile("femms");
124 void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
125 const FFTSample *input, FFTSample *tmp)
127 long k, n8, n4, n2, n;
128 const uint16_t *revtab = s->fft.revtab;
129 const FFTSample *tcos = s->tcos;
130 const FFTSample *tsin = s->tsin;
131 const FFTSample *in1, *in2;
132 FFTComplex *z = (FFTComplex *)tmp;
141 in2 = input + n2 - 1;
142 for(k = 0; k < n4; k++) {
143 // FIXME a single block is faster, but gcc 2.95 and 3.4.x on 32bit can't compile it
145 "movd %0, %%mm0 \n\t"
146 "movd %2, %%mm1 \n\t"
147 "punpckldq %1, %%mm0 \n\t"
148 "punpckldq %3, %%mm1 \n\t"
149 "movq %%mm0, %%mm2 \n\t"
150 "pfmul %%mm1, %%mm0 \n\t"
151 "pswapd %%mm1, %%mm1 \n\t"
152 "pfmul %%mm1, %%mm2 \n\t"
153 "pfpnacc %%mm2, %%mm0 \n\t"
154 ::"m"(in2[-2*k]), "m"(in1[2*k]),
155 "m"(tcos[k]), "m"(tsin[k])
158 "movq %%mm0, %0 \n\t"
163 ff_fft_calc(&s->fft, z);
165 /* post rotation + reordering */
166 for(k = 0; k < n4; k++) {
168 "movq %0, %%mm0 \n\t"
169 "movd %1, %%mm1 \n\t"
170 "punpckldq %2, %%mm1 \n\t"
171 "movq %%mm0, %%mm2 \n\t"
172 "pfmul %%mm1, %%mm0 \n\t"
173 "pswapd %%mm1, %%mm1 \n\t"
174 "pfmul %%mm1, %%mm2 \n\t"
175 "pfpnacc %%mm2, %%mm0 \n\t"
176 "movq %%mm0, %0 \n\t"
178 :"m"(tcos[k]), "m"(tsin[k])
183 asm volatile("movd %0, %%mm7" ::"r"(1<<31));
186 "movq (%4,%0), %%mm0 \n\t" // z[n8+k]
188 "pswapd -8(%4,%0), %%mm1 \n\t" // z[n8-1-k]
189 "movq %%mm0, %%mm2 \n\t"
190 "pxor %%mm7, %%mm2 \n\t"
191 "punpckldq %%mm1, %%mm2 \n\t"
192 "pswapd %%mm2, %%mm3 \n\t"
193 "punpckhdq %%mm1, %%mm0 \n\t"
194 "pswapd %%mm0, %%mm4 \n\t"
195 "pxor %%mm7, %%mm0 \n\t"
196 "pxor %%mm7, %%mm4 \n\t"
197 "movq %%mm3, -8(%3,%0) \n\t" // output[n-2-2*k] = { z[n8-1-k].im, -z[n8+k].re }
198 "movq %%mm4, -8(%2,%0) \n\t" // output[n2-2-2*k]= { -z[n8-1-k].re, z[n8+k].im }
200 "movq %%mm0, (%1,%0) \n\t" // output[2*k] = { -z[n8+k].im, z[n8-1-k].re }
201 "movq %%mm2, (%2,%0) \n\t" // output[n2+2*k] = { -z[n8+k].re, z[n8-1-k].im }
205 :"r"(output), "r"(output+n2), "r"(output+n), "r"(z+n8)
208 asm volatile("femms");