2
// This cache uses FFTW_MEASURE for the plans, and do not copy the data.
3
GEN_CACHE(zfftw3,(int n,int d)
7
,((caches_zfftw3[i].n==n) &&
8
(caches_zfftw3[i].direction==d))
9
,caches_zfftw3[id].direction = d;
10
// This working buffer is only used to compute the plan: we need it
11
// since FFTW_MEASURE destroys its input when computing a plan
12
caches_zfftw3[id].wrk = fftw_malloc(n * sizeof(double) * 2);
13
caches_zfftw3[id].plan = fftw_plan_dft_1d(n,
14
caches_zfftw3[id].wrk,
15
caches_zfftw3[id].wrk,
16
(d>0?FFTW_FORWARD:FFTW_BACKWARD),
17
FFTW_ESTIMATE | FFTW_UNALIGNED);
18
,//fftw_print_plan(caches_zfftw3[id].plan);
19
fftw_destroy_plan(caches_zfftw3[id].plan);
20
fftw_free(caches_zfftw3[id].wrk);
22
//fprintf(stderr, "aligned count %d\n", countaligned);
25
static void zfft_fftw3(complex_double * inout, int n, int dir, int
26
howmany, int normalize)
28
fftw_complex *ptr = (fftw_complex*)inout;
30
fftw_plan plan = NULL;
35
plan = caches_zfftw3[get_cache_id_zfftw3(n, dir)].plan;
39
for (i = 0; i < howmany; ++i, ptr += n) {
40
fftw_execute_dft(plan, ptr, ptr);
45
for (i = 0; i < howmany; ++i, ptr += n) {
46
fftw_execute_dft(plan, ptr, ptr);
51
fprintf(stderr, "zfft: invalid dir=%d\n", dir);
55
ptr =(fftw_complex*)inout;
56
for (i = n * howmany - 1; i >= 0; --i) {
57
*((double *) (ptr)) *= factor;
58
*((double *) (ptr++) + 1) *= factor;
59
//*((double *) (ptr)) /= n;
60
//*((double *) (ptr++) + 1) /= n;
65
GEN_CACHE(zfftw3,(int n,int d)
69
,((caches_zfftw3[i].n==n) &&
70
(caches_zfftw3[i].direction==d))
71
,caches_zfftw3[id].direction = d;
72
caches_zfftw3[id].ptr = fftw_malloc(sizeof(fftw_complex)*(n));
73
caches_zfftw3[id].plan = fftw_plan_dft_1d(n, caches_zfftw3[id].ptr,
74
caches_zfftw3[id].ptr,
75
(d>0?FFTW_FORWARD:FFTW_BACKWARD),
77
,fftw_destroy_plan(caches_zfftw3[id].plan);
78
fftw_free(caches_zfftw3[id].ptr);
81
static void zfft_fftw3(complex_double * inout, int n, int dir, int
82
howmany, int normalize)
84
complex_double *ptr = inout;
85
fftw_complex *ptrm = NULL;
86
fftw_plan plan = NULL;
90
plan = caches_zfftw3[get_cache_id_zfftw3(n, dir)].plan;
94
for (i = 0; i < howmany; ++i, ptr += n) {
96
caches_zfftw3[get_cache_id_zfftw3(n, dir)].ptr;
97
memcpy(ptrm, ptr, sizeof(double) * 2 * n);
99
memcpy(ptr, ptrm, sizeof(double) * 2 * n);
104
for (i = 0; i < howmany; ++i, ptr += n) {
106
caches_zfftw3[get_cache_id_zfftw3(n, dir)].ptr;
107
memcpy(ptrm, ptr, sizeof(double) * 2 * n);
109
memcpy(ptr, ptrm, sizeof(double) * 2 * n);
114
fprintf(stderr, "zfft: invalid dir=%d\n", dir);
119
for (i = n * howmany - 1; i >= 0; --i) {
120
*((double *) (ptr)) /= n;
121
*((double *) (ptr++) + 1) /= n;