mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 02:54:00 +00:00
Return passed value from black_box
By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away.
This commit is contained in:
parent
3d5fbae338
commit
2cc81ac531
@ -1332,10 +1332,11 @@ impl MetricMap {
|
|||||||
/// elimination.
|
/// elimination.
|
||||||
///
|
///
|
||||||
/// 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`.
|
||||||
pub fn black_box<T>(dummy: T) {
|
pub fn black_box<T>(dummy: T) -> T {
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user