1
Fork 0

black_box should use inline assembly on wasm32

This commit is contained in:
gnzlbg 2019-03-25 18:11:42 +01:00
parent cfa76c438a
commit 24db517419

View file

@ -99,17 +99,17 @@ pub fn spin_loop() {
/// This function is a no-op, and does not even read from `dummy`. /// This function is a no-op, and does not even read from `dummy`.
#[unstable(feature = "test", issue = "27812")] #[unstable(feature = "test", issue = "27812")]
pub fn black_box<T>(dummy: T) -> T { pub fn black_box<T>(dummy: T) -> T {
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))] { #[cfg(not(target_arch = "asmjs"))] {
// we need to "use" the argument in some way LLVM can't // we need to "use" the argument in some way LLVM can't
// introspect. // introspect.
unsafe { asm!("" : : "r"(&dummy)) } unsafe { asm!("" : : "r"(&dummy)) }
dummy dummy
} }
#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))] { #[cfg(target_arch = "asmjs")] {
unsafe { unsafe {
let ret = crate::ptr::read_volatile(&dummy); let ret = crate::ptr::read_volatile(&dummy);
crate::mem::forget(dummy); crate::mem::forget(dummy);
ret ret
} }
} }
} }