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
34
static void cdot(INT n, const E *x, const R *w,
35
R *or0, R *oi0, R *or1, R *oi1)
39
E rr = x[0], ri = 0, ir = x[1], ii = 0;
41
for (i = 1; i + i < n; ++i) {
54
static void hartley(INT n, const R *xr, const R *xi, INT xs, E *o,
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];
71
static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io)
73
const P *ego = (const P *) ego_;
75
INT n = ego->n, is = ego->is, os = ego->os;
76
const R *W = ego->td->W;
79
STACK_MALLOC(E *, buf, n * 2 * sizeof(E));
80
hartley(n, ri, ii, is, buf, ro, io);
82
for (i = 1; i + i < n; ++i) {
84
ro + i * os, io + i * os,
85
ro + (n - i) * os, io + (n - i) * os);
92
static void awake(plan *ego_, enum wakefulness wakefulness)
95
static const tw_instr half_tw[] = {
100
X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n,
104
static void print(const plan *ego_, printer *p)
106
const P *ego = (const P *) ego_;
108
p->print(p, "(dft-generic-%D)", ego->n);
111
static int applicable0(const problem *p_)
113
const problem_dft *p = (const problem_dft *) p_;
116
&& p->vecsz->rnk == 0
117
&& (p->sz->dims[0].n % 2) == 1
118
&& X(is_prime)(p->sz->dims[0].n)
122
static int applicable(const solver *ego, const problem *p_,
126
if (NO_SLOWP(plnr)) return 0;
127
if (!applicable0(p_)) return 0;
129
if (NO_LARGE_GENERICP(plnr)) {
130
const problem_dft *p = (const problem_dft *) p_;
131
if (p->sz->dims[0].n >= GENERIC_MIN_BAD) return 0;
136
static plan *mkplan(const solver *ego, const problem *p_, planner *plnr)
138
const problem_dft *p;
142
static const plan_adt padt = {
143
X(dft_solve), awake, print, X(plan_null_destroy)
146
if (!applicable(ego, p_, plnr))
149
pln = MKPLAN_DFT(P, &padt, apply);
151
p = (const problem_dft *) p_;
152
pln->n = n = p->sz->dims[0].n;
153
pln->is = p->sz->dims[0].is;
154
pln->os = p->sz->dims[0].os;
157
pln->super.super.ops.add = (n-1) * 5;
158
pln->super.super.ops.mul = 0;
159
pln->super.super.ops.fma = (n-1) * (n-1) ;
160
#if 0 /* these are nice pipelined sequential loads and should cost nothing */
161
pln->super.super.ops.other = (n-1)*(4 + 1 + 2 * (n-1)); /* approximate */
164
return &(pln->super.super);
167
static solver *mksolver(void)
169
static const solver_adt sadt = { PROBLEM_DFT, mkplan };
170
S *slv = MKSOLVER(S, &sadt);
171
return &(slv->super);
174
void X(dft_generic_register)(planner *p)
176
REGISTER_SOLVER(p, mksolver());