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