pub struct u8x8 { /* private fields */ }Expand description
Implementations§
Source§impl u8x8
impl u8x8
Sourcepub const fn from_array(a: [u8; 8]) -> Self
pub const fn from_array(a: [u8; 8]) -> Self
Converts an array of eight u8 values into a u8x8 value.
Sourcepub fn from_byte_slice<'a>(s: &'a [u8]) -> (&'a [u8], &'a [Self], &'a [u8])
pub fn from_byte_slice<'a>(s: &'a [u8]) -> (&'a [u8], &'a [Self], &'a [u8])
Reinterprets the given byte slice as a slice of u8x8, along with
individual leading and trailing bytes that are not aligned for
interpretation as u64.
This is a useful primitive for analyzing all bytes in a slice more efficiently than visiting each byte separately. The following example counts the number of non-space characters in a byte string:
// (in practice this could only be productive with a much larger
// input than this, but this is just for example.)
let input = b"The quick brown fox jumps over the lazy dog.";
let (start, middle, end) = u8x8::from_byte_slice(input);
const SPACE: u8 = b' ' ;
let space = u8x8::splat(SPACE); // vector of eight spaces
let mut non_space_count = 0;
// Deal with up to seven leading scalar bytes...
for b in start {
if *b != SPACE {
non_space_count += 1;
}
}
// First visit vectors of eight bytes at a time...
for v in middle {
let space_mask = v.equals(space); // returns vector of boolean values
non_space_count += space_mask.not().count_true();
}
// ...then deal with up to seven scalar stragglers.
for b in end {
if *b != SPACE {
non_space_count += 1;
}
}
assert_eq!(non_space_count, 36);Sourcepub fn from_byte_slice_mut<'a>(
s: &'a mut [u8],
) -> (&'a mut [u8], &'a mut [Self], &'a mut [u8])
pub fn from_byte_slice_mut<'a>( s: &'a mut [u8], ) -> (&'a mut [u8], &'a mut [Self], &'a mut [u8])
Reinterprets the given byte slice as a slice of u8x8, along with
individual leading and trailing bytes that are not aligned for
interpretation as u64.
This is a mutable version of Self::from_byte_slice.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Computes the bitwise complement of each element in the vector.
Sourcepub const fn bitor(self, other: Self) -> Self
pub const fn bitor(self, other: Self) -> Self
Computes a bitwise OR result for each element across both vectors.
Sourcepub const fn bitand(self, other: Self) -> Self
pub const fn bitand(self, other: Self) -> Self
Computes a bitwise AND result for each element across both vectors.
Sourcepub const fn bitxor(self, other: Self) -> Self
pub const fn bitxor(self, other: Self) -> Self
Computes a bitwise XOR result for each element across both vectors.
Sourcepub const fn equals(self, other: Self) -> mask8x8
pub const fn equals(self, other: Self) -> mask8x8
Compares each element across both vectors and returns a mask value
where true represents equality and false represents inequality.
Sourcepub const fn less_than(self, other: Self) -> mask8x8
pub const fn less_than(self, other: Self) -> mask8x8
Compares each element across both vectors and returns a mask value
with elements set to true where the corresponding element in self
is less than the corresponding element in other.
Sourcepub const fn greater_than(self, other: Self) -> mask8x8
pub const fn greater_than(self, other: Self) -> mask8x8
Compares each element across both vectors and returns a mask value
with elements set to true where the corresponding element in self
is less than the corresponding element in other.
Sourcepub const fn wrapping_add(self, other: Self) -> Self
pub const fn wrapping_add(self, other: Self) -> Self
Implements addition across corresponding elements, modulo 256.
Sourcepub const fn saturating_add(self, other: Self) -> Self
pub const fn saturating_add(self, other: Self) -> Self
Implements addition across corresponding elements, saturating at the maximum value 255.
Sourcepub const fn collect_sum(self) -> u64
pub const fn collect_sum(self) -> u64
Returns the sum of all of the elements in the vector togther.
Because the maximum value of each element is 255, the maximum value
of the result is 255*8=2040, but the return type is u64 just for
consistency with this type’s general assumption that u64 is the
system’s primary integer size.
Sourcepub const fn wrapping_sub(self, other: Self) -> Self
pub const fn wrapping_sub(self, other: Self) -> Self
Implements subtraction across corresponding elements, modulo 256.
Sourcepub const fn saturating_sub(self, other: Self) -> Self
pub const fn saturating_sub(self, other: Self) -> Self
Implements subtraction across corresponding elements, saturating at the minimum value 0.
Sourcepub const fn abs_difference(self, other: Self) -> Self
pub const fn abs_difference(self, other: Self) -> Self
Computes the absolute difference between corresponding elements.
Sourcepub const fn max(self, other: Self) -> Self
pub const fn max(self, other: Self) -> Self
Finds the maximum value for each element across both vectors.
Sourcepub const fn min(self, other: Self) -> Self
pub const fn min(self, other: Self) -> Self
Finds the minimum value for each element across both vectors.
Trait Implementations§
Source§impl AddAssign<u8> for u8x8
impl AddAssign<u8> for u8x8
Source§fn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
Implements the += operator using Self::wrapping_add.
Source§impl AddAssign for u8x8
impl AddAssign for u8x8
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Implements the += operator using Self::wrapping_add.
Source§impl BitAndAssign for u8x8
impl BitAndAssign for u8x8
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
Implements the &= operator using Self::bitand.
Source§impl BitOrAssign for u8x8
impl BitOrAssign for u8x8
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
Implements the |= operator using Self::bitor.
Source§impl BitXorAssign for u8x8
impl BitXorAssign for u8x8
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
Implements the ^= operator using Self::bitxor.
Source§impl IntoIterator for u8x8
impl IntoIterator for u8x8
Source§impl SubAssign<u8> for u8x8
impl SubAssign<u8> for u8x8
Source§fn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
Implements the -= operator using Self::wrapping_sub.
Source§impl SubAssign for u8x8
impl SubAssign for u8x8
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Implements the -= operator using Self::wrapping_sub.