/src/fftw3/rdft/rank0-rdft2.c
Line | Count | Source (jump to first uncovered line) |
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 | | /* plans for rank-0 RDFT2 (copy operations, plus setting 0 imag. parts) */ |
23 | | |
24 | | #include "rdft/rdft.h" |
25 | | |
26 | | #ifdef HAVE_STRING_H |
27 | | #include <string.h> /* for memcpy() */ |
28 | | #endif |
29 | | |
30 | | typedef struct { |
31 | | solver super; |
32 | | } S; |
33 | | |
34 | | typedef struct { |
35 | | plan_rdft super; |
36 | | INT vl; |
37 | | INT ivs, ovs; |
38 | | plan *cldcpy; |
39 | | } P; |
40 | | |
41 | | static int applicable(const problem *p_) |
42 | 0 | { |
43 | 0 | const problem_rdft2 *p = (const problem_rdft2 *) p_; |
44 | 0 | return (1 |
45 | 0 | && p->sz->rnk == 0 |
46 | 0 | && (p->kind == HC2R |
47 | 0 | || |
48 | 0 | (1 |
49 | 0 | && p->kind == R2HC |
50 | | |
51 | 0 | && p->vecsz->rnk <= 1 |
52 | | |
53 | 0 | && ((p->r0 != p->cr) |
54 | 0 | || |
55 | 0 | X(rdft2_inplace_strides)(p, RNK_MINFTY)) )) |
56 | 0 | ); |
57 | 0 | } |
58 | | |
59 | | static void apply_r2hc(const plan *ego_, R *r0, R *r1, R *cr, R *ci) |
60 | 0 | { |
61 | 0 | const P *ego = (const P *) ego_; |
62 | 0 | INT i, vl = ego->vl; |
63 | 0 | INT ivs = ego->ivs, ovs = ego->ovs; |
64 | |
|
65 | 0 | UNUSED(r1); /* rank-0 has no real odd-index elements */ |
66 | |
|
67 | 0 | for (i = 4; i <= vl; i += 4) { |
68 | 0 | R x0, x1, x2, x3; |
69 | 0 | x0 = *r0; r0 += ivs; |
70 | 0 | x1 = *r0; r0 += ivs; |
71 | 0 | x2 = *r0; r0 += ivs; |
72 | 0 | x3 = *r0; r0 += ivs; |
73 | 0 | *cr = x0; cr += ovs; |
74 | 0 | *ci = K(0.0); ci += ovs; |
75 | 0 | *cr = x1; cr += ovs; |
76 | 0 | *ci = K(0.0); ci += ovs; |
77 | 0 | *cr = x2; cr += ovs; |
78 | 0 | *ci = K(0.0); ci += ovs; |
79 | 0 | *cr = x3; cr += ovs; |
80 | 0 | *ci = K(0.0); ci += ovs; |
81 | 0 | } |
82 | 0 | for (; i < vl + 4; ++i) { |
83 | 0 | R x0; |
84 | 0 | x0 = *r0; r0 += ivs; |
85 | 0 | *cr = x0; cr += ovs; |
86 | 0 | *ci = K(0.0); ci += ovs; |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | /* in-place r2hc rank-0: set imaginary parts of output to 0 */ |
91 | | static void apply_r2hc_inplace(const plan *ego_, R *r0, R *r1, R *cr, R *ci) |
92 | 0 | { |
93 | 0 | const P *ego = (const P *) ego_; |
94 | 0 | INT i, vl = ego->vl; |
95 | 0 | INT ovs = ego->ovs; |
96 | |
|
97 | 0 | UNUSED(r0); UNUSED(r1); UNUSED(cr); |
98 | |
|
99 | 0 | for (i = 4; i <= vl; i += 4) { |
100 | 0 | *ci = K(0.0); ci += ovs; |
101 | 0 | *ci = K(0.0); ci += ovs; |
102 | 0 | *ci = K(0.0); ci += ovs; |
103 | 0 | *ci = K(0.0); ci += ovs; |
104 | 0 | } |
105 | 0 | for (; i < vl + 4; ++i) { |
106 | 0 | *ci = K(0.0); ci += ovs; |
107 | 0 | } |
108 | 0 | } |
109 | | |
110 | | /* a rank-0 HC2R rdft2 problem is just a copy from cr to r0, |
111 | | so we can use a rank-0 rdft plan */ |
112 | | static void apply_hc2r(const plan *ego_, R *r0, R *r1, R *cr, R *ci) |
113 | 0 | { |
114 | 0 | const P *ego = (const P *) ego_; |
115 | 0 | plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy; |
116 | 0 | UNUSED(ci); |
117 | 0 | UNUSED(r1); |
118 | 0 | cldcpy->apply((plan *) cldcpy, cr, r0); |
119 | 0 | } |
120 | | |
121 | | static void awake(plan *ego_, enum wakefulness wakefulness) |
122 | 0 | { |
123 | 0 | P *ego = (P *) ego_; |
124 | 0 | if (ego->cldcpy) |
125 | 0 | X(plan_awake)(ego->cldcpy, wakefulness); |
126 | 0 | } |
127 | | |
128 | | static void destroy(plan *ego_) |
129 | 0 | { |
130 | 0 | P *ego = (P *) ego_; |
131 | 0 | if (ego->cldcpy) |
132 | 0 | X(plan_destroy_internal)(ego->cldcpy); |
133 | 0 | } |
134 | | |
135 | | static void print(const plan *ego_, printer *p) |
136 | 0 | { |
137 | 0 | const P *ego = (const P *) ego_; |
138 | 0 | if (ego->cldcpy) |
139 | 0 | p->print(p, "(rdft2-hc2r-rank0%(%p%))", ego->cldcpy); |
140 | 0 | else |
141 | 0 | p->print(p, "(rdft2-r2hc-rank0%v)", ego->vl); |
142 | 0 | } |
143 | | |
144 | | static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) |
145 | 0 | { |
146 | 0 | const problem_rdft2 *p; |
147 | 0 | plan *cldcpy = (plan *) 0; |
148 | 0 | P *pln; |
149 | |
|
150 | 0 | static const plan_adt padt = { |
151 | 0 | X(rdft2_solve), awake, print, destroy |
152 | 0 | }; |
153 | |
|
154 | 0 | UNUSED(ego_); |
155 | |
|
156 | 0 | if (!applicable(p_)) |
157 | 0 | return (plan *) 0; |
158 | | |
159 | 0 | p = (const problem_rdft2 *) p_; |
160 | |
|
161 | 0 | if (p->kind == HC2R) { |
162 | 0 | cldcpy = X(mkplan_d)(plnr, |
163 | 0 | X(mkproblem_rdft_0_d)( |
164 | 0 | X(tensor_copy)(p->vecsz), |
165 | 0 | p->cr, p->r0)); |
166 | 0 | if (!cldcpy) return (plan *) 0; |
167 | 0 | } |
168 | | |
169 | 0 | pln = MKPLAN_RDFT2(P, &padt, |
170 | 0 | p->kind == R2HC ? |
171 | 0 | (p->r0 == p->cr ? apply_r2hc_inplace : apply_r2hc) |
172 | 0 | : apply_hc2r); |
173 | | |
174 | 0 | if (p->kind == R2HC) |
175 | 0 | X(tensor_tornk1)(p->vecsz, &pln->vl, &pln->ivs, &pln->ovs); |
176 | 0 | pln->cldcpy = cldcpy; |
177 | |
|
178 | 0 | if (p->kind == R2HC) { |
179 | | /* vl loads, 2*vl stores */ |
180 | 0 | X(ops_other)(3 * pln->vl, &pln->super.super.ops); |
181 | 0 | } |
182 | 0 | else { |
183 | 0 | pln->super.super.ops = cldcpy->ops; |
184 | 0 | } |
185 | |
|
186 | 0 | return &(pln->super.super); |
187 | 0 | } |
188 | | |
189 | | static solver *mksolver(void) |
190 | 1 | { |
191 | 1 | static const solver_adt sadt = { PROBLEM_RDFT2, mkplan, 0 }; |
192 | 1 | S *slv = MKSOLVER(S, &sadt); |
193 | 1 | return &(slv->super); |
194 | 1 | } |
195 | | |
196 | | void X(rdft2_rank0_register)(planner *p) |
197 | 1 | { |
198 | 1 | REGISTER_SOLVER(p, mksolver()); |
199 | 1 | } |