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