3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 FUNCTION(fft_real,pass_4) (const BASE in[],
27 const TYPE(gsl_complex) twiddle1[],
28 const TYPE(gsl_complex) twiddle2[],
29 const TYPE(gsl_complex) twiddle3[])
33 const size_t factor = 4;
34 const size_t m = n / factor;
35 const size_t q = n / product;
36 const size_t product_1 = product / factor;
38 for (k1 = 0; k1 < q; k1++)
40 const size_t from0 = k1 * product_1;
41 const size_t from1 = from0 + m;
42 const size_t from2 = from1 + m;
43 const size_t from3 = from2 + m;
45 const ATOMIC z0_real = VECTOR(in,istride,from0);
46 const ATOMIC z1_real = VECTOR(in,istride,from1);
47 const ATOMIC z2_real = VECTOR(in,istride,from2);
48 const ATOMIC z3_real = VECTOR(in,istride,from3);
50 /* compute x = W(4) z */
53 const ATOMIC t1_real = z0_real + z2_real;
56 const ATOMIC t2_real = z1_real + z3_real;
59 const ATOMIC t3_real = z0_real - z2_real;
61 /* t4 = - (z1 - z3) */
62 const ATOMIC t4_real = -(z1_real - z3_real);
65 const ATOMIC x0_real = t1_real + t2_real;
68 const ATOMIC x1_real = t3_real;
69 const ATOMIC x1_imag = t4_real;
72 const ATOMIC x2_real = t1_real - t2_real;
74 const size_t to0 = product * k1;
75 const size_t to1 = to0 + 2 * product_1 - 1;
76 const size_t to2 = to1 + 2 * product_1;
78 VECTOR(out,ostride,to0) = x0_real;
79 VECTOR(out,ostride,to1) = x1_real;
80 VECTOR(out,ostride,to1 + 1) = x1_imag;
81 VECTOR(out,ostride,to2) = x2_real;
87 for (k = 1; k < (product_1 + 1) / 2; k++)
89 ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag;
90 w1_real = GSL_REAL(twiddle1[k - 1]);
91 w1_imag = -GSL_IMAG(twiddle1[k - 1]);
92 w2_real = GSL_REAL(twiddle2[k - 1]);
93 w2_imag = -GSL_IMAG(twiddle2[k - 1]);
94 w3_real = GSL_REAL(twiddle3[k - 1]);
95 w3_imag = -GSL_IMAG(twiddle3[k - 1]);
97 for (k1 = 0; k1 < q; k1++)
99 const size_t from0 = k1 * product_1 + 2 * k - 1;
100 const size_t from1 = from0 + m;
101 const size_t from2 = from1 + m;
102 const size_t from3 = from2 + m;
104 const ATOMIC f0_real = VECTOR(in,istride,from0);
105 const ATOMIC f0_imag = VECTOR(in,istride,from0 + 1);
106 const ATOMIC f1_real = VECTOR(in,istride,from1);
107 const ATOMIC f1_imag = VECTOR(in,istride,from1 + 1);
108 const ATOMIC f2_real = VECTOR(in,istride,from2);
109 const ATOMIC f2_imag = VECTOR(in,istride,from2 + 1);
110 const ATOMIC f3_real = VECTOR(in,istride,from3);
111 const ATOMIC f3_imag = VECTOR(in,istride,from3 + 1);
113 const ATOMIC z0_real = f0_real;
114 const ATOMIC z0_imag = f0_imag;
115 const ATOMIC z1_real = w1_real * f1_real - w1_imag * f1_imag;
116 const ATOMIC z1_imag = w1_real * f1_imag + w1_imag * f1_real;
117 const ATOMIC z2_real = w2_real * f2_real - w2_imag * f2_imag;
118 const ATOMIC z2_imag = w2_real * f2_imag + w2_imag * f2_real;
119 const ATOMIC z3_real = w3_real * f3_real - w3_imag * f3_imag;
120 const ATOMIC z3_imag = w3_real * f3_imag + w3_imag * f3_real;
122 /* compute x = W(4) z */
125 const ATOMIC t1_real = z0_real + z2_real;
126 const ATOMIC t1_imag = z0_imag + z2_imag;
129 const ATOMIC t2_real = z1_real + z3_real;
130 const ATOMIC t2_imag = z1_imag + z3_imag;
133 const ATOMIC t3_real = z0_real - z2_real;
134 const ATOMIC t3_imag = z0_imag - z2_imag;
136 /* t4 = - (z1 - z3) */
137 const ATOMIC t4_real = -(z1_real - z3_real);
138 const ATOMIC t4_imag = -(z1_imag - z3_imag);
141 const ATOMIC x0_real = t1_real + t2_real;
142 const ATOMIC x0_imag = t1_imag + t2_imag;
145 const ATOMIC x1_real = t3_real - t4_imag;
146 const ATOMIC x1_imag = t3_imag + t4_real;
149 const ATOMIC x2_real = t1_real - t2_real;
150 const ATOMIC x2_imag = t1_imag - t2_imag;
153 const ATOMIC x3_real = t3_real + t4_imag;
154 const ATOMIC x3_imag = t3_imag - t4_real;
156 const size_t to0 = k1 * product + 2 * k - 1;
157 const size_t to1 = to0 + 2 * product_1;
158 const size_t to2 = 2 * product_1 - 2 * k + k1 * product - 1;
159 const size_t to3 = to2 + 2 * product_1;
161 VECTOR(out,ostride,to0) = x0_real;
162 VECTOR(out,ostride,to0 + 1) = x0_imag;
164 VECTOR(out,ostride,to1) = x1_real;
165 VECTOR(out,ostride,to1 + 1) = x1_imag;
167 VECTOR(out,ostride,to3) = x2_real;
168 VECTOR(out,ostride,to3 + 1) = -x2_imag;
170 VECTOR(out,ostride,to2) = x3_real;
171 VECTOR(out,ostride,to2 + 1) = -x3_imag;
175 if (product_1 % 2 == 1)
178 for (k1 = 0; k1 < q; k1++)
180 const size_t from0 = k1 * product_1 + product_1 - 1;
181 const size_t from1 = from0 + m;
182 const size_t from2 = from1 + m;
183 const size_t from3 = from2 + m;
185 const ATOMIC x0 = VECTOR(in,istride,from0);
186 const ATOMIC x1 = VECTOR(in,istride,from1);
187 const ATOMIC x2 = VECTOR(in,istride,from2);
188 const ATOMIC x3 = VECTOR(in,istride,from3);
190 const ATOMIC t1 = (1.0 / sqrt (2.0)) * (x1 - x3);
191 const ATOMIC t2 = (1.0 / sqrt (2.0)) * (x1 + x3);
193 const size_t to0 = k1 * product + 2 * k - 1;
194 const size_t to1 = to0 + 2 * product_1;
196 VECTOR(out,ostride,to0) = x0 + t1;
197 VECTOR(out,ostride,to0 + 1) = -x2 - t2;
199 VECTOR(out,ostride,to1) = x0 - t1;
200 VECTOR(out,ostride,to1 + 1) = x2 - t2;