| 1 |
/* fft/real_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_real,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 k, k1; |
| 32 |
|
| 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; |
| 37 |
|
| 38 |
for (k1 = 0; k1 < q; k1++) |
| 39 |
{ |
| 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; |
| 44 |
|
| 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); |
| 49 |
|
| 50 |
/* compute x = W(4) z */ |
| 51 |
|
| 52 |
/* t1 = z0 + z2 */ |
| 53 |
const ATOMIC t1_real = z0_real + z2_real; |
| 54 |
|
| 55 |
/* t2 = z1 + z3 */ |
| 56 |
const ATOMIC t2_real = z1_real + z3_real; |
| 57 |
|
| 58 |
/* t3 = z0 - z2 */ |
| 59 |
const ATOMIC t3_real = z0_real - z2_real; |
| 60 |
|
| 61 |
/* t4 = - (z1 - z3) */ |
| 62 |
const ATOMIC t4_real = -(z1_real - z3_real); |
| 63 |
|
| 64 |
/* x0 = t1 + t2 */ |
| 65 |
const ATOMIC x0_real = t1_real + t2_real; |
| 66 |
|
| 67 |
/* x1 = t3 + i t4 */ |
| 68 |
const ATOMIC x1_real = t3_real; |
| 69 |
const ATOMIC x1_imag = t4_real; |
| 70 |
|
| 71 |
/* x2 = t1 - t2 */ |
| 72 |
const ATOMIC x2_real = t1_real - t2_real; |
| 73 |
|
| 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; |
| 77 |
|
| 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; |
| 82 |
} |
| 83 |
|
| 84 |
if (product_1 == 1) |
| 85 |
return; |
| 86 |
|
| 87 |
for (k = 1; k < (product_1 + 1) / 2; k++) |
| 88 |
{ |
| 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]); |
| 96 |
|
| 97 |
for (k1 = 0; k1 < q; k1++) |
| 98 |
{ |
| 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; |
| 103 |
|
| 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); |
| 112 |
|
| 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; |
| 121 |
|
| 122 |
/* compute x = W(4) z */ |
| 123 |
|
| 124 |
/* t1 = z0 + z2 */ |
| 125 |
const ATOMIC t1_real = z0_real + z2_real; |
| 126 |
const ATOMIC t1_imag = z0_imag + z2_imag; |
| 127 |
|
| 128 |
/* t2 = z1 + z3 */ |
| 129 |
const ATOMIC t2_real = z1_real + z3_real; |
| 130 |
const ATOMIC t2_imag = z1_imag + z3_imag; |
| 131 |
|
| 132 |
/* t3 = z0 - z2 */ |
| 133 |
const ATOMIC t3_real = z0_real - z2_real; |
| 134 |
const ATOMIC t3_imag = z0_imag - z2_imag; |
| 135 |
|
| 136 |
/* t4 = - (z1 - z3) */ |
| 137 |
const ATOMIC t4_real = -(z1_real - z3_real); |
| 138 |
const ATOMIC t4_imag = -(z1_imag - z3_imag); |
| 139 |
|
| 140 |
/* x0 = t1 + t2 */ |
| 141 |
const ATOMIC x0_real = t1_real + t2_real; |
| 142 |
const ATOMIC x0_imag = t1_imag + t2_imag; |
| 143 |
|
| 144 |
/* x1 = t3 + i t4 */ |
| 145 |
const ATOMIC x1_real = t3_real - t4_imag; |
| 146 |
const ATOMIC x1_imag = t3_imag + t4_real; |
| 147 |
|
| 148 |
/* x2 = t1 - t2 */ |
| 149 |
const ATOMIC x2_real = t1_real - t2_real; |
| 150 |
const ATOMIC x2_imag = t1_imag - t2_imag; |
| 151 |
|
| 152 |
/* x3 = t3 - i t4 */ |
| 153 |
const ATOMIC x3_real = t3_real + t4_imag; |
| 154 |
const ATOMIC x3_imag = t3_imag - t4_real; |
| 155 |
|
| 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; |
| 160 |
|
| 161 |
VECTOR(out,ostride,to0) = x0_real; |
| 162 |
VECTOR(out,ostride,to0 + 1) = x0_imag; |
| 163 |
|
| 164 |
VECTOR(out,ostride,to1) = x1_real; |
| 165 |
VECTOR(out,ostride,to1 + 1) = x1_imag; |
| 166 |
|
| 167 |
VECTOR(out,ostride,to3) = x2_real; |
| 168 |
VECTOR(out,ostride,to3 + 1) = -x2_imag; |
| 169 |
|
| 170 |
VECTOR(out,ostride,to2) = x3_real; |
| 171 |
VECTOR(out,ostride,to2 + 1) = -x3_imag; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
if (product_1 % 2 == 1) |
| 176 |
return; |
| 177 |
|
| 178 |
for (k1 = 0; k1 < q; k1++) |
| 179 |
{ |
| 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; |
| 184 |
|
| 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); |
| 189 |
|
| 190 |
const ATOMIC t1 = (1.0 / sqrt (2.0)) * (x1 - x3); |
| 191 |
const ATOMIC t2 = (1.0 / sqrt (2.0)) * (x1 + x3); |
| 192 |
|
| 193 |
const size_t to0 = k1 * product + 2 * k - 1; |
| 194 |
const size_t to1 = to0 + 2 * product_1; |
| 195 |
|
| 196 |
VECTOR(out,ostride,to0) = x0 + t1; |
| 197 |
VECTOR(out,ostride,to0 + 1) = -x2 - t2; |
| 198 |
|
| 199 |
VECTOR(out,ostride,to1) = x0 - t1; |
| 200 |
VECTOR(out,ostride,to1 + 1) = x2 - t2; |
| 201 |
} |
| 202 |
return; |
| 203 |
} |