@@ -5,20 +5,11 @@ mod intrinsic;
5
5
mod json_parser;
6
6
mod types;
7
7
8
- use std:: fs:: { self , File } ;
9
-
10
- use rayon:: prelude:: * ;
11
-
8
+ use crate :: common:: SupportedArchitectureTest ;
12
9
use crate :: common:: cli:: ProcessedCli ;
13
- use crate :: common:: compare:: compare_outputs;
14
- use crate :: common:: gen_c:: { write_main_cpp, write_mod_cpp} ;
15
- use crate :: common:: gen_rust:: {
16
- compile_rust_programs, write_bin_cargo_toml, write_lib_cargo_toml, write_lib_rs, write_main_rs,
17
- } ;
10
+ use crate :: common:: compile_c:: CppCompilation ;
18
11
use crate :: common:: intrinsic:: Intrinsic ;
19
12
use crate :: common:: intrinsic_helpers:: TypeKind ;
20
- use crate :: common:: { SupportedArchitectureTest , chunk_info} ;
21
- use config:: { AARCH_CONFIGURATIONS , F16_FORMATTING_DEF , POLY128_OSTREAM_DEF , build_notices} ;
22
13
use intrinsic:: ArmIntrinsicType ;
23
14
use json_parser:: get_neon_intrinsics;
24
15
@@ -28,7 +19,30 @@ pub struct ArmArchitectureTest {
28
19
}
29
20
30
21
impl SupportedArchitectureTest for ArmArchitectureTest {
31
- fn create ( cli_options : ProcessedCli ) -> Box < Self > {
22
+ type IntrinsicImpl = ArmIntrinsicType ;
23
+
24
+ fn cli_options ( & self ) -> & ProcessedCli {
25
+ & self . cli_options
26
+ }
27
+
28
+ fn intrinsics ( & self ) -> & [ Intrinsic < ArmIntrinsicType > ] {
29
+ & self . intrinsics
30
+ }
31
+
32
+ const NOTICE : & str = config:: NOTICE ;
33
+
34
+ const PLATFORM_C_HEADERS : & [ & str ] = & [ "arm_neon.h" , "arm_acle.h" , "arm_fp16.h" ] ;
35
+ const PLATFORM_C_DEFINITIONS : & str = config:: POLY128_OSTREAM_DEF ;
36
+ const PLATFORM_C_FORWARD_DECLARATIONS : & str = config:: POLY128_OSTREAM_DECL ;
37
+
38
+ const PLATFORM_RUST_DEFINITIONS : & str = config:: F16_FORMATTING_DEF ;
39
+ const PLATFORM_RUST_CFGS : & str = config:: AARCH_CONFIGURATIONS ;
40
+
41
+ fn cpp_compilation ( & self ) -> Option < CppCompilation > {
42
+ compile:: build_cpp_compilation ( & self . cli_options )
43
+ }
44
+
45
+ fn create ( cli_options : ProcessedCli ) -> Self {
32
46
let a32 = cli_options. target . contains ( "v7" ) ;
33
47
let mut intrinsics = get_neon_intrinsics ( & cli_options. filename , & cli_options. target )
34
48
. expect ( "Error parsing input file" ) ;
@@ -50,149 +64,9 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
50
64
. collect :: < Vec < _ > > ( ) ;
51
65
intrinsics. dedup ( ) ;
52
66
53
- Box :: new ( Self {
67
+ Self {
54
68
intrinsics,
55
69
cli_options,
56
- } )
57
- }
58
-
59
- fn build_c_file ( & self ) -> bool {
60
- let c_target = "aarch64" ;
61
- let platform_headers = & [ "arm_neon.h" , "arm_acle.h" , "arm_fp16.h" ] ;
62
-
63
- let ( chunk_size, chunk_count) = chunk_info ( self . intrinsics . len ( ) ) ;
64
-
65
- let cpp_compiler_wrapped = compile:: build_cpp_compilation ( & self . cli_options ) ;
66
-
67
- let notice = & build_notices ( "// " ) ;
68
- fs:: create_dir_all ( "c_programs" ) . unwrap ( ) ;
69
- self . intrinsics
70
- . par_chunks ( chunk_size)
71
- . enumerate ( )
72
- . map ( |( i, chunk) | {
73
- let c_filename = format ! ( "c_programs/mod_{i}.cpp" ) ;
74
- let mut file = File :: create ( & c_filename) . unwrap ( ) ;
75
- write_mod_cpp ( & mut file, notice, c_target, platform_headers, chunk) . unwrap ( ) ;
76
-
77
- // compile this cpp file into a .o file.
78
- //
79
- // This is done because `cpp_compiler_wrapped` is None when
80
- // the --generate-only flag is passed
81
- if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
82
- let output = cpp_compiler
83
- . compile_object_file ( & format ! ( "mod_{i}.cpp" ) , & format ! ( "mod_{i}.o" ) ) ?;
84
- assert ! ( output. status. success( ) , "{output:?}" ) ;
85
- }
86
-
87
- Ok ( ( ) )
88
- } )
89
- . collect :: < Result < ( ) , std:: io:: Error > > ( )
90
- . unwrap ( ) ;
91
-
92
- let mut file = File :: create ( "c_programs/main.cpp" ) . unwrap ( ) ;
93
- write_main_cpp (
94
- & mut file,
95
- c_target,
96
- POLY128_OSTREAM_DEF ,
97
- self . intrinsics . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
98
- )
99
- . unwrap ( ) ;
100
-
101
- // This is done because `cpp_compiler_wrapped` is None when
102
- // the --generate-only flag is passed
103
- if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
104
- // compile this cpp file into a .o file
105
- info ! ( "compiling main.cpp" ) ;
106
- let output = cpp_compiler
107
- . compile_object_file ( "main.cpp" , "intrinsic-test-programs.o" )
108
- . unwrap ( ) ;
109
- assert ! ( output. status. success( ) , "{output:?}" ) ;
110
-
111
- let object_files = ( 0 ..chunk_count)
112
- . map ( |i| format ! ( "mod_{i}.o" ) )
113
- . chain ( [ "intrinsic-test-programs.o" . to_owned ( ) ] ) ;
114
-
115
- let output = cpp_compiler
116
- . link_executable ( object_files, "intrinsic-test-programs" )
117
- . unwrap ( ) ;
118
- assert ! ( output. status. success( ) , "{output:?}" ) ;
119
- }
120
-
121
- true
122
- }
123
-
124
- fn build_rust_file ( & self ) -> bool {
125
- std:: fs:: create_dir_all ( "rust_programs/src" ) . unwrap ( ) ;
126
-
127
- let architecture = if self . cli_options . target . contains ( "v7" ) {
128
- "arm"
129
- } else {
130
- "aarch64"
131
- } ;
132
-
133
- let ( chunk_size, chunk_count) = chunk_info ( self . intrinsics . len ( ) ) ;
134
-
135
- let mut cargo = File :: create ( "rust_programs/Cargo.toml" ) . unwrap ( ) ;
136
- write_bin_cargo_toml ( & mut cargo, chunk_count) . unwrap ( ) ;
137
-
138
- let mut main_rs = File :: create ( "rust_programs/src/main.rs" ) . unwrap ( ) ;
139
- write_main_rs (
140
- & mut main_rs,
141
- chunk_count,
142
- AARCH_CONFIGURATIONS ,
143
- "" ,
144
- self . intrinsics . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
145
- )
146
- . unwrap ( ) ;
147
-
148
- let target = & self . cli_options . target ;
149
- let toolchain = self . cli_options . toolchain . as_deref ( ) ;
150
- let linker = self . cli_options . linker . as_deref ( ) ;
151
-
152
- let notice = & build_notices ( "// " ) ;
153
- self . intrinsics
154
- . par_chunks ( chunk_size)
155
- . enumerate ( )
156
- . map ( |( i, chunk) | {
157
- std:: fs:: create_dir_all ( format ! ( "rust_programs/mod_{i}/src" ) ) ?;
158
-
159
- let rust_filename = format ! ( "rust_programs/mod_{i}/src/lib.rs" ) ;
160
- trace ! ( "generating `{rust_filename}`" ) ;
161
- let mut file = File :: create ( rust_filename) ?;
162
-
163
- let cfg = AARCH_CONFIGURATIONS ;
164
- let definitions = F16_FORMATTING_DEF ;
165
- write_lib_rs ( & mut file, architecture, notice, cfg, definitions, chunk) ?;
166
-
167
- let toml_filename = format ! ( "rust_programs/mod_{i}/Cargo.toml" ) ;
168
- trace ! ( "generating `{toml_filename}`" ) ;
169
- let mut file = File :: create ( toml_filename) . unwrap ( ) ;
170
-
171
- write_lib_cargo_toml ( & mut file, & format ! ( "mod_{i}" ) ) ?;
172
-
173
- Ok ( ( ) )
174
- } )
175
- . collect :: < Result < ( ) , std:: io:: Error > > ( )
176
- . unwrap ( ) ;
177
-
178
- compile_rust_programs ( toolchain, target, linker)
179
- }
180
-
181
- fn compare_outputs ( & self ) -> bool {
182
- if self . cli_options . toolchain . is_some ( ) {
183
- let intrinsics_name_list = self
184
- . intrinsics
185
- . iter ( )
186
- . map ( |i| i. name . clone ( ) )
187
- . collect :: < Vec < _ > > ( ) ;
188
-
189
- compare_outputs (
190
- & intrinsics_name_list,
191
- & self . cli_options . runner ,
192
- & self . cli_options . target ,
193
- )
194
- } else {
195
- true
196
70
}
197
71
}
198
72
}
0 commit comments