annotate src/fftw-3.3.3/api/mapflags.c @ 44:9894b839b0cb

Updated MSVC
author Chris Cannam
date Tue, 18 Oct 2016 15:58:42 +0100
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 "api.h"
Chris@10 22 #include <math.h>
Chris@10 23
Chris@10 24 /* a flag operation: x is either a flag, in which case xm == 0, or
Chris@10 25 a mask, in which case xm == x; using this we can compactly code
Chris@10 26 the various bit operations via (flags & x) ^ xm or (flags | x) ^ xm. */
Chris@10 27 typedef struct {
Chris@10 28 unsigned x, xm;
Chris@10 29 } flagmask;
Chris@10 30
Chris@10 31 typedef struct {
Chris@10 32 flagmask flag;
Chris@10 33 flagmask op;
Chris@10 34 } flagop;
Chris@10 35
Chris@10 36 #define FLAGP(f, msk)(((f) & (msk).x) ^ (msk).xm)
Chris@10 37 #define OP(f, msk)(((f) | (msk).x) ^ (msk).xm)
Chris@10 38
Chris@10 39 #define YES(x) {x, 0}
Chris@10 40 #define NO(x) {x, x}
Chris@10 41 #define IMPLIES(predicate, consequence) { predicate, consequence }
Chris@10 42 #define EQV(a, b) IMPLIES(YES(a), YES(b)), IMPLIES(NO(a), NO(b))
Chris@10 43 #define NEQV(a, b) IMPLIES(YES(a), NO(b)), IMPLIES(NO(a), YES(b))
Chris@10 44
Chris@10 45 static void map_flags(unsigned *iflags, unsigned *oflags,
Chris@10 46 const flagop flagmap[], int nmap)
Chris@10 47 {
Chris@10 48 int i;
Chris@10 49 for (i = 0; i < nmap; ++i)
Chris@10 50 if (FLAGP(*iflags, flagmap[i].flag))
Chris@10 51 *oflags = OP(*oflags, flagmap[i].op);
Chris@10 52 }
Chris@10 53
Chris@10 54 /* encoding of the planner timelimit into a BITS_FOR_TIMELIMIT-bits
Chris@10 55 nonnegative integer, such that we can still view the integer as
Chris@10 56 ``impatience'': higher means *lower* time limit, and 0 is the
Chris@10 57 highest possible value (about 1 year of calendar time) */
Chris@10 58 static unsigned timelimit_to_flags(double timelimit)
Chris@10 59 {
Chris@10 60 const double tmax = 365 * 24 * 3600;
Chris@10 61 const double tstep = 1.05;
Chris@10 62 const int nsteps = (1 << BITS_FOR_TIMELIMIT);
Chris@10 63 int x;
Chris@10 64
Chris@10 65 if (timelimit < 0 || timelimit >= tmax)
Chris@10 66 return 0;
Chris@10 67 if (timelimit <= 1.0e-10)
Chris@10 68 return nsteps - 1;
Chris@10 69
Chris@10 70 x = (int) (0.5 + (log(tmax / timelimit) / log(tstep)));
Chris@10 71
Chris@10 72 if (x < 0) x = 0;
Chris@10 73 if (x >= nsteps) x = nsteps - 1;
Chris@10 74 return x;
Chris@10 75 }
Chris@10 76
Chris@10 77 void X(mapflags)(planner *plnr, unsigned flags)
Chris@10 78 {
Chris@10 79 unsigned l, u, t;
Chris@10 80
Chris@10 81 /* map of api flags -> api flags, to implement consistency rules
Chris@10 82 and combination flags */
Chris@10 83 const flagop self_flagmap[] = {
Chris@10 84 /* in some cases (notably for halfcomplex->real transforms),
Chris@10 85 DESTROY_INPUT is the default, so we need to support
Chris@10 86 an inverse flag to disable it.
Chris@10 87
Chris@10 88 (PRESERVE, DESTROY) -> (PRESERVE, DESTROY)
Chris@10 89 (0, 0) (1, 0)
Chris@10 90 (0, 1) (0, 1)
Chris@10 91 (1, 0) (1, 0)
Chris@10 92 (1, 1) (1, 0)
Chris@10 93 */
Chris@10 94 IMPLIES(YES(FFTW_PRESERVE_INPUT), NO(FFTW_DESTROY_INPUT)),
Chris@10 95 IMPLIES(NO(FFTW_DESTROY_INPUT), YES(FFTW_PRESERVE_INPUT)),
Chris@10 96
Chris@10 97 IMPLIES(YES(FFTW_EXHAUSTIVE), YES(FFTW_PATIENT)),
Chris@10 98
Chris@10 99 IMPLIES(YES(FFTW_ESTIMATE), NO(FFTW_PATIENT)),
Chris@10 100 IMPLIES(YES(FFTW_ESTIMATE),
Chris@10 101 YES(FFTW_ESTIMATE_PATIENT
Chris@10 102 | FFTW_NO_INDIRECT_OP
Chris@10 103 | FFTW_ALLOW_PRUNING)),
Chris@10 104
Chris@10 105 IMPLIES(NO(FFTW_EXHAUSTIVE),
Chris@10 106 YES(FFTW_NO_SLOW)),
Chris@10 107
Chris@10 108 /* a canonical set of fftw2-like impatience flags */
Chris@10 109 IMPLIES(NO(FFTW_PATIENT),
Chris@10 110 YES(FFTW_NO_VRECURSE
Chris@10 111 | FFTW_NO_RANK_SPLITS
Chris@10 112 | FFTW_NO_VRANK_SPLITS
Chris@10 113 | FFTW_NO_NONTHREADED
Chris@10 114 | FFTW_NO_DFT_R2HC
Chris@10 115 | FFTW_NO_FIXED_RADIX_LARGE_N
Chris@10 116 | FFTW_BELIEVE_PCOST))
Chris@10 117 };
Chris@10 118
Chris@10 119 /* map of (processed) api flags to internal problem/planner flags */
Chris@10 120 const flagop l_flagmap[] = {
Chris@10 121 EQV(FFTW_PRESERVE_INPUT, NO_DESTROY_INPUT),
Chris@10 122 EQV(FFTW_NO_SIMD, NO_SIMD),
Chris@10 123 EQV(FFTW_CONSERVE_MEMORY, CONSERVE_MEMORY),
Chris@10 124 EQV(FFTW_NO_BUFFERING, NO_BUFFERING),
Chris@10 125 NEQV(FFTW_ALLOW_LARGE_GENERIC, NO_LARGE_GENERIC)
Chris@10 126 };
Chris@10 127
Chris@10 128 const flagop u_flagmap[] = {
Chris@10 129 IMPLIES(YES(FFTW_EXHAUSTIVE), NO(0xFFFFFFFF)),
Chris@10 130 IMPLIES(NO(FFTW_EXHAUSTIVE), YES(NO_UGLY)),
Chris@10 131
Chris@10 132 /* the following are undocumented, "beyond-guru" flags that
Chris@10 133 require some understanding of FFTW internals */
Chris@10 134 EQV(FFTW_ESTIMATE_PATIENT, ESTIMATE),
Chris@10 135 EQV(FFTW_ALLOW_PRUNING, ALLOW_PRUNING),
Chris@10 136 EQV(FFTW_BELIEVE_PCOST, BELIEVE_PCOST),
Chris@10 137 EQV(FFTW_NO_DFT_R2HC, NO_DFT_R2HC),
Chris@10 138 EQV(FFTW_NO_NONTHREADED, NO_NONTHREADED),
Chris@10 139 EQV(FFTW_NO_INDIRECT_OP, NO_INDIRECT_OP),
Chris@10 140 EQV(FFTW_NO_RANK_SPLITS, NO_RANK_SPLITS),
Chris@10 141 EQV(FFTW_NO_VRANK_SPLITS, NO_VRANK_SPLITS),
Chris@10 142 EQV(FFTW_NO_VRECURSE, NO_VRECURSE),
Chris@10 143 EQV(FFTW_NO_SLOW, NO_SLOW),
Chris@10 144 EQV(FFTW_NO_FIXED_RADIX_LARGE_N, NO_FIXED_RADIX_LARGE_N)
Chris@10 145 };
Chris@10 146
Chris@10 147 map_flags(&flags, &flags, self_flagmap, NELEM(self_flagmap));
Chris@10 148
Chris@10 149 l = u = 0;
Chris@10 150 map_flags(&flags, &l, l_flagmap, NELEM(l_flagmap));
Chris@10 151 map_flags(&flags, &u, u_flagmap, NELEM(u_flagmap));
Chris@10 152
Chris@10 153 /* enforce l <= u */
Chris@10 154 PLNR_L(plnr) = l;
Chris@10 155 PLNR_U(plnr) = u | l;
Chris@10 156
Chris@10 157 /* assert that the conversion didn't lose bits */
Chris@10 158 A(PLNR_L(plnr) == l);
Chris@10 159 A(PLNR_U(plnr) == (u | l));
Chris@10 160
Chris@10 161 /* compute flags representation of the timelimit */
Chris@10 162 t = timelimit_to_flags(plnr->timelimit);
Chris@10 163
Chris@10 164 PLNR_TIMELIMIT_IMPATIENCE(plnr) = t;
Chris@10 165 A(PLNR_TIMELIMIT_IMPATIENCE(plnr) == t);
Chris@10 166 }