bit_arch 0.1.2

High-level zero-cost bit manipulation
Documentation
//! Low-level `u32` and `u64` operations.
//!
//! These are useful if you can't afford to waste any performance on the API abstraction layer.
//! It often provides no noticeable improvement, but it makes the intent clear.
//!
//! This module is also useful if you want to use intrinsics like `extract_bitfield_control_*`
//! or `trailing_zeros_u16`. These can improve performance but are more advanced than their
//! abstract counterparts. This also includes the complete `_bittest*` family of operations.

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(always)]
        #[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 {
                    ::core::hint::cold_path();

                    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, $({ $safe:ident $safety_docs:expr })? $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."
            $(, "\n\n# Safety\n\n", $safety_docs)?
        )]
        pub $($safe)? 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::*;