comparison src/fftw-3.3.3/genfft/variable.ml @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 (*
2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
3 * Copyright (c) 2003, 2007-11 Matteo Frigo
4 * Copyright (c) 2003, 2007-11 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 type variable =
23 (* temporary variables generated automatically *)
24 | Temporary of int
25 (* memory locations, e.g., array elements *)
26 | Locative of (Unique.unique * Unique.unique *
27 (int -> string) * int * string)
28 (* constant values, e.g., twiddle factors *)
29 | Constant of (Unique.unique * string)
30
31 let hash v = Hashtbl.hash v
32
33 let same a b = (a == b)
34
35 let is_constant = function
36 | Constant _ -> true
37 | _ -> false
38
39 let is_temporary = function
40 | Temporary _ -> true
41 | _ -> false
42
43 let is_locative = function
44 | Locative _ -> true
45 | _ -> false
46
47 let same_location a b =
48 match (a, b) with
49 | (Locative (location_a, _, _, _, _), Locative (location_b, _, _, _, _)) ->
50 Unique.same location_a location_b
51 | _ -> false
52
53 let same_class a b =
54 match (a, b) with
55 | (Locative (_, class_a, _, _, _), Locative (_, class_b, _, _, _)) ->
56 Unique.same class_a class_b
57 | (Constant (class_a, _), Constant (class_b, _)) ->
58 Unique.same class_a class_b
59 | _ -> false
60
61 let make_temporary =
62 let tmp_count = ref 0
63 in fun () -> begin
64 tmp_count := !tmp_count + 1;
65 Temporary !tmp_count
66 end
67
68 let make_constant class_token name =
69 Constant (class_token, name)
70
71 let make_locative location_token class_token name i vs =
72 Locative (location_token, class_token, name, i, vs)
73
74 let vstride_of_locative = function
75 | Locative (_, _, _, _, vs) -> vs
76 | _ -> failwith "vstride_of_locative"
77
78 (* special naming conventions for variables *)
79 let rec base62_of_int k =
80 let x = k mod 62
81 and y = k / 62 in
82 let c =
83 if x < 10 then
84 Char.chr (x + Char.code '0')
85 else if x < 36 then
86 Char.chr (x + Char.code 'a' - 10)
87 else
88 Char.chr (x + Char.code 'A' - 36)
89 in
90 let s = String.make 1 c in
91 let r = if y == 0 then "" else base62_of_int y in
92 r ^ s
93
94 let varname_of_int k =
95 if !Magic.compact then
96 base62_of_int k
97 else
98 string_of_int k
99
100 let unparse = function
101 | Temporary k -> "T" ^ (varname_of_int k)
102 | Constant (_, name) -> name
103 | Locative (_, _, name, i, _) -> name i
104
105 let unparse_for_alignment m = function
106 | Locative (_, _, name, i, _) -> name (i mod m)
107 | _ -> failwith "unparse_for_alignment"
108