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