u8x8

Struct u8x8 

Source
pub struct u8x8 { /* private fields */ }
Expand description

A vector of eight u8 values, which can have SIMD-like operations applied to them without any explicit SIMD instructions.

This type is really just a u64, but its methods interpret it as eight u8 values where the same operation is applied to all eight values at once.

Implementations§

Source§

impl u8x8

Source

pub const ZEROES: Self

A u8x8 value where all eight elements are set to zero.

Source

pub const fn from_array(a: [u8; 8]) -> Self

Converts an array of eight u8 values into a u8x8 value.

Source

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);
Source

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.

Source

pub const fn splat(v: u8) -> Self

Returns a u8x8 with v in all eight of its elements.

Source

pub const fn to_array(self) -> [u8; 8]

Converts the vector into an array of eight u8 values.

Source

pub const fn complement(self) -> Self

Computes the bitwise complement of each element in the vector.

Source

pub const fn bitor(self, other: Self) -> Self

Computes a bitwise OR result for each element across both vectors.

Source

pub const fn bitand(self, other: Self) -> Self

Computes a bitwise AND result for each element across both vectors.

Source

pub const fn bitxor(self, other: Self) -> Self

Computes a bitwise XOR result for each element across both vectors.

Source

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.

Source

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.

Source

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.

Source

pub const fn wrapping_add(self, other: Self) -> Self

Implements addition across corresponding elements, modulo 256.

Source

pub const fn saturating_add(self, other: Self) -> Self

Implements addition across corresponding elements, saturating at the maximum value 255.

Source

pub const fn reduce_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.

Source

pub const fn wrapping_sub(self, other: Self) -> Self

Implements subtraction across corresponding elements, modulo 256.

Source

pub const fn saturating_sub(self, other: Self) -> Self

Implements subtraction across corresponding elements, saturating at the minimum value 0.

Source

pub const fn abs_difference(self, other: Self) -> Self

Computes the absolute difference between corresponding elements.

Source

pub const fn max(self, other: Self) -> Self

Finds the maximum value for each element across both vectors.

Source

pub const fn min(self, other: Self) -> Self

Finds the minimum value for each element across both vectors.

Source

pub const fn mean(self, other: Self) -> Self

Finds the integer mean value for each element across both vectors.

This is conceptually the same as (self + other)/2, computed without overflow.

Source

pub const fn popcount(self) -> Self

Counts the number of bits set in each element.

Trait Implementations§

Source§

impl Add<u8> for u8x8

Source§

fn add(self, rhs: u8) -> Self

Implements the + operator using Self::wrapping_add.

Source§

type Output = u8x8

The resulting type after applying the + operator.
Source§

impl Add for u8x8

Source§

fn add(self, rhs: Self) -> Self

Implements the + operator using Self::wrapping_add.

Source§

type Output = u8x8

The resulting type after applying the + operator.
Source§

impl AddAssign<u8> for u8x8

Source§

fn add_assign(&mut self, rhs: u8)

Implements the += operator using Self::wrapping_add.

Source§

impl AddAssign for u8x8

Source§

fn add_assign(&mut self, rhs: Self)

Implements the += operator using Self::wrapping_add.

Source§

impl BitAnd for u8x8

Source§

fn bitand(self, rhs: Self) -> Self

Implements the & operator using Self::bitand.

Source§

type Output = u8x8

The resulting type after applying the & operator.
Source§

impl BitAndAssign for u8x8

Source§

fn bitand_assign(&mut self, rhs: Self)

Implements the &= operator using Self::bitand.

Source§

impl BitOr for u8x8

Source§

fn bitor(self, rhs: Self) -> Self

Implements the | operator using Self::bitor.

Source§

type Output = u8x8

The resulting type after applying the | operator.
Source§

impl BitOrAssign for u8x8

Source§

fn bitor_assign(&mut self, rhs: Self)

Implements the |= operator using Self::bitor.

Source§

impl BitXor for u8x8

Source§

fn bitxor(self, rhs: Self) -> Self

Implements the ^ operator using Self::bitxor.

Source§

type Output = u8x8

The resulting type after applying the ^ operator.
Source§

impl BitXorAssign for u8x8

Source§

fn bitxor_assign(&mut self, rhs: Self)

Implements the ^= operator using Self::bitxor.

Source§

impl Clone for u8x8

Source§

fn clone(&self) -> u8x8

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for u8x8

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoIterator for u8x8

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<u8, 8>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Not for u8x8

Source§

fn not(self) -> Self

Implements the unary ! operator using Self::complement.

Source§

type Output = u8x8

The resulting type after applying the ! operator.
Source§

impl PartialEq for u8x8

Source§

fn eq(&self, other: &u8x8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<u8> for u8x8

Source§

fn sub(self, rhs: u8) -> Self

Implements the - operator using Self::wrapping_sub.

Source§

type Output = u8x8

The resulting type after applying the - operator.
Source§

impl Sub for u8x8

Source§

fn sub(self, rhs: Self) -> Self::Output

Implements the + operator using Self::wrapping_sub.

Source§

type Output = u8x8

The resulting type after applying the - operator.
Source§

impl SubAssign<u8> for u8x8

Source§

fn sub_assign(&mut self, rhs: u8)

Implements the -= operator using Self::wrapping_sub.

Source§

impl SubAssign for u8x8

Source§

fn sub_assign(&mut self, rhs: Self)

Implements the -= operator using Self::wrapping_sub.

Source§

impl Copy for u8x8

Source§

impl Eq for u8x8

Source§

impl StructuralPartialEq for u8x8

Auto Trait Implementations§

§

impl Freeze for u8x8

§

impl RefUnwindSafe for u8x8

§

impl Send for u8x8

§

impl Sync for u8x8

§

impl Unpin for u8x8

§

impl UnwindSafe for u8x8

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.