annotate src/fftw-3.3.5/rdft/indirect.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21
Chris@42 22
Chris@42 23 /* solvers/plans for vectors of small RDFT's that cannot be done
Chris@42 24 in-place directly. Use a rank-0 plan to rearrange the data
Chris@42 25 before or after the transform. Can also change an out-of-place
Chris@42 26 plan into a copy + in-place (where the in-place transform
Chris@42 27 is e.g. unit stride). */
Chris@42 28
Chris@42 29 /* FIXME: merge with rank-geq2.c(?), since this is just a special case
Chris@42 30 of a rank split where the first/second transform has rank 0. */
Chris@42 31
Chris@42 32 #include "rdft.h"
Chris@42 33
Chris@42 34 typedef problem *(*mkcld_t) (const problem_rdft *p);
Chris@42 35
Chris@42 36 typedef struct {
Chris@42 37 rdftapply apply;
Chris@42 38 problem *(*mkcld)(const problem_rdft *p);
Chris@42 39 const char *nam;
Chris@42 40 } ndrct_adt;
Chris@42 41
Chris@42 42 typedef struct {
Chris@42 43 solver super;
Chris@42 44 const ndrct_adt *adt;
Chris@42 45 } S;
Chris@42 46
Chris@42 47 typedef struct {
Chris@42 48 plan_rdft super;
Chris@42 49 plan *cldcpy, *cld;
Chris@42 50 const S *slv;
Chris@42 51 } P;
Chris@42 52
Chris@42 53 /*-----------------------------------------------------------------------*/
Chris@42 54 /* first rearrange, then transform */
Chris@42 55 static void apply_before(const plan *ego_, R *I, R *O)
Chris@42 56 {
Chris@42 57 const P *ego = (const P *) ego_;
Chris@42 58
Chris@42 59 {
Chris@42 60 plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
Chris@42 61 cldcpy->apply(ego->cldcpy, I, O);
Chris@42 62 }
Chris@42 63 {
Chris@42 64 plan_rdft *cld = (plan_rdft *) ego->cld;
Chris@42 65 cld->apply(ego->cld, O, O);
Chris@42 66 }
Chris@42 67 }
Chris@42 68
Chris@42 69 static problem *mkcld_before(const problem_rdft *p)
Chris@42 70 {
Chris@42 71 return X(mkproblem_rdft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_OS),
Chris@42 72 X(tensor_copy_inplace)(p->vecsz, INPLACE_OS),
Chris@42 73 p->O, p->O, p->kind);
Chris@42 74 }
Chris@42 75
Chris@42 76 static const ndrct_adt adt_before =
Chris@42 77 {
Chris@42 78 apply_before, mkcld_before, "rdft-indirect-before"
Chris@42 79 };
Chris@42 80
Chris@42 81 /*-----------------------------------------------------------------------*/
Chris@42 82 /* first transform, then rearrange */
Chris@42 83
Chris@42 84 static void apply_after(const plan *ego_, R *I, R *O)
Chris@42 85 {
Chris@42 86 const P *ego = (const P *) ego_;
Chris@42 87
Chris@42 88 {
Chris@42 89 plan_rdft *cld = (plan_rdft *) ego->cld;
Chris@42 90 cld->apply(ego->cld, I, I);
Chris@42 91 }
Chris@42 92 {
Chris@42 93 plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
Chris@42 94 cldcpy->apply(ego->cldcpy, I, O);
Chris@42 95 }
Chris@42 96 }
Chris@42 97
Chris@42 98 static problem *mkcld_after(const problem_rdft *p)
Chris@42 99 {
Chris@42 100 return X(mkproblem_rdft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_IS),
Chris@42 101 X(tensor_copy_inplace)(p->vecsz, INPLACE_IS),
Chris@42 102 p->I, p->I, p->kind);
Chris@42 103 }
Chris@42 104
Chris@42 105 static const ndrct_adt adt_after =
Chris@42 106 {
Chris@42 107 apply_after, mkcld_after, "rdft-indirect-after"
Chris@42 108 };
Chris@42 109
Chris@42 110 /*-----------------------------------------------------------------------*/
Chris@42 111 static void destroy(plan *ego_)
Chris@42 112 {
Chris@42 113 P *ego = (P *) ego_;
Chris@42 114 X(plan_destroy_internal)(ego->cld);
Chris@42 115 X(plan_destroy_internal)(ego->cldcpy);
Chris@42 116 }
Chris@42 117
Chris@42 118 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@42 119 {
Chris@42 120 P *ego = (P *) ego_;
Chris@42 121 X(plan_awake)(ego->cldcpy, wakefulness);
Chris@42 122 X(plan_awake)(ego->cld, wakefulness);
Chris@42 123 }
Chris@42 124
Chris@42 125 static void print(const plan *ego_, printer *p)
Chris@42 126 {
Chris@42 127 const P *ego = (const P *) ego_;
Chris@42 128 const S *s = ego->slv;
Chris@42 129 p->print(p, "(%s%(%p%)%(%p%))", s->adt->nam, ego->cld, ego->cldcpy);
Chris@42 130 }
Chris@42 131
Chris@42 132 static int applicable0(const solver *ego_, const problem *p_,
Chris@42 133 const planner *plnr)
Chris@42 134 {
Chris@42 135 const S *ego = (const S *) ego_;
Chris@42 136 const problem_rdft *p = (const problem_rdft *) p_;
Chris@42 137 return (1
Chris@42 138 && FINITE_RNK(p->vecsz->rnk)
Chris@42 139
Chris@42 140 /* problem must be a nontrivial transform, not just a copy */
Chris@42 141 && p->sz->rnk > 0
Chris@42 142
Chris@42 143 && (0
Chris@42 144
Chris@42 145 /* problem must be in-place & require some
Chris@42 146 rearrangement of the data */
Chris@42 147 || (p->I == p->O
Chris@42 148 && !(X(tensor_inplace_strides2)(p->sz, p->vecsz)))
Chris@42 149
Chris@42 150 /* or problem must be out of place, transforming
Chris@42 151 from stride 1/2 to bigger stride, for apply_after */
Chris@42 152 || (p->I != p->O && ego->adt->apply == apply_after
Chris@42 153 && !NO_DESTROY_INPUTP(plnr)
Chris@42 154 && X(tensor_min_istride)(p->sz) <= 2
Chris@42 155 && X(tensor_min_ostride)(p->sz) > 2)
Chris@42 156
Chris@42 157 /* or problem must be out of place, transforming
Chris@42 158 to stride 1/2 from bigger stride, for apply_before */
Chris@42 159 || (p->I != p->O && ego->adt->apply == apply_before
Chris@42 160 && X(tensor_min_ostride)(p->sz) <= 2
Chris@42 161 && X(tensor_min_istride)(p->sz) > 2)
Chris@42 162
Chris@42 163 )
Chris@42 164 );
Chris@42 165 }
Chris@42 166
Chris@42 167 static int applicable(const solver *ego_, const problem *p_,
Chris@42 168 const planner *plnr)
Chris@42 169 {
Chris@42 170 if (!applicable0(ego_, p_, plnr)) return 0;
Chris@42 171
Chris@42 172 if (NO_INDIRECT_OP_P(plnr)) {
Chris@42 173 const problem_rdft *p = (const problem_rdft *)p_;
Chris@42 174 if (p->I != p->O) return 0;
Chris@42 175 }
Chris@42 176
Chris@42 177 return 1;
Chris@42 178 }
Chris@42 179
Chris@42 180 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@42 181 {
Chris@42 182 const problem_rdft *p = (const problem_rdft *) p_;
Chris@42 183 const S *ego = (const S *) ego_;
Chris@42 184 P *pln;
Chris@42 185 plan *cld = 0, *cldcpy = 0;
Chris@42 186
Chris@42 187 static const plan_adt padt = {
Chris@42 188 X(rdft_solve), awake, print, destroy
Chris@42 189 };
Chris@42 190
Chris@42 191 if (!applicable(ego_, p_, plnr))
Chris@42 192 return (plan *) 0;
Chris@42 193
Chris@42 194 cldcpy = X(mkplan_d)(plnr,
Chris@42 195 X(mkproblem_rdft_0_d)(
Chris@42 196 X(tensor_append)(p->vecsz, p->sz),
Chris@42 197 p->I, p->O));
Chris@42 198 if (!cldcpy) goto nada;
Chris@42 199
Chris@42 200 cld = X(mkplan_f_d)(plnr, ego->adt->mkcld(p), NO_BUFFERING, 0, 0);
Chris@42 201 if (!cld) goto nada;
Chris@42 202
Chris@42 203 pln = MKPLAN_RDFT(P, &padt, ego->adt->apply);
Chris@42 204 pln->cld = cld;
Chris@42 205 pln->cldcpy = cldcpy;
Chris@42 206 pln->slv = ego;
Chris@42 207 X(ops_add)(&cld->ops, &cldcpy->ops, &pln->super.super.ops);
Chris@42 208
Chris@42 209 return &(pln->super.super);
Chris@42 210
Chris@42 211 nada:
Chris@42 212 X(plan_destroy_internal)(cld);
Chris@42 213 X(plan_destroy_internal)(cldcpy);
Chris@42 214 return (plan *)0;
Chris@42 215 }
Chris@42 216
Chris@42 217 static solver *mksolver(const ndrct_adt *adt)
Chris@42 218 {
Chris@42 219 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@42 220 S *slv = MKSOLVER(S, &sadt);
Chris@42 221 slv->adt = adt;
Chris@42 222 return &(slv->super);
Chris@42 223 }
Chris@42 224
Chris@42 225 void X(rdft_indirect_register)(planner *p)
Chris@42 226 {
Chris@42 227 unsigned i;
Chris@42 228 static const ndrct_adt *const adts[] = {
Chris@42 229 &adt_before, &adt_after
Chris@42 230 };
Chris@42 231
Chris@42 232 for (i = 0; i < sizeof(adts) / sizeof(adts[0]); ++i)
Chris@42 233 REGISTER_SOLVER(p, mksolver(adts[i]));
Chris@42 234 }