annotate src/fftw-3.3.3/dft/generic.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 89f5e221ed7b
children
rev   line source
cannam@95 1 /*
cannam@95 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
cannam@95 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
cannam@95 4 *
cannam@95 5 * This program is free software; you can redistribute it and/or modify
cannam@95 6 * it under the terms of the GNU General Public License as published by
cannam@95 7 * the Free Software Foundation; either version 2 of the License, or
cannam@95 8 * (at your option) any later version.
cannam@95 9 *
cannam@95 10 * This program is distributed in the hope that it will be useful,
cannam@95 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@95 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@95 13 * GNU General Public License for more details.
cannam@95 14 *
cannam@95 15 * You should have received a copy of the GNU General Public License
cannam@95 16 * along with this program; if not, write to the Free Software
cannam@95 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@95 18 *
cannam@95 19 */
cannam@95 20
cannam@95 21 #include "dft.h"
cannam@95 22
cannam@95 23 typedef struct {
cannam@95 24 solver super;
cannam@95 25 } S;
cannam@95 26
cannam@95 27 typedef struct {
cannam@95 28 plan_dft super;
cannam@95 29 twid *td;
cannam@95 30 INT n, is, os;
cannam@95 31 } P;
cannam@95 32
cannam@95 33
cannam@95 34 static void cdot(INT n, const E *x, const R *w,
cannam@95 35 R *or0, R *oi0, R *or1, R *oi1)
cannam@95 36 {
cannam@95 37 INT i;
cannam@95 38
cannam@95 39 E rr = x[0], ri = 0, ir = x[1], ii = 0;
cannam@95 40 x += 2;
cannam@95 41 for (i = 1; i + i < n; ++i) {
cannam@95 42 rr += x[0] * w[0];
cannam@95 43 ir += x[1] * w[0];
cannam@95 44 ri += x[2] * w[1];
cannam@95 45 ii += x[3] * w[1];
cannam@95 46 x += 4; w += 2;
cannam@95 47 }
cannam@95 48 *or0 = rr + ii;
cannam@95 49 *oi0 = ir - ri;
cannam@95 50 *or1 = rr - ii;
cannam@95 51 *oi1 = ir + ri;
cannam@95 52 }
cannam@95 53
cannam@95 54 static void hartley(INT n, const R *xr, const R *xi, INT xs, E *o,
cannam@95 55 R *pr, R *pi)
cannam@95 56 {
cannam@95 57 INT i;
cannam@95 58 E sr, si;
cannam@95 59 o[0] = sr = xr[0]; o[1] = si = xi[0]; o += 2;
cannam@95 60 for (i = 1; i + i < n; ++i) {
cannam@95 61 sr += (o[0] = xr[i * xs] + xr[(n - i) * xs]);
cannam@95 62 si += (o[1] = xi[i * xs] + xi[(n - i) * xs]);
cannam@95 63 o[2] = xr[i * xs] - xr[(n - i) * xs];
cannam@95 64 o[3] = xi[i * xs] - xi[(n - i) * xs];
cannam@95 65 o += 4;
cannam@95 66 }
cannam@95 67 *pr = sr;
cannam@95 68 *pi = si;
cannam@95 69 }
cannam@95 70
cannam@95 71 static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@95 72 {
cannam@95 73 const P *ego = (const P *) ego_;
cannam@95 74 INT i;
cannam@95 75 INT n = ego->n, is = ego->is, os = ego->os;
cannam@95 76 const R *W = ego->td->W;
cannam@95 77 E *buf;
cannam@95 78 size_t bufsz = n * 2 * sizeof(E);
cannam@95 79
cannam@95 80 BUF_ALLOC(E *, buf, bufsz);
cannam@95 81 hartley(n, ri, ii, is, buf, ro, io);
cannam@95 82
cannam@95 83 for (i = 1; i + i < n; ++i) {
cannam@95 84 cdot(n, buf, W,
cannam@95 85 ro + i * os, io + i * os,
cannam@95 86 ro + (n - i) * os, io + (n - i) * os);
cannam@95 87 W += n - 1;
cannam@95 88 }
cannam@95 89
cannam@95 90 BUF_FREE(buf, bufsz);
cannam@95 91 }
cannam@95 92
cannam@95 93 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@95 94 {
cannam@95 95 P *ego = (P *) ego_;
cannam@95 96 static const tw_instr half_tw[] = {
cannam@95 97 { TW_HALF, 1, 0 },
cannam@95 98 { TW_NEXT, 1, 0 }
cannam@95 99 };
cannam@95 100
cannam@95 101 X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n,
cannam@95 102 (ego->n - 1) / 2);
cannam@95 103 }
cannam@95 104
cannam@95 105 static void print(const plan *ego_, printer *p)
cannam@95 106 {
cannam@95 107 const P *ego = (const P *) ego_;
cannam@95 108
cannam@95 109 p->print(p, "(dft-generic-%D)", ego->n);
cannam@95 110 }
cannam@95 111
cannam@95 112 static int applicable(const solver *ego, const problem *p_,
cannam@95 113 const planner *plnr)
cannam@95 114 {
cannam@95 115 const problem_dft *p = (const problem_dft *) p_;
cannam@95 116 UNUSED(ego);
cannam@95 117
cannam@95 118 return (1
cannam@95 119 && p->sz->rnk == 1
cannam@95 120 && p->vecsz->rnk == 0
cannam@95 121 && (p->sz->dims[0].n % 2) == 1
cannam@95 122 && CIMPLIES(NO_LARGE_GENERICP(plnr), p->sz->dims[0].n < GENERIC_MIN_BAD)
cannam@95 123 && CIMPLIES(NO_SLOWP(plnr), p->sz->dims[0].n > GENERIC_MAX_SLOW)
cannam@95 124 && X(is_prime)(p->sz->dims[0].n)
cannam@95 125 );
cannam@95 126 }
cannam@95 127
cannam@95 128 static plan *mkplan(const solver *ego, const problem *p_, planner *plnr)
cannam@95 129 {
cannam@95 130 const problem_dft *p;
cannam@95 131 P *pln;
cannam@95 132 INT n;
cannam@95 133
cannam@95 134 static const plan_adt padt = {
cannam@95 135 X(dft_solve), awake, print, X(plan_null_destroy)
cannam@95 136 };
cannam@95 137
cannam@95 138 if (!applicable(ego, p_, plnr))
cannam@95 139 return (plan *)0;
cannam@95 140
cannam@95 141 pln = MKPLAN_DFT(P, &padt, apply);
cannam@95 142
cannam@95 143 p = (const problem_dft *) p_;
cannam@95 144 pln->n = n = p->sz->dims[0].n;
cannam@95 145 pln->is = p->sz->dims[0].is;
cannam@95 146 pln->os = p->sz->dims[0].os;
cannam@95 147 pln->td = 0;
cannam@95 148
cannam@95 149 pln->super.super.ops.add = (n-1) * 5;
cannam@95 150 pln->super.super.ops.mul = 0;
cannam@95 151 pln->super.super.ops.fma = (n-1) * (n-1) ;
cannam@95 152 #if 0 /* these are nice pipelined sequential loads and should cost nothing */
cannam@95 153 pln->super.super.ops.other = (n-1)*(4 + 1 + 2 * (n-1)); /* approximate */
cannam@95 154 #endif
cannam@95 155
cannam@95 156 return &(pln->super.super);
cannam@95 157 }
cannam@95 158
cannam@95 159 static solver *mksolver(void)
cannam@95 160 {
cannam@95 161 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
cannam@95 162 S *slv = MKSOLVER(S, &sadt);
cannam@95 163 return &(slv->super);
cannam@95 164 }
cannam@95 165
cannam@95 166 void X(dft_generic_register)(planner *p)
cannam@95 167 {
cannam@95 168 REGISTER_SOLVER(p, mksolver());
cannam@95 169 }