annotate src/fftw-3.3.3/genfft/gen_hc2cdft.ml @ 23:619f715526df sv_v2.1

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