Subversion Repositories shark

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 */
19
 
20
/*
21
 *
22
 * generic.c -- "generic" codelets.  They work for all n (and they are
23
 * slow)
24
 */
107 pj 25
#include <fftw-int.h>
2 pj 26
#include <stdlib.h>
27
 
28
void fftw_twiddle_generic(fftw_complex *A, const fftw_complex *W,
29
                          int m, int r, int n, int stride)
30
{
31
     int i, j, k;
32
     const fftw_complex *jp;
33
     fftw_complex *kp;
34
     fftw_complex *tmp = (fftw_complex *)
35
     fftw_malloc(r * sizeof(fftw_complex));
36
 
37
     for (i = 0; i < m; ++i) {
38
          for (k = 0, kp = tmp; k < r; ++k, kp++) {
39
               fftw_real r0, i0, rt, it, rw, iw;
40
               int l1 = i + m * k;
41
               int l0;
42
 
43
               r0 = i0 = 0.0;
44
               for (j = 0, jp = A + i * stride, l0 = 0; j < r; ++j,
45
                    jp += m * stride) {
46
                    rw = c_re(W[l0]);
47
                    iw = c_im(W[l0]);
48
                    rt = c_re(*jp);
49
                    it = c_im(*jp);
50
                    r0 += rt * rw - it * iw;
51
                    i0 += rt * iw + it * rw;
52
                    l0 += l1;
53
                    if (l0 >= n)
54
                         l0 -= n;
55
               }
56
               c_re(*kp) = r0;
57
               c_im(*kp) = i0;
58
          }
59
          for (k = 0, kp = A + i * stride; k < r; ++k, kp += m * stride)
60
               *kp = tmp[k];
61
     }
62
 
63
     fftw_free(tmp);
64
}
65
 
66
void fftwi_twiddle_generic(fftw_complex *A, const fftw_complex *W,
67
                           int m, int r, int n, int stride)
68
{
69
     int i, j, k;
70
     const fftw_complex *jp;
71
     fftw_complex *kp;
72
     fftw_complex *tmp = (fftw_complex *)
73
     fftw_malloc(r * sizeof(fftw_complex));
74
 
75
     for (i = 0; i < m; ++i) {
76
          for (k = 0, kp = tmp; k < r; ++k, kp++) {
77
               fftw_real r0, i0, rt, it, rw, iw;
78
               int l1 = i + m * k;
79
               int l0;
80
 
81
               r0 = i0 = 0.0;
82
               for (j = 0, jp = A + i * stride, l0 = 0; j < r; ++j,
83
                    jp += m * stride) {
84
                    rw = c_re(W[l0]);
85
                    iw = c_im(W[l0]);
86
                    rt = c_re(*jp);
87
                    it = c_im(*jp);
88
                    r0 += rt * rw + it * iw;
89
                    i0 += it * rw - rt * iw;
90
                    l0 += l1;
91
                    if (l0 >= n)
92
                         l0 -= n;
93
               }
94
               c_re(*kp) = r0;
95
               c_im(*kp) = i0;
96
          }
97
          for (k = 0, kp = A + i * stride; k < r; ++k, kp += m * stride)
98
               *kp = tmp[k];
99
     }
100
 
101
     fftw_free(tmp);
102
}