bitintr 0.1.13

Portable Bit Manipulation Intrinsics.
Documentation
use int::Int;

/// Parallel bits deposit.
///
/// See [`x86::bmi2::pdep`](fn.pdep.html).
#[inline]
pub fn pdep<T: Int>(x: T, mask_: T) -> T {
    let mut res = T::zero();
    let mut mask = mask_;
    let mut bb = T::one();
    loop {
        if mask == T::zero() {
            break;
        }
        if (x & bb) != T::zero() {
            res = res | (mask & mask.wrapping_neg());
        }
        mask = mask & (mask - T::one());
        bb = bb + bb;
    }
    res
}

pub trait PDEP {
    #[inline]
    fn pdep(self, Self) -> Self;
}

impl<T: Int> PDEP for T {
    #[inline]
    fn pdep(self, y: Self) -> Self {
        pdep(self, y)
    }
}