Force LLVM to use CMOV for binary search · patricklam/verify-rust-std@5119266 (original) (raw)
`@@ -1010,6 +1010,34 @@ pub const fn unlikely(b: bool) -> bool {
`
1010
1010
` b
`
1011
1011
`}
`
1012
1012
``
``
1013
`` +
/// Returns either true_val
or false_val
depending on condition b
with a
``
``
1014
`+
/// hint to the compiler that this condition is unlikely to be correctly
`
``
1015
`+
/// predicted by a CPU's branch predictor (e.g. a binary search).
`
``
1016
`+
///
`
``
1017
`` +
/// This is otherwise functionally equivalent to if b { true_val } else { false_val }
.
``
``
1018
`+
///
`
``
1019
`+
/// Note that, unlike most intrinsics, this is safe to call;
`
``
1020
`` +
/// it does not require an unsafe
block.
``
``
1021
`+
/// Therefore, implementations must not require the user to uphold
`
``
1022
`+
/// any safety invariants.
`
``
1023
`+
///
`
``
1024
`+
/// This intrinsic does not have a stable counterpart.
`
``
1025
`+
#[cfg(not(bootstrap))]
`
``
1026
`+
#[unstable(feature = "core_intrinsics", issue = "none")]
`
``
1027
`+
#[rustc_intrinsic]
`
``
1028
`+
#[rustc_nounwind]
`
``
1029
`+
#[miri::intrinsic_fallback_is_spec]
`
``
1030
`+
#[inline]
`
``
1031
`+
pub fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T {
`
``
1032
`+
if b { true_val } else { false_val }
`
``
1033
`+
}
`
``
1034
+
``
1035
`+
#[cfg(bootstrap)]
`
``
1036
`+
#[inline]
`
``
1037
`+
pub fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T {
`
``
1038
`+
if b { true_val } else { false_val }
`
``
1039
`+
}
`
``
1040
+
1013
1041
`extern "rust-intrinsic" {
`
1014
1042
`/// Executes a breakpoint trap, for inspection by a debugger.
`
1015
1043
`///
`