annotate fft/fftw/fftw-3.3.4/genfft/variable.ml @ 40:223f770b5341 kissfft-double tip

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