Skip to content

Verify that all intrinsics have a run-time test #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/core_arch/src/x86/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3437,7 +3437,7 @@ mod tests {
}

#[simd_test(enable = "sse")]
pub unsafe fn test_mm_cvtsi32_ss() {
unsafe fn test_mm_cvtsi32_ss() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were pub items for some reason and the check errored that they also needed tests..

let inputs = &[
(4555i32, 4555.0f32),
(322223333, 322223330.0),
Expand All @@ -3455,7 +3455,7 @@ mod tests {
}

#[simd_test(enable = "sse")]
pub unsafe fn test_mm_cvtss_f32() {
unsafe fn test_mm_cvtss_f32() {
let a = _mm_setr_ps(312.0134, 5.0, 6.0, 7.0);
assert_eq!(_mm_cvtss_f32(a), 312.0134);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core_arch/src/x86_64/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
}

#[simd_test(enable = "sse")]
pub unsafe fn test_mm_cvtsi64_ss() {
unsafe fn test_mm_cvtsi64_ss() {
let inputs = &[
(4555i64, 4555.0f32),
(322223333, 322223330.0),
Expand Down
36 changes: 33 additions & 3 deletions crates/stdarch-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,33 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {

let mut functions = Vec::new();
for &mut (ref mut file, ref path) in &mut files {
for item in file.items.drain(..) {
if let syn::Item::Fn(f) = item {
functions.push((f, path))
for mut item in file.items.drain(..) {
match item {
syn::Item::Fn(f) => functions.push((f, path)),
syn::Item::Mod(ref mut m) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdsimd-verify did not scan for function items within inline modules (mod { ... }) - since tests are inside a mod tests { ... } this is required to add them.

if let Some(ref mut m) = m.content {
for i in m.1.drain(..) {
if let syn::Item::Fn(f) = i {
functions.push((f, path))
}
}
}
}
_ => (),
}
}
}
assert!(!functions.is_empty());

let mut tests = std::collections::HashSet::<String>::new();
for f in &functions {
let id = format!("{}", f.0.ident);
if id.starts_with("test_") {
tests.insert(id);
}
}
assert!(!tests.is_empty());

functions.retain(|&(ref f, _)| {
if let syn::Visibility::Public(_) = f.vis {
if f.unsafety.is_some() {
Expand Down Expand Up @@ -84,6 +103,16 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
quote! { None }
};
let required_const = find_required_const(&f.attrs);

// strip leading underscore from fn name when building a test
// _mm_foo -> mm_foo such that the test name is test_mm_foo.
let test_name_string = format!("{}", name);
let mut test_name_id = test_name_string.as_str();
while test_name_id.starts_with('_') {
test_name_id = &test_name_id[1..];
}
let has_test = tests.contains(&format!("test_{}", test_name_id));

quote! {
Function {
name: stringify!(#name),
Expand All @@ -93,6 +122,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
instrs: &[#(#instrs),*],
file: stringify!(#path),
required_const: &[#(#required_const),*],
has_test: #has_test,
}
}
})
Expand Down
150 changes: 150 additions & 0 deletions crates/stdarch-verify/tests/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Function {
instrs: &'static [&'static str],
file: &'static str,
required_const: &'static [usize],
has_test: bool,
}

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

let mut all_valid = true;
'outer: for rust in FUNCTIONS {
if !rust.has_test {
let skip = [
"vaddq_s64",
"vaddq_u64",
"vrsqrte_f32",
"vtbl1_s8",
"vtbl1_u8",
"vtbl1_p8",
"vtbl2_s8",
"vtbl2_u8",
"vtbl2_p8",
"vtbl3_s8",
"vtbl3_u8",
"vtbl3_p8",
"vtbl4_s8",
"vtbl4_u8",
"vtbl4_p8",
"vtbx1_s8",
"vtbx1_u8",
"vtbx1_p8",
"vtbx2_s8",
"vtbx2_u8",
"vtbx2_p8",
"vtbx3_s8",
"vtbx3_u8",
"vtbx3_p8",
"vtbx4_s8",
"vtbx4_u8",
"vtbx4_p8",
"udf",
"_clz_u8",
"_clz_u16",
"_clz_u32",
"_rbit_u32",
"_rev_u16",
"_rev_u32",
"__breakpoint",
"vpminq_f32",
"vpminq_f64",
"vpmaxq_f32",
"vpmaxq_f64",
"vcombine_s8",
"vcombine_s16",
"vcombine_s32",
"vcombine_s64",
"vcombine_u8",
"vcombine_u16",
"vcombine_u32",
"vcombine_u64",
"vcombine_p64",
"vcombine_f32",
"vcombine_p8",
"vcombine_p16",
"vcombine_f64",
"vtbl1_s8",
"vtbl1_u8",
"vtbl1_p8",
"vtbl2_s8",
"vtbl2_u8",
"vtbl2_p8",
"vtbl3_s8",
"vtbl3_u8",
"vtbl3_p8",
"vtbl4_s8",
"vtbl4_u8",
"vtbl4_p8",
"vtbx1_s8",
"vtbx1_u8",
"vtbx1_p8",
"vtbx2_s8",
"vtbx2_u8",
"vtbx2_p8",
"vtbx3_s8",
"vtbx3_u8",
"vtbx3_p8",
"vtbx4_s8",
"vtbx4_u8",
"vtbx4_p8",
"vqtbl1_s8",
"vqtbl1q_s8",
"vqtbl1_u8",
"vqtbl1q_u8",
"vqtbl1_p8",
"vqtbl1q_p8",
"vqtbx1_s8",
"vqtbx1q_s8",
"vqtbx1_u8",
"vqtbx1q_u8",
"vqtbx1_p8",
"vqtbx1q_p8",
"vqtbl2_s8",
"vqtbl2q_s8",
"vqtbl2_u8",
"vqtbl2q_u8",
"vqtbl2_p8",
"vqtbl2q_p8",
"vqtbx2_s8",
"vqtbx2q_s8",
"vqtbx2_u8",
"vqtbx2q_u8",
"vqtbx2_p8",
"vqtbx2q_p8",
"vqtbl3_s8",
"vqtbl3q_s8",
"vqtbl3_u8",
"vqtbl3q_u8",
"vqtbl3_p8",
"vqtbl3q_p8",
"vqtbx3_s8",
"vqtbx3q_s8",
"vqtbx3_u8",
"vqtbx3q_u8",
"vqtbx3_p8",
"vqtbx3q_p8",
"vqtbl4_s8",
"vqtbl4q_s8",
"vqtbl4_u8",
"vqtbl4q_u8",
"vqtbl4_p8",
"vqtbl4q_p8",
"vqtbx4_s8",
"vqtbx4q_s8",
"vqtbx4_u8",
"vqtbx4q_u8",
"vqtbx4_p8",
"vqtbx4q_p8",
"brk",
"_rev_u64",
"_clz_u64",
"_rbit_u64",
"_cls_u32",
"_cls_u64",
];
if !skip.contains(&rust.name) {
println!(
"missing run-time test named `test_{}` for `{}`",
{
let mut id = rust.name;
while id.starts_with('_') {
id = &id[1..];
}
id
},
rust.name
);
all_valid = false;
}
}

// Skip some intrinsics that aren't NEON and are located in different
// places than the whitelists below.
match rust.name {
Expand Down
29 changes: 29 additions & 0 deletions crates/stdarch-verify/tests/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Function {
instrs: &'static [&'static str],
file: &'static str,
required_const: &'static [usize],
has_test: bool,
}

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

let mut all_valid = true;
for rust in FUNCTIONS {
if !rust.has_test {
let skip = [
"__msa_ceqi_d",
"__msa_cfcmsa",
"__msa_clei_s_d",
"__msa_clti_s_d",
"__msa_ctcmsa",
"__msa_ldi_d",
"__msa_maxi_s_d",
"__msa_mini_s_d",
"break_",
];
if !skip.contains(&rust.name) {
println!(
"missing run-time test named `test_{}` for `{}`",
{
let mut id = rust.name;
while id.starts_with('_') {
id = &id[1..];
}
id
},
rust.name
);
all_valid = false;
}
}

// Skip some intrinsics that aren't part of MSA
match rust.name {
"break_" => continue,
Expand Down
Loading