Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / fft / hc_pass_5.c
1 /* fft/hc_pass_5.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_5) (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                                   const TYPE(gsl_complex) twiddle4[])
31 {
32
33   size_t i, j, k, k1, jump;
34   size_t factor, q, m, product_1;
35
36   const ATOMIC sina = sin (2.0 * M_PI / 5.0);
37   const ATOMIC sinb = sin (2.0 * M_PI / 10.0);
38
39   i = 0;
40   j = 0;
41
42   factor = 5;
43   m = n / factor;
44   q = n / product;
45   product_1 = product / factor;
46   jump = (factor - 1) * q;
47
48   for (k1 = 0; k1 < product_1; k1++)
49     {
50       const size_t from0 = 5 * k1 * q;
51       const size_t from1 = from0 + 2 * q - 1;
52       const size_t from2 = from1 + 2 * q;
53
54       const ATOMIC z0_real = VECTOR(in,istride,from0);
55       const ATOMIC z1_real = VECTOR(in,istride,from1);
56       const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
57       const ATOMIC z2_real = VECTOR(in,istride,from2);
58       const ATOMIC z2_imag = VECTOR(in,istride,from2 + 1);
59
60       const ATOMIC t1_real = 2 * (z1_real + z2_real);
61       const ATOMIC t2_real = 2 * (sqrt (5.0) / 4.0) * (z1_real - z2_real);
62       const ATOMIC t3_real = z0_real - t1_real / 4.0;
63       const ATOMIC t4_real = t2_real + t3_real;
64       const ATOMIC t5_real = -t2_real + t3_real;
65       const ATOMIC t6_imag = 2 * (sina * z1_imag + sinb * z2_imag);
66       const ATOMIC t7_imag = 2 * (sinb * z1_imag - sina * z2_imag);
67
68       const ATOMIC x0_real = z0_real + t1_real;
69       const ATOMIC x1_real = t4_real - t6_imag;
70       const ATOMIC x2_real = t5_real - t7_imag;
71       const ATOMIC x3_real = t5_real + t7_imag;
72       const ATOMIC x4_real = t4_real + t6_imag;
73
74       const size_t to0 = q * k1;
75       const size_t to1 = to0 + m;
76       const size_t to2 = to1 + m;
77       const size_t to3 = to2 + m;
78       const size_t to4 = to3 + m;
79
80       VECTOR(out,ostride,to0) = x0_real;
81       VECTOR(out,ostride,to1) = x1_real;
82       VECTOR(out,ostride,to2) = x2_real;
83       VECTOR(out,ostride,to3) = x3_real;
84       VECTOR(out,ostride,to4) = x4_real;
85     }
86
87   if (q == 1)
88     return;
89
90   for (k = 1; k < (q + 1) / 2; k++)
91     {
92       const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
93       const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
94       const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
95       const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
96       const ATOMIC w3_real = GSL_REAL(twiddle3[k - 1]);
97       const ATOMIC w3_imag = GSL_IMAG(twiddle3[k - 1]);
98       const ATOMIC w4_real = GSL_REAL(twiddle4[k - 1]);
99       const ATOMIC w4_imag = GSL_IMAG(twiddle4[k - 1]);
100
101       for (k1 = 0; k1 < product_1; k1++)
102         {
103           const size_t from0 = 5 * k1 * q + 2 * k - 1;
104           const size_t from1 = from0 + 2 * q;
105           const size_t from2 = from1 + 2 * q;
106           const size_t from3 = 5 * k1 * q - 2 * k + 2 * q - 1;
107           const size_t from4 = from3 + 2 * q;
108
109           const ATOMIC z0_real = VECTOR(in,istride,from0);
110           const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
111
112           const ATOMIC z1_real = VECTOR(in,istride,from1);
113           const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
114
115           const ATOMIC z2_real = VECTOR(in,istride,from2);
116           const ATOMIC z2_imag = VECTOR(in,istride,from2 + 1);
117
118           const ATOMIC z3_real = VECTOR(in,istride,from4);
119           const ATOMIC z3_imag = -VECTOR(in,istride,from4 + 1);
120
121           const ATOMIC z4_real = VECTOR(in,istride,from3);
122           const ATOMIC z4_imag = -VECTOR(in,istride,from3 + 1);
123
124           /* compute x = W(5) z */
125
126           /* t1 = z1 + z4 */
127           const ATOMIC t1_real = z1_real + z4_real;
128           const ATOMIC t1_imag = z1_imag + z4_imag;
129
130           /* t2 = z2 + z3 */
131           const ATOMIC t2_real = z2_real + z3_real;
132           const ATOMIC t2_imag = z2_imag + z3_imag;
133
134           /* t3 = z1 - z4 */
135           const ATOMIC t3_real = z1_real - z4_real;
136           const ATOMIC t3_imag = z1_imag - z4_imag;
137
138           /* t4 = z2 - z3 */
139           const ATOMIC t4_real = z2_real - z3_real;
140           const ATOMIC t4_imag = z2_imag - z3_imag;
141
142           /* t5 = t1 + t2 */
143           const ATOMIC t5_real = t1_real + t2_real;
144           const ATOMIC t5_imag = t1_imag + t2_imag;
145
146           /* t6 = (sqrt(5)/4)(t1 - t2) */
147           const ATOMIC t6_real = (sqrt (5.0) / 4.0) * (t1_real - t2_real);
148           const ATOMIC t6_imag = (sqrt (5.0) / 4.0) * (t1_imag - t2_imag);
149
150           /* t7 = z0 - ((t5)/4) */
151           const ATOMIC t7_real = z0_real - t5_real / 4.0;
152           const ATOMIC t7_imag = z0_imag - t5_imag / 4.0;
153
154           /* t8 = t7 + t6 */
155           const ATOMIC t8_real = t7_real + t6_real;
156           const ATOMIC t8_imag = t7_imag + t6_imag;
157
158           /* t9 = t7 - t6 */
159           const ATOMIC t9_real = t7_real - t6_real;
160           const ATOMIC t9_imag = t7_imag - t6_imag;
161
162           /* t10 = sin(2 pi/5) t3 + sin(2 pi/10) t4 */
163           const ATOMIC t10_real = sina * t3_real + sinb * t4_real;
164           const ATOMIC t10_imag = sina * t3_imag + sinb * t4_imag;
165
166           /* t11 = sin(2 pi/10) t3 - sin(2 pi/5) t4 */
167           const ATOMIC t11_real = sinb * t3_real - sina * t4_real;
168           const ATOMIC t11_imag = sinb * t3_imag - sina * t4_imag;
169
170           /* x0 = z0 + t5 */
171           const ATOMIC x0_real = z0_real + t5_real;
172           const ATOMIC x0_imag = z0_imag + t5_imag;
173
174           /* x1 = t8 + i t10 */
175           const ATOMIC x1_real = t8_real - t10_imag;
176           const ATOMIC x1_imag = t8_imag + t10_real;
177
178           /* x2 = t9 + i t11 */
179           const ATOMIC x2_real = t9_real - t11_imag;
180           const ATOMIC x2_imag = t9_imag + t11_real;
181
182           /* x3 = t9 - i t11 */
183           const ATOMIC x3_real = t9_real + t11_imag;
184           const ATOMIC x3_imag = t9_imag - t11_real;
185
186           /* x4 = t8 - i t10 */
187           const ATOMIC x4_real = t8_real + t10_imag;
188           const ATOMIC x4_imag = t8_imag - t10_real;
189
190           const size_t to0 = k1 * q + 2 * k - 1;
191           const size_t to1 = to0 + m;
192           const size_t to2 = to1 + m;
193           const size_t to3 = to2 + m;
194           const size_t to4 = to3 + m;
195
196           /* apply twiddle factors */
197
198           /* to0 = 1 * x0 */
199           VECTOR(out,ostride,to0) = x0_real;
200           VECTOR(out,ostride,to0 + 1) = x0_imag;
201
202           /* to1 = w1 * x1 */
203           VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
204           VECTOR(out,ostride,to1 + 1) = w1_real * x1_imag + w1_imag * x1_real;
205
206           /* to2 = w2 * x2 */
207           VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
208           VECTOR(out,ostride,to2 + 1) = w2_real * x2_imag + w2_imag * x2_real;
209
210           /* to3 = w3 * x3 */
211           VECTOR(out,ostride,to3) = w3_real * x3_real - w3_imag * x3_imag;
212           VECTOR(out,ostride,to3 + 1) = w3_real * x3_imag + w3_imag * x3_real;
213
214           /* to4 = w4 * x4 */
215           VECTOR(out,ostride,to4) = w4_real * x4_real - w4_imag * x4_imag;
216           VECTOR(out,ostride,to4 + 1) = w4_real * x4_imag + w4_imag * x4_real;
217         }
218     }
219
220   if (q % 2 == 1)
221     return;
222
223   for (k1 = 0; k1 < product_1; k1++)
224     {
225       const size_t from0 = 5 * k1 * q + q - 1;
226       const size_t from1 = from0 + 2 * q;
227       const size_t from2 = from1 + 2 * q;
228
229       const ATOMIC z0_real = 2 * VECTOR(in,istride,from0);
230       const ATOMIC z0_imag = 2 * VECTOR(in,istride,from0 + 1);
231
232       const ATOMIC z1_real = 2 * VECTOR(in,istride,from1);
233       const ATOMIC z1_imag = 2 * VECTOR(in,istride,from1 + 1);
234
235       const ATOMIC z2_real = VECTOR(in,istride,from2);
236
237       const ATOMIC t1_real = z0_real + z1_real;
238       const ATOMIC t2_real = (t1_real / 4.0) - z2_real;
239       const ATOMIC t3_real = (sqrt (5.0) / 4.0) * (z0_real - z1_real);
240       const ATOMIC t4_real = sinb * z0_imag + sina * z1_imag;
241       const ATOMIC t5_real = sina * z0_imag - sinb * z1_imag;
242       const ATOMIC t6_real = t3_real + t2_real;
243       const ATOMIC t7_real = t3_real - t2_real;
244
245       const ATOMIC x0_real = t1_real + z2_real;
246       const ATOMIC x1_real = t6_real - t4_real;
247       const ATOMIC x2_real = t7_real - t5_real;
248       const ATOMIC x3_real = -t7_real - t5_real;
249       const ATOMIC x4_real = -t6_real - t4_real;
250
251       const size_t to0 = k1 * q + q - 1;
252       const size_t to1 = to0 + m;
253       const size_t to2 = to1 + m;
254       const size_t to3 = to2 + m;
255       const size_t to4 = to3 + m;
256
257       VECTOR(out,ostride,to0) = x0_real;
258       VECTOR(out,ostride,to1) = x1_real;
259       VECTOR(out,ostride,to2) = x2_real;
260       VECTOR(out,ostride,to3) = x3_real;
261       VECTOR(out,ostride,to4) = x4_real;
262     }
263   return;
264 }