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
/* $Id: direct2.c,v 1.24 2006-01-05 03:04:27 stevenj Exp $ */
23
/* direct RDFT2 R2HC/HC2R solver, if we have a codelet */
35
const kr2hc_desc *r2hc;
36
const khc2r_desc *hc2r;
55
static void apply_r2hc(const plan *ego_, R *r, R *rio, R *iio)
57
const P *ego = (const P *) ego_;
58
INT i, vl = ego->vl, ovs = ego->ovs;
59
ASSERT_ALIGNED_DOUBLE;
60
ego->k.r2hc(r, rio, iio, ego->is, ego->os, ego->os,
62
for (i = 0; i < vl; ++i, iio += ovs)
63
iio[0] = iio[ego->ilast] = 0;
66
static void apply_hc2r(const plan *ego_, R *r, R *rio, R *iio)
68
const P *ego = (const P *) ego_;
69
ASSERT_ALIGNED_DOUBLE;
70
ego->k.hc2r(rio, iio, r, ego->os, ego->os, ego->is,
71
ego->vl, ego->ivs, ego->ovs);
74
static void destroy(plan *ego_)
77
X(stride_destroy)(ego->is);
78
X(stride_destroy)(ego->os);
81
static void print(const plan *ego_, printer *p)
83
const P *ego = (const P *) ego_;
84
const S *s = ego->slv;
86
p->print(p, "(rdft2-%s-direct-%D%v \"%s\")",
87
X(rdft_kind_str)(s->kind), s->sz, ego->vl, s->nam);
90
static int applicable(const solver *ego_, const problem *p_)
92
const S *ego = (const S *) ego_;
93
const problem_rdft2 *p = (const problem_rdft2 *) p_;
100
&& p->vecsz->rnk <= 1
101
&& p->sz->dims[0].n == ego->sz
102
&& p->kind == ego->kind
104
/* check strides etc */
105
&& X(tensor_tornk1)(p->vecsz, &vl, &ivs, &ovs)
107
&& (ego->kind != R2HC ||
108
ego->desc.r2hc->genus->okp(ego->desc.r2hc,
109
p->r, p->rio, p->rio,
114
&& (ego->kind != HC2R ||
115
ego->desc.hc2r->genus->okp(ego->desc.hc2r,
116
p->rio, p->rio, p->r,
123
/* can operate out-of-place */
127
* can compute one transform in-place, no matter
128
* what the strides are.
130
|| p->vecsz->rnk == 0
132
/* can operate in-place as long as strides are the same */
133
|| X(rdft2_inplace_strides)(p, RNK_MINFTY)
138
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
140
const S *ego = (const S *) ego_;
142
const problem_rdft2 *p;
146
static const plan_adt padt = {
147
X(rdft2_solve), X(null_awake), print, destroy
152
if (!applicable(ego_, p_))
155
p = (const problem_rdft2 *) p_;
157
r2hc_kindp = p->kind == R2HC;
158
A(r2hc_kindp || p->kind == HC2R);
160
pln = MKPLAN_RDFT2(P, &padt, r2hc_kindp ? apply_r2hc : apply_hc2r);
166
pln->is = X(mkstride)(ego->sz, r2hc_kindp ? d.is : d.os);
167
pln->os = X(mkstride)(d.n/2 + 1, r2hc_kindp ? d.os : d.is);
169
X(tensor_tornk1)(p->vecsz, &pln->vl, &pln->ivs, &pln->ovs);
171
pln->ilast = (d.n % 2) ? 0 : (d.n/2) * d.os; /* Nyquist freq., if any */
174
X(ops_zero)(&pln->super.super.ops);
176
X(ops_madd2)(pln->vl / ego->desc.r2hc->genus->vl,
177
&ego->desc.r2hc->ops,
178
&pln->super.super.ops);
180
X(ops_madd2)(pln->vl / ego->desc.hc2r->genus->vl,
181
&ego->desc.hc2r->ops,
182
&pln->super.super.ops);
183
pln->super.super.ops.other += 2 * pln->vl; /* + 2 stores */
186
pln->super.super.could_prune_now_p = 1;
187
return &(pln->super.super);
191
solver *X(mksolver_rdft2_r2hc_direct)(kr2hc k, const kr2hc_desc *desc)
193
static const solver_adt sadt = { PROBLEM_RDFT2, mkplan };
194
S *slv = MKSOLVER(S, &sadt);
196
slv->desc.r2hc = desc;
198
slv->nam = desc->nam;
199
slv->kind = desc->genus->kind;
200
return &(slv->super);
203
solver *X(mksolver_rdft2_hc2r_direct)(khc2r k, const khc2r_desc *desc)
205
static const solver_adt sadt = { PROBLEM_RDFT2, mkplan };
206
S *slv = MKSOLVER(S, &sadt);
208
slv->desc.hc2r = desc;
210
slv->nam = desc->nam;
211
slv->kind = desc->genus->kind;
212
return &(slv->super);