Skip to content

Commit 896531d

Browse files
authored
Fix tests for a future nightly (#297)
In rust-lang/rust#47743 the SIMD types in the Rust ABI are being switched to getting passed through memory unconditionally rather than through LLVM's immediate registers. This means that a bunch of our assert_instr invocations started breaking as LLVM has more efficient methods of dealing with memory than the instructions themselves. This switches `assert_instr` to unconditionally use a shim that is an `extern` function which should revert back to the previous behavior, using the simd types as immediates and testing the same.
1 parent df54eac commit 896531d

File tree

1 file changed

+43
-50
lines changed
  • stdsimd-test/assert-instr-macro/src

1 file changed

+43
-50
lines changed

Diff for: stdsimd-test/assert-instr-macro/src/lib.rs

+43-50
Original file line numberDiff line numberDiff line change
@@ -43,55 +43,48 @@ pub fn assert_instr(
4343
&format!("assert_{}_{}", name.as_ref(), instr.as_ref())[..],
4444
);
4545
let shim_name = syn::Ident::from(format!("{}_shim", name.as_ref()));
46-
let (to_test, test_name) = if invoc.args.len() == 0 {
47-
(TokenStream::empty(), &func.ident)
48-
} else {
49-
let mut inputs = Vec::new();
50-
let mut input_vals = Vec::new();
51-
let ret = &func.decl.output;
52-
for arg in func.decl.inputs.iter() {
53-
let capture = match *arg {
54-
syn::FnArg::Captured(ref c) => c,
55-
_ => panic!("arguments must not have patterns"),
56-
};
57-
let ident = match capture.pat {
58-
syn::Pat::Ident(ref i) => &i.ident,
59-
_ => panic!("must have bare arguments"),
60-
};
61-
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
62-
Some(&(_, ref tts)) => {
63-
input_vals.push(quote! { #tts });
64-
}
65-
None => {
66-
inputs.push(capture);
67-
input_vals.push(quote! { #ident });
68-
}
69-
};
70-
}
46+
let mut inputs = Vec::new();
47+
let mut input_vals = Vec::new();
48+
let ret = &func.decl.output;
49+
for arg in func.decl.inputs.iter() {
50+
let capture = match *arg {
51+
syn::FnArg::Captured(ref c) => c,
52+
_ => panic!("arguments must not have patterns"),
53+
};
54+
let ident = match capture.pat {
55+
syn::Pat::Ident(ref i) => &i.ident,
56+
_ => panic!("must have bare arguments"),
57+
};
58+
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
59+
Some(&(_, ref tts)) => {
60+
input_vals.push(quote! { #tts });
61+
}
62+
None => {
63+
inputs.push(capture);
64+
input_vals.push(quote! { #ident });
65+
}
66+
};
67+
}
7168

72-
let attrs = func.attrs
73-
.iter()
74-
.filter(|attr| {
75-
attr.path
76-
.segments
77-
.first()
78-
.unwrap()
79-
.value()
80-
.ident
81-
.as_ref()
82-
.starts_with("target")
83-
})
84-
.collect::<Vec<_>>();
85-
let attrs = Append(&attrs);
86-
(
87-
quote! {
88-
#attrs
89-
unsafe fn #shim_name(#(#inputs),*) #ret {
90-
#name(#(#input_vals),*)
91-
}
92-
}.into(),
93-
&shim_name,
94-
)
69+
let attrs = func.attrs
70+
.iter()
71+
.filter(|attr| {
72+
attr.path
73+
.segments
74+
.first()
75+
.unwrap()
76+
.value()
77+
.ident
78+
.as_ref()
79+
.starts_with("target")
80+
})
81+
.collect::<Vec<_>>();
82+
let attrs = Append(&attrs);
83+
let to_test = quote! {
84+
#attrs
85+
unsafe extern fn #shim_name(#(#inputs),*) #ret {
86+
#name(#(#input_vals),*)
87+
}
9588
};
9689

9790
let tts: TokenStream = quote_spanned! {
@@ -102,8 +95,8 @@ pub fn assert_instr(
10295
fn #assert_name() {
10396
#to_test
10497

105-
::stdsimd_test::assert(#test_name as usize,
106-
stringify!(#test_name),
98+
::stdsimd_test::assert(#shim_name as usize,
99+
stringify!(#shim_name),
107100
stringify!(#instr));
108101
}
109102
}.into();

0 commit comments

Comments
 (0)