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