annotate src/fftw-3.3.5/genfft/simd.ml @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 (*
Chris@42 2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
Chris@42 3 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 5 *
Chris@42 6 * This program is free software; you can redistribute it and/or modify
Chris@42 7 * it under the terms of the GNU General Public License as published by
Chris@42 8 * the Free Software Foundation; either version 2 of the License, or
Chris@42 9 * (at your option) any later version.
Chris@42 10 *
Chris@42 11 * This program is distributed in the hope that it will be useful,
Chris@42 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 14 * GNU General Public License for more details.
Chris@42 15 *
Chris@42 16 * You should have received a copy of the GNU General Public License
Chris@42 17 * along with this program; if not, write to the Free Software
Chris@42 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 19 *
Chris@42 20 *)
Chris@42 21
Chris@42 22 open Expr
Chris@42 23 open List
Chris@42 24 open Printf
Chris@42 25 open Variable
Chris@42 26 open Annotate
Chris@42 27 open Simdmagic
Chris@42 28 open C
Chris@42 29
Chris@42 30 let realtype = "V"
Chris@42 31 let realtypep = realtype ^ " *"
Chris@42 32 let constrealtype = "const " ^ realtype
Chris@42 33 let constrealtypep = constrealtype ^ " *"
Chris@42 34 let alignment_mod = 2
Chris@42 35
Chris@42 36 (*
Chris@42 37 * SIMD C AST unparser
Chris@42 38 *)
Chris@42 39 let foldr_string_concat l = fold_right (^) l ""
Chris@42 40
Chris@42 41 let rec unparse_by_twiddle nam tw src =
Chris@42 42 sprintf "%s(&(%s),%s)" nam (Variable.unparse tw) (unparse_expr src)
Chris@42 43
Chris@42 44 and unparse_store dst = function
Chris@42 45 | Times (NaN MULTI_A, x) ->
Chris@42 46 sprintf "STM%d(&(%s),%s,%s,&(%s));\n"
Chris@42 47 !Simdmagic.store_multiple
Chris@42 48 (Variable.unparse dst) (unparse_expr x)
Chris@42 49 (Variable.vstride_of_locative dst)
Chris@42 50 (Variable.unparse_for_alignment alignment_mod dst)
Chris@42 51 | Times (NaN MULTI_B, Plus stuff) ->
Chris@42 52 sprintf "STN%d(&(%s)%s,%s);\n"
Chris@42 53 !Simdmagic.store_multiple
Chris@42 54 (Variable.unparse dst)
Chris@42 55 (List.fold_right (fun x a -> "," ^ (unparse_expr x) ^ a) stuff "")
Chris@42 56 (Variable.vstride_of_locative dst)
Chris@42 57 | src_expr ->
Chris@42 58 sprintf "ST(&(%s),%s,%s,&(%s));\n"
Chris@42 59 (Variable.unparse dst) (unparse_expr src_expr)
Chris@42 60 (Variable.vstride_of_locative dst)
Chris@42 61 (Variable.unparse_for_alignment alignment_mod dst)
Chris@42 62
Chris@42 63 and unparse_expr =
Chris@42 64 let rec unparse_plus = function
Chris@42 65 | [a] -> unparse_expr a
Chris@42 66
Chris@42 67 | (Uminus (Times (NaN I, b))) :: c :: d -> op2 "VFNMSI" [b] (c :: d)
Chris@42 68 | c :: (Uminus (Times (NaN I, b))) :: d -> op2 "VFNMSI" [b] (c :: d)
Chris@42 69 | (Uminus (Times (NaN CONJ, b))) :: c :: d -> op2 "VFNMSCONJ" [b] (c :: d)
Chris@42 70 | c :: (Uminus (Times (NaN CONJ, b))) :: d -> op2 "VFNMSCONJ" [b] (c :: d)
Chris@42 71 | (Times (NaN I, b)) :: c :: d -> op2 "VFMAI" [b] (c :: d)
Chris@42 72 | c :: (Times (NaN I, b)) :: d -> op2 "VFMAI" [b] (c :: d)
Chris@42 73 | (Times (NaN CONJ, b)) :: (Uminus c) :: d -> op2 "VFMSCONJ" [b] (c :: d)
Chris@42 74 | (Uminus c) :: (Times (NaN CONJ, b)) :: d -> op2 "VFMSCONJ" [b] (c :: d)
Chris@42 75 | (Times (NaN CONJ, b)) :: c :: d -> op2 "VFMACONJ" [b] (c :: d)
Chris@42 76 | c :: (Times (NaN CONJ, b)) :: d -> op2 "VFMACONJ" [b] (c :: d)
Chris@42 77 | (Times (NaN _, b)) :: (Uminus c) :: d -> failwith "VFMS NaN"
Chris@42 78 | (Uminus c) :: (Times (NaN _, b)) :: d -> failwith "VFMS NaN"
Chris@42 79
Chris@42 80 | (Uminus (Times (a, b))) :: c :: d -> op3 "VFNMS" a b (c :: d)
Chris@42 81 | c :: (Uminus (Times (a, b))) :: d -> op3 "VFNMS" a b (c :: d)
Chris@42 82 | (Times (a, b)) :: (Uminus c) :: d -> op3 "VFMS" a b (c :: negate d)
Chris@42 83 | (Uminus c) :: (Times (a, b)) :: d -> op3 "VFMS" a b (c :: negate d)
Chris@42 84 | (Times (a, b)) :: c :: d -> op3 "VFMA" a b (c :: d)
Chris@42 85 | c :: (Times (a, b)) :: d -> op3 "VFMA" a b (c :: d)
Chris@42 86
Chris@42 87 | (Uminus a :: b) -> op2 "VSUB" b [a]
Chris@42 88 | (b :: Uminus a :: c) -> op2 "VSUB" (b :: c) [a]
Chris@42 89 | (a :: b) -> op2 "VADD" [a] b
Chris@42 90 | [] -> failwith "unparse_plus"
Chris@42 91 and op3 nam a b c =
Chris@42 92 nam ^ "(" ^ (unparse_expr a) ^ ", " ^ (unparse_expr b) ^ ", " ^
Chris@42 93 (unparse_plus c) ^ ")"
Chris@42 94 and op2 nam a b =
Chris@42 95 nam ^ "(" ^ (unparse_plus a) ^ ", " ^ (unparse_plus b) ^ ")"
Chris@42 96 and op1 nam a =
Chris@42 97 nam ^ "(" ^ (unparse_expr a) ^ ")"
Chris@42 98 and negate = function
Chris@42 99 | [] -> []
Chris@42 100 | (Uminus x) :: y -> x :: negate y
Chris@42 101 | x :: y -> (Uminus x) :: negate y
Chris@42 102
Chris@42 103 in function
Chris@42 104 | CTimes(Load tw, src)
Chris@42 105 when Variable.is_constant tw && !Magic.generate_bytw ->
Chris@42 106 unparse_by_twiddle "BYTW" tw src
Chris@42 107 | CTimesJ(Load tw, src)
Chris@42 108 when Variable.is_constant tw && !Magic.generate_bytw ->
Chris@42 109 unparse_by_twiddle "BYTWJ" tw src
Chris@42 110 | Load v when is_locative(v) ->
Chris@42 111 sprintf "LD(&(%s), %s, &(%s))" (Variable.unparse v)
Chris@42 112 (Variable.vstride_of_locative v)
Chris@42 113 (Variable.unparse_for_alignment alignment_mod v)
Chris@42 114 | Load v when is_constant(v) -> sprintf "LDW(&(%s))" (Variable.unparse v)
Chris@42 115 | Load v -> Variable.unparse v
Chris@42 116 | Num n -> sprintf "LDK(%s)" (Number.to_konst n)
Chris@42 117 | NaN n -> failwith "NaN in unparse_expr"
Chris@42 118 | Plus [] -> "0.0 /* bug */"
Chris@42 119 | Plus [a] -> " /* bug */ " ^ (unparse_expr a)
Chris@42 120 | Plus a -> unparse_plus a
Chris@42 121 | Times(NaN I,b) -> op1 "VBYI" b
Chris@42 122 | Times(NaN CONJ,b) -> op1 "VCONJ" b
Chris@42 123 | Times(a,b) ->
Chris@42 124 sprintf "VMUL(%s, %s)" (unparse_expr a) (unparse_expr b)
Chris@42 125 | CTimes(a,Times(NaN I, b)) ->
Chris@42 126 sprintf "VZMULI(%s, %s)" (unparse_expr a) (unparse_expr b)
Chris@42 127 | CTimes(a,b) ->
Chris@42 128 sprintf "VZMUL(%s, %s)" (unparse_expr a) (unparse_expr b)
Chris@42 129 | CTimesJ(a,Times(NaN I, b)) ->
Chris@42 130 sprintf "VZMULIJ(%s, %s)" (unparse_expr a) (unparse_expr b)
Chris@42 131 | CTimesJ(a,b) ->
Chris@42 132 sprintf "VZMULJ(%s, %s)" (unparse_expr a) (unparse_expr b)
Chris@42 133 | Uminus a when !Magic.vneg -> op1 "VNEG" a
Chris@42 134 | Uminus a -> failwith "SIMD Uminus"
Chris@42 135 | _ -> failwith "unparse_expr"
Chris@42 136
Chris@42 137 and unparse_decl x = C.unparse_decl x
Chris@42 138
Chris@42 139 and unparse_ast ast =
Chris@42 140 let rec unparse_assignment = function
Chris@42 141 | Assign (v, x) when Variable.is_locative v ->
Chris@42 142 unparse_store v x
Chris@42 143 | Assign (v, x) ->
Chris@42 144 (Variable.unparse v) ^ " = " ^ (unparse_expr x) ^ ";\n"
Chris@42 145
Chris@42 146 and unparse_annotated force_bracket =
Chris@42 147 let rec unparse_code = function
Chris@42 148 | ADone -> ""
Chris@42 149 | AInstr i -> unparse_assignment i
Chris@42 150 | ASeq (a, b) ->
Chris@42 151 (unparse_annotated false a) ^ (unparse_annotated false b)
Chris@42 152 and declare_variables l =
Chris@42 153 let rec uvar = function
Chris@42 154 [] -> failwith "uvar"
Chris@42 155 | [v] -> (Variable.unparse v) ^ ";\n"
Chris@42 156 | a :: b -> (Variable.unparse a) ^ ", " ^ (uvar b)
Chris@42 157 in let rec vvar l =
Chris@42 158 let s = if !Magic.compact then 15 else 1 in
Chris@42 159 if (List.length l <= s) then
Chris@42 160 match l with
Chris@42 161 [] -> ""
Chris@42 162 | _ -> realtype ^ " " ^ (uvar l)
Chris@42 163 else
Chris@42 164 (vvar (Util.take s l)) ^ (vvar (Util.drop s l))
Chris@42 165 in vvar (List.filter Variable.is_temporary l)
Chris@42 166 in function
Chris@42 167 Annotate (_, _, decl, _, code) ->
Chris@42 168 if (not force_bracket) && (Util.null decl) then
Chris@42 169 unparse_code code
Chris@42 170 else "{\n" ^
Chris@42 171 (declare_variables decl) ^
Chris@42 172 (unparse_code code) ^
Chris@42 173 "}\n"
Chris@42 174
Chris@42 175 (* ---- *)
Chris@42 176 and unparse_plus = function
Chris@42 177 | [] -> ""
Chris@42 178 | (CUminus a :: b) -> " - " ^ (parenthesize a) ^ (unparse_plus b)
Chris@42 179 | (a :: b) -> " + " ^ (parenthesize a) ^ (unparse_plus b)
Chris@42 180 and parenthesize x = match x with
Chris@42 181 | (CVar _) -> unparse_ast x
Chris@42 182 | (CCall _) -> unparse_ast x
Chris@42 183 | (Integer _) -> unparse_ast x
Chris@42 184 | _ -> "(" ^ (unparse_ast x) ^ ")"
Chris@42 185
Chris@42 186 in match ast with
Chris@42 187 | Asch a -> (unparse_annotated true a)
Chris@42 188 | Return x -> "return " ^ unparse_ast x ^ ";"
Chris@42 189 | Simd_leavefun -> "VLEAVE();"
Chris@42 190 | For (a, b, c, d) ->
Chris@42 191 "for (" ^
Chris@42 192 unparse_ast a ^ "; " ^ unparse_ast b ^ "; " ^ unparse_ast c
Chris@42 193 ^ ")" ^ unparse_ast d
Chris@42 194 | If (a, d) ->
Chris@42 195 "if (" ^
Chris@42 196 unparse_ast a
Chris@42 197 ^ ")" ^ unparse_ast d
Chris@42 198 | Block (d, s) ->
Chris@42 199 if (s == []) then ""
Chris@42 200 else
Chris@42 201 "{\n" ^
Chris@42 202 foldr_string_concat (map unparse_decl d) ^
Chris@42 203 foldr_string_concat (map unparse_ast s) ^
Chris@42 204 "}\n"
Chris@42 205 | x -> C.unparse_ast x
Chris@42 206
Chris@42 207 and unparse_function = function
Chris@42 208 Fcn (typ, name, args, body) ->
Chris@42 209 let rec unparse_args = function
Chris@42 210 [Decl (a, b)] -> a ^ " " ^ b
Chris@42 211 | (Decl (a, b)) :: s -> a ^ " " ^ b ^ ", "
Chris@42 212 ^ unparse_args s
Chris@42 213 | [] -> ""
Chris@42 214 | _ -> failwith "unparse_function"
Chris@42 215 in
Chris@42 216 (typ ^ " " ^ name ^ "(" ^ unparse_args args ^ ")\n" ^
Chris@42 217 unparse_ast body)
Chris@42 218
Chris@42 219 let extract_constants f =
Chris@42 220 let constlist = flatten (map expr_to_constants (C.ast_to_expr_list f))
Chris@42 221 in map
Chris@42 222 (fun n ->
Chris@42 223 Tdecl
Chris@42 224 ("DVK(" ^ (Number.to_konst n) ^ ", " ^ (Number.to_string n) ^
Chris@42 225 ");\n"))
Chris@42 226 (unique_constants constlist)