4 * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
5 * Based on code Copyright (c) 2002 Fabrice Bellard.
7 * This library 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 of the License, or (at your option) any later version.
12 * This library 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 this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "../dsputil.h"
23 #include "gcc_fixes.h"
25 #include "dsputil_altivec.h"
28 those three macros are from libavcodec/fft.c
29 and are required for the reference C code
32 #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
34 FFTSample ax, ay, bx, by;\
44 #define MUL16(a,b) ((a) * (b))
45 #define CMUL(pre, pim, are, aim, bre, bim) \
47 pre = (MUL16(are, bre) - MUL16(aim, bim));\
48 pim = (MUL16(are, bim) + MUL16(bre, aim));\
53 * Do a complex FFT with the parameters defined in ff_fft_init(). The
54 * input data must be permuted before with s->revtab table. No
55 * 1.0/sqrt(n) normalization is done.
57 * This code assumes that the 'z' pointer is 16 bytes-aligned
58 * It also assumes all FFTComplex are 8 bytes-aligned pair of float
59 * The code is exactly the same as the SSE version, except
60 * that successive MUL + ADD/SUB have been merged into
61 * fused multiply-add ('vec_madd' in altivec)
63 void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
65 POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6);
66 #ifdef ALTIVEC_USE_REFERENCE_C_CODE
70 register FFTComplex *p, *q;
71 FFTComplex *exptab = s->exptab;
73 FFTSample tmp_re, tmp_im;
75 POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
84 BF(p[0].re, p[0].im, p[1].re, p[1].im,
85 p[0].re, p[0].im, p[1].re, p[1].im);
96 BF(p[0].re, p[0].im, p[2].re, p[2].im,
97 p[0].re, p[0].im, p[2].re, p[2].im);
98 BF(p[1].re, p[1].im, p[3].re, p[3].im,
99 p[1].re, p[1].im, -p[3].im, p[3].re);
104 BF(p[0].re, p[0].im, p[2].re, p[2].im,
105 p[0].re, p[0].im, p[2].re, p[2].im);
106 BF(p[1].re, p[1].im, p[3].re, p[3].im,
107 p[1].re, p[1].im, p[3].im, -p[3].re);
119 for (j = 0; j < nblocks; ++j) {
120 BF(p->re, p->im, q->re, q->im,
121 p->re, p->im, q->re, q->im);
125 for(l = nblocks; l < np2; l += nblocks) {
126 CMUL(tmp_re, tmp_im, exptab[l].re, exptab[l].im, q->re, q->im);
127 BF(p->re, p->im, q->re, q->im,
128 p->re, p->im, tmp_re, tmp_im);
136 nblocks = nblocks >> 1;
137 nloops = nloops << 1;
138 } while (nblocks != 0);
140 POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
142 #else /* ALTIVEC_USE_REFERENCE_C_CODE */
144 register const vector float vczero = (const vector float)(0.);
146 register const vector float vczero = (const vector float){0.,0.,0.,0.};
152 register FFTComplex *p, *q;
153 FFTComplex *cptr, *cptr1;
156 POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
161 vector float *r, a, b, a1, c1, c2;
163 r = (vector float *)&z[0];
179 a1 = vec_ld(sizeof(vector float), r);
181 b = vec_perm(a,a,vcprmle(1,0,3,2));
182 a = vec_madd(a,c1,b);
183 /* do the pass 0 butterfly */
185 b = vec_perm(a1,a1,vcprmle(1,0,3,2));
186 b = vec_madd(a1,c1,b);
187 /* do the pass 0 butterfly */
189 /* multiply third by -i */
190 b = vec_perm(b,b,vcprmle(2,3,1,0));
192 /* do the pass 1 butterfly */
193 vec_st(vec_madd(b,c2,a), 0, r);
194 vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
214 vector float a,b,c,t1;
216 a = vec_ld(0, (float*)p);
217 b = vec_ld(0, (float*)q);
220 c = vec_ld(0, (float*)cptr);
222 t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
223 c = vec_ld(sizeof(vector float), (float*)cptr);
225 b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
228 vec_st(vec_add(a,b), 0, (float*)p);
229 vec_st(vec_sub(a,b), 0, (float*)q);
240 nblocks = nblocks >> 1;
241 nloops = nloops << 1;
242 } while (nblocks != 0);
244 POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
246 #endif /* ALTIVEC_USE_REFERENCE_C_CODE */