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