Chris@82: /* Chris@82: * Copyright (c) 2003, 2007-14 Matteo Frigo Chris@82: * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology Chris@82: * Chris@82: * This program is free software; you can redistribute it and/or modify Chris@82: * it under the terms of the GNU General Public License as published by Chris@82: * the Free Software Foundation; either version 2 of the License, or Chris@82: * (at your option) any later version. Chris@82: * Chris@82: * This program is distributed in the hope that it will be useful, Chris@82: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@82: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@82: * GNU General Public License for more details. Chris@82: * Chris@82: * You should have received a copy of the GNU General Public License Chris@82: * along with this program; if not, write to the Free Software Chris@82: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@82: * Chris@82: */ Chris@82: Chris@82: /* routines shared by the various buffered solvers */ Chris@82: Chris@82: #include "kernel/ifftw.h" Chris@82: Chris@82: #define DEFAULT_MAXNBUF ((INT)256) Chris@82: Chris@82: /* approx. 512KB of buffers for complex data */ Chris@82: #define MAXBUFSZ (256 * 1024 / (INT)(sizeof(R))) Chris@82: Chris@82: INT X(nbuf)(INT n, INT vl, INT maxnbuf) Chris@82: { Chris@82: INT i, nbuf, lb; Chris@82: Chris@82: if (!maxnbuf) Chris@82: maxnbuf = DEFAULT_MAXNBUF; Chris@82: Chris@82: nbuf = X(imin)(maxnbuf, Chris@82: X(imin)(vl, X(imax)((INT)1, MAXBUFSZ / n))); Chris@82: Chris@82: /* Chris@82: * Look for a buffer number (not too small) that divides the Chris@82: * vector length, in order that we only need one child plan: Chris@82: */ Chris@82: lb = X(imax)(1, nbuf / 4); Chris@82: for (i = nbuf; i >= lb; --i) Chris@82: if (vl % i == 0) Chris@82: return i; Chris@82: Chris@82: /* whatever... */ Chris@82: return nbuf; Chris@82: } Chris@82: Chris@82: #define SKEW 6 /* need to be even for SIMD */ Chris@82: #define SKEWMOD 8 Chris@82: Chris@82: INT X(bufdist)(INT n, INT vl) Chris@82: { Chris@82: if (vl == 1) Chris@82: return n; Chris@82: else Chris@82: /* return smallest X such that X >= N and X == SKEW (mod SKEWMOD) */ Chris@82: return n + X(modulo)(SKEW - n, SKEWMOD); Chris@82: } Chris@82: Chris@82: int X(toobig)(INT n) Chris@82: { Chris@82: return n > MAXBUFSZ; Chris@82: } Chris@82: Chris@82: /* TRUE if there exists i < which such that maxnbuf[i] and Chris@82: maxnbuf[which] yield the same value, in which case we canonicalize Chris@82: on the minimum value */ Chris@82: int X(nbuf_redundant)(INT n, INT vl, size_t which, Chris@82: const INT *maxnbuf, size_t nmaxnbuf) Chris@82: { Chris@82: size_t i; Chris@82: (void)nmaxnbuf; /* UNUSED */ Chris@82: for (i = 0; i < which; ++i) Chris@82: if (X(nbuf)(n, vl, maxnbuf[i]) == X(nbuf)(n, vl, maxnbuf[which])) Chris@82: return 1; Chris@82: return 0; Chris@82: }