Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/genfft/gen_hc2cdft_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 R-stride"; | |
46 | |
47 "-with-ms", | |
48 Arg.String(fun x -> ums := arg_to_stride x), | |
49 " specialize for given ms" | |
50 ] | |
51 | |
52 let byi = Complex.times Complex.i | |
53 let byui = Complex.times (Complex.uminus Complex.i) | |
54 | |
55 let shuffle_eo fe fo i = if i mod 2 == 0 then fe (i/2) else fo ((i-1)/2) | |
56 | |
57 let generate n = | |
58 let rs = "rs" | |
59 and twarray = "W" | |
60 and m = "m" and mb = "mb" and me = "me" and ms = "ms" | |
61 | |
62 (* the array names are from the point of view of the complex array | |
63 (output in R2C, input in C2R) *) | |
64 and arp = "Rp" (* real, positive *) | |
65 and aip = "Ip" (* imag, positive *) | |
66 and arm = "Rm" (* real, negative *) | |
67 and aim = "Im" (* imag, negative *) | |
68 | |
69 in | |
70 | |
71 let sign = !Genutil.sign | |
72 and name = !Magic.codelet_name | |
73 and byvl x = choose_simd x (ctimes (CVar "VL", x)) | |
74 and bytwvl x = choose_simd x (ctimes (CVar "TWVL", x)) | |
75 and bytwvl_vl x = choose_simd x (ctimes (CVar "(TWVL/VL)", x)) in | |
76 | |
77 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 1 true in | |
78 let nt = num_twiddles n in | |
79 | |
80 let byw = bytwiddle n sign (twiddle_array nt twarray) in | |
81 | |
82 let vrs = either_stride (!urs) (C.SVar rs) in | |
83 let sms = stride_to_string "ms" !ums in | |
84 let msms = "-" ^ sms in | |
85 | |
86 (* assume a single location. No point in doing alias analysis *) | |
87 let the_location = (Unique.make (), Unique.make ()) in | |
88 let locations _ = the_location in | |
89 | |
90 let rlocp = (locative_array_c n | |
91 (C.array_subscript arp vrs) | |
92 (C.array_subscript aip vrs) | |
93 locations sms) | |
94 and rlocm = (locative_array_c n | |
95 (C.array_subscript arm vrs) | |
96 (C.array_subscript aim vrs) | |
97 locations msms) | |
98 and clocp = (locative_array_c n | |
99 (C.array_subscript arp vrs) | |
100 (C.array_subscript aip vrs) | |
101 locations sms) | |
102 and clocm = (locative_array_c n | |
103 (C.array_subscript arm vrs) | |
104 (C.array_subscript aim vrs) | |
105 locations msms) | |
106 in | |
107 let rloc i = if i mod 2 == 0 then rlocp (i/2) else rlocm ((i-1)/2) | |
108 and cloc i = if i < n - i then clocp i else clocm (n-1-i) | |
109 and sym n f i = | |
110 if (i < n - i) then | |
111 f i | |
112 else | |
113 Complex.times (Complex.nan Expr.CONJ) (f i) | |
114 and sym1 f i = | |
115 if i mod 2 == 0 then | |
116 Complex.plus [f i; | |
117 Complex.times (Complex.nan Expr.CONJ) (f (i+1))] | |
118 else | |
119 Complex.times (Complex.nan Expr.I) | |
120 (Complex.plus [Complex.uminus (f (i-1)); | |
121 Complex.times (Complex.nan Expr.CONJ) (f i)]) | |
122 and sym1i f i = | |
123 if i mod 2 == 0 then | |
124 Complex.plus [f i; | |
125 Complex.times (Complex.nan Expr.I) (f (i+1))] | |
126 else | |
127 Complex.times (Complex.nan Expr.CONJ) | |
128 (Complex.plus [f (i-1); | |
129 Complex.uminus | |
130 (Complex.times (Complex.nan Expr.I) (f i))]) | |
131 in | |
132 | |
133 let asch = | |
134 match !ditdif with | |
135 | DIT -> | |
136 let output = | |
137 (Complex.times Complex.half) @@ | |
138 (Trig.dft_via_rdft sign n (byw (sym1 (load_array_r n rloc)))) in | |
139 let odag = store_array_r n cloc (sym n output) in | |
140 standard_optimizer odag | |
141 | |
142 | DIF -> | |
143 let output = | |
144 byw (Trig.dft_via_rdft sign n (sym n (load_array_r n cloc))) | |
145 in | |
146 let odag = store_array_r n rloc (sym1i output) in | |
147 standard_optimizer odag | |
148 in | |
149 | |
150 let vms = CVar sms | |
151 and varp = CVar arp | |
152 and vaip = CVar aip | |
153 and varm = CVar arm | |
154 and vaim = CVar aim | |
155 and vm = CVar m and vmb = CVar mb and vme = CVar me | |
156 in | |
157 let body = Block ( | |
158 [Decl ("INT", m)], | |
159 [For (list_to_comma | |
160 [Expr_assign (vm, vmb); | |
161 Expr_assign (CVar twarray, | |
162 CPlus [CVar twarray; | |
163 ctimes (CPlus [vmb; CUminus (Integer 1)], | |
164 bytwvl_vl (Integer nt))])], | |
165 Binop (" < ", vm, vme), | |
166 list_to_comma | |
167 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]); | |
168 Expr_assign (varp, CPlus [varp; byvl vms]); | |
169 Expr_assign (vaip, CPlus [vaip; byvl vms]); | |
170 Expr_assign (varm, CPlus [varm; CUminus (byvl vms)]); | |
171 Expr_assign (vaim, CPlus [vaim; CUminus (byvl vms)]); | |
172 Expr_assign (CVar twarray, CPlus [CVar twarray; | |
173 bytwvl (Integer nt)]); | |
174 make_volatile_stride (4*n) (CVar rs) | |
175 ], | |
176 Asch asch)] | |
177 ) | |
178 in | |
179 | |
180 let tree = | |
181 Fcn ("static void", name, | |
182 [Decl (C.realtypep, arp); | |
183 Decl (C.realtypep, aip); | |
184 Decl (C.realtypep, arm); | |
185 Decl (C.realtypep, aim); | |
186 Decl (C.constrealtypep, twarray); | |
187 Decl (C.stridetype, rs); | |
188 Decl ("INT", mb); | |
189 Decl ("INT", me); | |
190 Decl ("INT", ms)], | |
191 finalize_fcn body) | |
192 in | |
193 let twinstr = | |
194 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n" | |
195 (twinstr_to_string "VL" (twdesc n)) | |
196 and desc = | |
197 Printf.sprintf | |
198 "static const hc2c_desc desc = {%d, %s, twinstr, &GENUS, %s};\n\n" | |
199 n (stringify name) (flops_of tree) | |
200 and register = "X(khc2c_register)" | |
201 | |
202 in | |
203 let init = | |
204 "\n" ^ | |
205 twinstr ^ | |
206 desc ^ | |
207 (declare_register_fcn name) ^ | |
208 (Printf.sprintf "{\n%s(p, %s, &desc, HC2C_VIA_DFT);\n}" register name) | |
209 in | |
210 | |
211 (unparse tree) ^ "\n" ^ init | |
212 | |
213 | |
214 let main () = | |
215 begin | |
216 Simdmagic.simd_mode := true; | |
217 parse (speclist @ Twiddle.speclist) usage; | |
218 print_string (generate (check_size ())); | |
219 end | |
220 | |
221 let _ = main() |