Skip to content

Commit c1cc6e2

Browse files
committed
Auto merge of #799 - gnzlbg:has_test, r=gnzlbg
Verify that all intrinsics have a run-time test Add a check to stdsimd-verify to check that all intrinsics have a run-time test. This is not the case right now, but we should at least not add intrinsics without tests.
2 parents b766730 + f9326bb commit c1cc6e2

File tree

6 files changed

+366
-6
lines changed

6 files changed

+366
-6
lines changed

crates/core_arch/src/x86/sse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,7 +3437,7 @@ mod tests {
34373437
}
34383438

34393439
#[simd_test(enable = "sse")]
3440-
pub unsafe fn test_mm_cvtsi32_ss() {
3440+
unsafe fn test_mm_cvtsi32_ss() {
34413441
let inputs = &[
34423442
(4555i32, 4555.0f32),
34433443
(322223333, 322223330.0),
@@ -3455,7 +3455,7 @@ mod tests {
34553455
}
34563456

34573457
#[simd_test(enable = "sse")]
3458-
pub unsafe fn test_mm_cvtss_f32() {
3458+
unsafe fn test_mm_cvtss_f32() {
34593459
let a = _mm_setr_ps(312.0134, 5.0, 6.0, 7.0);
34603460
assert_eq!(_mm_cvtss_f32(a), 312.0134);
34613461
}

crates/core_arch/src/x86_64/sse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ mod tests {
128128
}
129129

130130
#[simd_test(enable = "sse")]
131-
pub unsafe fn test_mm_cvtsi64_ss() {
131+
unsafe fn test_mm_cvtsi64_ss() {
132132
let inputs = &[
133133
(4555i64, 4555.0f32),
134134
(322223333, 322223330.0),

crates/stdarch-verify/src/lib.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,33 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
3737

3838
let mut functions = Vec::new();
3939
for &mut (ref mut file, ref path) in &mut files {
40-
for item in file.items.drain(..) {
41-
if let syn::Item::Fn(f) = item {
42-
functions.push((f, path))
40+
for mut item in file.items.drain(..) {
41+
match item {
42+
syn::Item::Fn(f) => functions.push((f, path)),
43+
syn::Item::Mod(ref mut m) => {
44+
if let Some(ref mut m) = m.content {
45+
for i in m.1.drain(..) {
46+
if let syn::Item::Fn(f) = i {
47+
functions.push((f, path))
48+
}
49+
}
50+
}
51+
}
52+
_ => (),
4353
}
4454
}
4555
}
4656
assert!(!functions.is_empty());
4757

58+
let mut tests = std::collections::HashSet::<String>::new();
59+
for f in &functions {
60+
let id = format!("{}", f.0.ident);
61+
if id.starts_with("test_") {
62+
tests.insert(id);
63+
}
64+
}
65+
assert!(!tests.is_empty());
66+
4867
functions.retain(|&(ref f, _)| {
4968
if let syn::Visibility::Public(_) = f.vis {
5069
if f.unsafety.is_some() {
@@ -84,6 +103,16 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
84103
quote! { None }
85104
};
86105
let required_const = find_required_const(&f.attrs);
106+
107+
// strip leading underscore from fn name when building a test
108+
// _mm_foo -> mm_foo such that the test name is test_mm_foo.
109+
let test_name_string = format!("{}", name);
110+
let mut test_name_id = test_name_string.as_str();
111+
while test_name_id.starts_with('_') {
112+
test_name_id = &test_name_id[1..];
113+
}
114+
let has_test = tests.contains(&format!("test_{}", test_name_id));
115+
87116
quote! {
88117
Function {
89118
name: stringify!(#name),
@@ -93,6 +122,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
93122
instrs: &[#(#instrs),*],
94123
file: stringify!(#path),
95124
required_const: &[#(#required_const),*],
125+
has_test: #has_test,
96126
}
97127
}
98128
})

crates/stdarch-verify/tests/arm.rs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct Function {
1818
instrs: &'static [&'static str],
1919
file: &'static str,
2020
required_const: &'static [usize],
21+
has_test: bool,
2122
}
2223

2324
static F16: Type = Type::PrimFloat(16);
@@ -197,6 +198,155 @@ fn verify_all_signatures() {
197198

198199
let mut all_valid = true;
199200
'outer: for rust in FUNCTIONS {
201+
if !rust.has_test {
202+
let skip = [
203+
"vaddq_s64",
204+
"vaddq_u64",
205+
"vrsqrte_f32",
206+
"vtbl1_s8",
207+
"vtbl1_u8",
208+
"vtbl1_p8",
209+
"vtbl2_s8",
210+
"vtbl2_u8",
211+
"vtbl2_p8",
212+
"vtbl3_s8",
213+
"vtbl3_u8",
214+
"vtbl3_p8",
215+
"vtbl4_s8",
216+
"vtbl4_u8",
217+
"vtbl4_p8",
218+
"vtbx1_s8",
219+
"vtbx1_u8",
220+
"vtbx1_p8",
221+
"vtbx2_s8",
222+
"vtbx2_u8",
223+
"vtbx2_p8",
224+
"vtbx3_s8",
225+
"vtbx3_u8",
226+
"vtbx3_p8",
227+
"vtbx4_s8",
228+
"vtbx4_u8",
229+
"vtbx4_p8",
230+
"udf",
231+
"_clz_u8",
232+
"_clz_u16",
233+
"_clz_u32",
234+
"_rbit_u32",
235+
"_rev_u16",
236+
"_rev_u32",
237+
"__breakpoint",
238+
"vpminq_f32",
239+
"vpminq_f64",
240+
"vpmaxq_f32",
241+
"vpmaxq_f64",
242+
"vcombine_s8",
243+
"vcombine_s16",
244+
"vcombine_s32",
245+
"vcombine_s64",
246+
"vcombine_u8",
247+
"vcombine_u16",
248+
"vcombine_u32",
249+
"vcombine_u64",
250+
"vcombine_p64",
251+
"vcombine_f32",
252+
"vcombine_p8",
253+
"vcombine_p16",
254+
"vcombine_f64",
255+
"vtbl1_s8",
256+
"vtbl1_u8",
257+
"vtbl1_p8",
258+
"vtbl2_s8",
259+
"vtbl2_u8",
260+
"vtbl2_p8",
261+
"vtbl3_s8",
262+
"vtbl3_u8",
263+
"vtbl3_p8",
264+
"vtbl4_s8",
265+
"vtbl4_u8",
266+
"vtbl4_p8",
267+
"vtbx1_s8",
268+
"vtbx1_u8",
269+
"vtbx1_p8",
270+
"vtbx2_s8",
271+
"vtbx2_u8",
272+
"vtbx2_p8",
273+
"vtbx3_s8",
274+
"vtbx3_u8",
275+
"vtbx3_p8",
276+
"vtbx4_s8",
277+
"vtbx4_u8",
278+
"vtbx4_p8",
279+
"vqtbl1_s8",
280+
"vqtbl1q_s8",
281+
"vqtbl1_u8",
282+
"vqtbl1q_u8",
283+
"vqtbl1_p8",
284+
"vqtbl1q_p8",
285+
"vqtbx1_s8",
286+
"vqtbx1q_s8",
287+
"vqtbx1_u8",
288+
"vqtbx1q_u8",
289+
"vqtbx1_p8",
290+
"vqtbx1q_p8",
291+
"vqtbl2_s8",
292+
"vqtbl2q_s8",
293+
"vqtbl2_u8",
294+
"vqtbl2q_u8",
295+
"vqtbl2_p8",
296+
"vqtbl2q_p8",
297+
"vqtbx2_s8",
298+
"vqtbx2q_s8",
299+
"vqtbx2_u8",
300+
"vqtbx2q_u8",
301+
"vqtbx2_p8",
302+
"vqtbx2q_p8",
303+
"vqtbl3_s8",
304+
"vqtbl3q_s8",
305+
"vqtbl3_u8",
306+
"vqtbl3q_u8",
307+
"vqtbl3_p8",
308+
"vqtbl3q_p8",
309+
"vqtbx3_s8",
310+
"vqtbx3q_s8",
311+
"vqtbx3_u8",
312+
"vqtbx3q_u8",
313+
"vqtbx3_p8",
314+
"vqtbx3q_p8",
315+
"vqtbl4_s8",
316+
"vqtbl4q_s8",
317+
"vqtbl4_u8",
318+
"vqtbl4q_u8",
319+
"vqtbl4_p8",
320+
"vqtbl4q_p8",
321+
"vqtbx4_s8",
322+
"vqtbx4q_s8",
323+
"vqtbx4_u8",
324+
"vqtbx4q_u8",
325+
"vqtbx4_p8",
326+
"vqtbx4q_p8",
327+
"brk",
328+
"_rev_u64",
329+
"_clz_u64",
330+
"_rbit_u64",
331+
"_cls_u32",
332+
"_cls_u64",
333+
];
334+
if !skip.contains(&rust.name) {
335+
println!(
336+
"missing run-time test named `test_{}` for `{}`",
337+
{
338+
let mut id = rust.name;
339+
while id.starts_with('_') {
340+
id = &id[1..];
341+
}
342+
id
343+
},
344+
rust.name
345+
);
346+
all_valid = false;
347+
}
348+
}
349+
200350
// Skip some intrinsics that aren't NEON and are located in different
201351
// places than the whitelists below.
202352
match rust.name {

crates/stdarch-verify/tests/mips.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct Function {
1616
instrs: &'static [&'static str],
1717
file: &'static str,
1818
required_const: &'static [usize],
19+
has_test: bool,
1920
}
2021

2122
static F16: Type = Type::PrimFloat(16);
@@ -200,6 +201,34 @@ fn verify_all_signatures() {
200201

201202
let mut all_valid = true;
202203
for rust in FUNCTIONS {
204+
if !rust.has_test {
205+
let skip = [
206+
"__msa_ceqi_d",
207+
"__msa_cfcmsa",
208+
"__msa_clei_s_d",
209+
"__msa_clti_s_d",
210+
"__msa_ctcmsa",
211+
"__msa_ldi_d",
212+
"__msa_maxi_s_d",
213+
"__msa_mini_s_d",
214+
"break_",
215+
];
216+
if !skip.contains(&rust.name) {
217+
println!(
218+
"missing run-time test named `test_{}` for `{}`",
219+
{
220+
let mut id = rust.name;
221+
while id.starts_with('_') {
222+
id = &id[1..];
223+
}
224+
id
225+
},
226+
rust.name
227+
);
228+
all_valid = false;
229+
}
230+
}
231+
203232
// Skip some intrinsics that aren't part of MSA
204233
match rust.name {
205234
"break_" => continue,

0 commit comments

Comments
 (0)