annotate src/fftw-3.3.5/rdft/hc2hc-direct.c @ 56:af97cad61ff0

Add updated build of PortAudio for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 03 Jan 2017 15:10:52 +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
Chris@42 22 #include "hc2hc.h"
Chris@42 23
Chris@42 24 typedef struct {
Chris@42 25 hc2hc_solver super;
Chris@42 26 const hc2hc_desc *desc;
Chris@42 27 khc2hc k;
Chris@42 28 int bufferedp;
Chris@42 29 } S;
Chris@42 30
Chris@42 31 typedef struct {
Chris@42 32 plan_hc2hc super;
Chris@42 33 khc2hc k;
Chris@42 34 plan *cld0, *cldm; /* children for 0th and middle butterflies */
Chris@42 35 INT r, m, v;
Chris@42 36 INT ms, vs, mb, me;
Chris@42 37 stride rs, brs;
Chris@42 38 twid *td;
Chris@42 39 const S *slv;
Chris@42 40 } P;
Chris@42 41
Chris@42 42 /*************************************************************
Chris@42 43 Nonbuffered code
Chris@42 44 *************************************************************/
Chris@42 45 static void apply(const plan *ego_, R *IO)
Chris@42 46 {
Chris@42 47 const P *ego = (const P *) ego_;
Chris@42 48 plan_rdft *cld0 = (plan_rdft *) ego->cld0;
Chris@42 49 plan_rdft *cldm = (plan_rdft *) ego->cldm;
Chris@42 50 INT i, m = ego->m, v = ego->v;
Chris@42 51 INT mb = ego->mb, me = ego->me;
Chris@42 52 INT ms = ego->ms, vs = ego->vs;
Chris@42 53
Chris@42 54 for (i = 0; i < v; ++i, IO += vs) {
Chris@42 55 cld0->apply((plan *) cld0, IO, IO);
Chris@42 56 ego->k(IO + ms * mb, IO + (m - mb) * ms,
Chris@42 57 ego->td->W, ego->rs, mb, me, ms);
Chris@42 58 cldm->apply((plan *) cldm, IO + (m/2) * ms, IO + (m/2) * ms);
Chris@42 59 }
Chris@42 60 }
Chris@42 61
Chris@42 62 /*************************************************************
Chris@42 63 Buffered code
Chris@42 64 *************************************************************/
Chris@42 65
Chris@42 66 /* should not be 2^k to avoid associativity conflicts */
Chris@42 67 static INT compute_batchsize(INT radix)
Chris@42 68 {
Chris@42 69 /* round up to multiple of 4 */
Chris@42 70 radix += 3;
Chris@42 71 radix &= -4;
Chris@42 72
Chris@42 73 return (radix + 2);
Chris@42 74 }
Chris@42 75
Chris@42 76 static void dobatch(const P *ego, R *IOp, R *IOm,
Chris@42 77 INT mb, INT me, R *bufp)
Chris@42 78 {
Chris@42 79 INT b = WS(ego->brs, 1);
Chris@42 80 INT rs = WS(ego->rs, 1);
Chris@42 81 INT r = ego->r;
Chris@42 82 INT ms = ego->ms;
Chris@42 83 R *bufm = bufp + b - 1;
Chris@42 84
Chris@42 85 X(cpy2d_ci)(IOp + mb * ms, bufp, r, rs, b, me - mb, ms, 1, 1);
Chris@42 86 X(cpy2d_ci)(IOm - mb * ms, bufm, r, rs, b, me - mb, -ms, -1, 1);
Chris@42 87
Chris@42 88 ego->k(bufp, bufm, ego->td->W, ego->brs, mb, me, 1);
Chris@42 89
Chris@42 90 X(cpy2d_co)(bufp, IOp + mb * ms, r, b, rs, me - mb, 1, ms, 1);
Chris@42 91 X(cpy2d_co)(bufm, IOm - mb * ms, r, b, rs, me - mb, -1, -ms, 1);
Chris@42 92 }
Chris@42 93
Chris@42 94 static void apply_buf(const plan *ego_, R *IO)
Chris@42 95 {
Chris@42 96 const P *ego = (const P *) ego_;
Chris@42 97 plan_rdft *cld0 = (plan_rdft *) ego->cld0;
Chris@42 98 plan_rdft *cldm = (plan_rdft *) ego->cldm;
Chris@42 99 INT i, j, m = ego->m, v = ego->v, r = ego->r;
Chris@42 100 INT mb = ego->mb, me = ego->me, ms = ego->ms;
Chris@42 101 INT batchsz = compute_batchsize(r);
Chris@42 102 R *buf;
Chris@42 103 size_t bufsz = r * batchsz * 2 * sizeof(R);
Chris@42 104
Chris@42 105 BUF_ALLOC(R *, buf, bufsz);
Chris@42 106
Chris@42 107 for (i = 0; i < v; ++i, IO += ego->vs) {
Chris@42 108 R *IOp = IO;
Chris@42 109 R *IOm = IO + m * ms;
Chris@42 110
Chris@42 111 cld0->apply((plan *) cld0, IO, IO);
Chris@42 112
Chris@42 113 for (j = mb; j + batchsz < me; j += batchsz)
Chris@42 114 dobatch(ego, IOp, IOm, j, j + batchsz, buf);
Chris@42 115
Chris@42 116 dobatch(ego, IOp, IOm, j, me, buf);
Chris@42 117
Chris@42 118 cldm->apply((plan *) cldm, IO + ms * (m/2), IO + ms * (m/2));
Chris@42 119 }
Chris@42 120
Chris@42 121 BUF_FREE(buf, bufsz);
Chris@42 122 }
Chris@42 123
Chris@42 124 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@42 125 {
Chris@42 126 P *ego = (P *) ego_;
Chris@42 127
Chris@42 128 X(plan_awake)(ego->cld0, wakefulness);
Chris@42 129 X(plan_awake)(ego->cldm, wakefulness);
Chris@42 130 X(twiddle_awake)(wakefulness, &ego->td, ego->slv->desc->tw,
Chris@42 131 ego->r * ego->m, ego->r, (ego->m - 1) / 2);
Chris@42 132 }
Chris@42 133
Chris@42 134 static void destroy(plan *ego_)
Chris@42 135 {
Chris@42 136 P *ego = (P *) ego_;
Chris@42 137 X(plan_destroy_internal)(ego->cld0);
Chris@42 138 X(plan_destroy_internal)(ego->cldm);
Chris@42 139 X(stride_destroy)(ego->rs);
Chris@42 140 X(stride_destroy)(ego->brs);
Chris@42 141 }
Chris@42 142
Chris@42 143 static void print(const plan *ego_, printer *p)
Chris@42 144 {
Chris@42 145 const P *ego = (const P *) ego_;
Chris@42 146 const S *slv = ego->slv;
Chris@42 147 const hc2hc_desc *e = slv->desc;
Chris@42 148 INT batchsz = compute_batchsize(ego->r);
Chris@42 149
Chris@42 150 if (slv->bufferedp)
Chris@42 151 p->print(p, "(hc2hc-directbuf/%D-%D/%D%v \"%s\"%(%p%)%(%p%))",
Chris@42 152 batchsz, ego->r, X(twiddle_length)(ego->r, e->tw),
Chris@42 153 ego->v, e->nam, ego->cld0, ego->cldm);
Chris@42 154 else
Chris@42 155 p->print(p, "(hc2hc-direct-%D/%D%v \"%s\"%(%p%)%(%p%))",
Chris@42 156 ego->r, X(twiddle_length)(ego->r, e->tw), ego->v, e->nam,
Chris@42 157 ego->cld0, ego->cldm);
Chris@42 158 }
Chris@42 159
Chris@42 160 static int applicable0(const S *ego, rdft_kind kind, INT r)
Chris@42 161 {
Chris@42 162 const hc2hc_desc *e = ego->desc;
Chris@42 163
Chris@42 164 return (1
Chris@42 165 && r == e->radix
Chris@42 166 && kind == e->genus->kind
Chris@42 167 );
Chris@42 168 }
Chris@42 169
Chris@42 170 static int applicable(const S *ego, rdft_kind kind, INT r, INT m, INT v,
Chris@42 171 const planner *plnr)
Chris@42 172 {
Chris@42 173 if (!applicable0(ego, kind, r))
Chris@42 174 return 0;
Chris@42 175
Chris@42 176 if (NO_UGLYP(plnr) && X(ct_uglyp)((ego->bufferedp? (INT)512 : (INT)16),
Chris@42 177 v, m * r, r))
Chris@42 178 return 0;
Chris@42 179
Chris@42 180 return 1;
Chris@42 181 }
Chris@42 182
Chris@42 183 #define CLDMP(m, mstart, mcount) (2 * ((mstart) + (mcount)) == (m) + 2)
Chris@42 184 #define CLD0P(mstart) ((mstart) == 0)
Chris@42 185
Chris@42 186 static plan *mkcldw(const hc2hc_solver *ego_,
Chris@42 187 rdft_kind kind, INT r, INT m, INT ms, INT v, INT vs,
Chris@42 188 INT mstart, INT mcount,
Chris@42 189 R *IO, planner *plnr)
Chris@42 190 {
Chris@42 191 const S *ego = (const S *) ego_;
Chris@42 192 P *pln;
Chris@42 193 const hc2hc_desc *e = ego->desc;
Chris@42 194 plan *cld0 = 0, *cldm = 0;
Chris@42 195 INT imid = (m / 2) * ms;
Chris@42 196 INT rs = m * ms;
Chris@42 197
Chris@42 198 static const plan_adt padt = {
Chris@42 199 0, awake, print, destroy
Chris@42 200 };
Chris@42 201
Chris@42 202 if (!applicable(ego, kind, r, m, v, plnr))
Chris@42 203 return (plan *)0;
Chris@42 204
Chris@42 205 cld0 = X(mkplan_d)(
Chris@42 206 plnr,
Chris@42 207 X(mkproblem_rdft_1_d)((CLD0P(mstart) ?
Chris@42 208 X(mktensor_1d)(r, rs, rs) : X(mktensor_0d)()),
Chris@42 209 X(mktensor_0d)(),
Chris@42 210 TAINT(IO, vs), TAINT(IO, vs),
Chris@42 211 kind));
Chris@42 212 if (!cld0) goto nada;
Chris@42 213
Chris@42 214 cldm = X(mkplan_d)(
Chris@42 215 plnr,
Chris@42 216 X(mkproblem_rdft_1_d)((CLDMP(m, mstart, mcount) ?
Chris@42 217 X(mktensor_1d)(r, rs, rs) : X(mktensor_0d)()),
Chris@42 218 X(mktensor_0d)(),
Chris@42 219 TAINT(IO + imid, vs), TAINT(IO + imid, vs),
Chris@42 220 kind == R2HC ? R2HCII : HC2RIII));
Chris@42 221 if (!cldm) goto nada;
Chris@42 222
Chris@42 223 pln = MKPLAN_HC2HC(P, &padt, ego->bufferedp ? apply_buf : apply);
Chris@42 224
Chris@42 225 pln->k = ego->k;
Chris@42 226 pln->td = 0;
Chris@42 227 pln->r = r; pln->rs = X(mkstride)(r, rs);
Chris@42 228 pln->m = m; pln->ms = ms;
Chris@42 229 pln->v = v; pln->vs = vs;
Chris@42 230 pln->slv = ego;
Chris@42 231 pln->brs = X(mkstride)(r, 2 * compute_batchsize(r));
Chris@42 232 pln->cld0 = cld0;
Chris@42 233 pln->cldm = cldm;
Chris@42 234 pln->mb = mstart + CLD0P(mstart);
Chris@42 235 pln->me = mstart + mcount - CLDMP(m, mstart, mcount);
Chris@42 236
Chris@42 237 X(ops_zero)(&pln->super.super.ops);
Chris@42 238 X(ops_madd2)(v * ((pln->me - pln->mb) / e->genus->vl),
Chris@42 239 &e->ops, &pln->super.super.ops);
Chris@42 240 X(ops_madd2)(v, &cld0->ops, &pln->super.super.ops);
Chris@42 241 X(ops_madd2)(v, &cldm->ops, &pln->super.super.ops);
Chris@42 242
Chris@42 243 if (ego->bufferedp)
Chris@42 244 pln->super.super.ops.other += 4 * r * (pln->me - pln->mb) * v;
Chris@42 245
Chris@42 246 pln->super.super.could_prune_now_p =
Chris@42 247 (!ego->bufferedp && r >= 5 && r < 64 && m >= r);
Chris@42 248
Chris@42 249 return &(pln->super.super);
Chris@42 250
Chris@42 251 nada:
Chris@42 252 X(plan_destroy_internal)(cld0);
Chris@42 253 X(plan_destroy_internal)(cldm);
Chris@42 254 return 0;
Chris@42 255 }
Chris@42 256
Chris@42 257 static void regone(planner *plnr, khc2hc codelet, const hc2hc_desc *desc,
Chris@42 258 int bufferedp)
Chris@42 259 {
Chris@42 260 S *slv = (S *)X(mksolver_hc2hc)(sizeof(S), desc->radix, mkcldw);
Chris@42 261 slv->k = codelet;
Chris@42 262 slv->desc = desc;
Chris@42 263 slv->bufferedp = bufferedp;
Chris@42 264 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@42 265 if (X(mksolver_hc2hc_hook)) {
Chris@42 266 slv = (S *)X(mksolver_hc2hc_hook)(sizeof(S), desc->radix, mkcldw);
Chris@42 267 slv->k = codelet;
Chris@42 268 slv->desc = desc;
Chris@42 269 slv->bufferedp = bufferedp;
Chris@42 270 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@42 271 }
Chris@42 272 }
Chris@42 273
Chris@42 274 void X(regsolver_hc2hc_direct)(planner *plnr, khc2hc codelet,
Chris@42 275 const hc2hc_desc *desc)
Chris@42 276 {
Chris@42 277 regone(plnr, codelet, desc, /* bufferedp */0);
Chris@42 278 regone(plnr, codelet, desc, /* bufferedp */1);
Chris@42 279 }