1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use word::{Word, ToWord, UnsignedWord};
use bitintr;
/// Clears all bits of `x` at position >= `bit`.
///
/// # Panics
///
/// If `bit >= bit_size()`.
///
/// # Intrinsics:
/// - BMI 2.0: bzhi.
///
/// # Examples
///
/// ```
/// use bitwise::word::*;
///
/// assert_eq!(0b1111_0010u8.clear_bits_geq(5u8), 0b0001_0010u8);
/// assert_eq!(clear_bits_geq(0b1111_0010u8, 5u8), 0b0001_0010u8);
/// ```
#[inline]
pub fn clear_bits_geq<T: Word, U: UnsignedWord>(x: T, bit: U) -> T {
debug_assert!(T::bit_size() > bit.to());
bitintr::x86::bmi2::bzhi(x, bit.to())
}
/// Method version of [`clear_bits_geq`](fn.clear_bits_geq.html).
pub trait ClearBitsGeq {
#[inline]
fn clear_bits_geq<U: UnsignedWord>(self, n: U) -> Self;
}
impl<T: Word> ClearBitsGeq for T {
#[inline]
fn clear_bits_geq<U: UnsignedWord>(self, n: U) -> Self {
clear_bits_geq(self, n)
}
}