Skip to content
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

Use a lighter dedup guard in the assert_instr test shims. #1211

Merged
merged 2 commits into from
Sep 8, 2021
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
19 changes: 8 additions & 11 deletions crates/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub fn assert_instr(
&format!("stdarch_test_shim_{}_{}", name, instr_str),
name.span(),
);
let shim_name_ptr = syn::Ident::new(
&format!("stdarch_test_shim_{}_{}_ptr", name, instr_str).to_ascii_uppercase(),
name.span(),
);
let mut inputs = Vec::new();
let mut input_vals = Vec::new();
let mut const_vals = Vec::new();
Expand Down Expand Up @@ -125,6 +129,9 @@ pub fn assert_instr(
};
let shim_name_str = format!("{}{}", shim_name, assert_name);
let to_test = quote! {

const #shim_name_ptr : *const u8 = #shim_name_str.as_ptr();

#attrs
#[no_mangle]
#[inline(never)]
Expand All @@ -140,17 +147,7 @@ pub fn assert_instr(
// generate some code that's hopefully very tight in terms of
// codegen but is otherwise unique to prevent code from being
// folded.
//
// This is avoided on Wasm32 right now since these functions aren't
// inlined which breaks our tests since each intrinsic looks like it
// calls functions. Turns out functions aren't similar enough to get
// merged on wasm32 anyway. This bug is tracked at
// rust-lang/rust#74320.
#[cfg(not(target_arch = "wasm32"))]
::stdarch_test::_DONT_DEDUP.store(
std::mem::transmute(#shim_name_str.as_bytes().as_ptr()),
std::sync::atomic::Ordering::Relaxed,
);
::stdarch_test::_DONT_DEDUP = #shim_name_ptr;
#name::<#(#const_vals),*>(#(#input_vals),*)
}
};
Expand Down
4 changes: 2 additions & 2 deletions crates/stdarch-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern crate cfg_if;

pub use assert_instr_macro::*;
pub use simd_test_macro::*;
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::atomic::AtomicPtr};
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str};

cfg_if! {
if #[cfg(target_arch = "wasm32")] {
Expand Down Expand Up @@ -189,4 +189,4 @@ pub fn assert_skip_test_ok(name: &str) {
}

// See comment in `assert-instr-macro` crate for why this exists
pub static _DONT_DEDUP: AtomicPtr<u8> = AtomicPtr::new(b"".as_ptr() as *mut _);
pub static mut _DONT_DEDUP: *const u8 = std::ptr::null();