macro_rules! arch_specific {
(#[doc = $docs:expr] $name:ident($($input_ident:ident: $input:ty),*) -> $ret:ty $fallback:block, $($x86_feature:tt),* = $x86_intrinsic:path) => {
#[inline(never)]
#[allow(unused_unsafe, unused_mut)]
#[doc = concat!($docs, "\n\nLowers to `", stringify!($x86_intrinsic), "` instruction with feature ", $("`", $x86_feature, "` or ",)* "a safe fallback.")]
pub fn $name($(mut $input_ident: $input),*) -> $ret {
#[cfg(all(
feature = "dynamic",
target_arch = "x86_64",
not(any($(target_feature = $x86_feature,)*)),
))]
{
if $(std::arch::is_x86_feature_detected!($x86_feature) || )* false {
unsafe {
$x86_intrinsic($($input_ident),*)
}
} else {
$fallback
}
}
#[cfg(all(
target_arch = "x86_64",
any($(target_feature = $x86_feature,)*),
))]
{
unsafe {
$x86_intrinsic($($input_ident),*)
}
}
#[cfg(any(
not(target_arch = "x86_64"),
all(
target_arch = "x86_64",
not(any($(target_feature = $x86_feature,)*)),
not(feature = "dynamic"),
),
))]
{
$fallback
}
}
};
(#[doc = $docs:expr] $name:ident($($input_ident:ident: $input:ty),*) -> $ret:ty $fallback:block, $x86_intrinsic:path) => {
#[inline(always)]
#[allow(unused_unsafe)]
#[doc = concat!($docs, "\n\nLowers to `", stringify!($x86_intrinsic), "` instruction on `x86_64` and a safe fallback for other architectures.")]
pub fn $name($($input_ident: $input),*) -> $ret {
#[cfg(target_arch = "x86_64")]
unsafe {
$x86_intrinsic($($input_ident),*)
}
#[cfg(not(target_arch = "x86_64"))]
{
$fallback
}
}
};
}
mod bmi1;
pub use bmi1::*;
mod bmi2;
pub use bmi2::*;
mod tbm;
pub use tbm::*;
mod abm;
pub use abm::*;
mod generic;
pub use generic::*;