gsl_fft__hc_pass_5.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. static void
  20. FUNCTION(fft_halfcomplex,pass_5) (const BASE in[],
  21. const size_t istride,
  22. BASE out[],
  23. const size_t ostride,
  24. const size_t product,
  25. const size_t n,
  26. const TYPE(gsl_complex) twiddle1[],
  27. const TYPE(gsl_complex) twiddle2[],
  28. const TYPE(gsl_complex) twiddle3[],
  29. const TYPE(gsl_complex) twiddle4[])
  30. {
  31. size_t i, j, k, k1, jump;
  32. size_t factor, q, m, product_1;
  33. const ATOMIC sina = sin (2.0 * M_PI / 5.0);
  34. const ATOMIC sinb = sin (2.0 * M_PI / 10.0);
  35. i = 0;
  36. j = 0;
  37. factor = 5;
  38. m = n / factor;
  39. q = n / product;
  40. product_1 = product / factor;
  41. jump = (factor - 1) * q;
  42. for (k1 = 0; k1 < product_1; k1++)
  43. {
  44. const size_t from0 = 5 * k1 * q;
  45. const size_t from1 = from0 + 2 * q - 1;
  46. const size_t from2 = from1 + 2 * q;
  47. const ATOMIC z0_real = VECTOR(in,istride,from0);
  48. const ATOMIC z1_real = VECTOR(in,istride,from1);
  49. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  50. const ATOMIC z2_real = VECTOR(in,istride,from2);
  51. const ATOMIC z2_imag = VECTOR(in,istride,from2 + 1);
  52. const ATOMIC t1_real = 2 * (z1_real + z2_real);
  53. const ATOMIC t2_real = 2 * (sqrt (5.0) / 4.0) * (z1_real - z2_real);
  54. const ATOMIC t3_real = z0_real - t1_real / 4.0;
  55. const ATOMIC t4_real = t2_real + t3_real;
  56. const ATOMIC t5_real = -t2_real + t3_real;
  57. const ATOMIC t6_imag = 2 * (sina * z1_imag + sinb * z2_imag);
  58. const ATOMIC t7_imag = 2 * (sinb * z1_imag - sina * z2_imag);
  59. const ATOMIC x0_real = z0_real + t1_real;
  60. const ATOMIC x1_real = t4_real - t6_imag;
  61. const ATOMIC x2_real = t5_real - t7_imag;
  62. const ATOMIC x3_real = t5_real + t7_imag;
  63. const ATOMIC x4_real = t4_real + t6_imag;
  64. const size_t to0 = q * k1;
  65. const size_t to1 = to0 + m;
  66. const size_t to2 = to1 + m;
  67. const size_t to3 = to2 + m;
  68. const size_t to4 = to3 + m;
  69. VECTOR(out,ostride,to0) = x0_real;
  70. VECTOR(out,ostride,to1) = x1_real;
  71. VECTOR(out,ostride,to2) = x2_real;
  72. VECTOR(out,ostride,to3) = x3_real;
  73. VECTOR(out,ostride,to4) = x4_real;
  74. }
  75. if (q == 1)
  76. return;
  77. for (k = 1; k < (q + 1) / 2; k++)
  78. {
  79. const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
  80. const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
  81. const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
  82. const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
  83. const ATOMIC w3_real = GSL_REAL(twiddle3[k - 1]);
  84. const ATOMIC w3_imag = GSL_IMAG(twiddle3[k - 1]);
  85. const ATOMIC w4_real = GSL_REAL(twiddle4[k - 1]);
  86. const ATOMIC w4_imag = GSL_IMAG(twiddle4[k - 1]);
  87. for (k1 = 0; k1 < product_1; k1++)
  88. {
  89. const size_t from0 = 5 * k1 * q + 2 * k - 1;
  90. const size_t from1 = from0 + 2 * q;
  91. const size_t from2 = from1 + 2 * q;
  92. const size_t from3 = 5 * k1 * q - 2 * k + 2 * q - 1;
  93. const size_t from4 = from3 + 2 * q;
  94. const ATOMIC z0_real = VECTOR(in,istride,from0);
  95. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  96. const ATOMIC z1_real = VECTOR(in,istride,from1);
  97. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  98. const ATOMIC z2_real = VECTOR(in,istride,from2);
  99. const ATOMIC z2_imag = VECTOR(in,istride,from2 + 1);
  100. const ATOMIC z3_real = VECTOR(in,istride,from4);
  101. const ATOMIC z3_imag = -VECTOR(in,istride,from4 + 1);
  102. const ATOMIC z4_real = VECTOR(in,istride,from3);
  103. const ATOMIC z4_imag = -VECTOR(in,istride,from3 + 1);
  104. /* compute x = W(5) z */
  105. /* t1 = z1 + z4 */
  106. const ATOMIC t1_real = z1_real + z4_real;
  107. const ATOMIC t1_imag = z1_imag + z4_imag;
  108. /* t2 = z2 + z3 */
  109. const ATOMIC t2_real = z2_real + z3_real;
  110. const ATOMIC t2_imag = z2_imag + z3_imag;
  111. /* t3 = z1 - z4 */
  112. const ATOMIC t3_real = z1_real - z4_real;
  113. const ATOMIC t3_imag = z1_imag - z4_imag;
  114. /* t4 = z2 - z3 */
  115. const ATOMIC t4_real = z2_real - z3_real;
  116. const ATOMIC t4_imag = z2_imag - z3_imag;
  117. /* t5 = t1 + t2 */
  118. const ATOMIC t5_real = t1_real + t2_real;
  119. const ATOMIC t5_imag = t1_imag + t2_imag;
  120. /* t6 = (sqrt(5)/4)(t1 - t2) */
  121. const ATOMIC t6_real = (sqrt (5.0) / 4.0) * (t1_real - t2_real);
  122. const ATOMIC t6_imag = (sqrt (5.0) / 4.0) * (t1_imag - t2_imag);
  123. /* t7 = z0 - ((t5)/4) */
  124. const ATOMIC t7_real = z0_real - t5_real / 4.0;
  125. const ATOMIC t7_imag = z0_imag - t5_imag / 4.0;
  126. /* t8 = t7 + t6 */
  127. const ATOMIC t8_real = t7_real + t6_real;
  128. const ATOMIC t8_imag = t7_imag + t6_imag;
  129. /* t9 = t7 - t6 */
  130. const ATOMIC t9_real = t7_real - t6_real;
  131. const ATOMIC t9_imag = t7_imag - t6_imag;
  132. /* t10 = sin(2 pi/5) t3 + sin(2 pi/10) t4 */
  133. const ATOMIC t10_real = sina * t3_real + sinb * t4_real;
  134. const ATOMIC t10_imag = sina * t3_imag + sinb * t4_imag;
  135. /* t11 = sin(2 pi/10) t3 - sin(2 pi/5) t4 */
  136. const ATOMIC t11_real = sinb * t3_real - sina * t4_real;
  137. const ATOMIC t11_imag = sinb * t3_imag - sina * t4_imag;
  138. /* x0 = z0 + t5 */
  139. const ATOMIC x0_real = z0_real + t5_real;
  140. const ATOMIC x0_imag = z0_imag + t5_imag;
  141. /* x1 = t8 + i t10 */
  142. const ATOMIC x1_real = t8_real - t10_imag;
  143. const ATOMIC x1_imag = t8_imag + t10_real;
  144. /* x2 = t9 + i t11 */
  145. const ATOMIC x2_real = t9_real - t11_imag;
  146. const ATOMIC x2_imag = t9_imag + t11_real;
  147. /* x3 = t9 - i t11 */
  148. const ATOMIC x3_real = t9_real + t11_imag;
  149. const ATOMIC x3_imag = t9_imag - t11_real;
  150. /* x4 = t8 - i t10 */
  151. const ATOMIC x4_real = t8_real + t10_imag;
  152. const ATOMIC x4_imag = t8_imag - t10_real;
  153. const size_t to0 = k1 * q + 2 * k - 1;
  154. const size_t to1 = to0 + m;
  155. const size_t to2 = to1 + m;
  156. const size_t to3 = to2 + m;
  157. const size_t to4 = to3 + m;
  158. /* apply twiddle factors */
  159. /* to0 = 1 * x0 */
  160. VECTOR(out,ostride,to0) = x0_real;
  161. VECTOR(out,ostride,to0 + 1) = x0_imag;
  162. /* to1 = w1 * x1 */
  163. VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
  164. VECTOR(out,ostride,to1 + 1) = w1_real * x1_imag + w1_imag * x1_real;
  165. /* to2 = w2 * x2 */
  166. VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
  167. VECTOR(out,ostride,to2 + 1) = w2_real * x2_imag + w2_imag * x2_real;
  168. /* to3 = w3 * x3 */
  169. VECTOR(out,ostride,to3) = w3_real * x3_real - w3_imag * x3_imag;
  170. VECTOR(out,ostride,to3 + 1) = w3_real * x3_imag + w3_imag * x3_real;
  171. /* to4 = w4 * x4 */
  172. VECTOR(out,ostride,to4) = w4_real * x4_real - w4_imag * x4_imag;
  173. VECTOR(out,ostride,to4 + 1) = w4_real * x4_imag + w4_imag * x4_real;
  174. }
  175. }
  176. if (q % 2 == 1)
  177. return;
  178. for (k1 = 0; k1 < product_1; k1++)
  179. {
  180. const size_t from0 = 5 * k1 * q + q - 1;
  181. const size_t from1 = from0 + 2 * q;
  182. const size_t from2 = from1 + 2 * q;
  183. const ATOMIC z0_real = 2 * VECTOR(in,istride,from0);
  184. const ATOMIC z0_imag = 2 * VECTOR(in,istride,from0 + 1);
  185. const ATOMIC z1_real = 2 * VECTOR(in,istride,from1);
  186. const ATOMIC z1_imag = 2 * VECTOR(in,istride,from1 + 1);
  187. const ATOMIC z2_real = VECTOR(in,istride,from2);
  188. const ATOMIC t1_real = z0_real + z1_real;
  189. const ATOMIC t2_real = (t1_real / 4.0) - z2_real;
  190. const ATOMIC t3_real = (sqrt (5.0) / 4.0) * (z0_real - z1_real);
  191. const ATOMIC t4_real = sinb * z0_imag + sina * z1_imag;
  192. const ATOMIC t5_real = sina * z0_imag - sinb * z1_imag;
  193. const ATOMIC t6_real = t3_real + t2_real;
  194. const ATOMIC t7_real = t3_real - t2_real;
  195. const ATOMIC x0_real = t1_real + z2_real;
  196. const ATOMIC x1_real = t6_real - t4_real;
  197. const ATOMIC x2_real = t7_real - t5_real;
  198. const ATOMIC x3_real = -t7_real - t5_real;
  199. const ATOMIC x4_real = -t6_real - t4_real;
  200. const size_t to0 = k1 * q + q - 1;
  201. const size_t to1 = to0 + m;
  202. const size_t to2 = to1 + m;
  203. const size_t to3 = to2 + m;
  204. const size_t to4 = to3 + m;
  205. VECTOR(out,ostride,to0) = x0_real;
  206. VECTOR(out,ostride,to1) = x1_real;
  207. VECTOR(out,ostride,to2) = x2_real;
  208. VECTOR(out,ostride,to3) = x3_real;
  209. VECTOR(out,ostride,to4) = x4_real;
  210. }
  211. return;
  212. }