annotate fft/fftw/fftw-3.3.4/genfft/gen_hc2cdft.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 open Util
Chris@19 23 open Genutil
Chris@19 24 open C
Chris@19 25
Chris@19 26
Chris@19 27 type ditdif = DIT | DIF
Chris@19 28 let ditdif = ref DIT
Chris@19 29 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number> [ -dit | -dif ]"
Chris@19 30
Chris@19 31 let urs = ref Stride_variable
Chris@19 32 let ums = ref Stride_variable
Chris@19 33
Chris@19 34 let speclist = [
Chris@19 35 "-dit",
Chris@19 36 Arg.Unit(fun () -> ditdif := DIT),
Chris@19 37 " generate a DIT codelet";
Chris@19 38
Chris@19 39 "-dif",
Chris@19 40 Arg.Unit(fun () -> ditdif := DIF),
Chris@19 41 " generate a DIF codelet";
Chris@19 42
Chris@19 43 "-with-rs",
Chris@19 44 Arg.String(fun x -> urs := arg_to_stride x),
Chris@19 45 " specialize for given R-stride";
Chris@19 46
Chris@19 47 "-with-ms",
Chris@19 48 Arg.String(fun x -> ums := arg_to_stride x),
Chris@19 49 " specialize for given ms"
Chris@19 50 ]
Chris@19 51
Chris@19 52 let byi = Complex.times Complex.i
Chris@19 53 let byui = Complex.times (Complex.uminus Complex.i)
Chris@19 54
Chris@19 55 let shuffle_eo fe fo i = if i mod 2 == 0 then fe (i/2) else fo ((i-1)/2)
Chris@19 56
Chris@19 57 let generate n =
Chris@19 58 let rs = "rs"
Chris@19 59 and twarray = "W"
Chris@19 60 and m = "m" and mb = "mb" and me = "me" and ms = "ms"
Chris@19 61
Chris@19 62 (* the array names are from the point of view of the complex array
Chris@19 63 (output in R2C, input in C2R) *)
Chris@19 64 and arp = "Rp" (* real, positive *)
Chris@19 65 and aip = "Ip" (* imag, positive *)
Chris@19 66 and arm = "Rm" (* real, negative *)
Chris@19 67 and aim = "Im" (* imag, negative *)
Chris@19 68
Chris@19 69 in
Chris@19 70
Chris@19 71 let sign = !Genutil.sign
Chris@19 72 and name = !Magic.codelet_name
Chris@19 73 and byvl x = choose_simd x (ctimes (CVar "VL", x)) in
Chris@19 74
Chris@19 75 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 1 false in
Chris@19 76 let nt = num_twiddles n in
Chris@19 77
Chris@19 78 let byw = bytwiddle n sign (twiddle_array nt twarray) in
Chris@19 79
Chris@19 80 let vrs = either_stride (!urs) (C.SVar rs) in
Chris@19 81
Chris@19 82 (* assume a single location. No point in doing alias analysis *)
Chris@19 83 let the_location = (Unique.make (), Unique.make ()) in
Chris@19 84 let locations _ = the_location in
Chris@19 85
Chris@19 86 let rlocp = (locative_array_c n
Chris@19 87 (C.array_subscript arp vrs)
Chris@19 88 (C.array_subscript aip vrs)
Chris@19 89 locations "BUG")
Chris@19 90 and rlocm = (locative_array_c n
Chris@19 91 (C.array_subscript arm vrs)
Chris@19 92 (C.array_subscript aim vrs)
Chris@19 93 locations "BUG")
Chris@19 94 and clocp = (locative_array_c n
Chris@19 95 (C.array_subscript arp vrs)
Chris@19 96 (C.array_subscript aip vrs)
Chris@19 97 locations "BUG")
Chris@19 98 and clocm = (locative_array_c n
Chris@19 99 (C.array_subscript arm vrs)
Chris@19 100 (C.array_subscript aim vrs)
Chris@19 101 locations "BUG")
Chris@19 102 in
Chris@19 103 let rloc i = if i mod 2 == 0 then rlocp (i/2) else rlocm ((i-1)/2)
Chris@19 104 and cloc i = if i < n - i then clocp i else clocm (n-1-i)
Chris@19 105 and sym n f i = if (i < n - i) then f i else Complex.conj (f i)
Chris@19 106 and sym1 f i =
Chris@19 107 if i mod 2 == 0 then
Chris@19 108 Complex.plus [f i; Complex.conj (f (i+1))]
Chris@19 109 else
Chris@19 110 Complex.times (Complex.uminus Complex.i)
Chris@19 111 (Complex.plus [f (i-1); Complex.uminus (Complex.conj (f i))])
Chris@19 112 and sym1i f i =
Chris@19 113 if i mod 2 == 0 then
Chris@19 114 Complex.plus [f i; Complex.times Complex.i (f (i+1))]
Chris@19 115 else
Chris@19 116 Complex.conj
Chris@19 117 (Complex.plus [f (i-1);
Chris@19 118 Complex.times (Complex.uminus Complex.i) (f i)])
Chris@19 119 in
Chris@19 120
Chris@19 121 let asch =
Chris@19 122 match !ditdif with
Chris@19 123 | DIT ->
Chris@19 124 let output =
Chris@19 125 (Complex.times Complex.half) @@
Chris@19 126 (Fft.dft sign n (byw (sym1 (load_array_c n rloc)))) in
Chris@19 127 let odag = store_array_c n cloc (sym n output) in
Chris@19 128 standard_optimizer odag
Chris@19 129
Chris@19 130 | DIF ->
Chris@19 131 let output =
Chris@19 132 byw (Fft.dft sign n (sym n (load_array_c n cloc)))
Chris@19 133 in
Chris@19 134 let odag = store_array_c n rloc (sym1i output) in
Chris@19 135 standard_optimizer odag
Chris@19 136 in
Chris@19 137
Chris@19 138 let vms = CVar "ms"
Chris@19 139 and varp = CVar arp
Chris@19 140 and vaip = CVar aip
Chris@19 141 and varm = CVar arm
Chris@19 142 and vaim = CVar aim
Chris@19 143 and vm = CVar m and vmb = CVar mb and vme = CVar me
Chris@19 144 in
Chris@19 145 let body = Block (
Chris@19 146 [Decl ("INT", m)],
Chris@19 147 [For (list_to_comma
Chris@19 148 [Expr_assign (vm, vmb);
Chris@19 149 Expr_assign (CVar twarray,
Chris@19 150 CPlus [CVar twarray;
Chris@19 151 ctimes (CPlus [vmb; CUminus (Integer 1)],
Chris@19 152 Integer nt)])],
Chris@19 153 Binop (" < ", vm, vme),
Chris@19 154 list_to_comma
Chris@19 155 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]);
Chris@19 156 Expr_assign (varp, CPlus [varp; byvl vms]);
Chris@19 157 Expr_assign (vaip, CPlus [vaip; byvl vms]);
Chris@19 158 Expr_assign (varm, CPlus [varm; CUminus (byvl vms)]);
Chris@19 159 Expr_assign (vaim, CPlus [vaim; CUminus (byvl vms)]);
Chris@19 160 Expr_assign (CVar twarray, CPlus [CVar twarray;
Chris@19 161 byvl (Integer nt)]);
Chris@19 162 make_volatile_stride (4*n) (CVar rs)
Chris@19 163 ],
Chris@19 164 Asch asch)]
Chris@19 165 )
Chris@19 166 in
Chris@19 167
Chris@19 168 let tree =
Chris@19 169 Fcn ("static void", name,
Chris@19 170 [Decl (C.realtypep, arp);
Chris@19 171 Decl (C.realtypep, aip);
Chris@19 172 Decl (C.realtypep, arm);
Chris@19 173 Decl (C.realtypep, aim);
Chris@19 174 Decl (C.constrealtypep, twarray);
Chris@19 175 Decl (C.stridetype, rs);
Chris@19 176 Decl ("INT", mb);
Chris@19 177 Decl ("INT", me);
Chris@19 178 Decl ("INT", ms)],
Chris@19 179 finalize_fcn body)
Chris@19 180 in
Chris@19 181 let twinstr =
Chris@19 182 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n"
Chris@19 183 (twinstr_to_string "VL" (twdesc n))
Chris@19 184 and desc =
Chris@19 185 Printf.sprintf
Chris@19 186 "static const hc2c_desc desc = {%d, \"%s\", twinstr, &GENUS, %s};\n\n"
Chris@19 187 n name (flops_of tree)
Chris@19 188 and register = "X(khc2c_register)"
Chris@19 189
Chris@19 190 in
Chris@19 191 let init =
Chris@19 192 "\n" ^
Chris@19 193 twinstr ^
Chris@19 194 desc ^
Chris@19 195 (declare_register_fcn name) ^
Chris@19 196 (Printf.sprintf "{\n%s(p, %s, &desc, HC2C_VIA_DFT);\n}" register name)
Chris@19 197 in
Chris@19 198
Chris@19 199 (unparse tree) ^ "\n" ^ init
Chris@19 200
Chris@19 201
Chris@19 202 let main () =
Chris@19 203 begin
Chris@19 204 parse (speclist @ Twiddle.speclist) usage;
Chris@19 205 print_string (generate (check_size ()));
Chris@19 206 end
Chris@19 207
Chris@19 208 let _ = main()