fftw3.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. */
  66. #define FFTW_DLL
  67. /*
  68. here and in kernel/ifftw.h if you are compiling/using FFTW as a
  69. DLL, in order to do the proper importing/exporting, or
  70. alternatively compile with -DFFTW_DLL or the equivalent
  71. command-line flag. This is not necessary under MinGW/Cygwin, where
  72. libtool does the imports/exports automatically. */
  73. #if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__))
  74. /* annoying Windows syntax for shared-library declarations */
  75. # if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */
  76. # define FFTW_EXTERN extern __declspec(dllexport)
  77. # else /* user is calling FFTW; import symbol */
  78. # define FFTW_EXTERN extern __declspec(dllimport)
  79. # endif
  80. #else
  81. # define FFTW_EXTERN extern
  82. #endif
  83. enum fftw_r2r_kind_do_not_use_me {
  84. FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2,
  85. FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6,
  86. FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10
  87. };
  88. struct fftw_iodim_do_not_use_me {
  89. int n; /* dimension size */
  90. int is; /* input stride */
  91. int os; /* output stride */
  92. };
  93. #include <stddef.h> /* for ptrdiff_t */
  94. struct fftw_iodim64_do_not_use_me {
  95. ptrdiff_t n; /* dimension size */
  96. ptrdiff_t is; /* input stride */
  97. ptrdiff_t os; /* output stride */
  98. };
  99. typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *);
  100. typedef int (*fftw_read_char_func_do_not_use_me)(void *);
  101. /*
  102. huge second-order macro that defines prototypes for all API
  103. functions. We expand this macro for each supported precision
  104. X: name-mangling macro
  105. R: real data type
  106. C: complex data type
  107. */
  108. #define FFTW_DEFINE_API(X, R, C) \
  109. \
  110. FFTW_DEFINE_COMPLEX(R, C); \
  111. \
  112. typedef struct X(plan_s) *X(plan); \
  113. \
  114. typedef struct fftw_iodim_do_not_use_me X(iodim); \
  115. typedef struct fftw_iodim64_do_not_use_me X(iodim64); \
  116. \
  117. typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \
  118. \
  119. typedef fftw_write_char_func_do_not_use_me X(write_char_func); \
  120. typedef fftw_read_char_func_do_not_use_me X(read_char_func); \
  121. \
  122. FFTW_EXTERN void X(execute)(const X(plan) p); \
  123. \
  124. FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \
  125. C *in, C *out, int sign, unsigned flags); \
  126. \
  127. FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \
  128. unsigned flags); \
  129. FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \
  130. C *in, C *out, int sign, unsigned flags); \
  131. FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \
  132. C *in, C *out, int sign, unsigned flags); \
  133. \
  134. FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \
  135. int howmany, \
  136. C *in, const int *inembed, \
  137. int istride, int idist, \
  138. C *out, const int *onembed, \
  139. int ostride, int odist, \
  140. int sign, unsigned flags); \
  141. \
  142. FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \
  143. int howmany_rank, \
  144. const X(iodim) *howmany_dims, \
  145. C *in, C *out, \
  146. int sign, unsigned flags); \
  147. FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \
  148. int howmany_rank, \
  149. const X(iodim) *howmany_dims, \
  150. R *ri, R *ii, R *ro, R *io, \
  151. unsigned flags); \
  152. \
  153. FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \
  154. const X(iodim64) *dims, \
  155. int howmany_rank, \
  156. const X(iodim64) *howmany_dims, \
  157. C *in, C *out, \
  158. int sign, unsigned flags); \
  159. FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \
  160. const X(iodim64) *dims, \
  161. int howmany_rank, \
  162. const X(iodim64) *howmany_dims, \
  163. R *ri, R *ii, R *ro, R *io, \
  164. unsigned flags); \
  165. \
  166. FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \
  167. FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \
  168. R *ro, R *io); \
  169. \
  170. FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \
  171. int howmany, \
  172. R *in, const int *inembed, \
  173. int istride, int idist, \
  174. C *out, const int *onembed, \
  175. int ostride, int odist, \
  176. unsigned flags); \
  177. \
  178. FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \
  179. R *in, C *out, unsigned flags); \
  180. \
  181. FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \
  182. FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \
  183. R *in, C *out, unsigned flags); \
  184. FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \
  185. int n2, \
  186. R *in, C *out, unsigned flags); \
  187. \
  188. \
  189. FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \
  190. int howmany, \
  191. C *in, const int *inembed, \
  192. int istride, int idist, \
  193. R *out, const int *onembed, \
  194. int ostride, int odist, \
  195. unsigned flags); \
  196. \
  197. FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \
  198. C *in, R *out, unsigned flags); \
  199. \
  200. FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \
  201. FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \
  202. C *in, R *out, unsigned flags); \
  203. FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \
  204. int n2, \
  205. C *in, R *out, unsigned flags); \
  206. \
  207. FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \
  208. int howmany_rank, \
  209. const X(iodim) *howmany_dims, \
  210. R *in, C *out, \
  211. unsigned flags); \
  212. FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \
  213. int howmany_rank, \
  214. const X(iodim) *howmany_dims, \
  215. C *in, R *out, \
  216. unsigned flags); \
  217. \
  218. FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \
  219. int rank, const X(iodim) *dims, \
  220. int howmany_rank, \
  221. const X(iodim) *howmany_dims, \
  222. R *in, R *ro, R *io, \
  223. unsigned flags); \
  224. FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \
  225. int rank, const X(iodim) *dims, \
  226. int howmany_rank, \
  227. const X(iodim) *howmany_dims, \
  228. R *ri, R *ii, R *out, \
  229. unsigned flags); \
  230. \
  231. FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \
  232. const X(iodim64) *dims, \
  233. int howmany_rank, \
  234. const X(iodim64) *howmany_dims, \
  235. R *in, C *out, \
  236. unsigned flags); \
  237. FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \
  238. const X(iodim64) *dims, \
  239. int howmany_rank, \
  240. const X(iodim64) *howmany_dims, \
  241. C *in, R *out, \
  242. unsigned flags); \
  243. \
  244. FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \
  245. int rank, const X(iodim64) *dims, \
  246. int howmany_rank, \
  247. const X(iodim64) *howmany_dims, \
  248. R *in, R *ro, R *io, \
  249. unsigned flags); \
  250. FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \
  251. int rank, const X(iodim64) *dims, \
  252. int howmany_rank, \
  253. const X(iodim64) *howmany_dims, \
  254. R *ri, R *ii, R *out, \
  255. unsigned flags); \
  256. \
  257. FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \
  258. FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \
  259. \
  260. FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \
  261. R *in, R *ro, R *io); \
  262. FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \
  263. R *ri, R *ii, R *out); \
  264. \
  265. FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \
  266. int howmany, \
  267. R *in, const int *inembed, \
  268. int istride, int idist, \
  269. R *out, const int *onembed, \
  270. int ostride, int odist, \
  271. const X(r2r_kind) *kind, unsigned flags); \
  272. \
  273. FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \
  274. const X(r2r_kind) *kind, unsigned flags); \
  275. \
  276. FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \
  277. X(r2r_kind) kind, unsigned flags); \
  278. FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \
  279. X(r2r_kind) kind0, X(r2r_kind) kind1, \
  280. unsigned flags); \
  281. FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \
  282. R *in, R *out, X(r2r_kind) kind0, \
  283. X(r2r_kind) kind1, X(r2r_kind) kind2, \
  284. unsigned flags); \
  285. \
  286. FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \
  287. int howmany_rank, \
  288. const X(iodim) *howmany_dims, \
  289. R *in, R *out, \
  290. const X(r2r_kind) *kind, unsigned flags); \
  291. \
  292. FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \
  293. int howmany_rank, \
  294. const X(iodim64) *howmany_dims, \
  295. R *in, R *out, \
  296. const X(r2r_kind) *kind, unsigned flags); \
  297. \
  298. FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \
  299. \
  300. FFTW_EXTERN void X(destroy_plan)(X(plan) p); \
  301. FFTW_EXTERN void X(forget_wisdom)(void); \
  302. FFTW_EXTERN void X(cleanup)(void); \
  303. \
  304. FFTW_EXTERN void X(set_timelimit)(double t); \
  305. \
  306. FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \
  307. FFTW_EXTERN int X(init_threads)(void); \
  308. FFTW_EXTERN void X(cleanup_threads)(void); \
  309. FFTW_EXTERN void X(make_planner_thread_safe)(void); \
  310. \
  311. FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \
  312. FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \
  313. FFTW_EXTERN char *X(export_wisdom_to_string)(void); \
  314. FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \
  315. void *data); \
  316. FFTW_EXTERN int X(import_system_wisdom)(void); \
  317. FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \
  318. FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \
  319. FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \
  320. FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \
  321. \
  322. FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \
  323. FFTW_EXTERN void X(print_plan)(const X(plan) p); \
  324. FFTW_EXTERN char *X(sprint_plan)(const X(plan) p); \
  325. \
  326. FFTW_EXTERN void *X(malloc)(size_t n); \
  327. FFTW_EXTERN R *X(alloc_real)(size_t n); \
  328. FFTW_EXTERN C *X(alloc_complex)(size_t n); \
  329. FFTW_EXTERN void X(free)(void *p); \
  330. \
  331. FFTW_EXTERN void X(flops)(const X(plan) p, \
  332. double *add, double *mul, double *fmas); \
  333. FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \
  334. FFTW_EXTERN double X(cost)(const X(plan) p); \
  335. \
  336. FFTW_EXTERN int X(alignment_of)(R *p); \
  337. FFTW_EXTERN const char X(version)[]; \
  338. FFTW_EXTERN const char X(cc)[]; \
  339. FFTW_EXTERN const char X(codelet_optim)[];
  340. /* end of FFTW_DEFINE_API macro */
  341. FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex)
  342. FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex)
  343. FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex)
  344. /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64
  345. for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */
  346. #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \
  347. && !(defined(__ICC) || defined(__INTEL_COMPILER) || defined(__CUDACC__) || defined(__PGI)) \
  348. && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__))
  349. # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I)
  350. /* note: __float128 is a typedef, which is not supported with the _Complex
  351. keyword in gcc, so instead we use this ugly __attribute__ version.
  352. However, we can't simply pass the __attribute__ version to
  353. FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer
  354. types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */
  355. # undef FFTW_DEFINE_COMPLEX
  356. # define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C
  357. # endif
  358. FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex)
  359. #endif
  360. #define FFTW_FORWARD (-1)
  361. #define FFTW_BACKWARD (+1)
  362. #define FFTW_NO_TIMELIMIT (-1.0)
  363. /* documented flags */
  364. #define FFTW_MEASURE (0U)
  365. #define FFTW_DESTROY_INPUT (1U << 0)
  366. #define FFTW_UNALIGNED (1U << 1)
  367. #define FFTW_CONSERVE_MEMORY (1U << 2)
  368. #define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */
  369. #define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */
  370. #define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */
  371. #define FFTW_ESTIMATE (1U << 6)
  372. #define FFTW_WISDOM_ONLY (1U << 21)
  373. /* undocumented beyond-guru flags */
  374. #define FFTW_ESTIMATE_PATIENT (1U << 7)
  375. #define FFTW_BELIEVE_PCOST (1U << 8)
  376. #define FFTW_NO_DFT_R2HC (1U << 9)
  377. #define FFTW_NO_NONTHREADED (1U << 10)
  378. #define FFTW_NO_BUFFERING (1U << 11)
  379. #define FFTW_NO_INDIRECT_OP (1U << 12)
  380. #define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */
  381. #define FFTW_NO_RANK_SPLITS (1U << 14)
  382. #define FFTW_NO_VRANK_SPLITS (1U << 15)
  383. #define FFTW_NO_VRECURSE (1U << 16)
  384. #define FFTW_NO_SIMD (1U << 17)
  385. #define FFTW_NO_SLOW (1U << 18)
  386. #define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19)
  387. #define FFTW_ALLOW_PRUNING (1U << 20)
  388. #ifdef __cplusplus
  389. } /* extern "C" */
  390. #endif /* __cplusplus */
  391. #endif /* FFTW3_H */