forked from FFTW/fftw3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvariable.ml
131 lines (107 loc) · 4.07 KB
/
variable.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
(*
* Copyright (c) 1997-1999 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*)
(* Data types and functions for dealing with variables in symbolic
* expressions and the abstract syntax tree. *)
(* Variables fall into one of four categories: temporary variables
* (which the generator can add or delete at will), named (fixed)
* variables, and the real/imaginary parts of complex arrays. Arrays
* can be either input arrays, output arrays, or arrays of precomputed
* twiddle factors (roots of unity). *)
type array = Input | Output | Twiddle
let arrayToString = function
| Input -> "in"
| Output -> "out"
| Twiddle -> "tw"
type variable =
| Temporary of int
| Named of string
| RealArrayElem of (array * int)
| ImagArrayElem of (array * int)
let make_temporary =
let tmp_count = ref 0
in fun () -> begin
tmp_count := !tmp_count + 1;
Temporary !tmp_count
end
let is_temporary = function
| Temporary _ -> true
| _ -> false
let is_real = function
| RealArrayElem _ -> true
| _ -> false
let is_imag = function
| ImagArrayElem _ -> true
| _ -> false
let is_output = function
| RealArrayElem (Output, _) -> true
| ImagArrayElem (Output, _) -> true
| _ -> false
let is_input = function
| RealArrayElem (Input, _) -> true
| ImagArrayElem (Input, _) -> true
| _ -> false
let is_twiddle = function
| RealArrayElem (Twiddle, _) -> true
| ImagArrayElem (Twiddle, _) -> true
| _ -> false
let is_locative x = (is_input x) || (is_output x)
let is_constant = is_twiddle
let same = (=)
let hash = function
| RealArrayElem(Input,i) -> i * 8
| ImagArrayElem(Input,i) -> -i * 8 + 1
| RealArrayElem(Output,i) -> i * 8 + 2
| ImagArrayElem(Output,i) -> -i * 8 + 3
| RealArrayElem(Twiddle,i) -> i * 8 + 4
| ImagArrayElem(Twiddle,i) -> -i * 8 + 5
| _ -> 0
let similar a b =
same a b ||
(match (a, b) with
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
| (ImagArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
| _ -> false)
(* true if assignment of a clobbers variable b *)
let clobbers a b = match (a, b) with
| (RealArrayElem (Output, k1), RealArrayElem (Input, k2)) -> k1 = k2
| (ImagArrayElem (Output, k1), ImagArrayElem (Input, k2)) -> k1 = k2
| _ -> false
(* true if a is the real part and b the imaginary of the same array *)
let real_imag a b = match (a, b) with
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 = k2
| _ -> false
(* true if a and b are elements of the same array, and a has smaller index *)
let increasing_indices a b = match (a, b) with
| (RealArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
| (RealArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
| (ImagArrayElem (a1, k1), RealArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
| (ImagArrayElem (a1, k1), ImagArrayElem (a2, k2)) -> a1 = a2 && k1 < k2
| _ -> false
let access array k = (RealArrayElem (array, k), ImagArrayElem (array, k))
let access_input = access Input
let access_output = access Output
let access_twiddle = access Twiddle
let make_named name = Named name
let unparse = function
| Temporary x -> "T" ^ (string_of_int x)
| Named s -> s
| RealArrayElem (a, x) -> "Re(" ^ (arrayToString a) ^ "[" ^
(string_of_int x) ^ "])"
| ImagArrayElem (a, x) -> "Im(" ^ (arrayToString a) ^ "[" ^
(string_of_int x) ^ "])"