use int::Int;
use alg;
#[cfg(RUSTC_IS_NIGHTLY)]
mod intrinsics {
use int::Int;
use std::mem::size_of;
use alg;
#[allow(dead_code)]
extern "platform-intrinsic" {
fn x86_bmi2_pdep_32(x: u32, y: u32) -> u32;
fn x86_bmi2_pdep_64(x: u64, y: u64) -> u64;
}
#[inline]
pub unsafe fn pdep<T: Int>(x: T, mask: T) -> T {
match size_of::<T>() * 8 {
32 => T::from_u32(x86_bmi2_pdep_32(x.to_u32(), mask.to_u32())),
64 => T::from_u64(x86_bmi2_pdep_64(x.to_u64(), mask.to_u64())),
_ => alg::x86::bmi2::pdep(x, mask),
}
}
}
#[inline]
pub fn pdep<T: Int>(x: T, mask: T) -> T {
#[cfg(RUSTC_IS_NIGHTLY)]
{
if cfg!(target_feature = "bmi2") {
unsafe { intrinsics::pdep(x, mask) }
} else {
alg::x86::bmi2::pdep(x, mask)
}
}
#[cfg(not(RUSTC_IS_NIGHTLY))]
{
alg::x86::bmi2::pdep(x, mask)
}
}
pub trait PDEP {
#[inline]
fn pdep(self, Self) -> Self;
}
impl<T: Int> PDEP for T {
#[inline]
fn pdep(self, mask: Self) -> Self {
pdep(self, mask)
}
}