Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / fft / hc_pass_4.c
1 /* fft/hc_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 void
21 FUNCTION(fft_halfcomplex,pass_4) (const BASE in[],
22                                   const size_t istride,
23                                   BASE out[],
24                                   const size_t ostride,
25                                   const size_t product,
26                                   const size_t n,
27                                   const TYPE(gsl_complex) twiddle1[],
28                                   const TYPE(gsl_complex) twiddle2[],
29                                   const TYPE(gsl_complex) twiddle3[])
30 {
31   size_t i, j, k, k1, jump;
32   size_t factor, q, m, product_1;
33
34   i = 0;
35   j = 0;
36
37   factor = 4;
38   m = n / factor;
39   q = n / product;
40   product_1 = product / factor;
41   jump = (factor - 1) * q;
42
43   for (k1 = 0; k1 < product_1; k1++)
44     {
45       const size_t from0 = 4 * k1 * q;
46       const size_t from1 = from0 + 2 * q - 1;
47       const size_t from2 = from1 + 2 * q;
48
49       const ATOMIC z0_real = VECTOR(in,istride,from0);
50       const ATOMIC z1_real = VECTOR(in,istride,from1);
51       const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
52       const ATOMIC z2_real = VECTOR(in,istride,from2);
53
54       const ATOMIC t1_real = z0_real + z2_real;
55       const ATOMIC t2_real = 2 * z1_real;
56       const ATOMIC t3_real = z0_real - z2_real;
57       const ATOMIC t4_imag = 2 * z1_imag;
58
59       const size_t to0 = q * k1;
60       const size_t to1 = to0 + m;
61       const size_t to2 = to1 + m;
62       const size_t to3 = to2 + m;
63
64       VECTOR(out,ostride,to0) = t1_real + t2_real;
65       VECTOR(out,ostride,to1) = t3_real - t4_imag;
66       VECTOR(out,ostride,to2) = t1_real - t2_real;
67       VECTOR(out,ostride,to3) = t3_real + t4_imag;
68     }
69
70   if (q == 1)
71     return;
72
73   for (k = 1; k < (q + 1) / 2; k++)
74     {
75       const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
76       const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
77       const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
78       const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
79       const ATOMIC w3_real = GSL_REAL(twiddle3[k - 1]);
80       const ATOMIC w3_imag = GSL_IMAG(twiddle3[k - 1]);
81
82       for (k1 = 0; k1 < product_1; k1++)
83         {
84           const size_t from0 = 4 * k1 * q + 2 * k - 1;
85           const size_t from1 = from0 + 2 * q;
86           const size_t from2 = 4 * k1 * q - 2 * k + 2 * q - 1;
87           const size_t from3 = from2 + 2 * q;
88
89           const ATOMIC z0_real = VECTOR(in,istride,from0);
90           const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
91
92           const ATOMIC z1_real = VECTOR(in,istride,from1);
93           const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
94
95           const ATOMIC z2_real = VECTOR(in,istride,from3);
96           const ATOMIC z2_imag = -VECTOR(in,istride,from3 + 1);
97
98           const ATOMIC z3_real = VECTOR(in,istride,from2);
99           const ATOMIC z3_imag = -VECTOR(in,istride,from2 + 1);
100
101           /* compute x = W(4) z */
102
103           /* t1 = z0 + z2 */
104           const ATOMIC t1_real = z0_real + z2_real;
105           const ATOMIC t1_imag = z0_imag + z2_imag;
106
107           /* t2 = z1 + z3 */
108           const ATOMIC t2_real = z1_real + z3_real;
109           const ATOMIC t2_imag = z1_imag + z3_imag;
110
111           /* t3 = z0 - z2 */
112           const ATOMIC t3_real = z0_real - z2_real;
113           const ATOMIC t3_imag = z0_imag - z2_imag;
114
115           /* t4 = (z1 - z3) */
116           const ATOMIC t4_real = (z1_real - z3_real);
117           const ATOMIC t4_imag = (z1_imag - z3_imag);
118
119           /* x0 = t1 + t2 */
120           const ATOMIC x0_real = t1_real + t2_real;
121           const ATOMIC x0_imag = t1_imag + t2_imag;
122
123           /* x1 = t3 + i t4 */
124           const ATOMIC x1_real = t3_real - t4_imag;
125           const ATOMIC x1_imag = t3_imag + t4_real;
126
127           /* x2 = t1 - t2 */
128           const ATOMIC x2_real = t1_real - t2_real;
129           const ATOMIC x2_imag = t1_imag - t2_imag;
130
131           /* x3 = t3 - i t4 */
132           const ATOMIC x3_real = t3_real + t4_imag;
133           const ATOMIC x3_imag = t3_imag - t4_real;
134
135           const size_t to0 = k1 * q + 2 * k - 1;
136           const size_t to1 = to0 + m;
137           const size_t to2 = to1 + m;
138           const size_t to3 = to2 + m;
139
140           VECTOR(out,ostride,to0) = x0_real;
141           VECTOR(out,ostride,to0 + 1) = x0_imag;
142
143           VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
144           VECTOR(out,ostride,to1 + 1) = w1_imag * x1_real + w1_real * x1_imag;
145
146           VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
147           VECTOR(out,ostride,to2 + 1) = w2_imag * x2_real + w2_real * x2_imag;
148
149           /* to3 = w3 * x3 */
150           VECTOR(out,ostride,to3) = w3_real * x3_real - w3_imag * x3_imag;
151           VECTOR(out,ostride,to3 + 1) = w3_real * x3_imag + w3_imag * x3_real;
152
153         }
154     }
155
156   if (q % 2 == 1)
157     return;
158
159   for (k1 = 0; k1 < product_1; k1++)
160     {
161       const size_t from0 = 4 * k1 * q + q - 1;
162       const size_t from1 = from0 + 2 * q;
163
164       const ATOMIC z0_real = VECTOR(in,istride,from0);
165       const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
166
167       const ATOMIC z1_real = VECTOR(in,istride,from1);
168       const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
169
170       const ATOMIC t1_real = sqrt (2.0) * (z0_imag + z1_imag);
171       const ATOMIC t2_real = sqrt (2.0) * (z0_real - z1_real);
172
173       const ATOMIC x0_real = 2 * (z0_real + z1_real);
174       const ATOMIC x1_real = t2_real - t1_real;
175       const ATOMIC x2_real = 2 * (z1_imag - z0_imag);
176       const ATOMIC x3_real = -(t2_real + t1_real);
177
178       const size_t to0 = k1 * q + q - 1;
179       const size_t to1 = to0 + m;
180       const size_t to2 = to1 + m;
181       const size_t to3 = to2 + m;
182
183       VECTOR(out,ostride,to0) = x0_real;
184       VECTOR(out,ostride,to1) = x1_real;
185       VECTOR(out,ostride,to2) = x2_real;
186       VECTOR(out,ostride,to3) = x3_real;
187     }
188   return;
189 }