comparison src/fftw-3.3.3/api/f77api.c @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
94:d278df1123f9 95:89f5e221ed7b
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 #include "api.h"
22 #include "dft.h"
23 #include "rdft.h"
24
25 #include "x77.h"
26
27 /* if F77_FUNC is not defined, then we don't know how to mangle identifiers
28 for the Fortran linker, and we must omit the f77 API. */
29 #if defined(F77_FUNC) || defined(WINDOWS_F77_MANGLING)
30
31 /*-----------------------------------------------------------------------*/
32 /* some internal functions used by the f77 api */
33
34 /* in fortran, the natural array ordering is column-major, which
35 corresponds to reversing the dimensions relative to C's row-major */
36 static int *reverse_n(int rnk, const int *n)
37 {
38 int *nrev;
39 int i;
40 A(FINITE_RNK(rnk));
41 nrev = (int *) MALLOC(sizeof(int) * rnk, PROBLEMS);
42 for (i = 0; i < rnk; ++i)
43 nrev[rnk - i - 1] = n[i];
44 return nrev;
45 }
46
47 /* f77 doesn't have data structures, so we have to pass iodims as
48 parallel arrays */
49 static X(iodim) *make_dims(int rnk, const int *n,
50 const int *is, const int *os)
51 {
52 X(iodim) *dims;
53 int i;
54 A(FINITE_RNK(rnk));
55 dims = (X(iodim) *) MALLOC(sizeof(X(iodim)) * rnk, PROBLEMS);
56 for (i = 0; i < rnk; ++i) {
57 dims[i].n = n[i];
58 dims[i].is = is[i];
59 dims[i].os = os[i];
60 }
61 return dims;
62 }
63
64 typedef struct {
65 void (*f77_write_char)(char *, void *);
66 void *data;
67 } write_char_data;
68
69 static void write_char(char c, void *d)
70 {
71 write_char_data *ad = (write_char_data *) d;
72 ad->f77_write_char(&c, ad->data);
73 }
74
75 typedef struct {
76 void (*f77_read_char)(int *, void *);
77 void *data;
78 } read_char_data;
79
80 static int read_char(void *d)
81 {
82 read_char_data *ed = (read_char_data *) d;
83 int c;
84 ed->f77_read_char(&c, ed->data);
85 return (c < 0 ? EOF : c);
86 }
87
88 static X(r2r_kind) *ints2kinds(int rnk, const int *ik)
89 {
90 if (!FINITE_RNK(rnk) || rnk == 0)
91 return 0;
92 else {
93 int i;
94 X(r2r_kind) *k;
95
96 k = (X(r2r_kind) *) MALLOC(sizeof(X(r2r_kind)) * rnk, PROBLEMS);
97 /* reverse order for Fortran -> C */
98 for (i = 0; i < rnk; ++i)
99 k[i] = (X(r2r_kind)) ik[rnk - 1 - i];
100 return k;
101 }
102 }
103
104 /*-----------------------------------------------------------------------*/
105
106 #define F77(a, A) F77x(x77(a), X77(A))
107
108 #ifndef WINDOWS_F77_MANGLING
109
110 #if defined(F77_FUNC)
111 # define F77x(a, A) F77_FUNC(a, A)
112 # include "f77funcs.h"
113 #endif
114
115 /* If identifiers with underscores are mangled differently than those
116 without underscores, then we include *both* mangling versions. The
117 reason is that the only Fortran compiler that does such differing
118 mangling is currently g77 (which adds an extra underscore to names
119 with underscores), whereas other compilers running on the same
120 machine are likely to use non-underscored mangling. (I'm sick
121 of users complaining that FFTW works with g77 but not with e.g.
122 pgf77 or ifc on the same machine.) Note that all FFTW identifiers
123 contain underscores, and configure picks g77 by default. */
124 #if defined(F77_FUNC_) && !defined(F77_FUNC_EQUIV)
125 # undef F77x
126 # define F77x(a, A) F77_FUNC_(a, A)
127 # include "f77funcs.h"
128 #endif
129
130 #else /* WINDOWS_F77_MANGLING */
131
132 /* Various mangling conventions common (?) under Windows. */
133
134 /* g77 */
135 # define WINDOWS_F77_FUNC(a, A) a ## __
136 # define F77x(a, A) WINDOWS_F77_FUNC(a, A)
137 # include "f77funcs.h"
138
139 /* Intel, etc. */
140 # undef WINDOWS_F77_FUNC
141 # define WINDOWS_F77_FUNC(a, A) a ## _
142 # include "f77funcs.h"
143
144 /* Digital/Compaq/HP Visual Fortran, Intel Fortran. stdcall attribute
145 is apparently required to adjust for calling conventions (callee
146 pops stack in stdcall). See also:
147 http://msdn.microsoft.com/library/en-us/vccore98/html/_core_mixed.2d.language_programming.3a_.overview.asp
148 */
149 # undef WINDOWS_F77_FUNC
150 # if defined(__GNUC__)
151 # define WINDOWS_F77_FUNC(a, A) __attribute__((stdcall)) A
152 # elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
153 # define WINDOWS_F77_FUNC(a, A) __stdcall A
154 # else
155 # define WINDOWS_F77_FUNC(a, A) A /* oh well */
156 # endif
157 # include "f77funcs.h"
158
159 #endif /* WINDOWS_F77_MANGLING */
160
161 #endif /* F77_FUNC */