Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/genfft/gen_twiddle.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 = "ri" | |
54 and iioarray = "ii" | |
55 and rs = "rs" | |
56 and twarray = "W" | |
57 and m = "m" and mb = "mb" and me = "me" and ms = "ms" in | |
58 | |
59 let sign = !Genutil.sign | |
60 and name = !Magic.codelet_name | |
61 and byvl x = choose_simd x (ctimes (CVar "(2 * VL)", x)) in | |
62 let ename = expand_name name in | |
63 | |
64 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 0 false in | |
65 let nt = num_twiddles n in | |
66 | |
67 let byw = bytwiddle n sign (twiddle_array nt twarray) in | |
68 | |
69 let vrs = either_stride (!urs) (C.SVar rs) in | |
70 let sms = stride_to_string "ms" !ums in | |
71 | |
72 let locations = unique_array_c n in | |
73 let iloc = | |
74 locative_array_c n | |
75 (C.array_subscript rioarray vrs) | |
76 (C.array_subscript iioarray vrs) | |
77 locations sms | |
78 and oloc = | |
79 locative_array_c n | |
80 (C.array_subscript rioarray vrs) | |
81 (C.array_subscript iioarray vrs) | |
82 locations sms | |
83 in | |
84 let liloc = load_array_c n iloc in | |
85 let output = | |
86 match !ditdif with | |
87 | DIT -> array n (Fft.dft sign n (byw liloc)) | |
88 | DIF -> array n (byw (Fft.dft sign n liloc)) | |
89 in | |
90 let odag = store_array_c n oloc output in | |
91 let annot = standard_optimizer odag in | |
92 | |
93 let vm = CVar m and vmb = CVar mb and vme = CVar me in | |
94 | |
95 let body = Block ( | |
96 [Decl ("INT", m)], | |
97 [For (list_to_comma | |
98 [Expr_assign (vm, vmb); | |
99 Expr_assign (CVar twarray, | |
100 CPlus [CVar twarray; | |
101 ctimes (vmb, Integer nt)])], | |
102 Binop (" < ", vm, vme), | |
103 list_to_comma | |
104 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]); | |
105 Expr_assign (CVar rioarray, CPlus [CVar rioarray; | |
106 byvl (CVar sms)]); | |
107 Expr_assign (CVar iioarray, CPlus [CVar iioarray; | |
108 byvl (CVar sms)]); | |
109 Expr_assign (CVar twarray, CPlus [CVar twarray; | |
110 byvl (Integer nt)]); | |
111 make_volatile_stride (2*n) (CVar rs) | |
112 ], | |
113 Asch annot)]) | |
114 in | |
115 | |
116 let tree = | |
117 Fcn (((if !Magic.standalone then "" else "static ") ^ "void"), | |
118 ename, | |
119 [Decl (C.realtypep, rioarray); | |
120 Decl (C.realtypep, iioarray); | |
121 Decl (C.constrealtypep, twarray); | |
122 Decl (C.stridetype, rs); | |
123 Decl ("INT", mb); | |
124 Decl ("INT", me); | |
125 Decl ("INT", ms)], | |
126 finalize_fcn body) | |
127 in | |
128 let twinstr = | |
129 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n" | |
130 (twinstr_to_string "(2 * VL)" (twdesc n)) | |
131 and desc = | |
132 Printf.sprintf | |
133 "static const ct_desc desc = {%d, %s, twinstr, &GENUS, %s, %s, %s, %s};\n\n" | |
134 n (stringify name) (flops_of tree) | |
135 (stride_to_solverparm !urs) "0" | |
136 (stride_to_solverparm !ums) | |
137 and register = | |
138 match !ditdif with | |
139 | DIT -> "X(kdft_dit_register)" | |
140 | DIF -> "X(kdft_dif_register)" | |
141 | |
142 in | |
143 let init = | |
144 "\n" ^ | |
145 twinstr ^ | |
146 desc ^ | |
147 (declare_register_fcn name) ^ | |
148 (Printf.sprintf "{\n%s(p, %s, &desc);\n}" register ename) | |
149 in | |
150 | |
151 (unparse tree) ^ "\n" ^ | |
152 (if !Magic.standalone then "" else init) | |
153 | |
154 | |
155 let main () = | |
156 begin | |
157 parse (speclist @ Twiddle.speclist) usage; | |
158 print_string (generate (check_size ())); | |
159 end | |
160 | |
161 let _ = main() |