annotate src/fftw-3.3.3/rdft/generic.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 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21 #include "rdft.h"
Chris@10 22
Chris@10 23 typedef struct {
Chris@10 24 solver super;
Chris@10 25 rdft_kind kind;
Chris@10 26 } S;
Chris@10 27
Chris@10 28 typedef struct {
Chris@10 29 plan_rdft super;
Chris@10 30 twid *td;
Chris@10 31 INT n, is, os;
Chris@10 32 rdft_kind kind;
Chris@10 33 } P;
Chris@10 34
Chris@10 35 /***************************************************************************/
Chris@10 36
Chris@10 37 static void cdot_r2hc(INT n, const E *x, const R *w, R *or0, R *oi1)
Chris@10 38 {
Chris@10 39 INT i;
Chris@10 40
Chris@10 41 E rr = x[0], ri = 0;
Chris@10 42 x += 1;
Chris@10 43 for (i = 1; i + i < n; ++i) {
Chris@10 44 rr += x[0] * w[0];
Chris@10 45 ri += x[1] * w[1];
Chris@10 46 x += 2; w += 2;
Chris@10 47 }
Chris@10 48 *or0 = rr;
Chris@10 49 *oi1 = ri;
Chris@10 50 }
Chris@10 51
Chris@10 52 static void hartley_r2hc(INT n, const R *xr, INT xs, E *o, R *pr)
Chris@10 53 {
Chris@10 54 INT i;
Chris@10 55 E sr;
Chris@10 56 o[0] = sr = xr[0]; o += 1;
Chris@10 57 for (i = 1; i + i < n; ++i) {
Chris@10 58 R a, b;
Chris@10 59 a = xr[i * xs];
Chris@10 60 b = xr[(n - i) * xs];
Chris@10 61 sr += (o[0] = a + b);
Chris@10 62 #if FFT_SIGN == -1
Chris@10 63 o[1] = b - a;
Chris@10 64 #else
Chris@10 65 o[1] = a - b;
Chris@10 66 #endif
Chris@10 67 o += 2;
Chris@10 68 }
Chris@10 69 *pr = sr;
Chris@10 70 }
Chris@10 71
Chris@10 72 static void apply_r2hc(const plan *ego_, R *I, R *O)
Chris@10 73 {
Chris@10 74 const P *ego = (const P *) ego_;
Chris@10 75 INT i;
Chris@10 76 INT n = ego->n, is = ego->is, os = ego->os;
Chris@10 77 const R *W = ego->td->W;
Chris@10 78 E *buf;
Chris@10 79 size_t bufsz = n * sizeof(E);
Chris@10 80
Chris@10 81 BUF_ALLOC(E *, buf, bufsz);
Chris@10 82 hartley_r2hc(n, I, is, buf, O);
Chris@10 83
Chris@10 84 for (i = 1; i + i < n; ++i) {
Chris@10 85 cdot_r2hc(n, buf, W, O + i * os, O + (n - i) * os);
Chris@10 86 W += n - 1;
Chris@10 87 }
Chris@10 88
Chris@10 89 BUF_FREE(buf, bufsz);
Chris@10 90 }
Chris@10 91
Chris@10 92
Chris@10 93 static void cdot_hc2r(INT n, const E *x, const R *w, R *or0, R *or1)
Chris@10 94 {
Chris@10 95 INT i;
Chris@10 96
Chris@10 97 E rr = x[0], ii = 0;
Chris@10 98 x += 1;
Chris@10 99 for (i = 1; i + i < n; ++i) {
Chris@10 100 rr += x[0] * w[0];
Chris@10 101 ii += x[1] * w[1];
Chris@10 102 x += 2; w += 2;
Chris@10 103 }
Chris@10 104 #if FFT_SIGN == -1
Chris@10 105 *or0 = rr - ii;
Chris@10 106 *or1 = rr + ii;
Chris@10 107 #else
Chris@10 108 *or0 = rr + ii;
Chris@10 109 *or1 = rr - ii;
Chris@10 110 #endif
Chris@10 111 }
Chris@10 112
Chris@10 113 static void hartley_hc2r(INT n, const R *x, INT xs, E *o, R *pr)
Chris@10 114 {
Chris@10 115 INT i;
Chris@10 116 E sr;
Chris@10 117
Chris@10 118 o[0] = sr = x[0]; o += 1;
Chris@10 119 for (i = 1; i + i < n; ++i) {
Chris@10 120 sr += (o[0] = x[i * xs] + x[i * xs]);
Chris@10 121 o[1] = x[(n - i) * xs] + x[(n - i) * xs];
Chris@10 122 o += 2;
Chris@10 123 }
Chris@10 124 *pr = sr;
Chris@10 125 }
Chris@10 126
Chris@10 127 static void apply_hc2r(const plan *ego_, R *I, R *O)
Chris@10 128 {
Chris@10 129 const P *ego = (const P *) ego_;
Chris@10 130 INT i;
Chris@10 131 INT n = ego->n, is = ego->is, os = ego->os;
Chris@10 132 const R *W = ego->td->W;
Chris@10 133 E *buf;
Chris@10 134 size_t bufsz = n * sizeof(E);
Chris@10 135
Chris@10 136 BUF_ALLOC(E *, buf, bufsz);
Chris@10 137 hartley_hc2r(n, I, is, buf, O);
Chris@10 138
Chris@10 139 for (i = 1; i + i < n; ++i) {
Chris@10 140 cdot_hc2r(n, buf, W, O + i * os, O + (n - i) * os);
Chris@10 141 W += n - 1;
Chris@10 142 }
Chris@10 143
Chris@10 144 BUF_FREE(buf, bufsz);
Chris@10 145 }
Chris@10 146
Chris@10 147
Chris@10 148 /***************************************************************************/
Chris@10 149
Chris@10 150 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@10 151 {
Chris@10 152 P *ego = (P *) ego_;
Chris@10 153 static const tw_instr half_tw[] = {
Chris@10 154 { TW_HALF, 1, 0 },
Chris@10 155 { TW_NEXT, 1, 0 }
Chris@10 156 };
Chris@10 157
Chris@10 158 X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n,
Chris@10 159 (ego->n - 1) / 2);
Chris@10 160 }
Chris@10 161
Chris@10 162 static void print(const plan *ego_, printer *p)
Chris@10 163 {
Chris@10 164 const P *ego = (const P *) ego_;
Chris@10 165
Chris@10 166 p->print(p, "(rdft-generic-%s-%D)",
Chris@10 167 ego->kind == R2HC ? "r2hc" : "hc2r",
Chris@10 168 ego->n);
Chris@10 169 }
Chris@10 170
Chris@10 171 static int applicable(const S *ego, const problem *p_,
Chris@10 172 const planner *plnr)
Chris@10 173 {
Chris@10 174 const problem_rdft *p = (const problem_rdft *) p_;
Chris@10 175 return (1
Chris@10 176 && p->sz->rnk == 1
Chris@10 177 && p->vecsz->rnk == 0
Chris@10 178 && (p->sz->dims[0].n % 2) == 1
Chris@10 179 && CIMPLIES(NO_LARGE_GENERICP(plnr), p->sz->dims[0].n < GENERIC_MIN_BAD)
Chris@10 180 && CIMPLIES(NO_SLOWP(plnr), p->sz->dims[0].n > GENERIC_MAX_SLOW)
Chris@10 181 && X(is_prime)(p->sz->dims[0].n)
Chris@10 182 && p->kind[0] == ego->kind
Chris@10 183 );
Chris@10 184 }
Chris@10 185
Chris@10 186 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@10 187 {
Chris@10 188 const S *ego = (const S *)ego_;
Chris@10 189 const problem_rdft *p;
Chris@10 190 P *pln;
Chris@10 191 INT n;
Chris@10 192
Chris@10 193 static const plan_adt padt = {
Chris@10 194 X(rdft_solve), awake, print, X(plan_null_destroy)
Chris@10 195 };
Chris@10 196
Chris@10 197 if (!applicable(ego, p_, plnr))
Chris@10 198 return (plan *)0;
Chris@10 199
Chris@10 200 p = (const problem_rdft *) p_;
Chris@10 201 pln = MKPLAN_RDFT(P, &padt,
Chris@10 202 R2HC_KINDP(p->kind[0]) ? apply_r2hc : apply_hc2r);
Chris@10 203
Chris@10 204 pln->n = n = p->sz->dims[0].n;
Chris@10 205 pln->is = p->sz->dims[0].is;
Chris@10 206 pln->os = p->sz->dims[0].os;
Chris@10 207 pln->td = 0;
Chris@10 208 pln->kind = ego->kind;
Chris@10 209
Chris@10 210 pln->super.super.ops.add = (n-1) * 2.5;
Chris@10 211 pln->super.super.ops.mul = 0;
Chris@10 212 pln->super.super.ops.fma = 0.5 * (n-1) * (n-1) ;
Chris@10 213 #if 0 /* these are nice pipelined sequential loads and should cost nothing */
Chris@10 214 pln->super.super.ops.other = (n-1)*(2 + 1 + (n-1)); /* approximate */
Chris@10 215 #endif
Chris@10 216
Chris@10 217 return &(pln->super.super);
Chris@10 218 }
Chris@10 219
Chris@10 220 static solver *mksolver(rdft_kind kind)
Chris@10 221 {
Chris@10 222 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@10 223 S *slv = MKSOLVER(S, &sadt);
Chris@10 224 slv->kind = kind;
Chris@10 225 return &(slv->super);
Chris@10 226 }
Chris@10 227
Chris@10 228 void X(rdft_generic_register)(planner *p)
Chris@10 229 {
Chris@10 230 REGISTER_SOLVER(p, mksolver(R2HC));
Chris@10 231 REGISTER_SOLVER(p, mksolver(HC2R));
Chris@10 232 }