fftw3.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * Copyright (c) 2003, 2007-14 Matteo Frigo
  3. * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
  4. *
  5. * The following statement of license applies *only* to this header file,
  6. * and *not* to the other files distributed with FFTW or derived therefrom:
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  20. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  25. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /***************************** NOTE TO USERS *********************************
  32. *
  33. * THIS IS A HEADER FILE, NOT A MANUAL
  34. *
  35. * If you want to know how to use FFTW, please read the manual,
  36. * online at http://www.fftw.org/doc/ and also included with FFTW.
  37. * For a quick start, see the manual's tutorial section.
  38. *
  39. * (Reading header files to learn how to use a library is a habit
  40. * stemming from code lacking a proper manual. Arguably, it's a
  41. * *bad* habit in most cases, because header files can contain
  42. * interfaces that are not part of the public, stable API.)
  43. *
  44. ****************************************************************************/
  45. #ifndef FFTW3_H
  46. #define FFTW3_H
  47. #include <stdio.h>
  48. #ifdef __cplusplus
  49. extern "C"
  50. {
  51. #endif /* __cplusplus */
  52. /* If <complex.h> is included, use the C99 complex type. Otherwise
  53. define a type bit-compatible with C99 complex */
  54. #if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I)
  55. # define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C
  56. #else
  57. # define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2]
  58. #endif
  59. #define FFTW_CONCAT(prefix, name) prefix ## name
  60. #define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name)
  61. #define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name)
  62. #define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name)
  63. #define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name)
  64. /* IMPORTANT: for Windows compilers, you should add a line
  65. #define FFTW_DLL
  66. here and in kernel/ifftw.h if you are compiling/using FFTW as a
  67. DLL, in order to do the proper importing/exporting, or
  68. alternatively compile with -DFFTW_DLL or the equivalent
  69. command-line flag. This is not necessary under MinGW/Cygwin, where
  70. libtool does the imports/exports automatically. */
  71. #if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__))
  72. /* annoying Windows syntax for shared-library declarations */
  73. # if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */
  74. # define FFTW_EXTERN extern __declspec(dllexport)
  75. # else /* user is calling FFTW; import symbol */
  76. # define FFTW_EXTERN extern __declspec(dllimport)
  77. # endif
  78. #else
  79. # define FFTW_EXTERN extern
  80. #endif
  81. enum fftw_r2r_kind_do_not_use_me {
  82. FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2,
  83. FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6,
  84. FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10
  85. };
  86. struct fftw_iodim_do_not_use_me {
  87. int n; /* dimension size */
  88. int is; /* input stride */
  89. int os; /* output stride */
  90. };
  91. #include <stddef.h> /* for ptrdiff_t */
  92. struct fftw_iodim64_do_not_use_me {
  93. ptrdiff_t n; /* dimension size */
  94. ptrdiff_t is; /* input stride */
  95. ptrdiff_t os; /* output stride */
  96. };
  97. typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *);
  98. typedef int (*fftw_read_char_func_do_not_use_me)(void *);
  99. /*
  100. huge second-order macro that defines prototypes for all API
  101. functions. We expand this macro for each supported precision
  102. X: name-mangling macro
  103. R: real data type
  104. C: complex data type
  105. */
  106. #define FFTW_DEFINE_API(X, R, C) \
  107. \
  108. FFTW_DEFINE_COMPLEX(R, C); \
  109. \
  110. typedef struct X(plan_s) *X(plan); \
  111. \
  112. typedef struct fftw_iodim_do_not_use_me X(iodim); \
  113. typedef struct fftw_iodim64_do_not_use_me X(iodim64); \
  114. \
  115. typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \
  116. \
  117. typedef fftw_write_char_func_do_not_use_me X(write_char_func); \
  118. typedef fftw_read_char_func_do_not_use_me X(read_char_func); \
  119. \
  120. FFTW_EXTERN void X(execute)(const X(plan) p); \
  121. \
  122. FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \
  123. C *in, C *out, int sign, unsigned flags); \
  124. \
  125. FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \
  126. unsigned flags); \
  127. FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \
  128. C *in, C *out, int sign, unsigned flags); \
  129. FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \
  130. C *in, C *out, int sign, unsigned flags); \
  131. \
  132. FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \
  133. int howmany, \
  134. C *in, const int *inembed, \
  135. int istride, int idist, \
  136. C *out, const int *onembed, \
  137. int ostride, int odist, \
  138. int sign, unsigned flags); \
  139. \
  140. FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \
  141. int howmany_rank, \
  142. const X(iodim) *howmany_dims, \
  143. C *in, C *out, \
  144. int sign, unsigned flags); \
  145. FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \
  146. int howmany_rank, \
  147. const X(iodim) *howmany_dims, \
  148. R *ri, R *ii, R *ro, R *io, \
  149. unsigned flags); \
  150. \
  151. FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \
  152. const X(iodim64) *dims, \
  153. int howmany_rank, \
  154. const X(iodim64) *howmany_dims, \
  155. C *in, C *out, \
  156. int sign, unsigned flags); \
  157. FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \
  158. const X(iodim64) *dims, \
  159. int howmany_rank, \
  160. const X(iodim64) *howmany_dims, \
  161. R *ri, R *ii, R *ro, R *io, \
  162. unsigned flags); \
  163. \
  164. FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \
  165. FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \
  166. R *ro, R *io); \
  167. \
  168. FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \
  169. int howmany, \
  170. R *in, const int *inembed, \
  171. int istride, int idist, \
  172. C *out, const int *onembed, \
  173. int ostride, int odist, \
  174. unsigned flags); \
  175. \
  176. FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \
  177. R *in, C *out, unsigned flags); \
  178. \
  179. FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \
  180. FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \
  181. R *in, C *out, unsigned flags); \
  182. FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \
  183. int n2, \
  184. R *in, C *out, unsigned flags); \
  185. \
  186. \
  187. FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \
  188. int howmany, \
  189. C *in, const int *inembed, \
  190. int istride, int idist, \
  191. R *out, const int *onembed, \
  192. int ostride, int odist, \
  193. unsigned flags); \
  194. \
  195. FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \
  196. C *in, R *out, unsigned flags); \
  197. \
  198. FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \
  199. FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \
  200. C *in, R *out, unsigned flags); \
  201. FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \
  202. int n2, \
  203. C *in, R *out, unsigned flags); \
  204. \
  205. FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \
  206. int howmany_rank, \
  207. const X(iodim) *howmany_dims, \
  208. R *in, C *out, \
  209. unsigned flags); \
  210. FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \
  211. int howmany_rank, \
  212. const X(iodim) *howmany_dims, \
  213. C *in, R *out, \
  214. unsigned flags); \
  215. \
  216. FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \
  217. int rank, const X(iodim) *dims, \
  218. int howmany_rank, \
  219. const X(iodim) *howmany_dims, \
  220. R *in, R *ro, R *io, \
  221. unsigned flags); \
  222. FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \
  223. int rank, const X(iodim) *dims, \
  224. int howmany_rank, \
  225. const X(iodim) *howmany_dims, \
  226. R *ri, R *ii, R *out, \
  227. unsigned flags); \
  228. \
  229. FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \
  230. const X(iodim64) *dims, \
  231. int howmany_rank, \
  232. const X(iodim64) *howmany_dims, \
  233. R *in, C *out, \
  234. unsigned flags); \
  235. FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \
  236. const X(iodim64) *dims, \
  237. int howmany_rank, \
  238. const X(iodim64) *howmany_dims, \
  239. C *in, R *out, \
  240. unsigned flags); \
  241. \
  242. FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \
  243. int rank, const X(iodim64) *dims, \
  244. int howmany_rank, \
  245. const X(iodim64) *howmany_dims, \
  246. R *in, R *ro, R *io, \
  247. unsigned flags); \
  248. FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \
  249. int rank, const X(iodim64) *dims, \
  250. int howmany_rank, \
  251. const X(iodim64) *howmany_dims, \
  252. R *ri, R *ii, R *out, \
  253. unsigned flags); \
  254. \
  255. FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \
  256. FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \
  257. \
  258. FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \
  259. R *in, R *ro, R *io); \
  260. FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \
  261. R *ri, R *ii, R *out); \
  262. \
  263. FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \
  264. int howmany, \
  265. R *in, const int *inembed, \
  266. int istride, int idist, \
  267. R *out, const int *onembed, \
  268. int ostride, int odist, \
  269. const X(r2r_kind) *kind, unsigned flags); \
  270. \
  271. FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \
  272. const X(r2r_kind) *kind, unsigned flags); \
  273. \
  274. FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \
  275. X(r2r_kind) kind, unsigned flags); \
  276. FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \
  277. X(r2r_kind) kind0, X(r2r_kind) kind1, \
  278. unsigned flags); \
  279. FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \
  280. R *in, R *out, X(r2r_kind) kind0, \
  281. X(r2r_kind) kind1, X(r2r_kind) kind2, \
  282. unsigned flags); \
  283. \
  284. FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \
  285. int howmany_rank, \
  286. const X(iodim) *howmany_dims, \
  287. R *in, R *out, \
  288. const X(r2r_kind) *kind, unsigned flags); \
  289. \
  290. FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \
  291. int howmany_rank, \
  292. const X(iodim64) *howmany_dims, \
  293. R *in, R *out, \
  294. const X(r2r_kind) *kind, unsigned flags); \
  295. \
  296. FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \
  297. \
  298. FFTW_EXTERN void X(destroy_plan)(X(plan) p); \
  299. FFTW_EXTERN void X(forget_wisdom)(void); \
  300. FFTW_EXTERN void X(cleanup)(void); \
  301. \
  302. FFTW_EXTERN void X(set_timelimit)(double t); \
  303. \
  304. FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \
  305. FFTW_EXTERN int X(init_threads)(void); \
  306. FFTW_EXTERN void X(cleanup_threads)(void); \
  307. \
  308. FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \
  309. FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \
  310. FFTW_EXTERN char *X(export_wisdom_to_string)(void); \
  311. FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \
  312. void *data); \
  313. FFTW_EXTERN int X(import_system_wisdom)(void); \
  314. FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \
  315. FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \
  316. FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \
  317. FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \
  318. \
  319. FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \
  320. FFTW_EXTERN void X(print_plan)(const X(plan) p); \
  321. FFTW_EXTERN char *X(sprint_plan)(const X(plan) p); \
  322. \
  323. FFTW_EXTERN void *X(malloc)(size_t n); \
  324. FFTW_EXTERN R *X(alloc_real)(size_t n); \
  325. FFTW_EXTERN C *X(alloc_complex)(size_t n); \
  326. FFTW_EXTERN void X(free)(void *p); \
  327. \
  328. FFTW_EXTERN void X(flops)(const X(plan) p, \
  329. double *add, double *mul, double *fmas); \
  330. FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \
  331. FFTW_EXTERN double X(cost)(const X(plan) p); \
  332. \
  333. FFTW_EXTERN int X(alignment_of)(R *p); \
  334. FFTW_EXTERN const char X(version)[]; \
  335. FFTW_EXTERN const char X(cc)[]; \
  336. FFTW_EXTERN const char X(codelet_optim)[];
  337. /* end of FFTW_DEFINE_API macro */
  338. FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex)
  339. FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex)
  340. FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex)
  341. /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64
  342. for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */
  343. #if defined(__GNUC__)
  344. # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \
  345. && !(defined(__ICC) || defined(__INTEL_COMPILER)) \
  346. && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__))
  347. # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I)
  348. /* note: __float128 is a typedef, which is not supported with the _Complex
  349. keyword in gcc, so instead we use this ugly __attribute__ version.
  350. However, we can't simply pass the __attribute__ version to
  351. FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer
  352. types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */
  353. # undef FFTW_DEFINE_COMPLEX
  354. # define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C
  355. # endif
  356. FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex)
  357. # endif
  358. #endif
  359. #define FFTW_FORWARD (-1)
  360. #define FFTW_BACKWARD (+1)
  361. #define FFTW_NO_TIMELIMIT (-1.0)
  362. /* documented flags */
  363. #define FFTW_MEASURE (0U)
  364. #define FFTW_DESTROY_INPUT (1U << 0)
  365. #define FFTW_UNALIGNED (1U << 1)
  366. #define FFTW_CONSERVE_MEMORY (1U << 2)
  367. #define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */
  368. #define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */
  369. #define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */
  370. #define FFTW_ESTIMATE (1U << 6)
  371. #define FFTW_WISDOM_ONLY (1U << 21)
  372. /* undocumented beyond-guru flags */
  373. #define FFTW_ESTIMATE_PATIENT (1U << 7)
  374. #define FFTW_BELIEVE_PCOST (1U << 8)
  375. #define FFTW_NO_DFT_R2HC (1U << 9)
  376. #define FFTW_NO_NONTHREADED (1U << 10)
  377. #define FFTW_NO_BUFFERING (1U << 11)
  378. #define FFTW_NO_INDIRECT_OP (1U << 12)
  379. #define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */
  380. #define FFTW_NO_RANK_SPLITS (1U << 14)
  381. #define FFTW_NO_VRANK_SPLITS (1U << 15)
  382. #define FFTW_NO_VRECURSE (1U << 16)
  383. #define FFTW_NO_SIMD (1U << 17)
  384. #define FFTW_NO_SLOW (1U << 18)
  385. #define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19)
  386. #define FFTW_ALLOW_PRUNING (1U << 20)
  387. #ifdef __cplusplus
  388. } /* extern "C" */
  389. #endif /* __cplusplus */
  390. #endif /* FFTW3_H */