| 1 |
#![cfg(target_feature = "bmi2")] |
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
/// Zero out all high bits in a `u32` starting at the index given. |
| 6 |
/// |
| 7 |
/// * **Intrinsic:** [`_bzhi_u32`] |
| 8 |
/// * **Assembly:** `bzhi r32, r32, r32` |
| 9 |
#[must_use] |
| 10 |
#[inline(always)] |
| 11 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 12 |
pub fn bit_zero_high_index_u32(a: u32, index: u32) -> u32 { |
| 13 |
unsafe { _bzhi_u32(a, index) } |
| 14 |
} |
| 15 |
|
| 16 |
/// Zero out all high bits in a `u64` starting at the index given. |
| 17 |
/// |
| 18 |
/// * **Intrinsic:** [`_bzhi_u64`] |
| 19 |
/// * **Assembly:** `bzhi r64, r64, r64` |
| 20 |
#[must_use] |
| 21 |
#[inline(always)] |
| 22 |
#[cfg(target_arch = "x86_64")] |
| 23 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 24 |
pub fn bit_zero_high_index_u64(a: u64, index: u32) -> u64 { |
| 25 |
unsafe { _bzhi_u64(a, index) } |
| 26 |
} |
| 27 |
|
| 28 |
/// Multiply two `u32`, outputting the low bits and storing the high bits in the |
| 29 |
/// reference. |
| 30 |
/// |
| 31 |
/// This does not read or write arithmetic flags. |
| 32 |
/// |
| 33 |
/// * **Intrinsic:** [`_mulx_u32`] |
| 34 |
/// * **Assembly:** `mulx r32, r32, m32` |
| 35 |
#[must_use] |
| 36 |
#[inline(always)] |
| 37 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 38 |
pub fn mul_extended_u32(a: u32, b: u32, extra: &mut u32) -> u32 { |
| 39 |
unsafe { _mulx_u32(a, b, extra) } |
| 40 |
} |
| 41 |
|
| 42 |
/// Multiply two `u64`, outputting the low bits and storing the high bits in the |
| 43 |
/// reference. |
| 44 |
/// |
| 45 |
/// This does not read or write arithmetic flags. |
| 46 |
/// |
| 47 |
/// * **Intrinsic:** [`_mulx_u64`] |
| 48 |
/// * **Assembly:** `mulx r64, r64, m64` |
| 49 |
#[must_use] |
| 50 |
#[inline(always)] |
| 51 |
#[cfg(target_arch = "x86_64")] |
| 52 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 53 |
pub fn mul_extended_u64(a: u64, b: u64, extra: &mut u64) -> u64 { |
| 54 |
unsafe { _mulx_u64(a, b, extra) } |
| 55 |
} |
| 56 |
|
| 57 |
/// Deposit contiguous low bits from a `u32` according to a mask. |
| 58 |
/// |
| 59 |
/// Other bits are zero. |
| 60 |
/// |
| 61 |
/// * **Intrinsic:** [`_pdep_u32`] |
| 62 |
/// * **Assembly:** `pdep r32, r32, r32` |
| 63 |
#[must_use] |
| 64 |
#[inline(always)] |
| 65 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 66 |
pub fn population_deposit_u32(a: u32, index: u32) -> u32 { |
| 67 |
unsafe { _pdep_u32(a, index) } |
| 68 |
} |
| 69 |
|
| 70 |
/// Deposit contiguous low bits from a `u64` according to a mask. |
| 71 |
/// |
| 72 |
/// Other bits are zero. |
| 73 |
/// |
| 74 |
/// * **Intrinsic:** [`_pdep_u64`] |
| 75 |
/// * **Assembly:** `pdep r64, r64, r64` |
| 76 |
#[must_use] |
| 77 |
#[inline(always)] |
| 78 |
#[cfg(target_arch = "x86_64")] |
| 79 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 80 |
pub fn population_deposit_u64(a: u64, index: u64) -> u64 { |
| 81 |
unsafe { _pdep_u64(a, index) } |
| 82 |
} |
| 83 |
|
| 84 |
/// Extract bits from a `u32` according to a mask. |
| 85 |
/// |
| 86 |
/// * **Intrinsic:** [`_pext_u32`] |
| 87 |
/// * **Assembly:** `pext r32, r32, r32` |
| 88 |
#[must_use] |
| 89 |
#[inline(always)] |
| 90 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 91 |
pub fn population_extract_u32(a: u32, index: u32) -> u32 { |
| 92 |
unsafe { _pext_u32(a, index) } |
| 93 |
} |
| 94 |
|
| 95 |
/// Extract bits from a `u64` according to a mask. |
| 96 |
/// |
| 97 |
/// * **Intrinsic:** [`_pext_u64`] |
| 98 |
/// * **Assembly:** `pext r64, r64, r64` |
| 99 |
#[must_use] |
| 100 |
#[inline(always)] |
| 101 |
#[cfg(target_arch = "x86_64")] |
| 102 |
#[cfg_attr(docsrs, doc(cfg(target_feature = "bmi2")))] |
| 103 |
pub fn population_extract_u64(a: u64, index: u64) -> u64 { |
| 104 |
unsafe { _pext_u64(a, index) } |
| 105 |
} |
| 106 |
|