annotate src/fftw-3.3.5/genfft/gen_hc2cdft_c.ml @ 148:b4bfdf10c4b3

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