Mercurial > hg > CbC > CbC_gcc
annotate gcc/config/arm/neon-testgen.ml @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
rev | line source |
---|---|
0 | 1 (* Auto-generate ARM Neon intrinsics tests. |
2 Copyright (C) 2006, 2007 Free Software Foundation, Inc. | |
3 Contributed by CodeSourcery. | |
4 | |
5 This file is part of GCC. | |
6 | |
7 GCC is free software; you can redistribute it and/or modify it under | |
8 the terms of the GNU General Public License as published by the Free | |
9 Software Foundation; either version 3, or (at your option) any later | |
10 version. | |
11 | |
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GCC; see the file COPYING3. If not see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 This is an O'Caml program. The O'Caml compiler is available from: | |
22 | |
23 http://caml.inria.fr/ | |
24 | |
25 Or from your favourite OS's friendly packaging system. Tested with version | |
26 3.09.2, though other versions will probably work too. | |
27 | |
28 Compile with: | |
29 ocamlc -c neon.ml | |
30 ocamlc -o neon-testgen neon.cmo neon-testgen.ml | |
31 | |
32 Run with: | |
33 cd /path/to/gcc/testsuite/gcc.target/arm/neon | |
34 /path/to/neon-testgen | |
35 *) | |
36 | |
37 open Neon | |
38 | |
39 type c_type_flags = Pointer | Const | |
40 | |
41 (* Open a test source file. *) | |
42 let open_test_file dir name = | |
43 try | |
44 open_out (dir ^ "/" ^ name ^ ".c") | |
45 with Sys_error str -> | |
46 failwith ("Could not create test source file " ^ name ^ ": " ^ str) | |
47 | |
48 (* Emit prologue code to a test source file. *) | |
49 let emit_prologue chan test_name = | |
50 Printf.fprintf chan "/* Test the `%s' ARM Neon intrinsic. */\n" test_name; | |
51 Printf.fprintf chan "/* This file was autogenerated by neon-testgen. */\n\n"; | |
52 Printf.fprintf chan "/* { dg-do assemble } */\n"; | |
53 Printf.fprintf chan "/* { dg-require-effective-target arm_neon_ok } */\n"; | |
54 Printf.fprintf chan | |
55 "/* { dg-options \"-save-temps -O0 -mfpu=neon -mfloat-abi=softfp\" } */\n"; | |
56 Printf.fprintf chan "\n#include \"arm_neon.h\"\n\n"; | |
57 Printf.fprintf chan "void test_%s (void)\n{\n" test_name | |
58 | |
59 (* Emit declarations of local variables that are going to be passed | |
60 to an intrinsic, together with one to take a returned value if needed. *) | |
61 let emit_automatics chan c_types = | |
62 let emit () = | |
63 ignore ( | |
64 List.fold_left (fun arg_number -> fun (flags, ty) -> | |
65 let pointer_bit = | |
66 if List.mem Pointer flags then "*" else "" | |
67 in | |
68 (* Const arguments to builtins are directly | |
69 written in as constants. *) | |
70 if not (List.mem Const flags) then | |
71 Printf.fprintf chan " %s %sarg%d_%s;\n" | |
72 ty pointer_bit arg_number ty; | |
73 arg_number + 1) | |
74 0 (List.tl c_types)) | |
75 in | |
76 match c_types with | |
77 (_, return_ty) :: tys -> | |
78 if return_ty <> "void" then | |
79 (* The intrinsic returns a value. *) | |
80 (Printf.fprintf chan " %s out_%s;\n" return_ty return_ty; | |
81 emit ()) | |
82 else | |
83 (* The intrinsic does not return a value. *) | |
84 emit () | |
85 | _ -> assert false | |
86 | |
87 (* Emit code to call an intrinsic. *) | |
88 let emit_call chan const_valuator c_types name elt_ty = | |
89 (if snd (List.hd c_types) <> "void" then | |
90 Printf.fprintf chan " out_%s = " (snd (List.hd c_types)) | |
91 else | |
92 Printf.fprintf chan " "); | |
93 Printf.fprintf chan "%s_%s (" (intrinsic_name name) (string_of_elt elt_ty); | |
94 let print_arg chan arg_number (flags, ty) = | |
95 (* If the argument is of const type, then directly write in the | |
96 constant now. *) | |
97 if List.mem Const flags then | |
98 match const_valuator with | |
99 None -> | |
100 if List.mem Pointer flags then | |
101 Printf.fprintf chan "0" | |
102 else | |
103 Printf.fprintf chan "1" | |
104 | Some f -> Printf.fprintf chan "%s" (string_of_int (f arg_number)) | |
105 else | |
106 Printf.fprintf chan "arg%d_%s" arg_number ty | |
107 in | |
108 let rec print_args arg_number tys = | |
109 match tys with | |
110 [] -> () | |
111 | [ty] -> print_arg chan arg_number ty | |
112 | ty::tys -> | |
113 print_arg chan arg_number ty; | |
114 Printf.fprintf chan ", "; | |
115 print_args (arg_number + 1) tys | |
116 in | |
117 print_args 0 (List.tl c_types); | |
118 Printf.fprintf chan ");\n" | |
119 | |
120 (* Emit epilogue code to a test source file. *) | |
121 let emit_epilogue chan features regexps = | |
122 let no_op = List.exists (fun feature -> feature = No_op) features in | |
123 Printf.fprintf chan "}\n\n"; | |
124 (if not no_op then | |
125 List.iter (fun regexp -> | |
126 Printf.fprintf chan | |
127 "/* { dg-final { scan-assembler \"%s\" } } */\n" regexp) | |
128 regexps | |
129 else | |
130 () | |
131 ); | |
132 Printf.fprintf chan "/* { dg-final { cleanup-saved-temps } } */\n" | |
133 | |
134 (* Check a list of C types to determine which ones are pointers and which | |
135 ones are const. *) | |
136 let check_types tys = | |
137 let tys' = | |
138 List.map (fun ty -> | |
139 let len = String.length ty in | |
140 if len > 2 && String.get ty (len - 2) = ' ' | |
141 && String.get ty (len - 1) = '*' | |
142 then ([Pointer], String.sub ty 0 (len - 2)) | |
143 else ([], ty)) tys | |
144 in | |
145 List.map (fun (flags, ty) -> | |
146 if String.length ty > 6 && String.sub ty 0 6 = "const " | |
147 then (Const :: flags, String.sub ty 6 ((String.length ty) - 6)) | |
148 else (flags, ty)) tys' | |
149 | |
150 (* Given an intrinsic shape, produce a regexp that will match | |
151 the right-hand sides of instructions generated by an intrinsic of | |
152 that shape. *) | |
153 let rec analyze_shape shape = | |
154 let rec n_things n thing = | |
155 match n with | |
156 0 -> [] | |
157 | n -> thing :: (n_things (n - 1) thing) | |
158 in | |
159 let rec analyze_shape_elt elt = | |
160 match elt with | |
161 Dreg -> "\\[dD\\]\\[0-9\\]+" | |
162 | Qreg -> "\\[qQ\\]\\[0-9\\]+" | |
163 | Corereg -> "\\[rR\\]\\[0-9\\]+" | |
164 | Immed -> "#\\[0-9\\]+" | |
165 | VecArray (1, elt) -> | |
166 let elt_regexp = analyze_shape_elt elt in | |
167 "((\\\\\\{" ^ elt_regexp ^ "\\\\\\})|(" ^ elt_regexp ^ "))" | |
168 | VecArray (n, elt) -> | |
169 let elt_regexp = analyze_shape_elt elt in | |
170 let alt1 = elt_regexp ^ "-" ^ elt_regexp in | |
171 let alt2 = commas (fun x -> x) (n_things n elt_regexp) "" in | |
172 "\\\\\\{((" ^ alt1 ^ ")|(" ^ alt2 ^ "))\\\\\\}" | |
173 | (PtrTo elt | CstPtrTo elt) -> | |
174 "\\\\\\[" ^ (analyze_shape_elt elt) ^ "\\\\\\]" | |
175 | Element_of_dreg -> (analyze_shape_elt Dreg) ^ "\\\\\\[\\[0-9\\]+\\\\\\]" | |
176 | Element_of_qreg -> (analyze_shape_elt Qreg) ^ "\\\\\\[\\[0-9\\]+\\\\\\]" | |
177 | All_elements_of_dreg -> (analyze_shape_elt Dreg) ^ "\\\\\\[\\\\\\]" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
178 | Alternatives (elts) -> "(" ^ (String.concat "|" (List.map analyze_shape_elt elts)) ^ ")" |
0 | 179 in |
180 match shape with | |
181 All (n, elt) -> commas analyze_shape_elt (n_things n elt) "" | |
182 | Long -> (analyze_shape_elt Qreg) ^ ", " ^ (analyze_shape_elt Dreg) ^ | |
183 ", " ^ (analyze_shape_elt Dreg) | |
184 | Long_noreg elt -> (analyze_shape_elt elt) ^ ", " ^ (analyze_shape_elt elt) | |
185 | Wide -> (analyze_shape_elt Qreg) ^ ", " ^ (analyze_shape_elt Qreg) ^ | |
186 ", " ^ (analyze_shape_elt Dreg) | |
187 | Wide_noreg elt -> analyze_shape (Long_noreg elt) | |
188 | Narrow -> (analyze_shape_elt Dreg) ^ ", " ^ (analyze_shape_elt Qreg) ^ | |
189 ", " ^ (analyze_shape_elt Qreg) | |
190 | Use_operands elts -> commas analyze_shape_elt (Array.to_list elts) "" | |
191 | By_scalar Dreg -> | |
192 analyze_shape (Use_operands [| Dreg; Dreg; Element_of_dreg |]) | |
193 | By_scalar Qreg -> | |
194 analyze_shape (Use_operands [| Qreg; Qreg; Element_of_dreg |]) | |
195 | By_scalar _ -> assert false | |
196 | Wide_lane -> | |
197 analyze_shape (Use_operands [| Qreg; Dreg; Element_of_dreg |]) | |
198 | Wide_scalar -> | |
199 analyze_shape (Use_operands [| Qreg; Dreg; Element_of_dreg |]) | |
200 | Pair_result elt -> | |
201 let elt_regexp = analyze_shape_elt elt in | |
202 elt_regexp ^ ", " ^ elt_regexp | |
203 | Unary_scalar _ -> "FIXME Unary_scalar" | |
204 | Binary_imm elt -> analyze_shape (Use_operands [| elt; elt; Immed |]) | |
205 | Narrow_imm -> analyze_shape (Use_operands [| Dreg; Qreg; Immed |]) | |
206 | Long_imm -> analyze_shape (Use_operands [| Qreg; Dreg; Immed |]) | |
207 | |
208 (* Generate tests for one intrinsic. *) | |
209 let test_intrinsic dir opcode features shape name munge elt_ty = | |
210 (* Open the test source file. *) | |
211 let test_name = name ^ (string_of_elt elt_ty) in | |
212 let chan = open_test_file dir test_name in | |
213 (* Work out what argument and return types the intrinsic has. *) | |
214 let c_arity, new_elt_ty = munge shape elt_ty in | |
215 let c_types = check_types (strings_of_arity c_arity) in | |
216 (* Extract any constant valuator (a function specifying what constant | |
217 values are to be written into the intrinsic call) from the features | |
218 list. *) | |
219 let const_valuator = | |
220 try | |
221 match (List.find (fun feature -> match feature with | |
222 Const_valuator _ -> true | |
223 | _ -> false) features) with | |
224 Const_valuator f -> Some f | |
225 | _ -> assert false | |
226 with Not_found -> None | |
227 in | |
228 (* Work out what instruction name(s) to expect. *) | |
229 let insns = get_insn_names features name in | |
230 let no_suffix = (new_elt_ty = NoElts) in | |
231 let insns = | |
232 if no_suffix then insns | |
233 else List.map (fun insn -> | |
234 let suffix = string_of_elt_dots new_elt_ty in | |
235 insn ^ "\\." ^ suffix) insns | |
236 in | |
237 (* Construct a regexp to match against the expected instruction name(s). *) | |
238 let insn_regexp = | |
239 match insns with | |
240 [] -> assert false | |
241 | [insn] -> insn | |
242 | _ -> | |
243 let rec calc_regexp insns cur_regexp = | |
244 match insns with | |
245 [] -> cur_regexp | |
246 | [insn] -> cur_regexp ^ "(" ^ insn ^ "))" | |
247 | insn::insns -> calc_regexp insns (cur_regexp ^ "(" ^ insn ^ ")|") | |
248 in calc_regexp insns "(" | |
249 in | |
250 (* Construct regexps to match against the instructions that this | |
251 intrinsic expands to. Watch out for any writeback character and | |
252 comments after the instruction. *) | |
253 let regexps = List.map (fun regexp -> insn_regexp ^ "\\[ \t\\]+" ^ regexp ^ | |
254 "!?\\(\\[ \t\\]+@\\[a-zA-Z0-9 \\]+\\)?\\n") | |
255 (analyze_all_shapes features shape analyze_shape) | |
256 in | |
257 (* Emit file and function prologues. *) | |
258 emit_prologue chan test_name; | |
259 (* Emit local variable declarations. *) | |
260 emit_automatics chan c_types; | |
261 Printf.fprintf chan "\n"; | |
262 (* Emit the call to the intrinsic. *) | |
263 emit_call chan const_valuator c_types name elt_ty; | |
264 (* Emit the function epilogue and the DejaGNU scan-assembler directives. *) | |
265 emit_epilogue chan features regexps; | |
266 (* Close the test file. *) | |
267 close_out chan | |
268 | |
269 (* Generate tests for one element of the "ops" table. *) | |
270 let test_intrinsic_group dir (opcode, features, shape, name, munge, types) = | |
271 List.iter (test_intrinsic dir opcode features shape name munge) types | |
272 | |
273 (* Program entry point. *) | |
274 let _ = | |
275 let directory = if Array.length Sys.argv <> 1 then Sys.argv.(1) else "." in | |
276 List.iter (test_intrinsic_group directory) (reinterp @ ops) | |
277 |