Chris@10
|
1 (*
|
Chris@10
|
2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
|
Chris@10
|
3 * Copyright (c) 2003, 2007-11 Matteo Frigo
|
Chris@10
|
4 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
|
Chris@10
|
5 *
|
Chris@10
|
6 * This program is free software; you can redistribute it and/or modify
|
Chris@10
|
7 * it under the terms of the GNU General Public License as published by
|
Chris@10
|
8 * the Free Software Foundation; either version 2 of the License, or
|
Chris@10
|
9 * (at your option) any later version.
|
Chris@10
|
10 *
|
Chris@10
|
11 * This program is distributed in the hope that it will be useful,
|
Chris@10
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@10
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@10
|
14 * GNU General Public License for more details.
|
Chris@10
|
15 *
|
Chris@10
|
16 * You should have received a copy of the GNU General Public License
|
Chris@10
|
17 * along with this program; if not, write to the Free Software
|
Chris@10
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Chris@10
|
19 *
|
Chris@10
|
20 *)
|
Chris@10
|
21
|
Chris@10
|
22 open Util
|
Chris@10
|
23 open Genutil
|
Chris@10
|
24 open C
|
Chris@10
|
25
|
Chris@10
|
26
|
Chris@10
|
27 type ditdif = DIT | DIF
|
Chris@10
|
28 let ditdif = ref DIT
|
Chris@10
|
29 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number> [ -dit | -dif ]"
|
Chris@10
|
30
|
Chris@10
|
31 let urs = ref Stride_variable
|
Chris@10
|
32
|
Chris@10
|
33 let speclist = [
|
Chris@10
|
34 "-dit",
|
Chris@10
|
35 Arg.Unit(fun () -> ditdif := DIT),
|
Chris@10
|
36 " generate a DIT codelet";
|
Chris@10
|
37
|
Chris@10
|
38 "-dif",
|
Chris@10
|
39 Arg.Unit(fun () -> ditdif := DIF),
|
Chris@10
|
40 " generate a DIF codelet";
|
Chris@10
|
41
|
Chris@10
|
42 "-with-rs",
|
Chris@10
|
43 Arg.String(fun x -> urs := arg_to_stride x),
|
Chris@10
|
44 " specialize for given R-stride";
|
Chris@10
|
45 ]
|
Chris@10
|
46
|
Chris@10
|
47 let byi = Complex.times Complex.i
|
Chris@10
|
48 let byui = Complex.times (Complex.uminus Complex.i)
|
Chris@10
|
49
|
Chris@10
|
50 let sym n f i = if (i < n - i) then f i else Complex.conj (f i)
|
Chris@10
|
51
|
Chris@10
|
52 let shuffle_eo fe fo i = if i mod 2 == 0 then fe (i/2) else fo ((i-1)/2)
|
Chris@10
|
53
|
Chris@10
|
54 let generate n =
|
Chris@10
|
55 let rs = "rs"
|
Chris@10
|
56 and twarray = "W"
|
Chris@10
|
57 and m = "m" and mb = "mb" and me = "me" and ms = "ms"
|
Chris@10
|
58
|
Chris@10
|
59 (* the array names are from the point of view of the complex array
|
Chris@10
|
60 (output in R2C, input in C2R) *)
|
Chris@10
|
61 and arp = "Rp" (* real, positive *)
|
Chris@10
|
62 and aip = "Ip" (* imag, positive *)
|
Chris@10
|
63 and arm = "Rm" (* real, negative *)
|
Chris@10
|
64 and aim = "Im" (* imag, negative *)
|
Chris@10
|
65
|
Chris@10
|
66 in
|
Chris@10
|
67
|
Chris@10
|
68 let sign = !Genutil.sign
|
Chris@10
|
69 and name = !Magic.codelet_name
|
Chris@10
|
70 and byvl x = choose_simd x (ctimes (CVar "VL", x)) in
|
Chris@10
|
71
|
Chris@10
|
72 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 1 false in
|
Chris@10
|
73 let nt = num_twiddles n in
|
Chris@10
|
74
|
Chris@10
|
75 let byw = bytwiddle n sign (twiddle_array nt twarray) in
|
Chris@10
|
76
|
Chris@10
|
77 let vrs = either_stride (!urs) (C.SVar rs) in
|
Chris@10
|
78
|
Chris@10
|
79 (* assume a single location. No point in doing alias analysis *)
|
Chris@10
|
80 let the_location = (Unique.make (), Unique.make ()) in
|
Chris@10
|
81 let locations _ = the_location in
|
Chris@10
|
82
|
Chris@10
|
83 let locr = (locative_array_c n
|
Chris@10
|
84 (C.array_subscript arp vrs)
|
Chris@10
|
85 (C.array_subscript arm vrs)
|
Chris@10
|
86 locations "BUG")
|
Chris@10
|
87 and loci = (locative_array_c n
|
Chris@10
|
88 (C.array_subscript aip vrs)
|
Chris@10
|
89 (C.array_subscript aim vrs)
|
Chris@10
|
90 locations "BUG")
|
Chris@10
|
91 and locp = (locative_array_c n
|
Chris@10
|
92 (C.array_subscript arp vrs)
|
Chris@10
|
93 (C.array_subscript aip vrs)
|
Chris@10
|
94 locations "BUG")
|
Chris@10
|
95 and locm = (locative_array_c n
|
Chris@10
|
96 (C.array_subscript arm vrs)
|
Chris@10
|
97 (C.array_subscript aim vrs)
|
Chris@10
|
98 locations "BUG")
|
Chris@10
|
99 in
|
Chris@10
|
100 let locri i = if i mod 2 == 0 then locr (i/2) else loci ((i-1)/2)
|
Chris@10
|
101 and locpm i = if i < n - i then locp i else locm (n-1-i)
|
Chris@10
|
102 in
|
Chris@10
|
103
|
Chris@10
|
104 let asch =
|
Chris@10
|
105 match !ditdif with
|
Chris@10
|
106 | DIT ->
|
Chris@10
|
107 let output = Fft.dft sign n (byw (load_array_c n locri)) in
|
Chris@10
|
108 let odag = store_array_c n locpm (sym n output) in
|
Chris@10
|
109 standard_optimizer odag
|
Chris@10
|
110
|
Chris@10
|
111 | DIF ->
|
Chris@10
|
112 let output = byw (Fft.dft sign n (sym n (load_array_c n locpm))) in
|
Chris@10
|
113 let odag = store_array_c n locri output in
|
Chris@10
|
114 standard_optimizer odag
|
Chris@10
|
115 in
|
Chris@10
|
116
|
Chris@10
|
117 let vms = CVar "ms"
|
Chris@10
|
118 and varp = CVar arp
|
Chris@10
|
119 and vaip = CVar aip
|
Chris@10
|
120 and varm = CVar arm
|
Chris@10
|
121 and vaim = CVar aim
|
Chris@10
|
122 and vm = CVar m and vmb = CVar mb and vme = CVar me
|
Chris@10
|
123 in
|
Chris@10
|
124 let body = Block (
|
Chris@10
|
125 [Decl ("INT", m)],
|
Chris@10
|
126 [For (list_to_comma
|
Chris@10
|
127 [Expr_assign (vm, vmb);
|
Chris@10
|
128 Expr_assign (CVar twarray,
|
Chris@10
|
129 CPlus [CVar twarray;
|
Chris@10
|
130 ctimes (CPlus [vmb; CUminus (Integer 1)],
|
Chris@10
|
131 Integer nt)])],
|
Chris@10
|
132 Binop (" < ", vm, vme),
|
Chris@10
|
133 list_to_comma
|
Chris@10
|
134 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]);
|
Chris@10
|
135 Expr_assign (varp, CPlus [varp; byvl vms]);
|
Chris@10
|
136 Expr_assign (vaip, CPlus [vaip; byvl vms]);
|
Chris@10
|
137 Expr_assign (varm, CPlus [varm; CUminus (byvl vms)]);
|
Chris@10
|
138 Expr_assign (vaim, CPlus [vaim; CUminus (byvl vms)]);
|
Chris@10
|
139 Expr_assign (CVar twarray, CPlus [CVar twarray;
|
Chris@10
|
140 byvl (Integer nt)]);
|
Chris@10
|
141 make_volatile_stride (4*n) (CVar rs)
|
Chris@10
|
142 ],
|
Chris@10
|
143 Asch asch)])
|
Chris@10
|
144 in
|
Chris@10
|
145
|
Chris@10
|
146 let tree =
|
Chris@10
|
147 Fcn ("static void", name,
|
Chris@10
|
148 [Decl (C.realtypep, arp);
|
Chris@10
|
149 Decl (C.realtypep, aip);
|
Chris@10
|
150 Decl (C.realtypep, arm);
|
Chris@10
|
151 Decl (C.realtypep, aim);
|
Chris@10
|
152 Decl (C.constrealtypep, twarray);
|
Chris@10
|
153 Decl (C.stridetype, rs);
|
Chris@10
|
154 Decl ("INT", mb);
|
Chris@10
|
155 Decl ("INT", me);
|
Chris@10
|
156 Decl ("INT", ms)],
|
Chris@10
|
157 finalize_fcn body)
|
Chris@10
|
158 in
|
Chris@10
|
159 let twinstr =
|
Chris@10
|
160 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n"
|
Chris@10
|
161 (twinstr_to_string "VL" (twdesc n))
|
Chris@10
|
162 and desc =
|
Chris@10
|
163 Printf.sprintf
|
Chris@10
|
164 "static const hc2c_desc desc = {%d, \"%s\", twinstr, &GENUS, %s};\n\n"
|
Chris@10
|
165 n name (flops_of tree)
|
Chris@10
|
166 and register = "X(khc2c_register)"
|
Chris@10
|
167
|
Chris@10
|
168 in
|
Chris@10
|
169 let init =
|
Chris@10
|
170 "\n" ^
|
Chris@10
|
171 twinstr ^
|
Chris@10
|
172 desc ^
|
Chris@10
|
173 (declare_register_fcn name) ^
|
Chris@10
|
174 (Printf.sprintf "{\n%s(p, %s, &desc, HC2C_VIA_RDFT);\n}" register name)
|
Chris@10
|
175 in
|
Chris@10
|
176
|
Chris@10
|
177 (unparse tree) ^ "\n" ^ init
|
Chris@10
|
178
|
Chris@10
|
179
|
Chris@10
|
180 let main () =
|
Chris@10
|
181 begin
|
Chris@10
|
182 parse (speclist @ Twiddle.speclist) usage;
|
Chris@10
|
183 print_string (generate (check_size ()));
|
Chris@10
|
184 end
|
Chris@10
|
185
|
Chris@10
|
186 let _ = main()
|