annotate src/fftw-3.3.3/genfft/variable.ml @ 168:ceec0dd9ec9c

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 07 Feb 2020 11:51:13 +0000
parents 89f5e221ed7b
children
rev   line source
cannam@95 1 (*
cannam@95 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
cannam@95 3 * Copyright (c) 2003, 2007-11 Matteo Frigo
cannam@95 4 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
cannam@95 5 *
cannam@95 6 * This program is free software; you can redistribute it and/or modify
cannam@95 7 * it under the terms of the GNU General Public License as published by
cannam@95 8 * the Free Software Foundation; either version 2 of the License, or
cannam@95 9 * (at your option) any later version.
cannam@95 10 *
cannam@95 11 * This program is distributed in the hope that it will be useful,
cannam@95 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@95 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@95 14 * GNU General Public License for more details.
cannam@95 15 *
cannam@95 16 * You should have received a copy of the GNU General Public License
cannam@95 17 * along with this program; if not, write to the Free Software
cannam@95 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@95 19 *
cannam@95 20 *)
cannam@95 21
cannam@95 22 type variable =
cannam@95 23 (* temporary variables generated automatically *)
cannam@95 24 | Temporary of int
cannam@95 25 (* memory locations, e.g., array elements *)
cannam@95 26 | Locative of (Unique.unique * Unique.unique *
cannam@95 27 (int -> string) * int * string)
cannam@95 28 (* constant values, e.g., twiddle factors *)
cannam@95 29 | Constant of (Unique.unique * string)
cannam@95 30
cannam@95 31 let hash v = Hashtbl.hash v
cannam@95 32
cannam@95 33 let same a b = (a == b)
cannam@95 34
cannam@95 35 let is_constant = function
cannam@95 36 | Constant _ -> true
cannam@95 37 | _ -> false
cannam@95 38
cannam@95 39 let is_temporary = function
cannam@95 40 | Temporary _ -> true
cannam@95 41 | _ -> false
cannam@95 42
cannam@95 43 let is_locative = function
cannam@95 44 | Locative _ -> true
cannam@95 45 | _ -> false
cannam@95 46
cannam@95 47 let same_location a b =
cannam@95 48 match (a, b) with
cannam@95 49 | (Locative (location_a, _, _, _, _), Locative (location_b, _, _, _, _)) ->
cannam@95 50 Unique.same location_a location_b
cannam@95 51 | _ -> false
cannam@95 52
cannam@95 53 let same_class a b =
cannam@95 54 match (a, b) with
cannam@95 55 | (Locative (_, class_a, _, _, _), Locative (_, class_b, _, _, _)) ->
cannam@95 56 Unique.same class_a class_b
cannam@95 57 | (Constant (class_a, _), Constant (class_b, _)) ->
cannam@95 58 Unique.same class_a class_b
cannam@95 59 | _ -> false
cannam@95 60
cannam@95 61 let make_temporary =
cannam@95 62 let tmp_count = ref 0
cannam@95 63 in fun () -> begin
cannam@95 64 tmp_count := !tmp_count + 1;
cannam@95 65 Temporary !tmp_count
cannam@95 66 end
cannam@95 67
cannam@95 68 let make_constant class_token name =
cannam@95 69 Constant (class_token, name)
cannam@95 70
cannam@95 71 let make_locative location_token class_token name i vs =
cannam@95 72 Locative (location_token, class_token, name, i, vs)
cannam@95 73
cannam@95 74 let vstride_of_locative = function
cannam@95 75 | Locative (_, _, _, _, vs) -> vs
cannam@95 76 | _ -> failwith "vstride_of_locative"
cannam@95 77
cannam@95 78 (* special naming conventions for variables *)
cannam@95 79 let rec base62_of_int k =
cannam@95 80 let x = k mod 62
cannam@95 81 and y = k / 62 in
cannam@95 82 let c =
cannam@95 83 if x < 10 then
cannam@95 84 Char.chr (x + Char.code '0')
cannam@95 85 else if x < 36 then
cannam@95 86 Char.chr (x + Char.code 'a' - 10)
cannam@95 87 else
cannam@95 88 Char.chr (x + Char.code 'A' - 36)
cannam@95 89 in
cannam@95 90 let s = String.make 1 c in
cannam@95 91 let r = if y == 0 then "" else base62_of_int y in
cannam@95 92 r ^ s
cannam@95 93
cannam@95 94 let varname_of_int k =
cannam@95 95 if !Magic.compact then
cannam@95 96 base62_of_int k
cannam@95 97 else
cannam@95 98 string_of_int k
cannam@95 99
cannam@95 100 let unparse = function
cannam@95 101 | Temporary k -> "T" ^ (varname_of_int k)
cannam@95 102 | Constant (_, name) -> name
cannam@95 103 | Locative (_, _, name, i, _) -> name i
cannam@95 104
cannam@95 105 let unparse_for_alignment m = function
cannam@95 106 | Locative (_, _, name, i, _) -> name (i mod m)
cannam@95 107 | _ -> failwith "unparse_for_alignment"
cannam@95 108