Chris@10: /* Chris@10: * Copyright (c) 2003, 2007-11 Matteo Frigo Chris@10: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology Chris@10: * Chris@10: * This program is free software; you can redistribute it and/or modify Chris@10: * it under the terms of the GNU General Public License as published by Chris@10: * the Free Software Foundation; either version 2 of the License, or Chris@10: * (at your option) any later version. Chris@10: * Chris@10: * This program is distributed in the hope that it will be useful, Chris@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@10: * GNU General Public License for more details. Chris@10: * Chris@10: * You should have received a copy of the GNU General Public License Chris@10: * along with this program; if not, write to the Free Software Chris@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@10: * Chris@10: */ Chris@10: Chris@10: Chris@10: /* FFTW internal header file */ Chris@10: #ifndef __IFFTW_H__ Chris@10: #define __IFFTW_H__ Chris@10: Chris@10: #include "config.h" Chris@10: Chris@10: #include /* size_t */ Chris@10: #include /* va_list */ Chris@10: #include /* ptrdiff_t */ Chris@10: Chris@10: #if HAVE_SYS_TYPES_H Chris@10: # include Chris@10: #endif Chris@10: Chris@10: #if HAVE_STDINT_H Chris@10: # include /* uintptr_t, maybe */ Chris@10: #endif Chris@10: Chris@10: #if HAVE_INTTYPES_H Chris@10: # include /* uintptr_t, maybe */ Chris@10: #endif Chris@10: Chris@10: #ifdef __cplusplus Chris@10: extern "C" Chris@10: { Chris@10: #endif /* __cplusplus */ Chris@10: Chris@10: /* Windows annoyances -- since tests/hook.c uses some internal Chris@10: FFTW functions, we need to given them the dllexport attribute Chris@10: under Windows when compiling as a DLL (see api/fftw3.h). */ Chris@10: #if defined(FFTW_EXTERN) Chris@10: # define IFFTW_EXTERN FFTW_EXTERN Chris@10: #elif (defined(FFTW_DLL) || defined(DLL_EXPORT)) \ Chris@10: && (defined(_WIN32) || defined(__WIN32__)) Chris@10: # define IFFTW_EXTERN extern __declspec(dllexport) Chris@10: #else Chris@10: # define IFFTW_EXTERN extern Chris@10: #endif Chris@10: Chris@10: /* determine precision and name-mangling scheme */ Chris@10: #define CONCAT(prefix, name) prefix ## name Chris@10: #if defined(FFTW_SINGLE) Chris@10: typedef float R; Chris@10: # define X(name) CONCAT(fftwf_, name) Chris@10: #elif defined(FFTW_LDOUBLE) Chris@10: typedef long double R; Chris@10: # define X(name) CONCAT(fftwl_, name) Chris@10: # define TRIGREAL_IS_LONG_DOUBLE Chris@10: #elif defined(FFTW_QUAD) Chris@10: typedef __float128 R; Chris@10: # define X(name) CONCAT(fftwq_, name) Chris@10: # define TRIGREAL_IS_QUAD Chris@10: #else Chris@10: typedef double R; Chris@10: # define X(name) CONCAT(fftw_, name) Chris@10: #endif Chris@10: Chris@10: /* Chris@10: integral type large enough to contain a stride (what ``int'' should Chris@10: have been in the first place. Chris@10: */ Chris@10: typedef ptrdiff_t INT; Chris@10: Chris@10: /* dummy use of unused parameters to silence compiler warnings */ Chris@10: #define UNUSED(x) (void)x Chris@10: Chris@10: #define NELEM(array) ((int) (sizeof(array) / sizeof((array)[0]))) Chris@10: Chris@10: #define FFT_SIGN (-1) /* sign convention for forward transforms */ Chris@10: extern void X(extract_reim)(int sign, R *c, R **r, R **i); Chris@10: Chris@10: #define REGISTER_SOLVER(p, s) X(solver_register)(p, s) Chris@10: Chris@10: #define STRINGIZEx(x) #x Chris@10: #define STRINGIZE(x) STRINGIZEx(x) Chris@10: #define CIMPLIES(ante, post) (!(ante) || (post)) Chris@10: Chris@10: /* define HAVE_SIMD if any simd extensions are supported */ Chris@10: #if defined(HAVE_SSE) || defined(HAVE_SSE2) || defined(HAVE_ALTIVEC) || \ Chris@10: defined(HAVE_MIPS_PS) || defined(HAVE_AVX) Chris@10: #define HAVE_SIMD 1 Chris@10: #else Chris@10: #define HAVE_SIMD 0 Chris@10: #endif Chris@10: Chris@10: extern int X(have_simd_sse2)(void); Chris@10: extern int X(have_simd_avx)(void); Chris@10: extern int X(have_simd_altivec)(void); Chris@10: extern int X(have_simd_neon)(void); Chris@10: Chris@10: /* forward declarations */ Chris@10: typedef struct problem_s problem; Chris@10: typedef struct plan_s plan; Chris@10: typedef struct solver_s solver; Chris@10: typedef struct planner_s planner; Chris@10: typedef struct printer_s printer; Chris@10: typedef struct scanner_s scanner; Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* alloca: */ Chris@10: #if HAVE_SIMD Chris@10: # ifdef HAVE_AVX Chris@10: # define MIN_ALIGNMENT 32 /* best alignment for AVX, conservative for Chris@10: * everything else */ Chris@10: # else Chris@10: /* Note that we cannot use 32-byte alignment for all SIMD. For Chris@10: example, MacOS X malloc is 16-byte aligned, but there was no Chris@10: posix_memalign in MacOS X until version 10.6. */ Chris@10: # define MIN_ALIGNMENT 16 Chris@10: # endif Chris@10: #endif Chris@10: Chris@10: #if defined(HAVE_ALLOCA) && defined(FFTW_ENABLE_ALLOCA) Chris@10: /* use alloca if available */ Chris@10: Chris@10: #ifndef alloca Chris@10: #ifdef __GNUC__ Chris@10: # define alloca __builtin_alloca Chris@10: #else Chris@10: # ifdef _MSC_VER Chris@10: # include Chris@10: # define alloca _alloca Chris@10: # else Chris@10: # if HAVE_ALLOCA_H Chris@10: # include Chris@10: # else Chris@10: # ifdef _AIX Chris@10: #pragma alloca Chris@10: # else Chris@10: # ifndef alloca /* predefined by HP cc +Olibcalls */ Chris@10: void *alloca(size_t); Chris@10: # endif Chris@10: # endif Chris@10: # endif Chris@10: # endif Chris@10: #endif Chris@10: #endif Chris@10: Chris@10: # ifdef MIN_ALIGNMENT Chris@10: # define STACK_MALLOC(T, p, n) \ Chris@10: { \ Chris@10: p = (T)alloca((n) + MIN_ALIGNMENT); \ Chris@10: p = (T)(((uintptr_t)p + (MIN_ALIGNMENT - 1)) & \ Chris@10: (~(uintptr_t)(MIN_ALIGNMENT - 1))); \ Chris@10: } Chris@10: # define STACK_FREE(n) Chris@10: # else /* HAVE_ALLOCA && !defined(MIN_ALIGNMENT) */ Chris@10: # define STACK_MALLOC(T, p, n) p = (T)alloca(n) Chris@10: # define STACK_FREE(n) Chris@10: # endif Chris@10: Chris@10: #else /* ! HAVE_ALLOCA */ Chris@10: /* use malloc instead of alloca */ Chris@10: # define STACK_MALLOC(T, p, n) p = (T)MALLOC(n, OTHER) Chris@10: # define STACK_FREE(n) X(ifree)(n) Chris@10: #endif /* ! HAVE_ALLOCA */ Chris@10: Chris@10: /* allocation of buffers. If these grow too large use malloc(), else Chris@10: use STACK_MALLOC (hopefully reducing to alloca()). */ Chris@10: Chris@10: /* 64KiB ought to be enough for anybody */ Chris@10: #define MAX_STACK_ALLOC ((size_t)64 * 1024) Chris@10: Chris@10: #define BUF_ALLOC(T, p, n) \ Chris@10: { \ Chris@10: if (n < MAX_STACK_ALLOC) { \ Chris@10: STACK_MALLOC(T, p, n); \ Chris@10: } else { \ Chris@10: p = (T)MALLOC(n, BUFFERS); \ Chris@10: } \ Chris@10: } Chris@10: Chris@10: #define BUF_FREE(p, n) \ Chris@10: { \ Chris@10: if (n < MAX_STACK_ALLOC) { \ Chris@10: STACK_FREE(p); \ Chris@10: } else { \ Chris@10: X(ifree)(p); \ Chris@10: } \ Chris@10: } Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* define uintptr_t if it is not already defined */ Chris@10: Chris@10: #ifndef HAVE_UINTPTR_T Chris@10: # if SIZEOF_VOID_P == 0 Chris@10: # error sizeof void* is unknown! Chris@10: # elif SIZEOF_UNSIGNED_INT == SIZEOF_VOID_P Chris@10: typedef unsigned int uintptr_t; Chris@10: # elif SIZEOF_UNSIGNED_LONG == SIZEOF_VOID_P Chris@10: typedef unsigned long uintptr_t; Chris@10: # elif SIZEOF_UNSIGNED_LONG_LONG == SIZEOF_VOID_P Chris@10: typedef unsigned long long uintptr_t; Chris@10: # else Chris@10: # error no unsigned integer type matches void* sizeof! Chris@10: # endif Chris@10: #endif Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* We can do an optimization for copying pairs of (aligned) floats Chris@10: when in single precision if 2*float = double. */ Chris@10: Chris@10: #define FFTW_2R_IS_DOUBLE (defined(FFTW_SINGLE) \ Chris@10: && SIZEOF_FLOAT != 0 \ Chris@10: && SIZEOF_DOUBLE == 2*SIZEOF_FLOAT) Chris@10: Chris@10: #define DOUBLE_ALIGNED(p) ((((uintptr_t)(p)) % sizeof(double)) == 0) Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* assert.c: */ Chris@10: IFFTW_EXTERN void X(assertion_failed)(const char *s, Chris@10: int line, const char *file); Chris@10: Chris@10: /* always check */ Chris@10: #define CK(ex) \ Chris@10: (void)((ex) || (X(assertion_failed)(#ex, __LINE__, __FILE__), 0)) Chris@10: Chris@10: #ifdef FFTW_DEBUG Chris@10: /* check only if debug enabled */ Chris@10: #define A(ex) \ Chris@10: (void)((ex) || (X(assertion_failed)(#ex, __LINE__, __FILE__), 0)) Chris@10: #else Chris@10: #define A(ex) /* nothing */ Chris@10: #endif Chris@10: Chris@10: extern void X(debug)(const char *format, ...); Chris@10: #define D X(debug) Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* kalloc.c: */ Chris@10: extern void *X(kernel_malloc)(size_t n); Chris@10: extern void X(kernel_free)(void *p); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* alloc.c: */ Chris@10: Chris@10: /* objects allocated by malloc, for statistical purposes */ Chris@10: enum malloc_tag { Chris@10: EVERYTHING, Chris@10: PLANS, Chris@10: SOLVERS, Chris@10: PROBLEMS, Chris@10: BUFFERS, Chris@10: HASHT, Chris@10: TENSORS, Chris@10: PLANNERS, Chris@10: SLVDESCS, Chris@10: TWIDDLES, Chris@10: STRIDES, Chris@10: OTHER, Chris@10: MALLOC_WHAT_LAST /* must be last */ Chris@10: }; Chris@10: Chris@10: IFFTW_EXTERN void X(ifree)(void *ptr); Chris@10: extern void X(ifree0)(void *ptr); Chris@10: Chris@10: #ifdef FFTW_DEBUG_MALLOC Chris@10: Chris@10: IFFTW_EXTERN void *X(malloc_debug)(size_t n, enum malloc_tag what, Chris@10: const char *file, int line); Chris@10: #define MALLOC(n, what) X(malloc_debug)(n, what, __FILE__, __LINE__) Chris@10: IFFTW_EXTERN void X(malloc_print_minfo)(int vrbose); Chris@10: Chris@10: #else /* ! FFTW_DEBUG_MALLOC */ Chris@10: Chris@10: IFFTW_EXTERN void *X(malloc_plain)(size_t sz); Chris@10: #define MALLOC(n, what) X(malloc_plain)(n) Chris@10: Chris@10: #endif Chris@10: Chris@10: #if defined(FFTW_DEBUG) && defined(FFTW_DEBUG_MALLOC) && (defined(HAVE_THREADS) || defined(HAVE_OPENMP)) Chris@10: extern int X(in_thread); Chris@10: # define IN_THREAD X(in_thread) Chris@10: # define THREAD_ON { int in_thread_save = X(in_thread); X(in_thread) = 1 Chris@10: # define THREAD_OFF X(in_thread) = in_thread_save; } Chris@10: #else Chris@10: # define IN_THREAD 0 Chris@10: # define THREAD_ON Chris@10: # define THREAD_OFF Chris@10: #endif Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* low-resolution clock */ Chris@10: Chris@10: #ifdef FAKE_CRUDE_TIME Chris@10: typedef int crude_time; Chris@10: #else Chris@10: # if TIME_WITH_SYS_TIME Chris@10: # include Chris@10: # include Chris@10: # else Chris@10: # if HAVE_SYS_TIME_H Chris@10: # include Chris@10: # else Chris@10: # include Chris@10: # endif Chris@10: # endif Chris@10: Chris@10: # ifdef HAVE_BSDGETTIMEOFDAY Chris@10: # ifndef HAVE_GETTIMEOFDAY Chris@10: # define gettimeofday BSDgettimeofday Chris@10: # define HAVE_GETTIMEOFDAY 1 Chris@10: # endif Chris@10: # endif Chris@10: Chris@10: # if defined(HAVE_GETTIMEOFDAY) Chris@10: typedef struct timeval crude_time; Chris@10: # else Chris@10: typedef clock_t crude_time; Chris@10: # endif Chris@10: #endif /* else FAKE_CRUDE_TIME */ Chris@10: Chris@10: crude_time X(get_crude_time)(void); Chris@10: double X(elapsed_since)(const planner *plnr, const problem *p, Chris@10: crude_time t0); /* time in seconds since t0 */ Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* ops.c: */ Chris@10: /* Chris@10: * ops counter. The total number of additions is add + fma Chris@10: * and the total number of multiplications is mul + fma. Chris@10: * Total flops = add + mul + 2 * fma Chris@10: */ Chris@10: typedef struct { Chris@10: double add; Chris@10: double mul; Chris@10: double fma; Chris@10: double other; Chris@10: } opcnt; Chris@10: Chris@10: void X(ops_zero)(opcnt *dst); Chris@10: void X(ops_other)(INT o, opcnt *dst); Chris@10: void X(ops_cpy)(const opcnt *src, opcnt *dst); Chris@10: Chris@10: void X(ops_add)(const opcnt *a, const opcnt *b, opcnt *dst); Chris@10: void X(ops_add2)(const opcnt *a, opcnt *dst); Chris@10: Chris@10: /* dst = m * a + b */ Chris@10: void X(ops_madd)(INT m, const opcnt *a, const opcnt *b, opcnt *dst); Chris@10: Chris@10: /* dst += m * a */ Chris@10: void X(ops_madd2)(INT m, const opcnt *a, opcnt *dst); Chris@10: Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* minmax.c: */ Chris@10: INT X(imax)(INT a, INT b); Chris@10: INT X(imin)(INT a, INT b); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* iabs.c: */ Chris@10: INT X(iabs)(INT a); Chris@10: Chris@10: /* inline version */ Chris@10: #define IABS(x) (((x) < 0) ? (0 - (x)) : (x)) Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* md5.c */ Chris@10: Chris@10: #if SIZEOF_UNSIGNED_INT >= 4 Chris@10: typedef unsigned int md5uint; Chris@10: #else Chris@10: typedef unsigned long md5uint; /* at least 32 bits as per C standard */ Chris@10: #endif Chris@10: Chris@10: typedef md5uint md5sig[4]; Chris@10: Chris@10: typedef struct { Chris@10: md5sig s; /* state and signature */ Chris@10: Chris@10: /* fields not meant to be used outside md5.c: */ Chris@10: unsigned char c[64]; /* stuff not yet processed */ Chris@10: unsigned l; /* total length. Should be 64 bits long, but this is Chris@10: good enough for us */ Chris@10: } md5; Chris@10: Chris@10: void X(md5begin)(md5 *p); Chris@10: void X(md5putb)(md5 *p, const void *d_, size_t len); Chris@10: void X(md5puts)(md5 *p, const char *s); Chris@10: void X(md5putc)(md5 *p, unsigned char c); Chris@10: void X(md5int)(md5 *p, int i); Chris@10: void X(md5INT)(md5 *p, INT i); Chris@10: void X(md5unsigned)(md5 *p, unsigned i); Chris@10: void X(md5end)(md5 *p); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* tensor.c: */ Chris@10: #define STRUCT_HACK_KR Chris@10: #undef STRUCT_HACK_C99 Chris@10: Chris@10: typedef struct { Chris@10: INT n; Chris@10: INT is; /* input stride */ Chris@10: INT os; /* output stride */ Chris@10: } iodim; Chris@10: Chris@10: typedef struct { Chris@10: int rnk; Chris@10: #if defined(STRUCT_HACK_KR) Chris@10: iodim dims[1]; Chris@10: #elif defined(STRUCT_HACK_C99) Chris@10: iodim dims[]; Chris@10: #else Chris@10: iodim *dims; Chris@10: #endif Chris@10: } tensor; Chris@10: Chris@10: /* Chris@10: Definition of rank -infinity. Chris@10: This definition has the property that if you want rank 0 or 1, Chris@10: you can simply test for rank <= 1. This is a common case. Chris@10: Chris@10: A tensor of rank -infinity has size 0. Chris@10: */ Chris@10: #define RNK_MINFTY ((int)(((unsigned) -1) >> 1)) Chris@10: #define FINITE_RNK(rnk) ((rnk) != RNK_MINFTY) Chris@10: Chris@10: typedef enum { INPLACE_IS, INPLACE_OS } inplace_kind; Chris@10: Chris@10: tensor *X(mktensor)(int rnk); Chris@10: tensor *X(mktensor_0d)(void); Chris@10: tensor *X(mktensor_1d)(INT n, INT is, INT os); Chris@10: tensor *X(mktensor_2d)(INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1); Chris@10: tensor *X(mktensor_3d)(INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT n2, INT is2, INT os2); Chris@10: tensor *X(mktensor_4d)(INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT n2, INT is2, INT os2, Chris@10: INT n3, INT is3, INT os3); Chris@10: tensor *X(mktensor_5d)(INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT n2, INT is2, INT os2, Chris@10: INT n3, INT is3, INT os3, Chris@10: INT n4, INT is4, INT os4); Chris@10: INT X(tensor_sz)(const tensor *sz); Chris@10: void X(tensor_md5)(md5 *p, const tensor *t); Chris@10: INT X(tensor_max_index)(const tensor *sz); Chris@10: INT X(tensor_min_istride)(const tensor *sz); Chris@10: INT X(tensor_min_ostride)(const tensor *sz); Chris@10: INT X(tensor_min_stride)(const tensor *sz); Chris@10: int X(tensor_inplace_strides)(const tensor *sz); Chris@10: int X(tensor_inplace_strides2)(const tensor *a, const tensor *b); Chris@10: int X(tensor_strides_decrease)(const tensor *sz, const tensor *vecsz, Chris@10: inplace_kind k); Chris@10: tensor *X(tensor_copy)(const tensor *sz); Chris@10: int X(tensor_kosherp)(const tensor *x); Chris@10: Chris@10: tensor *X(tensor_copy_inplace)(const tensor *sz, inplace_kind k); Chris@10: tensor *X(tensor_copy_except)(const tensor *sz, int except_dim); Chris@10: tensor *X(tensor_copy_sub)(const tensor *sz, int start_dim, int rnk); Chris@10: tensor *X(tensor_compress)(const tensor *sz); Chris@10: tensor *X(tensor_compress_contiguous)(const tensor *sz); Chris@10: tensor *X(tensor_append)(const tensor *a, const tensor *b); Chris@10: void X(tensor_split)(const tensor *sz, tensor **a, int a_rnk, tensor **b); Chris@10: int X(tensor_tornk1)(const tensor *t, INT *n, INT *is, INT *os); Chris@10: void X(tensor_destroy)(tensor *sz); Chris@10: void X(tensor_destroy2)(tensor *a, tensor *b); Chris@10: void X(tensor_destroy4)(tensor *a, tensor *b, tensor *c, tensor *d); Chris@10: void X(tensor_print)(const tensor *sz, printer *p); Chris@10: int X(dimcmp)(const iodim *a, const iodim *b); Chris@10: int X(tensor_equal)(const tensor *a, const tensor *b); Chris@10: int X(tensor_inplace_locations)(const tensor *sz, const tensor *vecsz); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* problem.c: */ Chris@10: enum { Chris@10: /* a problem that cannot be solved */ Chris@10: PROBLEM_UNSOLVABLE, Chris@10: Chris@10: PROBLEM_DFT, Chris@10: PROBLEM_RDFT, Chris@10: PROBLEM_RDFT2, Chris@10: Chris@10: /* for mpi/ subdirectory */ Chris@10: PROBLEM_MPI_DFT, Chris@10: PROBLEM_MPI_RDFT, Chris@10: PROBLEM_MPI_RDFT2, Chris@10: PROBLEM_MPI_TRANSPOSE, Chris@10: Chris@10: PROBLEM_LAST Chris@10: }; Chris@10: Chris@10: typedef struct { Chris@10: int problem_kind; Chris@10: void (*hash) (const problem *ego, md5 *p); Chris@10: void (*zero) (const problem *ego); Chris@10: void (*print) (const problem *ego, printer *p); Chris@10: void (*destroy) (problem *ego); Chris@10: } problem_adt; Chris@10: Chris@10: struct problem_s { Chris@10: const problem_adt *adt; Chris@10: }; Chris@10: Chris@10: problem *X(mkproblem)(size_t sz, const problem_adt *adt); Chris@10: void X(problem_destroy)(problem *ego); Chris@10: problem *X(mkproblem_unsolvable)(void); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* print.c */ Chris@10: struct printer_s { Chris@10: void (*print)(printer *p, const char *format, ...); Chris@10: void (*vprint)(printer *p, const char *format, va_list ap); Chris@10: void (*putchr)(printer *p, char c); Chris@10: void (*cleanup)(printer *p); Chris@10: int indent; Chris@10: int indent_incr; Chris@10: }; Chris@10: Chris@10: printer *X(mkprinter)(size_t size, Chris@10: void (*putchr)(printer *p, char c), Chris@10: void (*cleanup)(printer *p)); Chris@10: IFFTW_EXTERN void X(printer_destroy)(printer *p); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* scan.c */ Chris@10: struct scanner_s { Chris@10: int (*scan)(scanner *sc, const char *format, ...); Chris@10: int (*vscan)(scanner *sc, const char *format, va_list ap); Chris@10: int (*getchr)(scanner *sc); Chris@10: int ungotc; Chris@10: }; Chris@10: Chris@10: scanner *X(mkscanner)(size_t size, int (*getchr)(scanner *sc)); Chris@10: void X(scanner_destroy)(scanner *sc); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* plan.c: */ Chris@10: Chris@10: enum wakefulness { Chris@10: SLEEPY, Chris@10: AWAKE_ZERO, Chris@10: AWAKE_SQRTN_TABLE, Chris@10: AWAKE_SINCOS Chris@10: }; Chris@10: Chris@10: typedef struct { Chris@10: void (*solve)(const plan *ego, const problem *p); Chris@10: void (*awake)(plan *ego, enum wakefulness wakefulness); Chris@10: void (*print)(const plan *ego, printer *p); Chris@10: void (*destroy)(plan *ego); Chris@10: } plan_adt; Chris@10: Chris@10: struct plan_s { Chris@10: const plan_adt *adt; Chris@10: opcnt ops; Chris@10: double pcost; Chris@10: enum wakefulness wakefulness; /* used for debugging only */ Chris@10: int could_prune_now_p; Chris@10: }; Chris@10: Chris@10: plan *X(mkplan)(size_t size, const plan_adt *adt); Chris@10: void X(plan_destroy_internal)(plan *ego); Chris@10: IFFTW_EXTERN void X(plan_awake)(plan *ego, enum wakefulness wakefulness); Chris@10: void X(plan_null_destroy)(plan *ego); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* solver.c: */ Chris@10: typedef struct { Chris@10: int problem_kind; Chris@10: plan *(*mkplan)(const solver *ego, const problem *p, planner *plnr); Chris@10: void (*destroy)(solver *ego); Chris@10: } solver_adt; Chris@10: Chris@10: struct solver_s { Chris@10: const solver_adt *adt; Chris@10: int refcnt; Chris@10: }; Chris@10: Chris@10: solver *X(mksolver)(size_t size, const solver_adt *adt); Chris@10: void X(solver_use)(solver *ego); Chris@10: void X(solver_destroy)(solver *ego); Chris@10: void X(solver_register)(planner *plnr, solver *s); Chris@10: Chris@10: /* shorthand */ Chris@10: #define MKSOLVER(type, adt) (type *)X(mksolver)(sizeof(type), adt) Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* planner.c */ Chris@10: Chris@10: typedef struct slvdesc_s { Chris@10: solver *slv; Chris@10: const char *reg_nam; Chris@10: unsigned nam_hash; Chris@10: int reg_id; Chris@10: int next_for_same_problem_kind; Chris@10: } slvdesc; Chris@10: Chris@10: typedef struct solution_s solution; /* opaque */ Chris@10: Chris@10: /* interpretation of L and U: Chris@10: Chris@10: - if it returns a plan, the planner guarantees that all applicable Chris@10: plans at least as impatient as U have been tried, and that each Chris@10: plan in the solution is at least as impatient as L. Chris@10: Chris@10: - if it returns 0, the planner guarantees to have tried all solvers Chris@10: at least as impatient as L, and that none of them was applicable. Chris@10: Chris@10: The structure is packed to fit into 64 bits. Chris@10: */ Chris@10: Chris@10: typedef struct { Chris@10: unsigned l:20; Chris@10: unsigned hash_info:3; Chris@10: # define BITS_FOR_TIMELIMIT 9 Chris@10: unsigned timelimit_impatience:BITS_FOR_TIMELIMIT; Chris@10: unsigned u:20; Chris@10: Chris@10: /* abstraction break: we store the solver here to pad the Chris@10: structure to 64 bits. Otherwise, the struct is padded to 64 Chris@10: bits anyway, and another word is allocated for slvndx. */ Chris@10: # define BITS_FOR_SLVNDX 12 Chris@10: unsigned slvndx:BITS_FOR_SLVNDX; Chris@10: } flags_t; Chris@10: Chris@10: /* impatience flags */ Chris@10: enum { Chris@10: BELIEVE_PCOST = 0x0001, Chris@10: ESTIMATE = 0x0002, Chris@10: NO_DFT_R2HC = 0x0004, Chris@10: NO_SLOW = 0x0008, Chris@10: NO_VRECURSE = 0x0010, Chris@10: NO_INDIRECT_OP = 0x0020, Chris@10: NO_LARGE_GENERIC = 0x0040, Chris@10: NO_RANK_SPLITS = 0x0080, Chris@10: NO_VRANK_SPLITS = 0x0100, Chris@10: NO_NONTHREADED = 0x0200, Chris@10: NO_BUFFERING = 0x0400, Chris@10: NO_FIXED_RADIX_LARGE_N = 0x0800, Chris@10: NO_DESTROY_INPUT = 0x1000, Chris@10: NO_SIMD = 0x2000, Chris@10: CONSERVE_MEMORY = 0x4000, Chris@10: NO_DHT_R2HC = 0x8000, Chris@10: NO_UGLY = 0x10000, Chris@10: ALLOW_PRUNING = 0x20000 Chris@10: }; Chris@10: Chris@10: /* hashtable information */ Chris@10: enum { Chris@10: BLESSING = 0x1, /* save this entry */ Chris@10: H_VALID = 0x2, /* valid hastable entry */ Chris@10: H_LIVE = 0x4 /* entry is nonempty, implies H_VALID */ Chris@10: }; Chris@10: Chris@10: #define PLNR_L(plnr) ((plnr)->flags.l) Chris@10: #define PLNR_U(plnr) ((plnr)->flags.u) Chris@10: #define PLNR_TIMELIMIT_IMPATIENCE(plnr) ((plnr)->flags.timelimit_impatience) Chris@10: Chris@10: #define ESTIMATEP(plnr) (PLNR_U(plnr) & ESTIMATE) Chris@10: #define BELIEVE_PCOSTP(plnr) (PLNR_U(plnr) & BELIEVE_PCOST) Chris@10: #define ALLOW_PRUNINGP(plnr) (PLNR_U(plnr) & ALLOW_PRUNING) Chris@10: Chris@10: #define NO_INDIRECT_OP_P(plnr) (PLNR_L(plnr) & NO_INDIRECT_OP) Chris@10: #define NO_LARGE_GENERICP(plnr) (PLNR_L(plnr) & NO_LARGE_GENERIC) Chris@10: #define NO_RANK_SPLITSP(plnr) (PLNR_L(plnr) & NO_RANK_SPLITS) Chris@10: #define NO_VRANK_SPLITSP(plnr) (PLNR_L(plnr) & NO_VRANK_SPLITS) Chris@10: #define NO_VRECURSEP(plnr) (PLNR_L(plnr) & NO_VRECURSE) Chris@10: #define NO_DFT_R2HCP(plnr) (PLNR_L(plnr) & NO_DFT_R2HC) Chris@10: #define NO_SLOWP(plnr) (PLNR_L(plnr) & NO_SLOW) Chris@10: #define NO_UGLYP(plnr) (PLNR_L(plnr) & NO_UGLY) Chris@10: #define NO_FIXED_RADIX_LARGE_NP(plnr) \ Chris@10: (PLNR_L(plnr) & NO_FIXED_RADIX_LARGE_N) Chris@10: #define NO_NONTHREADEDP(plnr) \ Chris@10: ((PLNR_L(plnr) & NO_NONTHREADED) && (plnr)->nthr > 1) Chris@10: Chris@10: #define NO_DESTROY_INPUTP(plnr) (PLNR_L(plnr) & NO_DESTROY_INPUT) Chris@10: #define NO_SIMDP(plnr) (PLNR_L(plnr) & NO_SIMD) Chris@10: #define CONSERVE_MEMORYP(plnr) (PLNR_L(plnr) & CONSERVE_MEMORY) Chris@10: #define NO_DHT_R2HCP(plnr) (PLNR_L(plnr) & NO_DHT_R2HC) Chris@10: #define NO_BUFFERINGP(plnr) (PLNR_L(plnr) & NO_BUFFERING) Chris@10: Chris@10: typedef enum { FORGET_ACCURSED, FORGET_EVERYTHING } amnesia; Chris@10: Chris@10: typedef enum { Chris@10: /* WISDOM_NORMAL: planner may or may not use wisdom */ Chris@10: WISDOM_NORMAL, Chris@10: Chris@10: /* WISDOM_ONLY: planner must use wisdom and must avoid searching */ Chris@10: WISDOM_ONLY, Chris@10: Chris@10: /* WISDOM_IS_BOGUS: planner must return 0 as quickly as possible */ Chris@10: WISDOM_IS_BOGUS, Chris@10: Chris@10: /* WISDOM_IGNORE_INFEASIBLE: planner ignores infeasible wisdom */ Chris@10: WISDOM_IGNORE_INFEASIBLE, Chris@10: Chris@10: /* WISDOM_IGNORE_ALL: planner ignores all */ Chris@10: WISDOM_IGNORE_ALL Chris@10: } wisdom_state_t; Chris@10: Chris@10: typedef struct { Chris@10: void (*register_solver)(planner *ego, solver *s); Chris@10: plan *(*mkplan)(planner *ego, const problem *p); Chris@10: void (*forget)(planner *ego, amnesia a); Chris@10: void (*exprt)(planner *ego, printer *p); /* ``export'' is a reserved Chris@10: word in C++. */ Chris@10: int (*imprt)(planner *ego, scanner *sc); Chris@10: } planner_adt; Chris@10: Chris@10: /* hash table of solutions */ Chris@10: typedef struct { Chris@10: solution *solutions; Chris@10: unsigned hashsiz, nelem; Chris@10: Chris@10: /* statistics */ Chris@10: int lookup, succ_lookup, lookup_iter; Chris@10: int insert, insert_iter, insert_unknown; Chris@10: int nrehash; Chris@10: } hashtab; Chris@10: Chris@10: typedef enum { COST_SUM, COST_MAX } cost_kind; Chris@10: Chris@10: struct planner_s { Chris@10: const planner_adt *adt; Chris@10: void (*hook)(struct planner_s *plnr, plan *pln, Chris@10: const problem *p, int optimalp); Chris@10: double (*cost_hook)(const problem *p, double t, cost_kind k); Chris@10: int (*wisdom_ok_hook)(const problem *p, flags_t flags); Chris@10: void (*nowisdom_hook)(const problem *p); Chris@10: wisdom_state_t (*bogosity_hook)(wisdom_state_t state, const problem *p); Chris@10: Chris@10: /* solver descriptors */ Chris@10: slvdesc *slvdescs; Chris@10: unsigned nslvdesc, slvdescsiz; Chris@10: const char *cur_reg_nam; Chris@10: int cur_reg_id; Chris@10: int slvdescs_for_problem_kind[PROBLEM_LAST]; Chris@10: Chris@10: wisdom_state_t wisdom_state; Chris@10: Chris@10: hashtab htab_blessed; Chris@10: hashtab htab_unblessed; Chris@10: Chris@10: int nthr; Chris@10: flags_t flags; Chris@10: Chris@10: crude_time start_time; Chris@10: double timelimit; /* elapsed_since(start_time) at which to bail out */ Chris@10: int timed_out; /* whether most recent search timed out */ Chris@10: int need_timeout_check; Chris@10: Chris@10: /* various statistics */ Chris@10: int nplan; /* number of plans evaluated */ Chris@10: double pcost, epcost; /* total pcost of measured/estimated plans */ Chris@10: int nprob; /* number of problems evaluated */ Chris@10: }; Chris@10: Chris@10: planner *X(mkplanner)(void); Chris@10: void X(planner_destroy)(planner *ego); Chris@10: Chris@10: /* Chris@10: Iterate over all solvers. Read: Chris@10: Chris@10: @article{ baker93iterators, Chris@10: author = "Henry G. Baker, Jr.", Chris@10: title = "Iterators: Signs of Weakness in Object-Oriented Languages", Chris@10: journal = "{ACM} {OOPS} Messenger", Chris@10: volume = "4", Chris@10: number = "3", Chris@10: pages = "18--25" Chris@10: } Chris@10: */ Chris@10: #define FORALL_SOLVERS(ego, s, p, what) \ Chris@10: { \ Chris@10: unsigned _cnt; \ Chris@10: for (_cnt = 0; _cnt < ego->nslvdesc; ++_cnt) { \ Chris@10: slvdesc *p = ego->slvdescs + _cnt; \ Chris@10: solver *s = p->slv; \ Chris@10: what; \ Chris@10: } \ Chris@10: } Chris@10: Chris@10: #define FORALL_SOLVERS_OF_KIND(kind, ego, s, p, what) \ Chris@10: { \ Chris@10: int _cnt = ego->slvdescs_for_problem_kind[kind]; \ Chris@10: while (_cnt >= 0) { \ Chris@10: slvdesc *p = ego->slvdescs + _cnt; \ Chris@10: solver *s = p->slv; \ Chris@10: what; \ Chris@10: _cnt = p->next_for_same_problem_kind; \ Chris@10: } \ Chris@10: } Chris@10: Chris@10: Chris@10: /* make plan, destroy problem */ Chris@10: plan *X(mkplan_d)(planner *ego, problem *p); Chris@10: plan *X(mkplan_f_d)(planner *ego, problem *p, Chris@10: unsigned l_set, unsigned u_set, unsigned u_reset); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* stride.c: */ Chris@10: Chris@10: /* If PRECOMPUTE_ARRAY_INDICES is defined, precompute all strides. */ Chris@10: #if (defined(__i386__) || defined(__x86_64__) || _M_IX86 >= 500) && !defined(FFTW_LDOUBLE) Chris@10: #define PRECOMPUTE_ARRAY_INDICES Chris@10: #endif Chris@10: Chris@10: extern const INT X(an_INT_guaranteed_to_be_zero); Chris@10: Chris@10: #ifdef PRECOMPUTE_ARRAY_INDICES Chris@10: typedef INT *stride; Chris@10: #define WS(stride, i) (stride[i]) Chris@10: extern stride X(mkstride)(INT n, INT s); Chris@10: void X(stride_destroy)(stride p); Chris@10: /* hackery to prevent the compiler from copying the strides array Chris@10: onto the stack */ Chris@10: #define MAKE_VOLATILE_STRIDE(nptr, x) (x) = (x) + X(an_INT_guaranteed_to_be_zero) Chris@10: #else Chris@10: Chris@10: typedef INT stride; Chris@10: #define WS(stride, i) (stride * i) Chris@10: #define fftwf_mkstride(n, stride) stride Chris@10: #define fftw_mkstride(n, stride) stride Chris@10: #define fftwl_mkstride(n, stride) stride Chris@10: #define fftwf_stride_destroy(p) ((void) p) Chris@10: #define fftw_stride_destroy(p) ((void) p) Chris@10: #define fftwl_stride_destroy(p) ((void) p) Chris@10: Chris@10: /* hackery to prevent the compiler from ``optimizing'' induction Chris@10: variables in codelet loops. The problem is that for each K and for Chris@10: each expression of the form P[I + STRIDE * K] in a loop, most Chris@10: compilers will try to lift an induction variable PK := &P[I + STRIDE * K]. Chris@10: For large values of K this behavior overflows the Chris@10: register set, which is likely worse than doing the index computation Chris@10: in the first place. Chris@10: Chris@10: If we guess that there are more than Chris@10: ESTIMATED_AVAILABLE_INDEX_REGISTERS such pointers, we deliberately confuse Chris@10: the compiler by setting STRIDE ^= ZERO, where ZERO is a value guaranteed to Chris@10: be 0, but the compiler does not know this. Chris@10: Chris@10: 16 registers ought to be enough for anybody, or so the amd64 and ARM ISA's Chris@10: seem to imply. Chris@10: */ Chris@10: #define ESTIMATED_AVAILABLE_INDEX_REGISTERS 16 Chris@10: #define MAKE_VOLATILE_STRIDE(nptr, x) \ Chris@10: (nptr <= ESTIMATED_AVAILABLE_INDEX_REGISTERS ? \ Chris@10: 0 : \ Chris@10: ((x) = (x) ^ X(an_INT_guaranteed_to_be_zero))) Chris@10: #endif /* PRECOMPUTE_ARRAY_INDICES */ Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* solvtab.c */ Chris@10: Chris@10: struct solvtab_s { void (*reg)(planner *); const char *reg_nam; }; Chris@10: typedef struct solvtab_s solvtab[]; Chris@10: void X(solvtab_exec)(const solvtab tbl, planner *p); Chris@10: #define SOLVTAB(s) { s, STRINGIZE(s) } Chris@10: #define SOLVTAB_END { 0, 0 } Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* pickdim.c */ Chris@10: int X(pickdim)(int which_dim, const int *buddies, int nbuddies, Chris@10: const tensor *sz, int oop, int *dp); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* twiddle.c */ Chris@10: /* little language to express twiddle factors computation */ Chris@10: enum { TW_COS = 0, TW_SIN = 1, TW_CEXP = 2, TW_NEXT = 3, Chris@10: TW_FULL = 4, TW_HALF = 5 }; Chris@10: Chris@10: typedef struct { Chris@10: unsigned char op; Chris@10: signed char v; Chris@10: short i; Chris@10: } tw_instr; Chris@10: Chris@10: typedef struct twid_s { Chris@10: R *W; /* array of twiddle factors */ Chris@10: INT n, r, m; /* transform order, radix, # twiddle rows */ Chris@10: int refcnt; Chris@10: const tw_instr *instr; Chris@10: struct twid_s *cdr; Chris@10: enum wakefulness wakefulness; Chris@10: } twid; Chris@10: Chris@10: INT X(twiddle_length)(INT r, const tw_instr *p); Chris@10: void X(twiddle_awake)(enum wakefulness wakefulness, Chris@10: twid **pp, const tw_instr *instr, INT n, INT r, INT m); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* trig.c */ Chris@10: #if defined(TRIGREAL_IS_LONG_DOUBLE) Chris@10: typedef long double trigreal; Chris@10: #elif defined(TRIGREAL_IS_QUAD) Chris@10: typedef __float128 trigreal; Chris@10: #else Chris@10: typedef double trigreal; Chris@10: #endif Chris@10: Chris@10: typedef struct triggen_s triggen; Chris@10: Chris@10: struct triggen_s { Chris@10: void (*cexp)(triggen *t, INT m, R *result); Chris@10: void (*cexpl)(triggen *t, INT m, trigreal *result); Chris@10: void (*rotate)(triggen *p, INT m, R xr, R xi, R *res); Chris@10: Chris@10: INT twshft; Chris@10: INT twradix; Chris@10: INT twmsk; Chris@10: trigreal *W0, *W1; Chris@10: INT n; Chris@10: }; Chris@10: Chris@10: triggen *X(mktriggen)(enum wakefulness wakefulness, INT n); Chris@10: void X(triggen_destroy)(triggen *p); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* primes.c: */ Chris@10: Chris@10: #define MULMOD(x, y, p) \ Chris@10: (((x) <= 92681 - (y)) ? ((x) * (y)) % (p) : X(safe_mulmod)(x, y, p)) Chris@10: Chris@10: INT X(safe_mulmod)(INT x, INT y, INT p); Chris@10: INT X(power_mod)(INT n, INT m, INT p); Chris@10: INT X(find_generator)(INT p); Chris@10: INT X(first_divisor)(INT n); Chris@10: int X(is_prime)(INT n); Chris@10: INT X(next_prime)(INT n); Chris@10: int X(factors_into)(INT n, const INT *primes); Chris@10: int X(factors_into_small_primes)(INT n); Chris@10: INT X(choose_radix)(INT r, INT n); Chris@10: INT X(isqrt)(INT n); Chris@10: INT X(modulo)(INT a, INT n); Chris@10: Chris@10: #define GENERIC_MIN_BAD 173 /* min prime for which generic becomes bad */ Chris@10: Chris@10: /* thresholds below which certain solvers are considered SLOW. These are guesses Chris@10: believed to be conservative */ Chris@10: #define GENERIC_MAX_SLOW 16 Chris@10: #define RADER_MAX_SLOW 32 Chris@10: #define BLUESTEIN_MAX_SLOW 24 Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* rader.c: */ Chris@10: typedef struct rader_tls rader_tl; Chris@10: Chris@10: void X(rader_tl_insert)(INT k1, INT k2, INT k3, R *W, rader_tl **tl); Chris@10: R *X(rader_tl_find)(INT k1, INT k2, INT k3, rader_tl *t); Chris@10: void X(rader_tl_delete)(R *W, rader_tl **tl); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* copy/transposition routines */ Chris@10: Chris@10: /* lower bound to the cache size, for tiled routines */ Chris@10: #define CACHESIZE 8192 Chris@10: Chris@10: INT X(compute_tilesz)(INT vl, int how_many_tiles_in_cache); Chris@10: Chris@10: void X(tile2d)(INT n0l, INT n0u, INT n1l, INT n1u, INT tilesz, Chris@10: void (*f)(INT n0l, INT n0u, INT n1l, INT n1u, void *args), Chris@10: void *args); Chris@10: void X(cpy1d)(R *I, R *O, INT n0, INT is0, INT os0, INT vl); Chris@10: void X(cpy2d)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: void X(cpy2d_ci)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: void X(cpy2d_co)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: void X(cpy2d_tiled)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: void X(cpy2d_tiledbuf)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: void X(cpy2d_pair)(R *I0, R *I1, R *O0, R *O1, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1); Chris@10: void X(cpy2d_pair_ci)(R *I0, R *I1, R *O0, R *O1, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1); Chris@10: void X(cpy2d_pair_co)(R *I0, R *I1, R *O0, R *O1, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1); Chris@10: Chris@10: void X(transpose)(R *I, INT n, INT s0, INT s1, INT vl); Chris@10: void X(transpose_tiled)(R *I, INT n, INT s0, INT s1, INT vl); Chris@10: void X(transpose_tiledbuf)(R *I, INT n, INT s0, INT s1, INT vl); Chris@10: Chris@10: typedef void (*transpose_func)(R *I, INT n, INT s0, INT s1, INT vl); Chris@10: typedef void (*cpy2d_func)(R *I, R *O, Chris@10: INT n0, INT is0, INT os0, Chris@10: INT n1, INT is1, INT os1, Chris@10: INT vl); Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* misc stuff */ Chris@10: void X(null_awake)(plan *ego, enum wakefulness wakefulness); Chris@10: double X(iestimate_cost)(const planner *, const plan *, const problem *); Chris@10: Chris@10: #ifdef FFTW_RANDOM_ESTIMATOR Chris@10: extern unsigned X(random_estimate_seed); Chris@10: #endif Chris@10: Chris@10: double X(measure_execution_time)(const planner *plnr, Chris@10: plan *pln, const problem *p); Chris@10: int X(alignment_of)(R *p); Chris@10: unsigned X(hash)(const char *s); Chris@10: INT X(nbuf)(INT n, INT vl, INT maxnbuf); Chris@10: int X(nbuf_redundant)(INT n, INT vl, int which, Chris@10: const INT *maxnbuf, int nmaxnbuf); Chris@10: INT X(bufdist)(INT n, INT vl); Chris@10: int X(toobig)(INT n); Chris@10: int X(ct_uglyp)(INT min_n, INT v, INT n, INT r); Chris@10: Chris@10: #if HAVE_SIMD Chris@10: R *X(taint)(R *p, INT s); Chris@10: R *X(join_taint)(R *p1, R *p2); Chris@10: #define TAINT(p, s) X(taint)(p, s) Chris@10: #define UNTAINT(p) ((R *) (((uintptr_t) (p)) & ~(uintptr_t)3)) Chris@10: #define TAINTOF(p) (((uintptr_t)(p)) & 3) Chris@10: #define JOIN_TAINT(p1, p2) X(join_taint)(p1, p2) Chris@10: #else Chris@10: #define TAINT(p, s) (p) Chris@10: #define UNTAINT(p) (p) Chris@10: #define TAINTOF(p) 0 Chris@10: #define JOIN_TAINT(p1, p2) p1 Chris@10: #endif Chris@10: Chris@10: #ifdef FFTW_DEBUG_ALIGNMENT Chris@10: # define ASSERT_ALIGNED_DOUBLE { \ Chris@10: double __foo; \ Chris@10: CK(!(((uintptr_t) &__foo) & 0x7)); \ Chris@10: } Chris@10: #else Chris@10: # define ASSERT_ALIGNED_DOUBLE Chris@10: #endif /* FFTW_DEBUG_ALIGNMENT */ Chris@10: Chris@10: Chris@10: Chris@10: /*-----------------------------------------------------------------------*/ Chris@10: /* macros used in codelets to reduce source code size */ Chris@10: Chris@10: typedef R E; /* internal precision of codelets. */ Chris@10: Chris@10: #if defined(FFTW_LDOUBLE) Chris@10: # define K(x) ((E) x##L) Chris@10: #elif defined(FFTW_QUAD) Chris@10: # define K(x) ((E) x##Q) Chris@10: #else Chris@10: # define K(x) ((E) x) Chris@10: #endif Chris@10: #define DK(name, value) const E name = K(value) Chris@10: Chris@10: /* FMA macros */ Chris@10: Chris@10: #if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__) || defined(_POWER)) Chris@10: /* The obvious expression a * b + c does not work. If both x = a * b Chris@10: + c and y = a * b - c appear in the source, gcc computes t = a * b, Chris@10: x = t + c, y = t - c, thus destroying the fma. Chris@10: Chris@10: This peculiar coding seems to do the right thing on all of Chris@10: gcc-2.95, gcc-3.1, gcc-3.2, and gcc-3.3. It does the right thing Chris@10: on gcc-3.4 -fno-web (because the ``web'' pass splits the variable Chris@10: `x' for the single-assignment form). Chris@10: Chris@10: However, gcc-4.0 is a formidable adversary which succeeds in Chris@10: pessimizing two fma's into one multiplication and two additions. Chris@10: It does it very early in the game---before the optimization passes Chris@10: even start. The only real workaround seems to use fake inline asm Chris@10: such as Chris@10: Chris@10: asm ("# confuse gcc %0" : "=f"(a) : "0"(a)); Chris@10: return a * b + c; Chris@10: Chris@10: in each of the FMA, FMS, FNMA, and FNMS functions. However, this Chris@10: does not solve the problem either, because two equal asm statements Chris@10: count as a common subexpression! One must use *different* fake asm Chris@10: statements: Chris@10: Chris@10: in FMA: Chris@10: asm ("# confuse gcc for fma %0" : "=f"(a) : "0"(a)); Chris@10: Chris@10: in FMS: Chris@10: asm ("# confuse gcc for fms %0" : "=f"(a) : "0"(a)); Chris@10: Chris@10: etc. Chris@10: Chris@10: After these changes, gcc recalcitrantly generates the fma that was Chris@10: in the source to begin with. However, the extra asm() cruft Chris@10: confuses other passes of gcc, notably the instruction scheduler. Chris@10: (Of course, one could also generate the fma directly via inline Chris@10: asm, but this confuses the scheduler even more.) Chris@10: Chris@10: Steven and I have submitted more than one bug report to the gcc Chris@10: mailing list over the past few years, to no effect. Thus, I give Chris@10: up. gcc-4.0 can go to hell. I'll wait at least until gcc-4.3 is Chris@10: out before touching this crap again. Chris@10: */ Chris@10: static __inline__ E FMA(E a, E b, E c) Chris@10: { Chris@10: E x = a * b; Chris@10: x = x + c; Chris@10: return x; Chris@10: } Chris@10: Chris@10: static __inline__ E FMS(E a, E b, E c) Chris@10: { Chris@10: E x = a * b; Chris@10: x = x - c; Chris@10: return x; Chris@10: } Chris@10: Chris@10: static __inline__ E FNMA(E a, E b, E c) Chris@10: { Chris@10: E x = a * b; Chris@10: x = - (x + c); Chris@10: return x; Chris@10: } Chris@10: Chris@10: static __inline__ E FNMS(E a, E b, E c) Chris@10: { Chris@10: E x = a * b; Chris@10: x = - (x - c); Chris@10: return x; Chris@10: } Chris@10: #else Chris@10: #define FMA(a, b, c) (((a) * (b)) + (c)) Chris@10: #define FMS(a, b, c) (((a) * (b)) - (c)) Chris@10: #define FNMA(a, b, c) (- (((a) * (b)) + (c))) Chris@10: #define FNMS(a, b, c) ((c) - ((a) * (b))) Chris@10: #endif Chris@10: Chris@10: #ifdef __cplusplus Chris@10: } /* extern "C" */ Chris@10: #endif /* __cplusplus */ Chris@10: Chris@10: #endif /* __IFFTW_H__ */