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