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