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