annotate src/fftw-3.3.8/api/f77api.c @ 83:ae30d91d2ffe

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