2
* Copyright (c) 2003, 2006 Matteo Frigo
3
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
/* express a twiddle problem in terms of dft + multiplication by
31
INT r, m, s, vl, vs, mstart, mcount;
34
/* defined only for solver1: */
41
static void mktwiddle(P *ego, enum wakefulness wakefulness)
43
static const tw_instr tw[] = { { TW_FULL, 0, 0 }, { TW_NEXT, 1, 0 } };
45
/* note that R and M are swapped, to allow for sequential
46
access both to data and twiddles */
47
X(twiddle_awake)(wakefulness, &ego->td, tw,
48
ego->r * ego->m, ego->m, ego->r);
51
static void bytwiddle(const P *ego, R *rio, R *iio)
54
INT r = ego->r, m = ego->m, s = ego->s, vl = ego->vl, vs = ego->vs;
55
INT mcount = ego->mcount, mstart = ego->mstart;
56
INT jstart = mstart == 0;
57
INT jrem_W = 2 * ((m - 1) - (mcount - jstart));
58
INT jrem_p = s * (m - mcount);
62
for (i = 0; i < vl; ++i) {
63
const R *W = ego->td->W + 2 * (mstart - 1 + jstart);
65
/* loop invariant: p = rio + s * (k * m + j) + i * vs. */
68
for (k = 1, p += s * m, W += 2 * (m - 1); k < r; ++k) {
69
for (j = jstart, p += jstart*s; j < mcount; ++j, p += s) {
74
p[0] = xr * wr + xi * wi;
75
p[ip] = xi * wr - xr * wi;
84
static int applicable(INT r, INT m, const planner *plnr)
92
static void apply_dit(const plan *ego_, R *rio, R *iio)
94
const P *ego = (const P *) ego_;
97
bytwiddle(ego, rio, iio);
99
cld = (plan_dft *) ego->cld;
100
cld->apply(ego->cld, rio, iio, rio, iio);
103
static void apply_dif(const plan *ego_, R *rio, R *iio)
105
const P *ego = (const P *) ego_;
108
cld = (plan_dft *) ego->cld;
109
cld->apply(ego->cld, rio, iio, rio, iio);
111
bytwiddle(ego, rio, iio);
114
static void awake(plan *ego_, enum wakefulness wakefulness)
117
X(plan_awake)(ego->cld, wakefulness);
118
mktwiddle(ego, wakefulness);
121
static void destroy(plan *ego_)
124
X(plan_destroy_internal)(ego->cld);
127
static void print(const plan *ego_, printer *p)
129
const P *ego = (const P *) ego_;
130
p->print(p, "(dftw-generic-%s-%D-%D%v%(%p%))",
131
ego->dec == DECDIT ? "dit" : "dif",
132
ego->r, ego->m, ego->vl, ego->cld);
135
static plan *mkcldw(const ct_solver *ego_,
136
int dec, INT r, INT m, INT s, INT vl, INT vs,
137
INT mstart, INT mcount,
141
const S *ego = (const S *)ego_;
145
static const plan_adt padt = {
146
0, awake, print, destroy
149
A(mstart >= 0 && mstart + mcount <= m);
150
if (!applicable(r, m, plnr))
153
cld = X(mkplan_d)(plnr,
155
X(mktensor_1d)(r, m * s, m * s),
156
X(mktensor_2d)(mcount, s, s, vl, vs, vs),
161
pln = MKPLAN_DFTW(P, &padt, dec == DECDIT ? apply_dit : apply_dif);
169
pln->mstart = mstart;
170
pln->mcount = mcount;
175
double n0 = (r - 1) * (mcount - 1) * vl;
176
pln->super.super.ops = cld->ops;
177
pln->super.super.ops.mul += 8 * n0;
178
pln->super.super.ops.add += 4 * n0;
179
pln->super.super.ops.other += 8 * n0;
181
return &(pln->super.super);
184
X(plan_destroy_internal)(cld);
188
static void regsolver(planner *plnr, INT r, int dec)
190
S *slv = (S *)X(mksolver_ct)(sizeof(S), r, dec, mkcldw);
191
REGISTER_SOLVER(plnr, &(slv->super));
192
if (X(mksolver_ct_hook)) {
193
slv = (S *)X(mksolver_ct_hook)(sizeof(S), r, dec, mkcldw);
194
REGISTER_SOLVER(plnr, &(slv->super));
198
void X(ct_generic_register)(planner *p)
200
regsolver(p, 0, DECDIT);
201
regsolver(p, 0, DECDIF);