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