annotate src/fftw-3.3.8/api/mapflags.c @ 169:223a55898ab9 tip default

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