/src/fftw3/rdft/direct-r2r.c
Line | Count | Source |
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 | | |
22 | | /* direct RDFT solver, using r2r codelets */ |
23 | | |
24 | | #include "rdft/rdft.h" |
25 | | |
26 | | typedef struct { |
27 | | solver super; |
28 | | const kr2r_desc *desc; |
29 | | kr2r k; |
30 | | } S; |
31 | | |
32 | | typedef struct { |
33 | | plan_rdft super; |
34 | | |
35 | | INT vl, ivs, ovs; |
36 | | stride is, os; |
37 | | kr2r k; |
38 | | const S *slv; |
39 | | } P; |
40 | | |
41 | | static void apply(const plan *ego_, R *I, R *O) |
42 | 0 | { |
43 | 0 | const P *ego = (const P *) ego_; |
44 | 0 | ASSERT_ALIGNED_DOUBLE; |
45 | 0 | ego->k(I, O, ego->is, ego->os, ego->vl, ego->ivs, ego->ovs); |
46 | 0 | } |
47 | | |
48 | | static void destroy(plan *ego_) |
49 | 0 | { |
50 | 0 | P *ego = (P *) ego_; |
51 | 0 | X(stride_destroy)(ego->is); |
52 | 0 | X(stride_destroy)(ego->os); |
53 | 0 | } |
54 | | |
55 | | static void print(const plan *ego_, printer *p) |
56 | 0 | { |
57 | 0 | const P *ego = (const P *) ego_; |
58 | 0 | const S *s = ego->slv; |
59 | |
|
60 | 0 | p->print(p, "(rdft-%s-direct-r2r-%D%v \"%s\")", |
61 | 0 | X(rdft_kind_str)(s->desc->kind), s->desc->n, |
62 | 0 | ego->vl, s->desc->nam); |
63 | 0 | } |
64 | | |
65 | | static int applicable(const solver *ego_, const problem *p_) |
66 | 658 | { |
67 | 658 | const S *ego = (const S *) ego_; |
68 | 658 | const problem_rdft *p = (const problem_rdft *) p_; |
69 | 658 | INT vl; |
70 | 658 | INT ivs, ovs; |
71 | | |
72 | 658 | return ( |
73 | 658 | 1 |
74 | 658 | && p->sz->rnk == 1 |
75 | 0 | && p->vecsz->rnk <= 1 |
76 | 0 | && p->sz->dims[0].n == ego->desc->n |
77 | 0 | && p->kind[0] == ego->desc->kind |
78 | | |
79 | | /* check strides etc */ |
80 | 0 | && X(tensor_tornk1)(p->vecsz, &vl, &ivs, &ovs) |
81 | | |
82 | 0 | && (0 |
83 | | /* can operate out-of-place */ |
84 | 0 | || p->I != p->O |
85 | | |
86 | | /* computing one transform */ |
87 | 0 | || vl == 1 |
88 | | |
89 | | /* can operate in-place as long as strides are the same */ |
90 | 0 | || X(tensor_inplace_strides2)(p->sz, p->vecsz) |
91 | 0 | ) |
92 | 658 | ); |
93 | 658 | } |
94 | | |
95 | | static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) |
96 | 658 | { |
97 | 658 | const S *ego = (const S *) ego_; |
98 | 658 | P *pln; |
99 | 658 | const problem_rdft *p; |
100 | 658 | iodim *d; |
101 | | |
102 | 658 | static const plan_adt padt = { |
103 | 658 | X(rdft_solve), X(null_awake), print, destroy |
104 | 658 | }; |
105 | | |
106 | 658 | UNUSED(plnr); |
107 | | |
108 | 658 | if (!applicable(ego_, p_)) |
109 | 658 | return (plan *)0; |
110 | | |
111 | 0 | p = (const problem_rdft *) p_; |
112 | | |
113 | |
|
114 | 0 | pln = MKPLAN_RDFT(P, &padt, apply); |
115 | |
|
116 | 0 | d = p->sz->dims; |
117 | |
|
118 | 0 | pln->k = ego->k; |
119 | |
|
120 | 0 | pln->is = X(mkstride)(d->n, d->is); |
121 | 0 | pln->os = X(mkstride)(d->n, d->os); |
122 | |
|
123 | 0 | X(tensor_tornk1)(p->vecsz, &pln->vl, &pln->ivs, &pln->ovs); |
124 | |
|
125 | 0 | pln->slv = ego; |
126 | 0 | X(ops_zero)(&pln->super.super.ops); |
127 | 0 | X(ops_madd2)(pln->vl / ego->desc->genus->vl, |
128 | 0 | &ego->desc->ops, |
129 | 0 | &pln->super.super.ops); |
130 | |
|
131 | 0 | pln->super.super.could_prune_now_p = 1; |
132 | |
|
133 | 0 | return &(pln->super.super); |
134 | 658 | } |
135 | | |
136 | | /* constructor */ |
137 | | solver *X(mksolver_rdft_r2r_direct)(kr2r k, const kr2r_desc *desc) |
138 | 2 | { |
139 | 2 | static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 }; |
140 | 2 | S *slv = MKSOLVER(S, &sadt); |
141 | 2 | slv->k = k; |
142 | 2 | slv->desc = desc; |
143 | 2 | return &(slv->super); |
144 | 2 | } |
145 | | |