annotate fft/fftw/fftw-3.3.4/api/mapflags.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21 #include "api.h"
Chris@19 22 #include <math.h>
Chris@19 23
Chris@19 24 /* a flag operation: x is either a flag, in which case xm == 0, or
Chris@19 25 a mask, in which case xm == x; using this we can compactly code
Chris@19 26 the various bit operations via (flags & x) ^ xm or (flags | x) ^ xm. */
Chris@19 27 typedef struct {
Chris@19 28 unsigned x, xm;
Chris@19 29 } flagmask;
Chris@19 30
Chris@19 31 typedef struct {
Chris@19 32 flagmask flag;
Chris@19 33 flagmask op;
Chris@19 34 } flagop;
Chris@19 35
Chris@19 36 #define FLAGP(f, msk)(((f) & (msk).x) ^ (msk).xm)
Chris@19 37 #define OP(f, msk)(((f) | (msk).x) ^ (msk).xm)
Chris@19 38
Chris@19 39 #define YES(x) {x, 0}
Chris@19 40 #define NO(x) {x, x}
Chris@19 41 #define IMPLIES(predicate, consequence) { predicate, consequence }
Chris@19 42 #define EQV(a, b) IMPLIES(YES(a), YES(b)), IMPLIES(NO(a), NO(b))
Chris@19 43 #define NEQV(a, b) IMPLIES(YES(a), NO(b)), IMPLIES(NO(a), YES(b))
Chris@19 44
Chris@19 45 static void map_flags(unsigned *iflags, unsigned *oflags,
Chris@19 46 const flagop flagmap[], int nmap)
Chris@19 47 {
Chris@19 48 int i;
Chris@19 49 for (i = 0; i < nmap; ++i)
Chris@19 50 if (FLAGP(*iflags, flagmap[i].flag))
Chris@19 51 *oflags = OP(*oflags, flagmap[i].op);
Chris@19 52 }
Chris@19 53
Chris@19 54 /* encoding of the planner timelimit into a BITS_FOR_TIMELIMIT-bits
Chris@19 55 nonnegative integer, such that we can still view the integer as
Chris@19 56 ``impatience'': higher means *lower* time limit, and 0 is the
Chris@19 57 highest possible value (about 1 year of calendar time) */
Chris@19 58 static unsigned timelimit_to_flags(double timelimit)
Chris@19 59 {
Chris@19 60 const double tmax = 365 * 24 * 3600;
Chris@19 61 const double tstep = 1.05;
Chris@19 62 const int nsteps = (1 << BITS_FOR_TIMELIMIT);
Chris@19 63 int x;
Chris@19 64
Chris@19 65 if (timelimit < 0 || timelimit >= tmax)
Chris@19 66 return 0;
Chris@19 67 if (timelimit <= 1.0e-10)
Chris@19 68 return nsteps - 1;
Chris@19 69
Chris@19 70 x = (int) (0.5 + (log(tmax / timelimit) / log(tstep)));
Chris@19 71
Chris@19 72 if (x < 0) x = 0;
Chris@19 73 if (x >= nsteps) x = nsteps - 1;
Chris@19 74 return x;
Chris@19 75 }
Chris@19 76
Chris@19 77 void X(mapflags)(planner *plnr, unsigned flags)
Chris@19 78 {
Chris@19 79 unsigned l, u, t;
Chris@19 80
Chris@19 81 /* map of api flags -> api flags, to implement consistency rules
Chris@19 82 and combination flags */
Chris@19 83 const flagop self_flagmap[] = {
Chris@19 84 /* in some cases (notably for halfcomplex->real transforms),
Chris@19 85 DESTROY_INPUT is the default, so we need to support
Chris@19 86 an inverse flag to disable it.
Chris@19 87
Chris@19 88 (PRESERVE, DESTROY) -> (PRESERVE, DESTROY)
Chris@19 89 (0, 0) (1, 0)
Chris@19 90 (0, 1) (0, 1)
Chris@19 91 (1, 0) (1, 0)
Chris@19 92 (1, 1) (1, 0)
Chris@19 93 */
Chris@19 94 IMPLIES(YES(FFTW_PRESERVE_INPUT), NO(FFTW_DESTROY_INPUT)),
Chris@19 95 IMPLIES(NO(FFTW_DESTROY_INPUT), YES(FFTW_PRESERVE_INPUT)),
Chris@19 96
Chris@19 97 IMPLIES(YES(FFTW_EXHAUSTIVE), YES(FFTW_PATIENT)),
Chris@19 98
Chris@19 99 IMPLIES(YES(FFTW_ESTIMATE), NO(FFTW_PATIENT)),
Chris@19 100 IMPLIES(YES(FFTW_ESTIMATE),
Chris@19 101 YES(FFTW_ESTIMATE_PATIENT
Chris@19 102 | FFTW_NO_INDIRECT_OP
Chris@19 103 | FFTW_ALLOW_PRUNING)),
Chris@19 104
Chris@19 105 IMPLIES(NO(FFTW_EXHAUSTIVE),
Chris@19 106 YES(FFTW_NO_SLOW)),
Chris@19 107
Chris@19 108 /* a canonical set of fftw2-like impatience flags */
Chris@19 109 IMPLIES(NO(FFTW_PATIENT),
Chris@19 110 YES(FFTW_NO_VRECURSE
Chris@19 111 | FFTW_NO_RANK_SPLITS
Chris@19 112 | FFTW_NO_VRANK_SPLITS
Chris@19 113 | FFTW_NO_NONTHREADED
Chris@19 114 | FFTW_NO_DFT_R2HC
Chris@19 115 | FFTW_NO_FIXED_RADIX_LARGE_N
Chris@19 116 | FFTW_BELIEVE_PCOST))
Chris@19 117 };
Chris@19 118
Chris@19 119 /* map of (processed) api flags to internal problem/planner flags */
Chris@19 120 const flagop l_flagmap[] = {
Chris@19 121 EQV(FFTW_PRESERVE_INPUT, NO_DESTROY_INPUT),
Chris@19 122 EQV(FFTW_NO_SIMD, NO_SIMD),
Chris@19 123 EQV(FFTW_CONSERVE_MEMORY, CONSERVE_MEMORY),
Chris@19 124 EQV(FFTW_NO_BUFFERING, NO_BUFFERING),
Chris@19 125 NEQV(FFTW_ALLOW_LARGE_GENERIC, NO_LARGE_GENERIC)
Chris@19 126 };
Chris@19 127
Chris@19 128 const flagop u_flagmap[] = {
Chris@19 129 IMPLIES(YES(FFTW_EXHAUSTIVE), NO(0xFFFFFFFF)),
Chris@19 130 IMPLIES(NO(FFTW_EXHAUSTIVE), YES(NO_UGLY)),
Chris@19 131
Chris@19 132 /* the following are undocumented, "beyond-guru" flags that
Chris@19 133 require some understanding of FFTW internals */
Chris@19 134 EQV(FFTW_ESTIMATE_PATIENT, ESTIMATE),
Chris@19 135 EQV(FFTW_ALLOW_PRUNING, ALLOW_PRUNING),
Chris@19 136 EQV(FFTW_BELIEVE_PCOST, BELIEVE_PCOST),
Chris@19 137 EQV(FFTW_NO_DFT_R2HC, NO_DFT_R2HC),
Chris@19 138 EQV(FFTW_NO_NONTHREADED, NO_NONTHREADED),
Chris@19 139 EQV(FFTW_NO_INDIRECT_OP, NO_INDIRECT_OP),
Chris@19 140 EQV(FFTW_NO_RANK_SPLITS, NO_RANK_SPLITS),
Chris@19 141 EQV(FFTW_NO_VRANK_SPLITS, NO_VRANK_SPLITS),
Chris@19 142 EQV(FFTW_NO_VRECURSE, NO_VRECURSE),
Chris@19 143 EQV(FFTW_NO_SLOW, NO_SLOW),
Chris@19 144 EQV(FFTW_NO_FIXED_RADIX_LARGE_N, NO_FIXED_RADIX_LARGE_N)
Chris@19 145 };
Chris@19 146
Chris@19 147 map_flags(&flags, &flags, self_flagmap, NELEM(self_flagmap));
Chris@19 148
Chris@19 149 l = u = 0;
Chris@19 150 map_flags(&flags, &l, l_flagmap, NELEM(l_flagmap));
Chris@19 151 map_flags(&flags, &u, u_flagmap, NELEM(u_flagmap));
Chris@19 152
Chris@19 153 /* enforce l <= u */
Chris@19 154 PLNR_L(plnr) = l;
Chris@19 155 PLNR_U(plnr) = u | l;
Chris@19 156
Chris@19 157 /* assert that the conversion didn't lose bits */
Chris@19 158 A(PLNR_L(plnr) == l);
Chris@19 159 A(PLNR_U(plnr) == (u | l));
Chris@19 160
Chris@19 161 /* compute flags representation of the timelimit */
Chris@19 162 t = timelimit_to_flags(plnr->timelimit);
Chris@19 163
Chris@19 164 PLNR_TIMELIMIT_IMPATIENCE(plnr) = t;
Chris@19 165 A(PLNR_TIMELIMIT_IMPATIENCE(plnr) == t);
Chris@19 166 }