annotate src/fftw-3.3.5/api/f77api.c @ 42:2cd0e3b3e1fd

Current fftw source
author Chris Cannam
date Tue, 18 Oct 2016 13:40:26 +0100
parents
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21 #include "api.h"
Chris@42 22 #include "dft.h"
Chris@42 23 #include "rdft.h"
Chris@42 24
Chris@42 25 #include "x77.h"
Chris@42 26
Chris@42 27 /* if F77_FUNC is not defined, then we don't know how to mangle identifiers
Chris@42 28 for the Fortran linker, and we must omit the f77 API. */
Chris@42 29 #if defined(F77_FUNC) || defined(WINDOWS_F77_MANGLING)
Chris@42 30
Chris@42 31 /*-----------------------------------------------------------------------*/
Chris@42 32 /* some internal functions used by the f77 api */
Chris@42 33
Chris@42 34 /* in fortran, the natural array ordering is column-major, which
Chris@42 35 corresponds to reversing the dimensions relative to C's row-major */
Chris@42 36 static int *reverse_n(int rnk, const int *n)
Chris@42 37 {
Chris@42 38 int *nrev;
Chris@42 39 int i;
Chris@42 40 A(FINITE_RNK(rnk));
Chris@42 41 nrev = (int *) MALLOC(sizeof(int) * (unsigned)rnk, PROBLEMS);
Chris@42 42 for (i = 0; i < rnk; ++i)
Chris@42 43 nrev[rnk - i - 1] = n[i];
Chris@42 44 return nrev;
Chris@42 45 }
Chris@42 46
Chris@42 47 /* f77 doesn't have data structures, so we have to pass iodims as
Chris@42 48 parallel arrays */
Chris@42 49 static X(iodim) *make_dims(int rnk, const int *n,
Chris@42 50 const int *is, const int *os)
Chris@42 51 {
Chris@42 52 X(iodim) *dims;
Chris@42 53 int i;
Chris@42 54 A(FINITE_RNK(rnk));
Chris@42 55 dims = (X(iodim) *) MALLOC(sizeof(X(iodim)) * (unsigned)rnk, PROBLEMS);
Chris@42 56 for (i = 0; i < rnk; ++i) {
Chris@42 57 dims[i].n = n[i];
Chris@42 58 dims[i].is = is[i];
Chris@42 59 dims[i].os = os[i];
Chris@42 60 }
Chris@42 61 return dims;
Chris@42 62 }
Chris@42 63
Chris@42 64 typedef struct {
Chris@42 65 void (*f77_write_char)(char *, void *);
Chris@42 66 void *data;
Chris@42 67 } write_char_data;
Chris@42 68
Chris@42 69 static void write_char(char c, void *d)
Chris@42 70 {
Chris@42 71 write_char_data *ad = (write_char_data *) d;
Chris@42 72 ad->f77_write_char(&c, ad->data);
Chris@42 73 }
Chris@42 74
Chris@42 75 typedef struct {
Chris@42 76 void (*f77_read_char)(int *, void *);
Chris@42 77 void *data;
Chris@42 78 } read_char_data;
Chris@42 79
Chris@42 80 static int read_char(void *d)
Chris@42 81 {
Chris@42 82 read_char_data *ed = (read_char_data *) d;
Chris@42 83 int c;
Chris@42 84 ed->f77_read_char(&c, ed->data);
Chris@42 85 return (c < 0 ? EOF : c);
Chris@42 86 }
Chris@42 87
Chris@42 88 static X(r2r_kind) *ints2kinds(int rnk, const int *ik)
Chris@42 89 {
Chris@42 90 if (!FINITE_RNK(rnk) || rnk == 0)
Chris@42 91 return 0;
Chris@42 92 else {
Chris@42 93 int i;
Chris@42 94 X(r2r_kind) *k;
Chris@42 95
Chris@42 96 k = (X(r2r_kind) *) MALLOC(sizeof(X(r2r_kind)) * (unsigned)rnk, PROBLEMS);
Chris@42 97 /* reverse order for Fortran -> C */
Chris@42 98 for (i = 0; i < rnk; ++i)
Chris@42 99 k[i] = (X(r2r_kind)) ik[rnk - 1 - i];
Chris@42 100 return k;
Chris@42 101 }
Chris@42 102 }
Chris@42 103
Chris@42 104 /*-----------------------------------------------------------------------*/
Chris@42 105
Chris@42 106 #define F77(a, A) F77x(x77(a), X77(A))
Chris@42 107
Chris@42 108 #ifndef WINDOWS_F77_MANGLING
Chris@42 109
Chris@42 110 #if defined(F77_FUNC)
Chris@42 111 # define F77x(a, A) F77_FUNC(a, A)
Chris@42 112 # include "f77funcs.h"
Chris@42 113 #endif
Chris@42 114
Chris@42 115 /* If identifiers with underscores are mangled differently than those
Chris@42 116 without underscores, then we include *both* mangling versions. The
Chris@42 117 reason is that the only Fortran compiler that does such differing
Chris@42 118 mangling is currently g77 (which adds an extra underscore to names
Chris@42 119 with underscores), whereas other compilers running on the same
Chris@42 120 machine are likely to use non-underscored mangling. (I'm sick
Chris@42 121 of users complaining that FFTW works with g77 but not with e.g.
Chris@42 122 pgf77 or ifc on the same machine.) Note that all FFTW identifiers
Chris@42 123 contain underscores, and configure picks g77 by default. */
Chris@42 124 #if defined(F77_FUNC_) && !defined(F77_FUNC_EQUIV)
Chris@42 125 # undef F77x
Chris@42 126 # define F77x(a, A) F77_FUNC_(a, A)
Chris@42 127 # include "f77funcs.h"
Chris@42 128 #endif
Chris@42 129
Chris@42 130 #else /* WINDOWS_F77_MANGLING */
Chris@42 131
Chris@42 132 /* Various mangling conventions common (?) under Windows. */
Chris@42 133
Chris@42 134 /* g77 */
Chris@42 135 # define WINDOWS_F77_FUNC(a, A) a ## __
Chris@42 136 # define F77x(a, A) WINDOWS_F77_FUNC(a, A)
Chris@42 137 # include "f77funcs.h"
Chris@42 138
Chris@42 139 /* Intel, etc. */
Chris@42 140 # undef WINDOWS_F77_FUNC
Chris@42 141 # define WINDOWS_F77_FUNC(a, A) a ## _
Chris@42 142 # include "f77funcs.h"
Chris@42 143
Chris@42 144 /* Digital/Compaq/HP Visual Fortran, Intel Fortran. stdcall attribute
Chris@42 145 is apparently required to adjust for calling conventions (callee
Chris@42 146 pops stack in stdcall). See also:
Chris@42 147 http://msdn.microsoft.com/library/en-us/vccore98/html/_core_mixed.2d.language_programming.3a_.overview.asp
Chris@42 148 */
Chris@42 149 # undef WINDOWS_F77_FUNC
Chris@42 150 # if defined(__GNUC__)
Chris@42 151 # define WINDOWS_F77_FUNC(a, A) __attribute__((stdcall)) A
Chris@42 152 # elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
Chris@42 153 # define WINDOWS_F77_FUNC(a, A) __stdcall A
Chris@42 154 # else
Chris@42 155 # define WINDOWS_F77_FUNC(a, A) A /* oh well */
Chris@42 156 # endif
Chris@42 157 # include "f77funcs.h"
Chris@42 158
Chris@42 159 #endif /* WINDOWS_F77_MANGLING */
Chris@42 160
Chris@42 161 #endif /* F77_FUNC */