Skip to content

Commit

Permalink
Fix tests for a future nightly (#297)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton authored Jan 25, 2018
1 parent df54eac commit 896531d
Showing 1 changed file with 43 additions and 50 deletions.
93 changes: 43 additions & 50 deletions stdsimd-test/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,48 @@ pub fn assert_instr(
&format!("assert_{}_{}", name.as_ref(), instr.as_ref())[..],
);
let shim_name = syn::Ident::from(format!("{}_shim", name.as_ref()));
let (to_test, test_name) = if invoc.args.len() == 0 {
(TokenStream::empty(), &func.ident)
} else {
let mut inputs = Vec::new();
let mut input_vals = Vec::new();
let ret = &func.decl.output;
for arg in func.decl.inputs.iter() {
let capture = match *arg {
syn::FnArg::Captured(ref c) => c,
_ => panic!("arguments must not have patterns"),
};
let ident = match capture.pat {
syn::Pat::Ident(ref i) => &i.ident,
_ => panic!("must have bare arguments"),
};
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
Some(&(_, ref tts)) => {
input_vals.push(quote! { #tts });
}
None => {
inputs.push(capture);
input_vals.push(quote! { #ident });
}
};
}
let mut inputs = Vec::new();
let mut input_vals = Vec::new();
let ret = &func.decl.output;
for arg in func.decl.inputs.iter() {
let capture = match *arg {
syn::FnArg::Captured(ref c) => c,
_ => panic!("arguments must not have patterns"),
};
let ident = match capture.pat {
syn::Pat::Ident(ref i) => &i.ident,
_ => panic!("must have bare arguments"),
};
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
Some(&(_, ref tts)) => {
input_vals.push(quote! { #tts });
}
None => {
inputs.push(capture);
input_vals.push(quote! { #ident });
}
};
}

let attrs = func.attrs
.iter()
.filter(|attr| {
attr.path
.segments
.first()
.unwrap()
.value()
.ident
.as_ref()
.starts_with("target")
})
.collect::<Vec<_>>();
let attrs = Append(&attrs);
(
quote! {
#attrs
unsafe fn #shim_name(#(#inputs),*) #ret {
#name(#(#input_vals),*)
}
}.into(),
&shim_name,
)
let attrs = func.attrs
.iter()
.filter(|attr| {
attr.path
.segments
.first()
.unwrap()
.value()
.ident
.as_ref()
.starts_with("target")
})
.collect::<Vec<_>>();
let attrs = Append(&attrs);
let to_test = quote! {
#attrs
unsafe extern fn #shim_name(#(#inputs),*) #ret {
#name(#(#input_vals),*)
}
};

let tts: TokenStream = quote_spanned! {
Expand All @@ -102,8 +95,8 @@ pub fn assert_instr(
fn #assert_name() {
#to_test

::stdsimd_test::assert(#test_name as usize,
stringify!(#test_name),
::stdsimd_test::assert(#shim_name as usize,
stringify!(#shim_name),
stringify!(#instr));
}
}.into();
Expand Down

0 comments on commit 896531d

Please sign in to comment.