Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/dft/generic.c @ 42:2cd0e3b3e1fd
Current fftw source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
41:481f5f8c5634 | 42:2cd0e3b3e1fd |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
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 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU 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 | |
21 #include "dft.h" | |
22 | |
23 typedef struct { | |
24 solver super; | |
25 } S; | |
26 | |
27 typedef struct { | |
28 plan_dft super; | |
29 twid *td; | |
30 INT n, is, os; | |
31 } P; | |
32 | |
33 | |
34 static void cdot(INT n, const E *x, const R *w, | |
35 R *or0, R *oi0, R *or1, R *oi1) | |
36 { | |
37 INT i; | |
38 | |
39 E rr = x[0], ri = 0, ir = x[1], ii = 0; | |
40 x += 2; | |
41 for (i = 1; i + i < n; ++i) { | |
42 rr += x[0] * w[0]; | |
43 ir += x[1] * w[0]; | |
44 ri += x[2] * w[1]; | |
45 ii += x[3] * w[1]; | |
46 x += 4; w += 2; | |
47 } | |
48 *or0 = rr + ii; | |
49 *oi0 = ir - ri; | |
50 *or1 = rr - ii; | |
51 *oi1 = ir + ri; | |
52 } | |
53 | |
54 static void hartley(INT n, const R *xr, const R *xi, INT xs, E *o, | |
55 R *pr, R *pi) | |
56 { | |
57 INT i; | |
58 E sr, si; | |
59 o[0] = sr = xr[0]; o[1] = si = xi[0]; o += 2; | |
60 for (i = 1; i + i < n; ++i) { | |
61 sr += (o[0] = xr[i * xs] + xr[(n - i) * xs]); | |
62 si += (o[1] = xi[i * xs] + xi[(n - i) * xs]); | |
63 o[2] = xr[i * xs] - xr[(n - i) * xs]; | |
64 o[3] = xi[i * xs] - xi[(n - i) * xs]; | |
65 o += 4; | |
66 } | |
67 *pr = sr; | |
68 *pi = si; | |
69 } | |
70 | |
71 static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io) | |
72 { | |
73 const P *ego = (const P *) ego_; | |
74 INT i; | |
75 INT n = ego->n, is = ego->is, os = ego->os; | |
76 const R *W = ego->td->W; | |
77 E *buf; | |
78 size_t bufsz = n * 2 * sizeof(E); | |
79 | |
80 BUF_ALLOC(E *, buf, bufsz); | |
81 hartley(n, ri, ii, is, buf, ro, io); | |
82 | |
83 for (i = 1; i + i < n; ++i) { | |
84 cdot(n, buf, W, | |
85 ro + i * os, io + i * os, | |
86 ro + (n - i) * os, io + (n - i) * os); | |
87 W += n - 1; | |
88 } | |
89 | |
90 BUF_FREE(buf, bufsz); | |
91 } | |
92 | |
93 static void awake(plan *ego_, enum wakefulness wakefulness) | |
94 { | |
95 P *ego = (P *) ego_; | |
96 static const tw_instr half_tw[] = { | |
97 { TW_HALF, 1, 0 }, | |
98 { TW_NEXT, 1, 0 } | |
99 }; | |
100 | |
101 X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n, | |
102 (ego->n - 1) / 2); | |
103 } | |
104 | |
105 static void print(const plan *ego_, printer *p) | |
106 { | |
107 const P *ego = (const P *) ego_; | |
108 | |
109 p->print(p, "(dft-generic-%D)", ego->n); | |
110 } | |
111 | |
112 static int applicable(const solver *ego, const problem *p_, | |
113 const planner *plnr) | |
114 { | |
115 const problem_dft *p = (const problem_dft *) p_; | |
116 UNUSED(ego); | |
117 | |
118 return (1 | |
119 && p->sz->rnk == 1 | |
120 && p->vecsz->rnk == 0 | |
121 && (p->sz->dims[0].n % 2) == 1 | |
122 && CIMPLIES(NO_LARGE_GENERICP(plnr), p->sz->dims[0].n < GENERIC_MIN_BAD) | |
123 && CIMPLIES(NO_SLOWP(plnr), p->sz->dims[0].n > GENERIC_MAX_SLOW) | |
124 && X(is_prime)(p->sz->dims[0].n) | |
125 ); | |
126 } | |
127 | |
128 static plan *mkplan(const solver *ego, const problem *p_, planner *plnr) | |
129 { | |
130 const problem_dft *p; | |
131 P *pln; | |
132 INT n; | |
133 | |
134 static const plan_adt padt = { | |
135 X(dft_solve), awake, print, X(plan_null_destroy) | |
136 }; | |
137 | |
138 if (!applicable(ego, p_, plnr)) | |
139 return (plan *)0; | |
140 | |
141 pln = MKPLAN_DFT(P, &padt, apply); | |
142 | |
143 p = (const problem_dft *) p_; | |
144 pln->n = n = p->sz->dims[0].n; | |
145 pln->is = p->sz->dims[0].is; | |
146 pln->os = p->sz->dims[0].os; | |
147 pln->td = 0; | |
148 | |
149 pln->super.super.ops.add = (n-1) * 5; | |
150 pln->super.super.ops.mul = 0; | |
151 pln->super.super.ops.fma = (n-1) * (n-1) ; | |
152 #if 0 /* these are nice pipelined sequential loads and should cost nothing */ | |
153 pln->super.super.ops.other = (n-1)*(4 + 1 + 2 * (n-1)); /* approximate */ | |
154 #endif | |
155 | |
156 return &(pln->super.super); | |
157 } | |
158 | |
159 static solver *mksolver(void) | |
160 { | |
161 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 }; | |
162 S *slv = MKSOLVER(S, &sadt); | |
163 return &(slv->super); | |
164 } | |
165 | |
166 void X(dft_generic_register)(planner *p) | |
167 { | |
168 REGISTER_SOLVER(p, mksolver()); | |
169 } |