gsl_fft__hc_pass_4.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. static void
  20. FUNCTION(fft_halfcomplex,pass_4) (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. {
  30. size_t i, j, k, k1, jump;
  31. size_t factor, q, m, product_1;
  32. i = 0;
  33. j = 0;
  34. factor = 4;
  35. m = n / factor;
  36. q = n / product;
  37. product_1 = product / factor;
  38. jump = (factor - 1) * q;
  39. for (k1 = 0; k1 < product_1; k1++)
  40. {
  41. const size_t from0 = 4 * k1 * q;
  42. const size_t from1 = from0 + 2 * q - 1;
  43. const size_t from2 = from1 + 2 * q;
  44. const ATOMIC z0_real = VECTOR(in,istride,from0);
  45. const ATOMIC z1_real = VECTOR(in,istride,from1);
  46. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  47. const ATOMIC z2_real = VECTOR(in,istride,from2);
  48. const ATOMIC t1_real = z0_real + z2_real;
  49. const ATOMIC t2_real = 2 * z1_real;
  50. const ATOMIC t3_real = z0_real - z2_real;
  51. const ATOMIC t4_imag = 2 * z1_imag;
  52. const size_t to0 = q * k1;
  53. const size_t to1 = to0 + m;
  54. const size_t to2 = to1 + m;
  55. const size_t to3 = to2 + m;
  56. VECTOR(out,ostride,to0) = t1_real + t2_real;
  57. VECTOR(out,ostride,to1) = t3_real - t4_imag;
  58. VECTOR(out,ostride,to2) = t1_real - t2_real;
  59. VECTOR(out,ostride,to3) = t3_real + t4_imag;
  60. }
  61. if (q == 1)
  62. return;
  63. for (k = 1; k < (q + 1) / 2; k++)
  64. {
  65. const ATOMIC w1_real = GSL_REAL(twiddle1[k - 1]);
  66. const ATOMIC w1_imag = GSL_IMAG(twiddle1[k - 1]);
  67. const ATOMIC w2_real = GSL_REAL(twiddle2[k - 1]);
  68. const ATOMIC w2_imag = GSL_IMAG(twiddle2[k - 1]);
  69. const ATOMIC w3_real = GSL_REAL(twiddle3[k - 1]);
  70. const ATOMIC w3_imag = GSL_IMAG(twiddle3[k - 1]);
  71. for (k1 = 0; k1 < product_1; k1++)
  72. {
  73. const size_t from0 = 4 * k1 * q + 2 * k - 1;
  74. const size_t from1 = from0 + 2 * q;
  75. const size_t from2 = 4 * k1 * q - 2 * k + 2 * q - 1;
  76. const size_t from3 = from2 + 2 * q;
  77. const ATOMIC z0_real = VECTOR(in,istride,from0);
  78. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  79. const ATOMIC z1_real = VECTOR(in,istride,from1);
  80. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  81. const ATOMIC z2_real = VECTOR(in,istride,from3);
  82. const ATOMIC z2_imag = -VECTOR(in,istride,from3 + 1);
  83. const ATOMIC z3_real = VECTOR(in,istride,from2);
  84. const ATOMIC z3_imag = -VECTOR(in,istride,from2 + 1);
  85. /* compute x = W(4) z */
  86. /* t1 = z0 + z2 */
  87. const ATOMIC t1_real = z0_real + z2_real;
  88. const ATOMIC t1_imag = z0_imag + z2_imag;
  89. /* t2 = z1 + z3 */
  90. const ATOMIC t2_real = z1_real + z3_real;
  91. const ATOMIC t2_imag = z1_imag + z3_imag;
  92. /* t3 = z0 - z2 */
  93. const ATOMIC t3_real = z0_real - z2_real;
  94. const ATOMIC t3_imag = z0_imag - z2_imag;
  95. /* t4 = (z1 - z3) */
  96. const ATOMIC t4_real = (z1_real - z3_real);
  97. const ATOMIC t4_imag = (z1_imag - z3_imag);
  98. /* x0 = t1 + t2 */
  99. const ATOMIC x0_real = t1_real + t2_real;
  100. const ATOMIC x0_imag = t1_imag + t2_imag;
  101. /* x1 = t3 + i t4 */
  102. const ATOMIC x1_real = t3_real - t4_imag;
  103. const ATOMIC x1_imag = t3_imag + t4_real;
  104. /* x2 = t1 - t2 */
  105. const ATOMIC x2_real = t1_real - t2_real;
  106. const ATOMIC x2_imag = t1_imag - t2_imag;
  107. /* x3 = t3 - i t4 */
  108. const ATOMIC x3_real = t3_real + t4_imag;
  109. const ATOMIC x3_imag = t3_imag - t4_real;
  110. const size_t to0 = k1 * q + 2 * k - 1;
  111. const size_t to1 = to0 + m;
  112. const size_t to2 = to1 + m;
  113. const size_t to3 = to2 + m;
  114. VECTOR(out,ostride,to0) = x0_real;
  115. VECTOR(out,ostride,to0 + 1) = x0_imag;
  116. VECTOR(out,ostride,to1) = w1_real * x1_real - w1_imag * x1_imag;
  117. VECTOR(out,ostride,to1 + 1) = w1_imag * x1_real + w1_real * x1_imag;
  118. VECTOR(out,ostride,to2) = w2_real * x2_real - w2_imag * x2_imag;
  119. VECTOR(out,ostride,to2 + 1) = w2_imag * x2_real + w2_real * x2_imag;
  120. /* to3 = w3 * x3 */
  121. VECTOR(out,ostride,to3) = w3_real * x3_real - w3_imag * x3_imag;
  122. VECTOR(out,ostride,to3 + 1) = w3_real * x3_imag + w3_imag * x3_real;
  123. }
  124. }
  125. if (q % 2 == 1)
  126. return;
  127. for (k1 = 0; k1 < product_1; k1++)
  128. {
  129. const size_t from0 = 4 * k1 * q + q - 1;
  130. const size_t from1 = from0 + 2 * q;
  131. const ATOMIC z0_real = VECTOR(in,istride,from0);
  132. const ATOMIC z0_imag = VECTOR(in,istride,from0 + 1);
  133. const ATOMIC z1_real = VECTOR(in,istride,from1);
  134. const ATOMIC z1_imag = VECTOR(in,istride,from1 + 1);
  135. const ATOMIC t1_real = sqrt (2.0) * (z0_imag + z1_imag);
  136. const ATOMIC t2_real = sqrt (2.0) * (z0_real - z1_real);
  137. const ATOMIC x0_real = 2 * (z0_real + z1_real);
  138. const ATOMIC x1_real = t2_real - t1_real;
  139. const ATOMIC x2_real = 2 * (z1_imag - z0_imag);
  140. const ATOMIC x3_real = -(t2_real + t1_real);
  141. const size_t to0 = k1 * q + q - 1;
  142. const size_t to1 = to0 + m;
  143. const size_t to2 = to1 + m;
  144. const size_t to3 = to2 + m;
  145. VECTOR(out,ostride,to0) = x0_real;
  146. VECTOR(out,ostride,to1) = x1_real;
  147. VECTOR(out,ostride,to2) = x2_real;
  148. VECTOR(out,ostride,to3) = x3_real;
  149. }
  150. return;
  151. }