#[repr(transparent)]pub struct BitMask<const N: usize>(pub u64);Expand description
Bit-packed predicate mask for exactly N SIMD lanes.
The inner u64 stores one bit per lane: bit i = lane i is active.
Invariant: (self.0 >> N) == 0 (high bits always clear).
N must satisfy N <= 64. Violations are caught by a const assertion in ALL_ACTIVE.
Tuple Fields§
§0: u64Implementations§
Source§impl<const N: usize> BitMask<N>
impl<const N: usize> BitMask<N>
Sourcepub const ALL_ACTIVE: BitMask<N>
pub const ALL_ACTIVE: BitMask<N>
Sourcepub const NONE_ACTIVE: BitMask<N>
pub const NONE_ACTIVE: BitMask<N>
No lanes active.
Sourcepub const fn leading_k(k: usize) -> BitMask<N>
pub const fn leading_k(k: usize) -> BitMask<N>
First k lanes active, rest inactive. Clamps k to N.
This is a const fn so it can be used in const contexts.
§Examples
use hermes_simd_core::mask::BitMask;
assert_eq!(BitMask::<8>::leading_k(5).0, 0b00011111);
assert_eq!(BitMask::<8>::leading_k(0).0, 0);
assert_eq!(BitMask::<8>::leading_k(8).0, 0xFF);Sourcepub fn from_bools(bits: &[bool]) -> BitMask<N>
pub fn from_bools(bits: &[bool]) -> BitMask<N>
Build a mask from a bool slice of length N.
Bit i is set if bits[i] is true.
§Panics
Panics in debug mode if bits.len() != N.
Sourcepub fn is_all_active(self) -> bool
pub fn is_all_active(self) -> bool
Returns true if all N lanes are active.
Sourcepub fn is_none_active(self) -> bool
pub fn is_none_active(self) -> bool
Returns true if no lanes are active.
Sourcepub fn is_lane_active(self, i: usize) -> bool
pub fn is_lane_active(self, i: usize) -> bool
Source§impl<const N: usize> BitMask<N>
impl<const N: usize> BitMask<N>
Sourcepub unsafe fn to_native_mask<T, Arch>(self) -> <Arch as SimdKernel<T>>::Maskwhere
T: NumericElement,
Arch: SimdKernel<T>,
pub unsafe fn to_native_mask<T, Arch>(self) -> <Arch as SimdKernel<T>>::Maskwhere
T: NumericElement,
Arch: SimdKernel<T>,
Convert this BitMask<N> to the native hardware mask type for Arch.
Delegates to SimdKernel::mask_from_bitmask
using the inner u64 value.
Zero runtime cost: the compiler inlines this into a single instruction on
AVX-512 (KMOV), a vector comparison + blend mask on AVX2, or a bool-array
copy on scalar backends.
§Safety
Processor must support the target feature of Arch.
§Example
use hermes_simd_core::mask::BitMask;
use hermes_simd_core::kernel::SimdKernel;
use hermes_simd_intrinsics::Scalar;
let bm = BitMask::<4>::leading_k(3);
// SAFETY: `Scalar` has no target-feature precondition.
let native: <Scalar as SimdKernel<f32>>::Mask =
unsafe { bm.to_native_mask::<f32, Scalar>() };
assert_eq!(native, [true, true, true, false]);Source§impl<const N: usize> BitMask<N>
impl<const N: usize> BitMask<N>
Sourcepub fn active_lanes(self) -> BitMaskIter<N> ⓘ
pub fn active_lanes(self) -> BitMaskIter<N> ⓘ
Convenience method to iterate active lane indices without consuming.
Equivalent to (*self).into_iter() since BitMask<N>: Copy.
Trait Implementations§
Source§impl<const N: usize> Archive for BitMask<N>
impl<const N: usize> Archive for BitMask<N>
Source§type Archived = ArchivedBitMask<N>
type Archived = ArchivedBitMask<N>
Source§type Resolver = BitMaskResolver<N>
type Resolver = BitMaskResolver<N>
Source§fn resolve(
&self,
resolver: <BitMask<N> as Archive>::Resolver,
out: Place<<BitMask<N> as Archive>::Archived>,
)
fn resolve( &self, resolver: <BitMask<N> as Archive>::Resolver, out: Place<<BitMask<N> as Archive>::Archived>, )
Source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreimpl<const N: usize> Copy for BitMask<N>
impl<const N: usize> Eq for BitMask<N>
Source§impl<const N: usize> IntoIterator for BitMask<N>
impl<const N: usize> IntoIterator for BitMask<N>
Source§fn into_iter(self) -> BitMaskIter<N> ⓘ
fn into_iter(self) -> BitMaskIter<N> ⓘ
Iterate over active lane indices in ascending order.
§Example
use hermes_simd_core::mask::BitMask;
let mask = BitMask::<8>::from_bools(&[true, false, true, false, true, false, false, false]);
let indices: Vec<usize> = mask.into_iter().collect();
assert_eq!(indices, vec![0, 2, 4]);Source§type IntoIter = BitMaskIter<N>
type IntoIter = BitMaskIter<N>
impl<const N: usize> StructuralPartialEq for BitMask<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for BitMask<N>
impl<const N: usize> RefUnwindSafe for BitMask<N>
impl<const N: usize> Send for BitMask<N>
impl<const N: usize> Sync for BitMask<N>
impl<const N: usize> Unpin for BitMask<N>
impl<const N: usize> UnsafeUnpin for BitMask<N>
impl<const N: usize> UnwindSafe for BitMask<N>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.