1 module dfftw3.fftw3;
2 
3 import std.array;
4 public import std.complex;
5 
6 extern(C)
7 {
8 	enum fftw_r2r_kind_do_not_use_me
9 	{
10 		FFTW_R2HC=0,
11 		FFTW_HC2R=1,
12 		FFTW_DHT=2,
13 		FFTW_REDFT00=3,
14 		FFTW_REDFT01=4,
15 		FFTW_REDFT10=5,
16 		FFTW_REDFT11=6,
17 		FFTW_RODFT00=7,
18 		FFTW_RODFT01=8,
19 		FFTW_RODFT10=9,
20 		FFTW_RODFT11=10
21 	}
22 
23 	struct fftw_iodim_do_not_use_me
24 	{
25 		int n;
26 		int _is;
27 		int os;
28 	}
29 
30 	struct fftw_iodim64_do_not_use_me
31 	{
32 		ptrdiff_t n;
33 		ptrdiff_t _is;
34 		ptrdiff_t os;
35 	}
36 }
37 
38 alias fftw_write_char_func_do_not_use_me = extern (C) void function(char c, void *);
39 alias fftw_read_char_func_do_not_use_me = extern (C) int function(void *);
40 
41 private
42 {
43 	string createAlias(string prefix, string newIdent, string oldIdent)
44 	{
45 		return "alias " ~ prefix ~ newIdent ~ " = " ~ oldIdent ~ ";";
46 	}
47 
48 	string createFunction(string prefix, string funcName, string retType, string[] params)
49 	{
50 		return retType ~ " " ~ prefix ~ funcName ~ "(" ~ join(params, ", ") ~ ");";
51 	}
52 
53 	auto createApi(string prefix, string realType, string complexType)
54 	{
55 		string complexPtrType = complexType ~ " *";
56 		string realPtrType = realType ~ " *";
57 		string planType = prefix ~ "plan";
58 		string iodimPtrType = prefix ~ "iodim *";
59 		string iodim64PtrType = prefix ~ "iodim64 *";
60 
61 		return join([
62 			
63 			createAlias(prefix, "plan", "void *"),
64 			
65 			createAlias(prefix, "iodim", "fftw_iodim_do_not_use_me"),
66 			createAlias(prefix, "iodim64", "fftw_iodim64_do_not_use_me"),
67 			
68 			createAlias(prefix, "r2r_kind", "fftw_r2r_kind_do_not_use_me"),
69 			
70 			createAlias(prefix, "write_char_func", "fftw_write_char_func_do_not_use_me"),
71 			createAlias(prefix, "read_char_func", "fftw_read_char_func_do_not_use_me"),
72 			
73 			createFunction(prefix, "execute", "void", ["const " ~ planType]),
74 
75 			createFunction(prefix, "plan_dft", planType, [
76 				"int",
77 				"const int *",
78 				complexPtrType,
79 				complexPtrType,
80 				"int",
81 				"uint"
82 			]),
83 
84 			createFunction(prefix, "plan_dft_1d", planType, [
85 				"int",
86 				complexPtrType,
87 				complexPtrType,
88 				"int",
89 				"uint"
90 			]),
91 			createFunction(prefix, "plan_dft_2d", planType, [
92 				"int",
93 				"int",
94 				complexPtrType,
95 				complexPtrType,
96 				"int",
97 				"uint"
98 			]),
99 			createFunction(prefix, "plan_dft_3d", planType, [
100 				"int",
101 				"int",
102 				"int",
103 				complexPtrType,
104 				complexPtrType,
105 				"int",
106 				"uint"
107 			]),
108 
109 			createFunction(prefix, "plan_many_dft", planType, [
110 				"int",
111 				"const int *",
112 				"int",
113 				complexPtrType,
114 				"const int *",
115 				"int",
116 				"int",
117 				complexPtrType,
118 				"const int *",
119 				"int",
120 				"int",
121 				"int",
122 				"uint"
123 			]),
124 
125 			createFunction(prefix, "plan_guru_dft", planType, [
126 				"int",
127 				"const " ~ iodimPtrType,
128 				"int",
129 				"const " ~ iodimPtrType,
130 				complexPtrType,
131 				complexPtrType,
132 				"int",
133 				"uint"
134 			]),
135 			createFunction(prefix, "plan_guru_split_dft", planType, [
136 				"int",
137 				"const " ~ iodimPtrType,
138 				"int",
139 				"const " ~ iodimPtrType,
140 				realPtrType,
141 				realPtrType,
142 				realPtrType,
143 				realPtrType,
144 				"int",
145 				"uint"
146 			]),
147 
148 			createFunction(prefix, "plan_guru64_dft", planType, [
149 				"int",
150 				"const " ~ iodim64PtrType,
151 				"int",
152 				"const " ~ iodim64PtrType,
153 				complexPtrType,
154 				complexPtrType,
155 				"int",
156 				"uint"
157 			]),
158 			createFunction(prefix, "plan_guru64_split_dft", planType, [
159 				"int",
160 				"const " ~ iodim64PtrType,
161 				"int",
162 				"const " ~ iodim64PtrType,
163 				realPtrType,
164 				realPtrType,
165 				realPtrType,
166 				realPtrType,
167 				"int",
168 				"uint"
169 			]),
170 
171 			createFunction(prefix, "execute_dft", "void", [
172 				"const " ~ planType,
173 				complexPtrType,
174 				complexPtrType
175 			]),
176 			createFunction(prefix, "execute_split_dft", "void", [
177 				"const " ~ planType,
178 				realPtrType,
179 				realPtrType,
180 				realPtrType,
181 				realPtrType
182 			]),
183 
184 			createFunction(prefix, "plan_many_dft_r2c", planType, [
185 				"int",
186 				"const int *",
187 				"int",
188 				realPtrType,
189 				"const int *",
190 				"int",
191 				"int",
192 				complexPtrType,
193 				"const int *",
194 				"int",
195 				"int",
196 				"uint"
197 			]),
198 
199 			createFunction(prefix, "plan_dft_r2c", planType, [
200 				"int",
201 				"const int *",
202 				realPtrType,
203 				complexPtrType,
204 				"uint"
205 			]),
206 
207 			createFunction(prefix, "plan_dft_r2c_1d", planType, [
208 				"int",
209 				realPtrType,
210 				complexPtrType,
211 				"uint"
212 			]),
213 			createFunction(prefix, "plan_dft_r2c_2d", planType, [
214 				"int",
215 				"int",
216 				realPtrType,
217 				complexPtrType,
218 				"uint"
219 			]),
220 			createFunction(prefix, "plan_dft_r2c_3d", planType, [
221 				"int",
222 				"int",
223 				"int",
224 				realPtrType,
225 				complexPtrType,
226 				"uint"
227 			]),
228 
229 			createFunction(prefix, "plan_many_dft_c2r", planType, [
230 				"int",
231 				"const int *",
232 				"int",
233 				complexPtrType,
234 				"const int *",
235 				"int",
236 				"int",
237 				realPtrType,
238 				"const int *",
239 				"int",
240 				"int",
241 				"uint"
242 			]),
243 
244 			createFunction(prefix, "plan_dft_c2r", planType, [
245 				"int",
246 				"const int *",
247 				complexPtrType,
248 				realPtrType,
249 				"uint"
250 			]),
251 
252 			createFunction(prefix, "plan_dft_c2r_1d", planType, [
253 				"int",
254 				complexPtrType,
255 				realPtrType,
256 				"uint"
257 			]),
258 			createFunction(prefix, "plan_dft_c2r_2d", planType, [
259 				"int",
260 				"int",
261 				complexPtrType,
262 				realPtrType,
263 				"uint"
264 			]),
265 			createFunction(prefix, "plan_dft_c2r_3d", planType, [
266 				"int",
267 				"int",
268 				"int",
269 				complexPtrType,
270 				realPtrType,
271 				"uint"
272 			]),
273 
274 			createFunction(prefix, "plan_guru_dft_r2c", planType, [
275 				"int",
276 				"const " ~ iodimPtrType,
277 				"int",
278 				"const " ~ iodimPtrType,
279 				realPtrType,
280 				complexPtrType,
281 				"uint"
282 			]),
283 			createFunction(prefix, "plan_guru_dft_c2r", planType, [
284 				"int",
285 				"const " ~ iodimPtrType,
286 				"int",
287 				"const " ~ iodimPtrType,
288 				complexPtrType,
289 				realPtrType,
290 				"uint"
291 			]),
292 
293 			createFunction(prefix, "plan_guru_split_dft_r2c", planType, [
294 				"int",
295 				"const " ~ iodimPtrType,
296 				"int",
297 				"const " ~  iodimPtrType,
298 				realPtrType,
299 				realPtrType,
300 				realPtrType,
301 				"uint"
302 			]),
303 			createFunction(prefix, "plan_guru_split_dft_c2r", planType, [
304 				"int",
305 				"const " ~ iodimPtrType,
306 				"int",
307 				"const " ~  iodimPtrType,
308 				realPtrType,
309 				realPtrType,
310 				realPtrType,
311 				"uint"
312 			]),
313 
314 			createFunction(prefix, "plan_guru64_dft_r2c", planType, [
315 				"int",
316 				"const " ~ iodim64PtrType,
317 				"int",
318 				"const " ~ iodim64PtrType,
319 				realPtrType,
320 				complexPtrType,
321 				"uint"
322 			]),
323 			createFunction(prefix, "plan_guru64_dft_c2r", planType, [
324 				"int",
325 				"const " ~ iodim64PtrType,
326 				"int",
327 				"const " ~ iodim64PtrType,
328 				complexPtrType,
329 				realPtrType,
330 				"uint"
331 			]),
332 
333 			createFunction(prefix, "plan_guru64_split_dft_r2c", planType, [
334 				"int",
335 				"const " ~ iodim64PtrType,
336 				"int",
337 				"const " ~  iodim64PtrType,
338 				realPtrType,
339 				realPtrType,
340 				realPtrType,
341 				"uint"
342 			]),
343 			createFunction(prefix, "plan_guru64_split_dft_c2r", planType, [
344 				"int",
345 				"const " ~ iodim64PtrType,
346 				"int",
347 				"const " ~  iodim64PtrType,
348 				realPtrType,
349 				realPtrType,
350 				realPtrType,
351 				"uint"
352 			]),
353 
354 			createFunction(prefix, "execute_dft_r2c", "void", [
355 				"const " ~ planType,
356 				realPtrType,
357 				complexPtrType
358 			]),
359 			createFunction(prefix, "execute_dft_c2r", "void", [
360 				"const " ~ planType,
361 				complexPtrType,
362 				realPtrType
363 			]),
364 
365 			createFunction(prefix, "execute_split_dft_r2c", "void", [
366 				"const " ~ planType,
367 				realPtrType,
368 				realPtrType,
369 				realPtrType
370 			]),
371 			createFunction(prefix, "execute_split_dft_c2r", "void", [
372 				"const " ~ planType,
373 				realPtrType,
374 				realPtrType,
375 				realPtrType
376 			]),
377 
378 			createFunction(prefix, "plan_many_r2r", planType, [
379 				"int",
380 				"const int *",
381 				"int",
382 				realPtrType,
383 				"const int *",
384 				"int",
385 				"int",
386 				realPtrType,
387 				"const int *",
388 				"int",
389 				"int",
390 				"const " ~ prefix ~ "r2r_kind *",
391 				"uint"
392 			]),
393 			
394 			createFunction(prefix, "plan_r2r", planType, [
395 				"int",
396 				"const int *",
397 				realPtrType,
398 				realPtrType,
399 				"const " ~ prefix ~ "r2r_kind *",
400 				"uint"
401 			]),
402 
403 			createFunction(prefix, "plan_r2r_1d", planType, [
404 				"int",
405 				realPtrType,
406 				realPtrType,
407 				prefix ~ "r2r_kind",
408 				"uint"
409 			]),
410 			createFunction(prefix, "plan_r2r_2d", planType, [
411 				"int",
412 				"int",
413 				realPtrType,
414 				realPtrType,
415 				prefix ~ "r2r_kind",
416 				"uint"
417 			]),
418 			createFunction(prefix, "plan_r2r_3d", planType, [
419 				"int",
420 				"int",
421 				"int",
422 				realPtrType,
423 				realPtrType,
424 				prefix ~ "r2r_kind",
425 				"uint"
426 			]),
427 
428 			createFunction(prefix, "plan_guru_r2r", planType, [
429 				"int",
430 				"const " ~ iodimPtrType,
431 				"int",
432 				"const " ~ iodimPtrType,
433 				realPtrType,
434 				realPtrType,
435 				"const " ~ prefix ~ "r2r_kind *",
436 				"uint"
437 			]),
438 
439 			createFunction(prefix, "plan_guru64_r2r", planType, [
440 				"int",
441 				"const " ~ iodim64PtrType,
442 				"int",
443 				"const " ~ iodim64PtrType,
444 				realPtrType,
445 				realPtrType,
446 				"const " ~ prefix ~ "r2r_kind *",
447 				"uint"
448 			]),
449 
450 			createFunction(prefix, "execute_r2r", "void", [
451 				"const " ~ planType,
452 				realPtrType,
453 				realPtrType
454 			]),
455 
456 			createFunction(prefix, "destroy_plan", "void", [
457 				planType
458 			]),
459 			createFunction(prefix, "forget_wisdom", "void", [
460 			]),
461 			createFunction(prefix, "cleanup", "void", [
462 			]),
463 
464 			createFunction(prefix, "set_timelimit", "void", [
465 				"double"
466 			]),
467 
468 			createFunction(prefix, "plan_with_nthreads", "void", [
469 				"int"
470 			]),
471 			createFunction(prefix, "init_threads", "int", [
472 			]),
473 			createFunction(prefix, "cleanup_threads", "void", [
474 			]),
475 
476 			createFunction(prefix, "export_wisdom_to_filename", "int", [
477 				"const char *"
478 			]),
479 			createFunction(prefix, "export_wisdom_to_file", "void", [
480 				"void *"
481 			]),
482 			createFunction(prefix, "export_wisdom_to_string", "char *", [
483 			]),
484 			createFunction(prefix, "export_wisdom", "void", [
485 				prefix ~ "write_char_func",
486 				"void *"
487 			]),
488 			createFunction(prefix, "import_system_wisdom", "int", [
489 			]),
490 			createFunction(prefix, "import_wisdom_from_filename", "int", [
491 				"const char *"
492 			]),
493 			createFunction(prefix, "import_wisdom_from_file", "int", [
494 				"void *"
495 			]),
496 			createFunction(prefix, "import_wisdom_from_string", "int", [
497 				"const char *"
498 			]),
499 			createFunction(prefix, "import_wisdom", "int", [
500 				prefix ~ "read_char_func",
501 				"void *"
502 			]),
503 
504 			createFunction(prefix, "fprint_plan", "void", [
505 				"const " ~ planType,
506 				"void *"
507 			]),
508 			createFunction(prefix, "print_plan", "void", [
509 				"const " ~ planType
510 			]),
511 			createFunction(prefix, "sprint_plan", "char *", [
512 				"const " ~ planType
513 			]),
514 
515 			createFunction(prefix, "malloc", "void *", [
516 				"size_t"
517 			]),
518 			createFunction(prefix, "alloc_real", realPtrType, [
519 				"size_t"
520 			]),
521 			createFunction(prefix, "alloc_complex", complexPtrType, [
522 				"size_t"
523 			]),
524 			createFunction(prefix, "free", "void", [
525 				"void *"
526 			]),
527 
528 			createFunction(prefix, "flops", "void", [
529 				"const " ~ planType,
530 				"double *",
531 				"double *",
532 				"double *"
533 			]),
534 			createFunction(prefix, "estimate_cost", "double", [
535 				"const " ~ planType
536 			]),
537 			createFunction(prefix, "cost", "double", [
538 				"const " ~ planType
539 			]),
540 
541 			createFunction(prefix, "alignment_of", "int", [
542 				realPtrType
543 			])//,
544 			//"const char *" ~ prefix ~ "version;",
545 			//"const char *" ~ prefix ~ "cc;",
546 			//"const char *" ~ prefix ~ "codelet_optim;"
547 
548 		], "\n");
549 	}
550 }
551 
552 extern(C)
553 {
554 	mixin(createApi("fftw_", "double", "Complex!double"));
555 	mixin(createApi("fftwf_", "float", "Complex!float"));
556 	mixin(createApi("fftwl_", "real", "Complex!real"));
557 }
558 
559 enum FFTW_FORWARD = -1;
560 enum FFTW_BACKWARD = 1;
561 
562 enum FFTW_NO_TIMELIMIT = -1.0;
563 
564 enum FFTW_MEASURE = (0U);
565 enum FFTW_DESTROY_INPUT = (1U << 0);
566 enum FFTW_UNALIGNED = (1U << 1);
567 enum FFTW_CONSERVE_MEMORY = (1U << 2);
568 enum FFTW_EXHAUSTIVE = (1U << 3);
569 enum FFTW_PRESERVE_INPUT = (1U << 4);
570 enum FFTW_PATIENT = (1U << 5);
571 enum FFTW_ESTIMATE = (1U << 6);
572 enum FFTW_WISDOM_ONLY = (1U << 21);
573 
574 enum FFTW_ESTIMATE_PATIENT = (1U << 7);
575 enum FFTW_BELIEVE_PCOST = (1U << 8);
576 enum FFTW_NO_DFT_R2HC = (1U << 9);
577 enum FFTW_NO_NONTHREADED = (1U << 10);
578 enum FFTW_NO_BUFFERING = (1U << 11);
579 enum FFTW_NO_INDIRECT_OP = (1U << 12);
580 enum FFTW_ALLOW_LARGE_GENERIC = (1U << 13);
581 enum FFTW_NO_RANK_SPLITS = (1U << 14);
582 enum FFTW_NO_VRANK_SPLITS = (1U << 15);
583 enum FFTW_NO_VRECURSE = (1U << 16);
584 enum FFTW_NO_SIMD = (1U << 17);
585 enum FFTW_NO_SLOW = (1U << 18);
586 enum FFTW_NO_FIXED_RADIX_LARGE_N = (1U << 19);
587 enum FFTW_ALLOW_PRUNING = (1U << 20);