Debian Codegraph @

external/gsl/gsl_fft__c_pass_4.c

raw
1 /* fft/c_pass_4.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 static int
21 FUNCTION(fft_complex,pass_4) (const BASE in[],
22 const size_t istride,
23 BASE out[],
24 const size_t ostride,
25 const gsl_fft_direction sign,
26 const size_t product,
27 const size_t n,
28 const TYPE(gsl_complex) twiddle1[],
29 const TYPE(gsl_complex) twiddle2[],
30 const TYPE(gsl_complex) twiddle3[])
31 {
32 size_t i = 0, j = 0;
33 size_t k, k1;
34
35 const size_t factor = 4;
36 const size_t m = n / factor;
37 const size_t q = n / product;
38 const size_t p_1 = product / factor;
39 const size_t jump = (factor - 1) * p_1;
40
41 for (k = 0; k < q; k++)
42 {
43 ATOMIC w1_real, w1_imag, w2_real, w2_imag, w3_real, w3_imag;
44
45 if (k == 0)
46 {
47 w1_real = 1.0;
48 w1_imag = 0.0;
49 w2_real = 1.0;
50 w2_imag = 0.0;
51 w3_real = 1.0;
52 w3_imag = 0.0;
53 }
54 else
55 {
56 if (sign == gsl_fft_forward)
57 {
58 /* forward tranform */
59 w1_real = GSL_REAL(twiddle1[k - 1]);
60 w1_imag = GSL_IMAG(twiddle1[k - 1]);
61 w2_real = GSL_REAL(twiddle2[k - 1]);
62 w2_imag = GSL_IMAG(twiddle2[k - 1]);
63 w3_real = GSL_REAL(twiddle3[k - 1]);
64 w3_imag = GSL_IMAG(twiddle3[k - 1]);
65 }
66 else
67 {
68 /* backward tranform: w -> conjugate(w) */
69 w1_real = GSL_REAL(twiddle1[k - 1]);
70 w1_imag = -GSL_IMAG(twiddle1[k - 1]);
71 w2_real = GSL_REAL(twiddle2[k - 1]);
72 w2_imag = -GSL_IMAG(twiddle2[k - 1]);
73 w3_real = GSL_REAL(twiddle3[k - 1]);
74 w3_imag = -GSL_IMAG(twiddle3[k - 1]);
75 }
76 }
77
78 for (k1 = 0; k1 < p_1; k1++)
79 {
80 const ATOMIC z0_real = REAL(in,istride,i);
81 const ATOMIC z0_imag = IMAG(in,istride,i);
82 const ATOMIC z1_real = REAL(in,istride,i+m);
83 const ATOMIC z1_imag = IMAG(in,istride,i+m);
84 const ATOMIC z2_real = REAL(in,istride,i+2*m);
85 const ATOMIC z2_imag = IMAG(in,istride,i+2*m);
86 const ATOMIC z3_real = REAL(in,istride,i+3*m);
87 const ATOMIC z3_imag = IMAG(in,istride,i+3*m);
88
89 /* compute x = W(4) z */
90
91 /* t1 = z0 + z2 */
92 const ATOMIC t1_real = z0_real + z2_real;
93 const ATOMIC t1_imag = z0_imag + z2_imag;
94
95 /* t2 = z1 + z3 */
96 const ATOMIC t2_real = z1_real + z3_real;
97 const ATOMIC t2_imag = z1_imag + z3_imag;
98
99 /* t3 = z0 - z2 */
100 const ATOMIC t3_real = z0_real - z2_real;
101 const ATOMIC t3_imag = z0_imag - z2_imag;
102
103 /* t4 = (+/-) (z1 - z3) */
104 const ATOMIC t4_real = ((int) sign) * (z1_real - z3_real);
105 const ATOMIC t4_imag = ((int) sign) * (z1_imag - z3_imag);
106
107 /* x0 = t1 + t2 */
108 const ATOMIC x0_real = t1_real + t2_real;
109 const ATOMIC x0_imag = t1_imag + t2_imag;
110
111 /* x1 = t3 + i t4 */
112 const ATOMIC x1_real = t3_real - t4_imag;
113 const ATOMIC x1_imag = t3_imag + t4_real;
114
115 /* x2 = t1 - t2 */
116 const ATOMIC x2_real = t1_real - t2_real;
117 const ATOMIC x2_imag = t1_imag - t2_imag;
118
119 /* x3 = t3 - i t4 */
120 const ATOMIC x3_real = t3_real + t4_imag;
121 const ATOMIC x3_imag = t3_imag - t4_real;
122
123 /* apply twiddle factors */
124
125 /* to0 = 1 * x0 */
126 REAL(out,ostride,j) = x0_real;
127 IMAG(out,ostride,j) = x0_imag;
128
129 /* to1 = w1 * x1 */
130 REAL(out, ostride, j + p_1) = w1_real * x1_real - w1_imag * x1_imag;
131 IMAG(out, ostride, j + p_1) = w1_real * x1_imag + w1_imag * x1_real;
132
133 /* to2 = w2 * x2 */
134 REAL(out, ostride, j + 2 * p_1) = w2_real * x2_real - w2_imag * x2_imag;
135 IMAG(out, ostride, j + 2 * p_1) = w2_real * x2_imag + w2_imag * x2_real;
136
137 /* to3 = w3 * x3 */
138 REAL(out, ostride, j + 3 * p_1) = w3_real * x3_real - w3_imag * x3_imag;
139 IMAG(out, ostride, j + 3 * p_1) = w3_real * x3_imag + w3_imag * x3_real;
140
141 i++;
142 j++;
143 }
144 j += jump;
145 }
146 return 0;
147 }