Chris@10: /* Chris@10: * Copyright (c) 2003, 2007-11 Matteo Frigo Chris@10: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology Chris@10: * Chris@10: * This program is free software; you can redistribute it and/or modify Chris@10: * it under the terms of the GNU General Public License as published by Chris@10: * the Free Software Foundation; either version 2 of the License, or Chris@10: * (at your option) any later version. Chris@10: * Chris@10: * This program is distributed in the hope that it will be useful, Chris@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@10: * GNU General Public License for more details. Chris@10: * Chris@10: * You should have received a copy of the GNU General Public License Chris@10: * along with this program; if not, write to the Free Software Chris@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@10: * Chris@10: */ Chris@10: Chris@10: #include "api.h" Chris@10: #include Chris@10: Chris@10: /* a flag operation: x is either a flag, in which case xm == 0, or Chris@10: a mask, in which case xm == x; using this we can compactly code Chris@10: the various bit operations via (flags & x) ^ xm or (flags | x) ^ xm. */ Chris@10: typedef struct { Chris@10: unsigned x, xm; Chris@10: } flagmask; Chris@10: Chris@10: typedef struct { Chris@10: flagmask flag; Chris@10: flagmask op; Chris@10: } flagop; Chris@10: Chris@10: #define FLAGP(f, msk)(((f) & (msk).x) ^ (msk).xm) Chris@10: #define OP(f, msk)(((f) | (msk).x) ^ (msk).xm) Chris@10: Chris@10: #define YES(x) {x, 0} Chris@10: #define NO(x) {x, x} Chris@10: #define IMPLIES(predicate, consequence) { predicate, consequence } Chris@10: #define EQV(a, b) IMPLIES(YES(a), YES(b)), IMPLIES(NO(a), NO(b)) Chris@10: #define NEQV(a, b) IMPLIES(YES(a), NO(b)), IMPLIES(NO(a), YES(b)) Chris@10: Chris@10: static void map_flags(unsigned *iflags, unsigned *oflags, Chris@10: const flagop flagmap[], int nmap) Chris@10: { Chris@10: int i; Chris@10: for (i = 0; i < nmap; ++i) Chris@10: if (FLAGP(*iflags, flagmap[i].flag)) Chris@10: *oflags = OP(*oflags, flagmap[i].op); Chris@10: } Chris@10: Chris@10: /* encoding of the planner timelimit into a BITS_FOR_TIMELIMIT-bits Chris@10: nonnegative integer, such that we can still view the integer as Chris@10: ``impatience'': higher means *lower* time limit, and 0 is the Chris@10: highest possible value (about 1 year of calendar time) */ Chris@10: static unsigned timelimit_to_flags(double timelimit) Chris@10: { Chris@10: const double tmax = 365 * 24 * 3600; Chris@10: const double tstep = 1.05; Chris@10: const int nsteps = (1 << BITS_FOR_TIMELIMIT); Chris@10: int x; Chris@10: Chris@10: if (timelimit < 0 || timelimit >= tmax) Chris@10: return 0; Chris@10: if (timelimit <= 1.0e-10) Chris@10: return nsteps - 1; Chris@10: Chris@10: x = (int) (0.5 + (log(tmax / timelimit) / log(tstep))); Chris@10: Chris@10: if (x < 0) x = 0; Chris@10: if (x >= nsteps) x = nsteps - 1; Chris@10: return x; Chris@10: } Chris@10: Chris@10: void X(mapflags)(planner *plnr, unsigned flags) Chris@10: { Chris@10: unsigned l, u, t; Chris@10: Chris@10: /* map of api flags -> api flags, to implement consistency rules Chris@10: and combination flags */ Chris@10: const flagop self_flagmap[] = { Chris@10: /* in some cases (notably for halfcomplex->real transforms), Chris@10: DESTROY_INPUT is the default, so we need to support Chris@10: an inverse flag to disable it. Chris@10: Chris@10: (PRESERVE, DESTROY) -> (PRESERVE, DESTROY) Chris@10: (0, 0) (1, 0) Chris@10: (0, 1) (0, 1) Chris@10: (1, 0) (1, 0) Chris@10: (1, 1) (1, 0) Chris@10: */ Chris@10: IMPLIES(YES(FFTW_PRESERVE_INPUT), NO(FFTW_DESTROY_INPUT)), Chris@10: IMPLIES(NO(FFTW_DESTROY_INPUT), YES(FFTW_PRESERVE_INPUT)), Chris@10: Chris@10: IMPLIES(YES(FFTW_EXHAUSTIVE), YES(FFTW_PATIENT)), Chris@10: Chris@10: IMPLIES(YES(FFTW_ESTIMATE), NO(FFTW_PATIENT)), Chris@10: IMPLIES(YES(FFTW_ESTIMATE), Chris@10: YES(FFTW_ESTIMATE_PATIENT Chris@10: | FFTW_NO_INDIRECT_OP Chris@10: | FFTW_ALLOW_PRUNING)), Chris@10: Chris@10: IMPLIES(NO(FFTW_EXHAUSTIVE), Chris@10: YES(FFTW_NO_SLOW)), Chris@10: Chris@10: /* a canonical set of fftw2-like impatience flags */ Chris@10: IMPLIES(NO(FFTW_PATIENT), Chris@10: YES(FFTW_NO_VRECURSE Chris@10: | FFTW_NO_RANK_SPLITS Chris@10: | FFTW_NO_VRANK_SPLITS Chris@10: | FFTW_NO_NONTHREADED Chris@10: | FFTW_NO_DFT_R2HC Chris@10: | FFTW_NO_FIXED_RADIX_LARGE_N Chris@10: | FFTW_BELIEVE_PCOST)) Chris@10: }; Chris@10: Chris@10: /* map of (processed) api flags to internal problem/planner flags */ Chris@10: const flagop l_flagmap[] = { Chris@10: EQV(FFTW_PRESERVE_INPUT, NO_DESTROY_INPUT), Chris@10: EQV(FFTW_NO_SIMD, NO_SIMD), Chris@10: EQV(FFTW_CONSERVE_MEMORY, CONSERVE_MEMORY), Chris@10: EQV(FFTW_NO_BUFFERING, NO_BUFFERING), Chris@10: NEQV(FFTW_ALLOW_LARGE_GENERIC, NO_LARGE_GENERIC) Chris@10: }; Chris@10: Chris@10: const flagop u_flagmap[] = { Chris@10: IMPLIES(YES(FFTW_EXHAUSTIVE), NO(0xFFFFFFFF)), Chris@10: IMPLIES(NO(FFTW_EXHAUSTIVE), YES(NO_UGLY)), Chris@10: Chris@10: /* the following are undocumented, "beyond-guru" flags that Chris@10: require some understanding of FFTW internals */ Chris@10: EQV(FFTW_ESTIMATE_PATIENT, ESTIMATE), Chris@10: EQV(FFTW_ALLOW_PRUNING, ALLOW_PRUNING), Chris@10: EQV(FFTW_BELIEVE_PCOST, BELIEVE_PCOST), Chris@10: EQV(FFTW_NO_DFT_R2HC, NO_DFT_R2HC), Chris@10: EQV(FFTW_NO_NONTHREADED, NO_NONTHREADED), Chris@10: EQV(FFTW_NO_INDIRECT_OP, NO_INDIRECT_OP), Chris@10: EQV(FFTW_NO_RANK_SPLITS, NO_RANK_SPLITS), Chris@10: EQV(FFTW_NO_VRANK_SPLITS, NO_VRANK_SPLITS), Chris@10: EQV(FFTW_NO_VRECURSE, NO_VRECURSE), Chris@10: EQV(FFTW_NO_SLOW, NO_SLOW), Chris@10: EQV(FFTW_NO_FIXED_RADIX_LARGE_N, NO_FIXED_RADIX_LARGE_N) Chris@10: }; Chris@10: Chris@10: map_flags(&flags, &flags, self_flagmap, NELEM(self_flagmap)); Chris@10: Chris@10: l = u = 0; Chris@10: map_flags(&flags, &l, l_flagmap, NELEM(l_flagmap)); Chris@10: map_flags(&flags, &u, u_flagmap, NELEM(u_flagmap)); Chris@10: Chris@10: /* enforce l <= u */ Chris@10: PLNR_L(plnr) = l; Chris@10: PLNR_U(plnr) = u | l; Chris@10: Chris@10: /* assert that the conversion didn't lose bits */ Chris@10: A(PLNR_L(plnr) == l); Chris@10: A(PLNR_U(plnr) == (u | l)); Chris@10: Chris@10: /* compute flags representation of the timelimit */ Chris@10: t = timelimit_to_flags(plnr->timelimit); Chris@10: Chris@10: PLNR_TIMELIMIT_IMPATIENCE(plnr) = t; Chris@10: A(PLNR_TIMELIMIT_IMPATIENCE(plnr) == t); Chris@10: }