annotate src/fftw-3.3.8/genfft/gen_hc2cdft.ml @ 168:ceec0dd9ec9c

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