Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lovely-error/6a88ed1f84c8e22b1189868b36e75e6d to your computer and use it in GitHub Desktop.
Save lovely-error/6a88ed1f84c8e22b1189868b36e75e6d to your computer and use it in GitHub Desktop.
macro if_nospec {
($cond:expr, $on_true:block, $on_false:block) => {
{
if core::hint::likely($cond) {
core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst);
#[allow(unused_unsafe)] unsafe {
core::arch::asm!("lfence");
}
$on_true
} else {
#[allow(unused_unsafe)] unsafe {
core::arch::asm!("lfence");
}
$on_false
}
}
},
($cond:expr, $on_true:block) => {
{
if core::hint::likely($cond) {
core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst);
#[allow(unused_unsafe)] unsafe {
core::arch::asm!("lfence");
}
$on_true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment