comparison src/fftw-3.3.3/kernel/buffered.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 /* routines shared by the various buffered solvers */
22
23 #include "ifftw.h"
24
25 #define DEFAULT_MAXNBUF ((INT)256)
26
27 /* approx. 512KB of buffers for complex data */
28 #define MAXBUFSZ (256 * 1024 / (INT)(sizeof(R)))
29
30 INT X(nbuf)(INT n, INT vl, INT maxnbuf)
31 {
32 INT i, nbuf, lb;
33
34 if (!maxnbuf)
35 maxnbuf = DEFAULT_MAXNBUF;
36
37 nbuf = X(imin)(maxnbuf,
38 X(imin)(vl, X(imax)((INT)1, MAXBUFSZ / n)));
39
40 /*
41 * Look for a buffer number (not too small) that divides the
42 * vector length, in order that we only need one child plan:
43 */
44 lb = X(imax)(1, nbuf / 4);
45 for (i = nbuf; i >= lb; --i)
46 if (vl % i == 0)
47 return i;
48
49 /* whatever... */
50 return nbuf;
51 }
52
53 #define SKEW 6 /* need to be even for SIMD */
54 #define SKEWMOD 8
55
56 INT X(bufdist)(INT n, INT vl)
57 {
58 if (vl == 1)
59 return n;
60 else
61 /* return smallest X such that X >= N and X == SKEW (mod SKEWMOD) */
62 return n + X(modulo)(SKEW - n, SKEWMOD);
63 }
64
65 int X(toobig)(INT n)
66 {
67 return n > MAXBUFSZ;
68 }
69
70 /* TRUE if there exists i < which such that maxnbuf[i] and
71 maxnbuf[which] yield the same value, in which case we canonicalize
72 on the minimum value */
73 int X(nbuf_redundant)(INT n, INT vl, int which,
74 const INT *maxnbuf, int nmaxnbuf)
75 {
76 int i;
77 (void)nmaxnbuf; /* UNUSED */
78 for (i = 0; i < which; ++i)
79 if (X(nbuf)(n, vl, maxnbuf[i]) == X(nbuf)(n, vl, maxnbuf[which]))
80 return 1;
81 return 0;
82 }