black_box should use inline assembly on wasm32
This commit is contained in:
parent
cfa76c438a
commit
24db517419
1 changed files with 3 additions and 3 deletions
|
@ -99,13 +99,13 @@ 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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue