|
1 |
| -use super::config::{AARCH_CONFIGURATIONS, POLY128_OSTREAM_DEF, build_notices}; |
2 |
| -use super::intrinsic::ArmIntrinsicType; |
3 |
| -use crate::common::argument::Argument; |
4 | 1 | use crate::common::compile_c::CompilationCommandBuilder;
|
5 |
| -use crate::common::gen_c::{compile_c, create_c_filenames, generate_c_program}; |
6 |
| -use crate::common::gen_rust::{compile_rust, create_rust_filenames, generate_rust_program}; |
7 |
| -use crate::common::indentation::Indentation; |
8 |
| -use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition}; |
9 |
| -use crate::common::intrinsic_helpers::IntrinsicTypeDefinition; |
10 |
| -use crate::common::write_file; |
11 |
| -use itertools::Itertools; |
12 |
| -use rayon::prelude::*; |
| 2 | +use crate::common::gen_c::compile_c; |
13 | 3 |
|
14 |
| -// The number of times each intrinsic will be called. |
15 |
| -const PASSES: u32 = 20; |
16 |
| - |
17 |
| -fn gen_code_c( |
18 |
| - indentation: Indentation, |
19 |
| - intrinsic: &Intrinsic<ArmIntrinsicType>, |
20 |
| - constraints: &[&Argument<ArmIntrinsicType>], |
21 |
| - name: String, |
22 |
| - target: &str, |
23 |
| -) -> String { |
24 |
| - if let Some((current, constraints)) = constraints.split_last() { |
25 |
| - let range = current |
26 |
| - .constraint |
27 |
| - .iter() |
28 |
| - .map(|c| c.to_range()) |
29 |
| - .flat_map(|r| r.into_iter()); |
30 |
| - |
31 |
| - let body_indentation = indentation.nested(); |
32 |
| - range |
33 |
| - .map(|i| { |
34 |
| - format!( |
35 |
| - "{indentation}{{\n\ |
36 |
| - {body_indentation}{ty} {name} = {val};\n\ |
37 |
| - {pass}\n\ |
38 |
| - {indentation}}}", |
39 |
| - name = current.name, |
40 |
| - ty = current.ty.c_type(), |
41 |
| - val = i, |
42 |
| - pass = gen_code_c( |
43 |
| - body_indentation, |
44 |
| - intrinsic, |
45 |
| - constraints, |
46 |
| - format!("{name}-{i}"), |
47 |
| - target, |
48 |
| - ) |
49 |
| - ) |
50 |
| - }) |
51 |
| - .join("\n") |
52 |
| - } else { |
53 |
| - intrinsic.generate_loop_c(indentation, &name, PASSES, target) |
54 |
| - } |
55 |
| -} |
56 |
| - |
57 |
| -fn generate_c_program_arm( |
58 |
| - header_files: &[&str], |
59 |
| - intrinsic: &Intrinsic<ArmIntrinsicType>, |
60 |
| - target: &str, |
61 |
| -) -> String { |
62 |
| - let constraints = intrinsic |
63 |
| - .arguments |
64 |
| - .iter() |
65 |
| - .filter(|&i| i.has_constraint()) |
66 |
| - .collect_vec(); |
67 |
| - |
68 |
| - let indentation = Indentation::default(); |
69 |
| - generate_c_program( |
70 |
| - build_notices("// ").as_str(), |
71 |
| - header_files, |
72 |
| - "aarch64", |
73 |
| - &[POLY128_OSTREAM_DEF], |
74 |
| - intrinsic |
75 |
| - .arguments |
76 |
| - .gen_arglists_c(indentation, PASSES) |
77 |
| - .as_str(), |
78 |
| - gen_code_c( |
79 |
| - indentation.nested(), |
80 |
| - intrinsic, |
81 |
| - constraints.as_slice(), |
82 |
| - Default::default(), |
83 |
| - target, |
84 |
| - ) |
85 |
| - .as_str(), |
86 |
| - ) |
87 |
| -} |
88 |
| - |
89 |
| -fn gen_code_rust( |
90 |
| - indentation: Indentation, |
91 |
| - intrinsic: &Intrinsic<ArmIntrinsicType>, |
92 |
| - constraints: &[&Argument<ArmIntrinsicType>], |
93 |
| - name: String, |
94 |
| -) -> String { |
95 |
| - println!("{}", name); |
96 |
| - if let Some((current, constraints)) = constraints.split_last() { |
97 |
| - let range = current |
98 |
| - .constraint |
99 |
| - .iter() |
100 |
| - .map(|c| c.to_range()) |
101 |
| - .flat_map(|r| r.into_iter()); |
102 |
| - |
103 |
| - let body_indentation = indentation.nested(); |
104 |
| - range |
105 |
| - .map(|i| { |
106 |
| - format!( |
107 |
| - "{indentation}{{\n\ |
108 |
| - {body_indentation}const {name}: {ty} = {val};\n\ |
109 |
| - {pass}\n\ |
110 |
| - {indentation}}}", |
111 |
| - name = current.name, |
112 |
| - ty = current.ty.rust_type(), |
113 |
| - val = i, |
114 |
| - pass = gen_code_rust( |
115 |
| - body_indentation, |
116 |
| - intrinsic, |
117 |
| - constraints, |
118 |
| - format!("{name}-{i}") |
119 |
| - ) |
120 |
| - ) |
121 |
| - }) |
122 |
| - .join("\n") |
123 |
| - } else { |
124 |
| - intrinsic.generate_loop_rust(indentation, &name, PASSES) |
125 |
| - } |
126 |
| -} |
127 |
| - |
128 |
| -fn generate_rust_program_arm(intrinsic: &Intrinsic<ArmIntrinsicType>, target: &str) -> String { |
129 |
| - let constraints = intrinsic |
130 |
| - .arguments |
131 |
| - .iter() |
132 |
| - .filter(|i| i.has_constraint()) |
133 |
| - .collect_vec(); |
134 |
| - |
135 |
| - let indentation = Indentation::default(); |
136 |
| - let final_target = if target.contains("v7") { |
137 |
| - "arm" |
138 |
| - } else { |
139 |
| - "aarch64" |
140 |
| - }; |
141 |
| - generate_rust_program( |
142 |
| - build_notices("// ").as_str(), |
143 |
| - AARCH_CONFIGURATIONS, |
144 |
| - final_target, |
145 |
| - intrinsic |
146 |
| - .arguments |
147 |
| - .gen_arglists_rust(indentation.nested(), PASSES) |
148 |
| - .as_str(), |
149 |
| - gen_code_rust( |
150 |
| - indentation.nested(), |
151 |
| - intrinsic, |
152 |
| - &constraints, |
153 |
| - Default::default(), |
154 |
| - ) |
155 |
| - .as_str(), |
156 |
| - ) |
157 |
| -} |
158 |
| - |
159 |
| -fn compile_c_arm( |
| 4 | +pub fn compile_c_arm( |
160 | 5 | intrinsics_name_list: &Vec<String>,
|
161 | 6 | compiler: &str,
|
162 | 7 | target: &str,
|
@@ -217,54 +62,3 @@ fn compile_c_arm(
|
217 | 62 |
|
218 | 63 | compile_c(&compiler_commands)
|
219 | 64 | }
|
220 |
| - |
221 |
| -pub fn build_c( |
222 |
| - intrinsics: &Vec<Intrinsic<ArmIntrinsicType>>, |
223 |
| - compiler: Option<&str>, |
224 |
| - target: &str, |
225 |
| - cxx_toolchain_dir: Option<&str>, |
226 |
| -) -> bool { |
227 |
| - let intrinsics_name_list = intrinsics |
228 |
| - .par_iter() |
229 |
| - .map(|i| i.name.clone()) |
230 |
| - .collect::<Vec<_>>(); |
231 |
| - let filename_mapping = create_c_filenames(&intrinsics_name_list); |
232 |
| - |
233 |
| - intrinsics.par_iter().for_each(|i| { |
234 |
| - let c_code = generate_c_program_arm(&["arm_neon.h", "arm_acle.h", "arm_fp16.h"], i, target); |
235 |
| - match filename_mapping.get(&i.name) { |
236 |
| - Some(filename) => write_file(filename, c_code), |
237 |
| - None => {} |
238 |
| - }; |
239 |
| - }); |
240 |
| - |
241 |
| - match compiler { |
242 |
| - None => true, |
243 |
| - Some(compiler) => compile_c_arm(&intrinsics_name_list, compiler, target, cxx_toolchain_dir), |
244 |
| - } |
245 |
| -} |
246 |
| - |
247 |
| -pub fn build_rust( |
248 |
| - intrinsics: &[Intrinsic<ArmIntrinsicType>], |
249 |
| - toolchain: Option<&str>, |
250 |
| - target: &str, |
251 |
| - linker: Option<&str>, |
252 |
| -) -> bool { |
253 |
| - let intrinsics_name_list = intrinsics |
254 |
| - .par_iter() |
255 |
| - .map(|i| i.name.clone()) |
256 |
| - .collect::<Vec<_>>(); |
257 |
| - let filename_mapping = create_rust_filenames(&intrinsics_name_list); |
258 |
| - |
259 |
| - intrinsics.par_iter().for_each(|i| { |
260 |
| - let rust_code = generate_rust_program_arm(i, target); |
261 |
| - match filename_mapping.get(&i.name) { |
262 |
| - Some(filename) => write_file(filename, rust_code), |
263 |
| - None => {} |
264 |
| - } |
265 |
| - }); |
266 |
| - |
267 |
| - let intrinsics_name_list = intrinsics.iter().map(|i| i.name.as_str()).collect_vec(); |
268 |
| - |
269 |
| - compile_rust(&intrinsics_name_list, toolchain, target, linker) |
270 |
| -} |
0 commit comments