annotate fft/fftw/fftw-3.3.4/api/f77api.c @ 40:223f770b5341 kissfft-double tip

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