annotate src/fftw-3.3.5/rdft/generic.c @ 54:5f67a29f0fc7

Rebuild MAD with 64-bit FPM
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 30 Nov 2016 20:59:17 +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 #include "rdft.h"
Chris@42 22
Chris@42 23 typedef struct {
Chris@42 24 solver super;
Chris@42 25 rdft_kind kind;
Chris@42 26 } S;
Chris@42 27
Chris@42 28 typedef struct {
Chris@42 29 plan_rdft super;
Chris@42 30 twid *td;
Chris@42 31 INT n, is, os;
Chris@42 32 rdft_kind kind;
Chris@42 33 } P;
Chris@42 34
Chris@42 35 /***************************************************************************/
Chris@42 36
Chris@42 37 static void cdot_r2hc(INT n, const E *x, const R *w, R *or0, R *oi1)
Chris@42 38 {
Chris@42 39 INT i;
Chris@42 40
Chris@42 41 E rr = x[0], ri = 0;
Chris@42 42 x += 1;
Chris@42 43 for (i = 1; i + i < n; ++i) {
Chris@42 44 rr += x[0] * w[0];
Chris@42 45 ri += x[1] * w[1];
Chris@42 46 x += 2; w += 2;
Chris@42 47 }
Chris@42 48 *or0 = rr;
Chris@42 49 *oi1 = ri;
Chris@42 50 }
Chris@42 51
Chris@42 52 static void hartley_r2hc(INT n, const R *xr, INT xs, E *o, R *pr)
Chris@42 53 {
Chris@42 54 INT i;
Chris@42 55 E sr;
Chris@42 56 o[0] = sr = xr[0]; o += 1;
Chris@42 57 for (i = 1; i + i < n; ++i) {
Chris@42 58 R a, b;
Chris@42 59 a = xr[i * xs];
Chris@42 60 b = xr[(n - i) * xs];
Chris@42 61 sr += (o[0] = a + b);
Chris@42 62 #if FFT_SIGN == -1
Chris@42 63 o[1] = b - a;
Chris@42 64 #else
Chris@42 65 o[1] = a - b;
Chris@42 66 #endif
Chris@42 67 o += 2;
Chris@42 68 }
Chris@42 69 *pr = sr;
Chris@42 70 }
Chris@42 71
Chris@42 72 static void apply_r2hc(const plan *ego_, R *I, R *O)
Chris@42 73 {
Chris@42 74 const P *ego = (const P *) ego_;
Chris@42 75 INT i;
Chris@42 76 INT n = ego->n, is = ego->is, os = ego->os;
Chris@42 77 const R *W = ego->td->W;
Chris@42 78 E *buf;
Chris@42 79 size_t bufsz = n * sizeof(E);
Chris@42 80
Chris@42 81 BUF_ALLOC(E *, buf, bufsz);
Chris@42 82 hartley_r2hc(n, I, is, buf, O);
Chris@42 83
Chris@42 84 for (i = 1; i + i < n; ++i) {
Chris@42 85 cdot_r2hc(n, buf, W, O + i * os, O + (n - i) * os);
Chris@42 86 W += n - 1;
Chris@42 87 }
Chris@42 88
Chris@42 89 BUF_FREE(buf, bufsz);
Chris@42 90 }
Chris@42 91
Chris@42 92
Chris@42 93 static void cdot_hc2r(INT n, const E *x, const R *w, R *or0, R *or1)
Chris@42 94 {
Chris@42 95 INT i;
Chris@42 96
Chris@42 97 E rr = x[0], ii = 0;
Chris@42 98 x += 1;
Chris@42 99 for (i = 1; i + i < n; ++i) {
Chris@42 100 rr += x[0] * w[0];
Chris@42 101 ii += x[1] * w[1];
Chris@42 102 x += 2; w += 2;
Chris@42 103 }
Chris@42 104 #if FFT_SIGN == -1
Chris@42 105 *or0 = rr - ii;
Chris@42 106 *or1 = rr + ii;
Chris@42 107 #else
Chris@42 108 *or0 = rr + ii;
Chris@42 109 *or1 = rr - ii;
Chris@42 110 #endif
Chris@42 111 }
Chris@42 112
Chris@42 113 static void hartley_hc2r(INT n, const R *x, INT xs, E *o, R *pr)
Chris@42 114 {
Chris@42 115 INT i;
Chris@42 116 E sr;
Chris@42 117
Chris@42 118 o[0] = sr = x[0]; o += 1;
Chris@42 119 for (i = 1; i + i < n; ++i) {
Chris@42 120 sr += (o[0] = x[i * xs] + x[i * xs]);
Chris@42 121 o[1] = x[(n - i) * xs] + x[(n - i) * xs];
Chris@42 122 o += 2;
Chris@42 123 }
Chris@42 124 *pr = sr;
Chris@42 125 }
Chris@42 126
Chris@42 127 static void apply_hc2r(const plan *ego_, R *I, R *O)
Chris@42 128 {
Chris@42 129 const P *ego = (const P *) ego_;
Chris@42 130 INT i;
Chris@42 131 INT n = ego->n, is = ego->is, os = ego->os;
Chris@42 132 const R *W = ego->td->W;
Chris@42 133 E *buf;
Chris@42 134 size_t bufsz = n * sizeof(E);
Chris@42 135
Chris@42 136 BUF_ALLOC(E *, buf, bufsz);
Chris@42 137 hartley_hc2r(n, I, is, buf, O);
Chris@42 138
Chris@42 139 for (i = 1; i + i < n; ++i) {
Chris@42 140 cdot_hc2r(n, buf, W, O + i * os, O + (n - i) * os);
Chris@42 141 W += n - 1;
Chris@42 142 }
Chris@42 143
Chris@42 144 BUF_FREE(buf, bufsz);
Chris@42 145 }
Chris@42 146
Chris@42 147
Chris@42 148 /***************************************************************************/
Chris@42 149
Chris@42 150 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@42 151 {
Chris@42 152 P *ego = (P *) ego_;
Chris@42 153 static const tw_instr half_tw[] = {
Chris@42 154 { TW_HALF, 1, 0 },
Chris@42 155 { TW_NEXT, 1, 0 }
Chris@42 156 };
Chris@42 157
Chris@42 158 X(twiddle_awake)(wakefulness, &ego->td, half_tw, ego->n, ego->n,
Chris@42 159 (ego->n - 1) / 2);
Chris@42 160 }
Chris@42 161
Chris@42 162 static void print(const plan *ego_, printer *p)
Chris@42 163 {
Chris@42 164 const P *ego = (const P *) ego_;
Chris@42 165
Chris@42 166 p->print(p, "(rdft-generic-%s-%D)",
Chris@42 167 ego->kind == R2HC ? "r2hc" : "hc2r",
Chris@42 168 ego->n);
Chris@42 169 }
Chris@42 170
Chris@42 171 static int applicable(const S *ego, const problem *p_,
Chris@42 172 const planner *plnr)
Chris@42 173 {
Chris@42 174 const problem_rdft *p = (const problem_rdft *) p_;
Chris@42 175 return (1
Chris@42 176 && p->sz->rnk == 1
Chris@42 177 && p->vecsz->rnk == 0
Chris@42 178 && (p->sz->dims[0].n % 2) == 1
Chris@42 179 && CIMPLIES(NO_LARGE_GENERICP(plnr), p->sz->dims[0].n < GENERIC_MIN_BAD)
Chris@42 180 && CIMPLIES(NO_SLOWP(plnr), p->sz->dims[0].n > GENERIC_MAX_SLOW)
Chris@42 181 && X(is_prime)(p->sz->dims[0].n)
Chris@42 182 && p->kind[0] == ego->kind
Chris@42 183 );
Chris@42 184 }
Chris@42 185
Chris@42 186 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@42 187 {
Chris@42 188 const S *ego = (const S *)ego_;
Chris@42 189 const problem_rdft *p;
Chris@42 190 P *pln;
Chris@42 191 INT n;
Chris@42 192
Chris@42 193 static const plan_adt padt = {
Chris@42 194 X(rdft_solve), awake, print, X(plan_null_destroy)
Chris@42 195 };
Chris@42 196
Chris@42 197 if (!applicable(ego, p_, plnr))
Chris@42 198 return (plan *)0;
Chris@42 199
Chris@42 200 p = (const problem_rdft *) p_;
Chris@42 201 pln = MKPLAN_RDFT(P, &padt,
Chris@42 202 R2HC_KINDP(p->kind[0]) ? apply_r2hc : apply_hc2r);
Chris@42 203
Chris@42 204 pln->n = n = p->sz->dims[0].n;
Chris@42 205 pln->is = p->sz->dims[0].is;
Chris@42 206 pln->os = p->sz->dims[0].os;
Chris@42 207 pln->td = 0;
Chris@42 208 pln->kind = ego->kind;
Chris@42 209
Chris@42 210 pln->super.super.ops.add = (n-1) * 2.5;
Chris@42 211 pln->super.super.ops.mul = 0;
Chris@42 212 pln->super.super.ops.fma = 0.5 * (n-1) * (n-1) ;
Chris@42 213 #if 0 /* these are nice pipelined sequential loads and should cost nothing */
Chris@42 214 pln->super.super.ops.other = (n-1)*(2 + 1 + (n-1)); /* approximate */
Chris@42 215 #endif
Chris@42 216
Chris@42 217 return &(pln->super.super);
Chris@42 218 }
Chris@42 219
Chris@42 220 static solver *mksolver(rdft_kind kind)
Chris@42 221 {
Chris@42 222 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@42 223 S *slv = MKSOLVER(S, &sadt);
Chris@42 224 slv->kind = kind;
Chris@42 225 return &(slv->super);
Chris@42 226 }
Chris@42 227
Chris@42 228 void X(rdft_generic_register)(planner *p)
Chris@42 229 {
Chris@42 230 REGISTER_SOLVER(p, mksolver(R2HC));
Chris@42 231 REGISTER_SOLVER(p, mksolver(HC2R));
Chris@42 232 }