Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/genfft/gen_twiddle_c.ml @ 167:bd3cc4d1df30
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
166:cbd6d7e562c7 | 167:bd3cc4d1df30 |
---|---|
1 (* | |
2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology | |
3 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 * | |
20 *) | |
21 | |
22 open Util | |
23 open Genutil | |
24 open C | |
25 | |
26 | |
27 type ditdif = DIT | DIF | |
28 let ditdif = ref DIT | |
29 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number> [ -dit | -dif ]" | |
30 | |
31 let urs = ref Stride_variable | |
32 let ums = ref Stride_variable | |
33 | |
34 let speclist = [ | |
35 "-dit", | |
36 Arg.Unit(fun () -> ditdif := DIT), | |
37 " generate a DIT codelet"; | |
38 | |
39 "-dif", | |
40 Arg.Unit(fun () -> ditdif := DIF), | |
41 " generate a DIF codelet"; | |
42 | |
43 "-with-rs", | |
44 Arg.String(fun x -> urs := arg_to_stride x), | |
45 " specialize for given i/o stride"; | |
46 | |
47 "-with-ms", | |
48 Arg.String(fun x -> ums := arg_to_stride x), | |
49 " specialize for given ms" | |
50 ] | |
51 | |
52 let generate n = | |
53 let rioarray = "x" | |
54 and rs = "rs" | |
55 and twarray = "W" | |
56 and m = "m" and mb = "mb" and me = "me" and ms = "ms" in | |
57 | |
58 let sign = !Genutil.sign | |
59 and name = !Magic.codelet_name | |
60 and byvl x = choose_simd x (ctimes (CVar "VL", x)) | |
61 and bytwvl x = choose_simd x (ctimes (CVar "TWVL", x)) | |
62 and bytwvl_vl x = choose_simd x (ctimes (CVar "(TWVL/VL)", x)) in | |
63 let ename = expand_name name in | |
64 | |
65 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 0 true in | |
66 let nt = num_twiddles n in | |
67 | |
68 let byw = bytwiddle n sign (twiddle_array nt twarray) in | |
69 | |
70 let vrs = either_stride (!urs) (C.SVar rs) in | |
71 let sms = stride_to_string "ms" !ums in | |
72 | |
73 let locations = unique_array_c n in | |
74 let iloc = | |
75 locative_array_c n | |
76 (C.array_subscript rioarray vrs) | |
77 (C.array_subscript "BUG" vrs) | |
78 locations sms | |
79 and oloc = | |
80 locative_array_c n | |
81 (C.array_subscript rioarray vrs) | |
82 (C.array_subscript "BUG" vrs) | |
83 locations sms | |
84 in | |
85 let liloc = load_array_r n iloc in | |
86 let fft = Trig.dft_via_rdft in | |
87 let output = | |
88 match !ditdif with | |
89 | DIT -> array n (fft sign n (byw liloc)) | |
90 | DIF -> array n (byw (fft sign n liloc)) | |
91 in | |
92 let odag = store_array_r n oloc output in | |
93 let annot = standard_optimizer odag in | |
94 | |
95 let vm = CVar m and vmb = CVar mb and vme = CVar me in | |
96 | |
97 let body = Block ( | |
98 [Decl ("INT", m); | |
99 Decl (C.realtypep, rioarray)], | |
100 [Stmt_assign (CVar rioarray, | |
101 CVar (if (sign < 0) then "ri" else "ii")); | |
102 For (list_to_comma | |
103 [Expr_assign (vm, vmb); | |
104 Expr_assign (CVar twarray, | |
105 CPlus [CVar twarray; | |
106 ctimes (vmb, | |
107 bytwvl_vl (Integer nt))])], | |
108 Binop (" < ", vm, vme), | |
109 list_to_comma | |
110 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]); | |
111 Expr_assign (CVar rioarray, CPlus [CVar rioarray; | |
112 byvl (CVar sms)]); | |
113 Expr_assign (CVar twarray, CPlus [CVar twarray; | |
114 bytwvl (Integer nt)]); | |
115 make_volatile_stride n (CVar rs) | |
116 ], | |
117 Asch annot)]) | |
118 in | |
119 | |
120 let tree = | |
121 Fcn (((if !Magic.standalone then "" else "static ") ^ "void"), | |
122 ename, | |
123 [Decl (C.realtypep, "ri"); | |
124 Decl (C.realtypep, "ii"); | |
125 Decl (C.constrealtypep, twarray); | |
126 Decl (C.stridetype, rs); | |
127 Decl ("INT", mb); | |
128 Decl ("INT", me); | |
129 Decl ("INT", ms)], | |
130 finalize_fcn body) | |
131 in | |
132 let twinstr = | |
133 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n" | |
134 (twinstr_to_string "VL" (twdesc n)) | |
135 and desc = | |
136 Printf.sprintf | |
137 "static const ct_desc desc = {%d, %s, twinstr, &GENUS, %s, %s, %s, %s};\n\n" | |
138 n (stringify name) (flops_of tree) | |
139 (stride_to_solverparm !urs) "0" | |
140 (stride_to_solverparm !ums) | |
141 and register = | |
142 match !ditdif with | |
143 | DIT -> "X(kdft_dit_register)" | |
144 | DIF -> "X(kdft_dif_register)" | |
145 | |
146 in | |
147 let init = | |
148 "\n" ^ | |
149 twinstr ^ | |
150 desc ^ | |
151 (declare_register_fcn name) ^ | |
152 (Printf.sprintf "{\n%s(p, %s, &desc);\n}" register ename) | |
153 in | |
154 | |
155 (unparse tree) ^ "\n" ^ (if !Magic.standalone then "" else init) | |
156 | |
157 | |
158 let main () = | |
159 begin | |
160 Simdmagic.simd_mode := true; | |
161 parse (speclist @ Twiddle.speclist) usage; | |
162 print_string (generate (check_size ())); | |
163 end | |
164 | |
165 let _ = main() |