annotate src/fftw-3.3.5/genfft/gen_hc2cdft.ml @ 56:af97cad61ff0

Add updated build of PortAudio for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 03 Jan 2017 15:10:52 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 (*
Chris@42 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
Chris@42 3 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 5 *
Chris@42 6 * This program is free software; you can redistribute it and/or modify
Chris@42 7 * it under the terms of the GNU General Public License as published by
Chris@42 8 * the Free Software Foundation; either version 2 of the License, or
Chris@42 9 * (at your option) any later version.
Chris@42 10 *
Chris@42 11 * This program is distributed in the hope that it will be useful,
Chris@42 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 14 * GNU General Public License for more details.
Chris@42 15 *
Chris@42 16 * You should have received a copy of the GNU General Public License
Chris@42 17 * along with this program; if not, write to the Free Software
Chris@42 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 19 *
Chris@42 20 *)
Chris@42 21
Chris@42 22 open Util
Chris@42 23 open Genutil
Chris@42 24 open C
Chris@42 25
Chris@42 26
Chris@42 27 type ditdif = DIT | DIF
Chris@42 28 let ditdif = ref DIT
Chris@42 29 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number> [ -dit | -dif ]"
Chris@42 30
Chris@42 31 let urs = ref Stride_variable
Chris@42 32 let ums = ref Stride_variable
Chris@42 33
Chris@42 34 let speclist = [
Chris@42 35 "-dit",
Chris@42 36 Arg.Unit(fun () -> ditdif := DIT),
Chris@42 37 " generate a DIT codelet";
Chris@42 38
Chris@42 39 "-dif",
Chris@42 40 Arg.Unit(fun () -> ditdif := DIF),
Chris@42 41 " generate a DIF codelet";
Chris@42 42
Chris@42 43 "-with-rs",
Chris@42 44 Arg.String(fun x -> urs := arg_to_stride x),
Chris@42 45 " specialize for given R-stride";
Chris@42 46
Chris@42 47 "-with-ms",
Chris@42 48 Arg.String(fun x -> ums := arg_to_stride x),
Chris@42 49 " specialize for given ms"
Chris@42 50 ]
Chris@42 51
Chris@42 52 let byi = Complex.times Complex.i
Chris@42 53 let byui = Complex.times (Complex.uminus Complex.i)
Chris@42 54
Chris@42 55 let shuffle_eo fe fo i = if i mod 2 == 0 then fe (i/2) else fo ((i-1)/2)
Chris@42 56
Chris@42 57 let generate n =
Chris@42 58 let rs = "rs"
Chris@42 59 and twarray = "W"
Chris@42 60 and m = "m" and mb = "mb" and me = "me" and ms = "ms"
Chris@42 61
Chris@42 62 (* the array names are from the point of view of the complex array
Chris@42 63 (output in R2C, input in C2R) *)
Chris@42 64 and arp = "Rp" (* real, positive *)
Chris@42 65 and aip = "Ip" (* imag, positive *)
Chris@42 66 and arm = "Rm" (* real, negative *)
Chris@42 67 and aim = "Im" (* imag, negative *)
Chris@42 68
Chris@42 69 in
Chris@42 70
Chris@42 71 let sign = !Genutil.sign
Chris@42 72 and name = !Magic.codelet_name
Chris@42 73 and byvl x = choose_simd x (ctimes (CVar "VL", x)) in
Chris@42 74
Chris@42 75 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 1 false in
Chris@42 76 let nt = num_twiddles n in
Chris@42 77
Chris@42 78 let byw = bytwiddle n sign (twiddle_array nt twarray) in
Chris@42 79
Chris@42 80 let vrs = either_stride (!urs) (C.SVar rs) in
Chris@42 81
Chris@42 82 (* assume a single location. No point in doing alias analysis *)
Chris@42 83 let the_location = (Unique.make (), Unique.make ()) in
Chris@42 84 let locations _ = the_location in
Chris@42 85
Chris@42 86 let rlocp = (locative_array_c n
Chris@42 87 (C.array_subscript arp vrs)
Chris@42 88 (C.array_subscript aip vrs)
Chris@42 89 locations "BUG")
Chris@42 90 and rlocm = (locative_array_c n
Chris@42 91 (C.array_subscript arm vrs)
Chris@42 92 (C.array_subscript aim vrs)
Chris@42 93 locations "BUG")
Chris@42 94 and clocp = (locative_array_c n
Chris@42 95 (C.array_subscript arp vrs)
Chris@42 96 (C.array_subscript aip vrs)
Chris@42 97 locations "BUG")
Chris@42 98 and clocm = (locative_array_c n
Chris@42 99 (C.array_subscript arm vrs)
Chris@42 100 (C.array_subscript aim vrs)
Chris@42 101 locations "BUG")
Chris@42 102 in
Chris@42 103 let rloc i = if i mod 2 == 0 then rlocp (i/2) else rlocm ((i-1)/2)
Chris@42 104 and cloc i = if i < n - i then clocp i else clocm (n-1-i)
Chris@42 105 and sym n f i = if (i < n - i) then f i else Complex.conj (f i)
Chris@42 106 and sym1 f i =
Chris@42 107 if i mod 2 == 0 then
Chris@42 108 Complex.plus [f i; Complex.conj (f (i+1))]
Chris@42 109 else
Chris@42 110 Complex.times (Complex.uminus Complex.i)
Chris@42 111 (Complex.plus [f (i-1); Complex.uminus (Complex.conj (f i))])
Chris@42 112 and sym1i f i =
Chris@42 113 if i mod 2 == 0 then
Chris@42 114 Complex.plus [f i; Complex.times Complex.i (f (i+1))]
Chris@42 115 else
Chris@42 116 Complex.conj
Chris@42 117 (Complex.plus [f (i-1);
Chris@42 118 Complex.times (Complex.uminus Complex.i) (f i)])
Chris@42 119 in
Chris@42 120
Chris@42 121 let asch =
Chris@42 122 match !ditdif with
Chris@42 123 | DIT ->
Chris@42 124 let output =
Chris@42 125 (Complex.times Complex.half) @@
Chris@42 126 (Fft.dft sign n (byw (sym1 (load_array_c n rloc)))) in
Chris@42 127 let odag = store_array_c n cloc (sym n output) in
Chris@42 128 standard_optimizer odag
Chris@42 129
Chris@42 130 | DIF ->
Chris@42 131 let output =
Chris@42 132 byw (Fft.dft sign n (sym n (load_array_c n cloc)))
Chris@42 133 in
Chris@42 134 let odag = store_array_c n rloc (sym1i output) in
Chris@42 135 standard_optimizer odag
Chris@42 136 in
Chris@42 137
Chris@42 138 let vms = CVar "ms"
Chris@42 139 and varp = CVar arp
Chris@42 140 and vaip = CVar aip
Chris@42 141 and varm = CVar arm
Chris@42 142 and vaim = CVar aim
Chris@42 143 and vm = CVar m and vmb = CVar mb and vme = CVar me
Chris@42 144 in
Chris@42 145 let body = Block (
Chris@42 146 [Decl ("INT", m)],
Chris@42 147 [For (list_to_comma
Chris@42 148 [Expr_assign (vm, vmb);
Chris@42 149 Expr_assign (CVar twarray,
Chris@42 150 CPlus [CVar twarray;
Chris@42 151 ctimes (CPlus [vmb; CUminus (Integer 1)],
Chris@42 152 Integer nt)])],
Chris@42 153 Binop (" < ", vm, vme),
Chris@42 154 list_to_comma
Chris@42 155 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]);
Chris@42 156 Expr_assign (varp, CPlus [varp; byvl vms]);
Chris@42 157 Expr_assign (vaip, CPlus [vaip; byvl vms]);
Chris@42 158 Expr_assign (varm, CPlus [varm; CUminus (byvl vms)]);
Chris@42 159 Expr_assign (vaim, CPlus [vaim; CUminus (byvl vms)]);
Chris@42 160 Expr_assign (CVar twarray, CPlus [CVar twarray;
Chris@42 161 byvl (Integer nt)]);
Chris@42 162 make_volatile_stride (4*n) (CVar rs)
Chris@42 163 ],
Chris@42 164 Asch asch)]
Chris@42 165 )
Chris@42 166 in
Chris@42 167
Chris@42 168 let tree =
Chris@42 169 Fcn ("static void", name,
Chris@42 170 [Decl (C.realtypep, arp);
Chris@42 171 Decl (C.realtypep, aip);
Chris@42 172 Decl (C.realtypep, arm);
Chris@42 173 Decl (C.realtypep, aim);
Chris@42 174 Decl (C.constrealtypep, twarray);
Chris@42 175 Decl (C.stridetype, rs);
Chris@42 176 Decl ("INT", mb);
Chris@42 177 Decl ("INT", me);
Chris@42 178 Decl ("INT", ms)],
Chris@42 179 finalize_fcn body)
Chris@42 180 in
Chris@42 181 let twinstr =
Chris@42 182 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n"
Chris@42 183 (twinstr_to_string "VL" (twdesc n))
Chris@42 184 and desc =
Chris@42 185 Printf.sprintf
Chris@42 186 "static const hc2c_desc desc = {%d, \"%s\", twinstr, &GENUS, %s};\n\n"
Chris@42 187 n name (flops_of tree)
Chris@42 188 and register = "X(khc2c_register)"
Chris@42 189
Chris@42 190 in
Chris@42 191 let init =
Chris@42 192 "\n" ^
Chris@42 193 twinstr ^
Chris@42 194 desc ^
Chris@42 195 (declare_register_fcn name) ^
Chris@42 196 (Printf.sprintf "{\n%s(p, %s, &desc, HC2C_VIA_DFT);\n}" register name)
Chris@42 197 in
Chris@42 198
Chris@42 199 (unparse tree) ^ "\n" ^ init
Chris@42 200
Chris@42 201
Chris@42 202 let main () =
Chris@42 203 begin
Chris@42 204 parse (speclist @ Twiddle.speclist) usage;
Chris@42 205 print_string (generate (check_size ()));
Chris@42 206 end
Chris@42 207
Chris@42 208 let _ = main()