annotate src/fftw-3.3.8/genfft/gen_twiddle_c.ml @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents d0c2a83c1364
children
rev   line source
Chris@82 1 (*
Chris@82 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
Chris@82 3 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@82 4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@82 5 *
Chris@82 6 * This program is free software; you can redistribute it and/or modify
Chris@82 7 * it under the terms of the GNU General Public License as published by
Chris@82 8 * the Free Software Foundation; either version 2 of the License, or
Chris@82 9 * (at your option) any later version.
Chris@82 10 *
Chris@82 11 * This program is distributed in the hope that it will be useful,
Chris@82 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@82 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@82 14 * GNU General Public License for more details.
Chris@82 15 *
Chris@82 16 * You should have received a copy of the GNU General Public License
Chris@82 17 * along with this program; if not, write to the Free Software
Chris@82 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@82 19 *
Chris@82 20 *)
Chris@82 21
Chris@82 22 open Util
Chris@82 23 open Genutil
Chris@82 24 open C
Chris@82 25
Chris@82 26
Chris@82 27 type ditdif = DIT | DIF
Chris@82 28 let ditdif = ref DIT
Chris@82 29 let usage = "Usage: " ^ Sys.argv.(0) ^ " -n <number> [ -dit | -dif ]"
Chris@82 30
Chris@82 31 let urs = ref Stride_variable
Chris@82 32 let ums = ref Stride_variable
Chris@82 33
Chris@82 34 let speclist = [
Chris@82 35 "-dit",
Chris@82 36 Arg.Unit(fun () -> ditdif := DIT),
Chris@82 37 " generate a DIT codelet";
Chris@82 38
Chris@82 39 "-dif",
Chris@82 40 Arg.Unit(fun () -> ditdif := DIF),
Chris@82 41 " generate a DIF codelet";
Chris@82 42
Chris@82 43 "-with-rs",
Chris@82 44 Arg.String(fun x -> urs := arg_to_stride x),
Chris@82 45 " specialize for given i/o stride";
Chris@82 46
Chris@82 47 "-with-ms",
Chris@82 48 Arg.String(fun x -> ums := arg_to_stride x),
Chris@82 49 " specialize for given ms"
Chris@82 50 ]
Chris@82 51
Chris@82 52 let generate n =
Chris@82 53 let rioarray = "x"
Chris@82 54 and rs = "rs"
Chris@82 55 and twarray = "W"
Chris@82 56 and m = "m" and mb = "mb" and me = "me" and ms = "ms" in
Chris@82 57
Chris@82 58 let sign = !Genutil.sign
Chris@82 59 and name = !Magic.codelet_name
Chris@82 60 and byvl x = choose_simd x (ctimes (CVar "VL", x))
Chris@82 61 and bytwvl x = choose_simd x (ctimes (CVar "TWVL", x))
Chris@82 62 and bytwvl_vl x = choose_simd x (ctimes (CVar "(TWVL/VL)", x)) in
Chris@82 63 let ename = expand_name name in
Chris@82 64
Chris@82 65 let (bytwiddle, num_twiddles, twdesc) = Twiddle.twiddle_policy 0 true in
Chris@82 66 let nt = num_twiddles n in
Chris@82 67
Chris@82 68 let byw = bytwiddle n sign (twiddle_array nt twarray) in
Chris@82 69
Chris@82 70 let vrs = either_stride (!urs) (C.SVar rs) in
Chris@82 71 let sms = stride_to_string "ms" !ums in
Chris@82 72
Chris@82 73 let locations = unique_array_c n in
Chris@82 74 let iloc =
Chris@82 75 locative_array_c n
Chris@82 76 (C.array_subscript rioarray vrs)
Chris@82 77 (C.array_subscript "BUG" vrs)
Chris@82 78 locations sms
Chris@82 79 and oloc =
Chris@82 80 locative_array_c n
Chris@82 81 (C.array_subscript rioarray vrs)
Chris@82 82 (C.array_subscript "BUG" vrs)
Chris@82 83 locations sms
Chris@82 84 in
Chris@82 85 let liloc = load_array_r n iloc in
Chris@82 86 let fft = Trig.dft_via_rdft in
Chris@82 87 let output =
Chris@82 88 match !ditdif with
Chris@82 89 | DIT -> array n (fft sign n (byw liloc))
Chris@82 90 | DIF -> array n (byw (fft sign n liloc))
Chris@82 91 in
Chris@82 92 let odag = store_array_r n oloc output in
Chris@82 93 let annot = standard_optimizer odag in
Chris@82 94
Chris@82 95 let vm = CVar m and vmb = CVar mb and vme = CVar me in
Chris@82 96
Chris@82 97 let body = Block (
Chris@82 98 [Decl ("INT", m);
Chris@82 99 Decl (C.realtypep, rioarray)],
Chris@82 100 [Stmt_assign (CVar rioarray,
Chris@82 101 CVar (if (sign < 0) then "ri" else "ii"));
Chris@82 102 For (list_to_comma
Chris@82 103 [Expr_assign (vm, vmb);
Chris@82 104 Expr_assign (CVar twarray,
Chris@82 105 CPlus [CVar twarray;
Chris@82 106 ctimes (vmb,
Chris@82 107 bytwvl_vl (Integer nt))])],
Chris@82 108 Binop (" < ", vm, vme),
Chris@82 109 list_to_comma
Chris@82 110 [Expr_assign (vm, CPlus [vm; byvl (Integer 1)]);
Chris@82 111 Expr_assign (CVar rioarray, CPlus [CVar rioarray;
Chris@82 112 byvl (CVar sms)]);
Chris@82 113 Expr_assign (CVar twarray, CPlus [CVar twarray;
Chris@82 114 bytwvl (Integer nt)]);
Chris@82 115 make_volatile_stride n (CVar rs)
Chris@82 116 ],
Chris@82 117 Asch annot)])
Chris@82 118 in
Chris@82 119
Chris@82 120 let tree =
Chris@82 121 Fcn (((if !Magic.standalone then "" else "static ") ^ "void"),
Chris@82 122 ename,
Chris@82 123 [Decl (C.realtypep, "ri");
Chris@82 124 Decl (C.realtypep, "ii");
Chris@82 125 Decl (C.constrealtypep, twarray);
Chris@82 126 Decl (C.stridetype, rs);
Chris@82 127 Decl ("INT", mb);
Chris@82 128 Decl ("INT", me);
Chris@82 129 Decl ("INT", ms)],
Chris@82 130 finalize_fcn body)
Chris@82 131 in
Chris@82 132 let twinstr =
Chris@82 133 Printf.sprintf "static const tw_instr twinstr[] = %s;\n\n"
Chris@82 134 (twinstr_to_string "VL" (twdesc n))
Chris@82 135 and desc =
Chris@82 136 Printf.sprintf
Chris@82 137 "static const ct_desc desc = {%d, %s, twinstr, &GENUS, %s, %s, %s, %s};\n\n"
Chris@82 138 n (stringify name) (flops_of tree)
Chris@82 139 (stride_to_solverparm !urs) "0"
Chris@82 140 (stride_to_solverparm !ums)
Chris@82 141 and register =
Chris@82 142 match !ditdif with
Chris@82 143 | DIT -> "X(kdft_dit_register)"
Chris@82 144 | DIF -> "X(kdft_dif_register)"
Chris@82 145
Chris@82 146 in
Chris@82 147 let init =
Chris@82 148 "\n" ^
Chris@82 149 twinstr ^
Chris@82 150 desc ^
Chris@82 151 (declare_register_fcn name) ^
Chris@82 152 (Printf.sprintf "{\n%s(p, %s, &desc);\n}" register ename)
Chris@82 153 in
Chris@82 154
Chris@82 155 (unparse tree) ^ "\n" ^ (if !Magic.standalone then "" else init)
Chris@82 156
Chris@82 157
Chris@82 158 let main () =
Chris@82 159 begin
Chris@82 160 Simdmagic.simd_mode := true;
Chris@82 161 parse (speclist @ Twiddle.speclist) usage;
Chris@82 162 print_string (generate (check_size ()));
Chris@82 163 end
Chris@82 164
Chris@82 165 let _ = main()