37
35
/***************************************************************************/
39
static void apply_dit(const plan *ego_, R *I, R *O)
41
const P *ego = (const P *) ego_;
52
plan_rdft *cld = (plan_rdft *) ego->cld;
53
cld->apply((plan *) cld, I, O);
58
STACK_MALLOC(E *, buf, r * 2 * sizeof(E));
60
osm = (m = ego->m) * (os = ego->os);
68
/* compute the transform of the r 0th elements (which are real) */
69
for (i = 0; i + i < r; ++i) {
73
for (j = 0, wp = 0; j < r; ++j) {
87
/* store the transform back onto the A array */
89
for (i = 1; i + i < r; ++i) {
90
X[i * osm] = buf[2*i];
91
YO[-i * osm] = buf[2*i+1];
98
/* compute the transform of the middle elements (which are complex) */
99
for (k = 1; k + k < m; ++k, X += os, YI -= os, YO -= os) {
100
for (i = 0; i < r; ++i) {
104
for (j = 0, wp = 0; j < r; ++j) {
109
rsum += re * tw_r - im * tw_i;
110
isum += re * tw_i + im * tw_r;
119
/* store the transform back onto the A array */
120
for (i = 0; i + i < r; ++i) {
121
X[i * osm] = buf[2*i];
122
YO[-i * osm] = buf[2*i+1];
125
X[i * osm] = -buf[2*i+1];
126
YO[-i * osm] = buf[2*i];
130
/* no final element, since m is odd */
135
static void apply_dif(const plan *ego_, R *I, R *O)
137
const P *ego = (const P *) ego_;
149
STACK_MALLOC(E *, buf, r * 2 * sizeof(E));
151
ism = (m = ego->m) * (is = ego->os);
160
* compute the transform of the r 0th elements (which are halfcomplex)
161
* yielding real numbers
163
/* copy the input into the temporary array */
165
for (i = 1; i + i < r; ++i) {
166
buf[2*i] = X[i * ism];
167
buf[2*i+1] = YI[-i * ism];
170
for (i = 0; i < r; ++i) {
173
for (j = 1, wp = wincr; j + j < r; ++j) {
178
rsum += re * tw_r + im * tw_i;
183
X[i * ism] = K(2.0) * rsum + buf[0];
190
/* compute the transform of the middle elements (which are complex) */
191
for (k = 1; k + k < m; ++k, X += is, YI -= is, YO -= is) {
192
/* copy the input into the temporary array */
193
for (i = 0; i + i < r; ++i) {
194
buf[2*i] = X[i * ism];
195
buf[2*i+1] = YI[-i * ism];
198
buf[2*i+1] = -X[i * ism];
199
buf[2*i] = YI[-i * ism];
202
for (i = 0; i < r; ++i) {
206
for (j = 0, wp = k * i; j < r; ++j) {
211
rsum += re * tw_r + im * tw_i;
212
isum += im * tw_r - re * tw_i;
222
/* no final element, since m is odd */
227
plan_rdft *cld = (plan_rdft *) ego->cld;
228
cld->apply((plan *) cld, I, O);
37
static void cdot_r2hc(INT n, const E *x, const R *w, R *or0, R *oi1)
43
for (i = 1; i + i < n; ++i) {
52
static void hartley_r2hc(INT n, const R *xr, INT xs, E *o, R *pr)
56
o[0] = sr = xr[0]; o += 1;
57
for (i = 1; i + i < n; ++i) {
72
static void apply_r2hc(const plan *ego_, R *I, R *O)
74
const P *ego = (const P *) ego_;
76
INT n = ego->n, is = ego->is, os = ego->os;
77
const R *W = ego->td->W;
80
STACK_MALLOC(E *, buf, n * sizeof(E));
81
hartley_r2hc(n, I, is, buf, O);
83
for (i = 1; i + i < n; ++i) {
84
cdot_r2hc(n, buf, W, O + i * os, O + (n - i) * os);
92
static void cdot_hc2r(INT n, const E *x, const R *w, R *or0, R *or1)
98
for (i = 1; i + i < n; ++i) {
112
static void hartley_hc2r(INT n, const R *x, INT xs, E *o, R *pr)
117
o[0] = sr = x[0]; o += 1;
118
for (i = 1; i + i < n; ++i) {
119
sr += (o[0] = x[i * xs] + x[i * xs]);
120
o[1] = x[(n - i) * xs] + x[(n - i) * xs];
126
static void apply_hc2r(const plan *ego_, R *I, R *O)
128
const P *ego = (const P *) ego_;
130
INT n = ego->n, is = ego->is, os = ego->os;
131
const R *W = ego->td->W;
134
STACK_MALLOC(E *, buf, n * sizeof(E));
135
hartley_hc2r(n, I, is, buf, O);
137
for (i = 1; i + i < n; ++i) {
138
cdot_hc2r(n, buf, W, O + i * os, O + (n - i) * os);
233
146
/***************************************************************************/
235
static void awake(plan *ego_, int flg)
148
static void awake(plan *ego_, enum wakefulness wakefulness)
237
150
P *ego = (P *) ego_;
238
static const tw_instr generic_tw[] = {
239
{ TW_GENERIC, 0, 0 },
151
static const tw_instr half_tw[] = {
240
153
{ TW_NEXT, 1, 0 }
243
AWAKE(ego->cld, flg);
244
/* FIXME: can we get away with fewer twiddles? */
245
X(twiddle_awake)(flg, &ego->td, generic_tw,
246
ego->r * ego->m, ego->r, ego->m);
249
static void destroy(plan *ego_)
252
X(plan_destroy_internal)(ego->cld);
156
X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n,
255
160
static void print(const plan *ego_, printer *p)
257
162
const P *ego = (const P *) ego_;
259
p->print(p, "(rdft-generic-%s-%d%(%p%))",
260
ego->kind == R2HC ? "r2hc-dit" : "hc2r-dif",
164
p->print(p, "(rdft-generic-%s-%D)",
165
ego->kind == R2HC ? "r2hc" : "hc2r",
264
static int applicable0(const solver *ego_, const problem *p_)
169
static int applicable0(const S *ego, const problem *p_)
267
const S *ego = (const S *) ego_;
268
const problem_rdft *p = (const problem_rdft *) p_;
271
&& p->vecsz->rnk == 0
272
&& p->sz->dims[0].n > 1
273
&& p->sz->dims[0].n % 2 /* ensure r and n/r odd */
274
&& p->kind[0] == ego->kind
171
const problem_rdft *p = (const problem_rdft *) p_;
174
&& p->vecsz->rnk == 0
175
&& (p->sz->dims[0].n % 2) == 1
176
&& X(is_prime)(p->sz->dims[0].n)
177
&& p->kind[0] == ego->kind
281
static int applicable(const solver *ego_, const problem *p_,
181
static int applicable(const S *ego, const problem *p_,
282
182
const planner *plnr)
284
if (NO_UGLYP(plnr)) return 0; /* always ugly */
285
if (!applicable0(ego_, p_)) return 0;
184
if (NO_SLOWP(plnr)) return 0;
185
if (!applicable0(ego, p_)) return 0;
287
187
if (NO_LARGE_GENERICP(plnr)) {
288
188
const problem_rdft *p = (const problem_rdft *) p_;
289
if (X(first_divisor)(p->sz->dims[0].n) >= GENERIC_MIN_BAD) return 0;
189
if (p->sz->dims[0].n >= GENERIC_MIN_BAD) return 0;
294
static plan *mkplan(const solver *ego, const problem *p_, planner *plnr)
194
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
296
const problem_rdft *p = (const problem_rdft *) p_;
300
plan *cld = (plan *) 0;
196
const S *ego = (const S *)ego_;
197
const problem_rdft *p;
303
201
static const plan_adt padt = {
304
X(rdft_solve), awake, print, destroy
202
X(rdft_solve), awake, print, X(plan_null_destroy)
307
205
if (!applicable(ego, p_, plnr))
310
n = p->sz->dims[0].n;
311
is = p->sz->dims[0].is;
312
os = p->sz->dims[0].os;
314
r = X(first_divisor)(n);
317
if (R2HC_KINDP(p->kind[0])) {
318
cldp = X(mkproblem_rdft_d)(X(mktensor_1d)(m, r * is, os),
319
X(mktensor_1d)(r, is, m * os),
320
p->I, p->O, p->kind);
323
cldp = X(mkproblem_rdft_d)(X(mktensor_1d)(m, is, r * os),
324
X(mktensor_1d)(r, m * is, os),
325
p->I, p->O, p->kind);
327
if (!(cld = X(mkplan_d)(plnr, cldp))) goto nada;
329
pln = MKPLAN_RDFT(P, &padt, R2HC_KINDP(p->kind[0]) ? apply_dit:apply_dif);
331
pln->os = R2HC_KINDP(p->kind[0]) ? os : is;
208
p = (const problem_rdft *) p_;
209
pln = MKPLAN_RDFT(P, &padt,
210
R2HC_KINDP(p->kind[0]) ? apply_r2hc : apply_hc2r);
212
pln->n = n = p->sz->dims[0].n;
213
pln->is = p->sz->dims[0].is;
214
pln->os = p->sz->dims[0].os;
336
pln->kind = p->kind[0];
216
pln->kind = ego->kind;
338
X(ops_zero)(&pln->super.super.ops);
339
pln->super.super.ops.add = 4 * r * r;
340
pln->super.super.ops.mul = 4 * r * r;
341
/* loads + stores, minus loads + stores for all DIT codelets */
342
pln->super.super.ops.other = 4 * r + 4 * r * r - (6*r - 2);
343
X(ops_madd)((m - 1)/2, &pln->super.super.ops, &cld->ops,
344
&pln->super.super.ops);
345
pln->super.super.ops.add += 2 * r * r;
346
pln->super.super.ops.mul += 2 * r * r;
347
pln->super.super.ops.other += 3 * r + 3 * r * r - 2*r;
218
pln->super.super.ops.add = (n-1) * 2.5;
219
pln->super.super.ops.mul = 0;
220
pln->super.super.ops.fma = 0.5 * (n-1) * (n-1) ;
221
#if 0 /* these are nice pipelined sequential loads and should cost nothing */
222
pln->super.super.ops.other = (n-1)*(2 + 1 + (n-1)); /* approximate */
349
225
return &(pln->super.super);
352
X(plan_destroy_internal)(cld);
359
228
static solver *mksolver(rdft_kind kind)
361
static const solver_adt sadt = { mkplan };
230
static const solver_adt sadt = { PROBLEM_RDFT, mkplan };
362
231
S *slv = MKSOLVER(S, &sadt);
363
232
slv->kind = kind;
364
233
return &(slv->super);