annotate src/fftw-3.3.8/dft/dftw-genericbuf.c @ 82:d0c2a83c1364

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
rev   line source
Chris@82 1 /*
Chris@82 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@82 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@82 4 *
Chris@82 5 * This program is free software; you can redistribute it and/or modify
Chris@82 6 * it under the terms of the GNU General Public License as published by
Chris@82 7 * the Free Software Foundation; either version 2 of the License, or
Chris@82 8 * (at your option) any later version.
Chris@82 9 *
Chris@82 10 * This program is distributed in the hope that it will be useful,
Chris@82 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@82 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@82 13 * GNU General Public License for more details.
Chris@82 14 *
Chris@82 15 * You should have received a copy of the GNU General Public License
Chris@82 16 * along with this program; if not, write to the Free Software
Chris@82 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@82 18 *
Chris@82 19 */
Chris@82 20
Chris@82 21 /* express a twiddle problem in terms of dft + multiplication by
Chris@82 22 twiddle factors */
Chris@82 23
Chris@82 24 #include "dft/ct.h"
Chris@82 25
Chris@82 26 typedef struct {
Chris@82 27 ct_solver super;
Chris@82 28 INT batchsz;
Chris@82 29 } S;
Chris@82 30
Chris@82 31 typedef struct {
Chris@82 32 plan_dftw super;
Chris@82 33
Chris@82 34 INT r, rs, m, ms, v, vs, mb, me;
Chris@82 35 INT batchsz;
Chris@82 36 plan *cld;
Chris@82 37
Chris@82 38 triggen *t;
Chris@82 39 const S *slv;
Chris@82 40 } P;
Chris@82 41
Chris@82 42
Chris@82 43 #define BATCHDIST(r) ((r) + 16)
Chris@82 44
Chris@82 45 /**************************************************************/
Chris@82 46 static void bytwiddle(const P *ego, INT mb, INT me, R *buf, R *rio, R *iio)
Chris@82 47 {
Chris@82 48 INT j, k;
Chris@82 49 INT r = ego->r, rs = ego->rs, ms = ego->ms;
Chris@82 50 triggen *t = ego->t;
Chris@82 51 for (j = 0; j < r; ++j) {
Chris@82 52 for (k = mb; k < me; ++k)
Chris@82 53 t->rotate(t, j * k,
Chris@82 54 rio[j * rs + k * ms],
Chris@82 55 iio[j * rs + k * ms],
Chris@82 56 &buf[j * 2 + 2 * BATCHDIST(r) * (k - mb) + 0]);
Chris@82 57 }
Chris@82 58 }
Chris@82 59
Chris@82 60 static int applicable0(const S *ego,
Chris@82 61 INT r, INT irs, INT ors,
Chris@82 62 INT m, INT v,
Chris@82 63 INT mcount)
Chris@82 64 {
Chris@82 65 return (1
Chris@82 66 && v == 1
Chris@82 67 && irs == ors
Chris@82 68 && mcount >= ego->batchsz
Chris@82 69 && mcount % ego->batchsz == 0
Chris@82 70 && r >= 64
Chris@82 71 && m >= r
Chris@82 72 );
Chris@82 73 }
Chris@82 74
Chris@82 75 static int applicable(const S *ego,
Chris@82 76 INT r, INT irs, INT ors,
Chris@82 77 INT m, INT v,
Chris@82 78 INT mcount,
Chris@82 79 const planner *plnr)
Chris@82 80 {
Chris@82 81 if (!applicable0(ego, r, irs, ors, m, v, mcount))
Chris@82 82 return 0;
Chris@82 83 if (NO_UGLYP(plnr) && m * r < 65536)
Chris@82 84 return 0;
Chris@82 85
Chris@82 86 return 1;
Chris@82 87 }
Chris@82 88
Chris@82 89 static void dobatch(const P *ego, INT mb, INT me, R *buf, R *rio, R *iio)
Chris@82 90 {
Chris@82 91 plan_dft *cld;
Chris@82 92 INT ms = ego->ms;
Chris@82 93
Chris@82 94 bytwiddle(ego, mb, me, buf, rio, iio);
Chris@82 95
Chris@82 96 cld = (plan_dft *) ego->cld;
Chris@82 97 cld->apply(ego->cld, buf, buf + 1, buf, buf + 1);
Chris@82 98 X(cpy2d_pair_co)(buf, buf + 1,
Chris@82 99 rio + ms * mb, iio + ms * mb,
Chris@82 100 me-mb, 2 * BATCHDIST(ego->r), ms,
Chris@82 101 ego->r, 2, ego->rs);
Chris@82 102 }
Chris@82 103
Chris@82 104 static void apply(const plan *ego_, R *rio, R *iio)
Chris@82 105 {
Chris@82 106 const P *ego = (const P *) ego_;
Chris@82 107 R *buf = (R *) MALLOC(sizeof(R) * 2 * BATCHDIST(ego->r) * ego->batchsz,
Chris@82 108 BUFFERS);
Chris@82 109 INT m;
Chris@82 110
Chris@82 111 for (m = ego->mb; m < ego->me; m += ego->batchsz)
Chris@82 112 dobatch(ego, m, m + ego->batchsz, buf, rio, iio);
Chris@82 113
Chris@82 114 A(m == ego->me);
Chris@82 115
Chris@82 116 X(ifree)(buf);
Chris@82 117 }
Chris@82 118
Chris@82 119 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@82 120 {
Chris@82 121 P *ego = (P *) ego_;
Chris@82 122 X(plan_awake)(ego->cld, wakefulness);
Chris@82 123
Chris@82 124 switch (wakefulness) {
Chris@82 125 case SLEEPY:
Chris@82 126 X(triggen_destroy)(ego->t); ego->t = 0;
Chris@82 127 break;
Chris@82 128 default:
Chris@82 129 ego->t = X(mktriggen)(AWAKE_SQRTN_TABLE, ego->r * ego->m);
Chris@82 130 break;
Chris@82 131 }
Chris@82 132 }
Chris@82 133
Chris@82 134 static void destroy(plan *ego_)
Chris@82 135 {
Chris@82 136 P *ego = (P *) ego_;
Chris@82 137 X(plan_destroy_internal)(ego->cld);
Chris@82 138 }
Chris@82 139
Chris@82 140 static void print(const plan *ego_, printer *p)
Chris@82 141 {
Chris@82 142 const P *ego = (const P *) ego_;
Chris@82 143 p->print(p, "(dftw-genericbuf/%D-%D-%D%(%p%))",
Chris@82 144 ego->batchsz, ego->r, ego->m, ego->cld);
Chris@82 145 }
Chris@82 146
Chris@82 147 static plan *mkcldw(const ct_solver *ego_,
Chris@82 148 INT r, INT irs, INT ors,
Chris@82 149 INT m, INT ms,
Chris@82 150 INT v, INT ivs, INT ovs,
Chris@82 151 INT mstart, INT mcount,
Chris@82 152 R *rio, R *iio,
Chris@82 153 planner *plnr)
Chris@82 154 {
Chris@82 155 const S *ego = (const S *)ego_;
Chris@82 156 P *pln;
Chris@82 157 plan *cld = 0;
Chris@82 158 R *buf;
Chris@82 159
Chris@82 160 static const plan_adt padt = {
Chris@82 161 0, awake, print, destroy
Chris@82 162 };
Chris@82 163
Chris@82 164 UNUSED(ivs); UNUSED(ovs); UNUSED(rio); UNUSED(iio);
Chris@82 165
Chris@82 166 A(mstart >= 0 && mstart + mcount <= m);
Chris@82 167 if (!applicable(ego, r, irs, ors, m, v, mcount, plnr))
Chris@82 168 return (plan *)0;
Chris@82 169
Chris@82 170 buf = (R *) MALLOC(sizeof(R) * 2 * BATCHDIST(r) * ego->batchsz, BUFFERS);
Chris@82 171 cld = X(mkplan_d)(plnr,
Chris@82 172 X(mkproblem_dft_d)(
Chris@82 173 X(mktensor_1d)(r, 2, 2),
Chris@82 174 X(mktensor_1d)(ego->batchsz,
Chris@82 175 2 * BATCHDIST(r),
Chris@82 176 2 * BATCHDIST(r)),
Chris@82 177 buf, buf + 1, buf, buf + 1
Chris@82 178 )
Chris@82 179 );
Chris@82 180 X(ifree)(buf);
Chris@82 181 if (!cld) goto nada;
Chris@82 182
Chris@82 183 pln = MKPLAN_DFTW(P, &padt, apply);
Chris@82 184 pln->slv = ego;
Chris@82 185 pln->cld = cld;
Chris@82 186 pln->r = r;
Chris@82 187 pln->m = m;
Chris@82 188 pln->ms = ms;
Chris@82 189 pln->rs = irs;
Chris@82 190 pln->batchsz = ego->batchsz;
Chris@82 191 pln->mb = mstart;
Chris@82 192 pln->me = mstart + mcount;
Chris@82 193
Chris@82 194 {
Chris@82 195 double n0 = (r - 1) * (mcount - 1);
Chris@82 196 pln->super.super.ops = cld->ops;
Chris@82 197 pln->super.super.ops.mul += 8 * n0;
Chris@82 198 pln->super.super.ops.add += 4 * n0;
Chris@82 199 pln->super.super.ops.other += 8 * n0;
Chris@82 200 }
Chris@82 201 return &(pln->super.super);
Chris@82 202
Chris@82 203 nada:
Chris@82 204 X(plan_destroy_internal)(cld);
Chris@82 205 return (plan *) 0;
Chris@82 206 }
Chris@82 207
Chris@82 208 static void regsolver(planner *plnr, INT r, INT batchsz)
Chris@82 209 {
Chris@82 210 S *slv = (S *)X(mksolver_ct)(sizeof(S), r, DECDIT, mkcldw, 0);
Chris@82 211 slv->batchsz = batchsz;
Chris@82 212 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@82 213
Chris@82 214 if (X(mksolver_ct_hook)) {
Chris@82 215 slv = (S *)X(mksolver_ct_hook)(sizeof(S), r, DECDIT, mkcldw, 0);
Chris@82 216 slv->batchsz = batchsz;
Chris@82 217 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@82 218 }
Chris@82 219
Chris@82 220 }
Chris@82 221
Chris@82 222 void X(ct_genericbuf_register)(planner *p)
Chris@82 223 {
Chris@82 224 static const INT radices[] = { -1, -2, -4, -8, -16, -32, -64 };
Chris@82 225 static const INT batchsizes[] = { 4, 8, 16, 32, 64 };
Chris@82 226 unsigned i, j;
Chris@82 227
Chris@82 228 for (i = 0; i < sizeof(radices) / sizeof(radices[0]); ++i)
Chris@82 229 for (j = 0; j < sizeof(batchsizes) / sizeof(batchsizes[0]); ++j)
Chris@82 230 regsolver(p, radices[i], batchsizes[j]);
Chris@82 231 }