Skip to main content

Vector

Trait Vector 

Source
pub trait Vector: Copy + Debug {
    type Mask: MoveMask;

    const BYTES: usize;
    const ALIGN: usize;

    // Required methods
    fn splat(byte: u8) -> Self;
    unsafe fn load_aligned(data: *const u8) -> Self;
    unsafe fn load_unaligned(data: *const u8) -> Self;
    fn movemask(self) -> Self::Mask;
    fn cmpeq(self, vector2: Self) -> Self;
    fn or(self, vector2: Self) -> Self;
    fn add(self, vector2: Self) -> Self;
    fn gt(self, vector2: Self) -> Self;

    // Provided method
    fn movemask_will_have_non_zero(self) -> bool { ... }
}
Expand description

A trait for describing vector operations used by vectorized searchers.

The trait is highly constrained to low level vector operations needed. In general, it was invented mostly to be generic over x86’s __m128i and __m256i types. At time of writing, it also supports wasm and aarch64 128-bit vector types as well.

§Safety

All methods are not safe since they are intended to be implemented using vendor intrinsics, which are also not safe. Callers must ensure that the appropriate target features are enabled in the calling function, and that the current CPU supports them. All implementations should avoid marking the routines with #[target_feature] and instead mark them as #[\inline(always)] to ensure they get appropriately inlined. (inline(always) cannot be used with target_feature.)

Required Associated Constants§

Source

const BYTES: usize

The number of bytes in the vector. That is, this is the size of the vector in memory.

Source

const ALIGN: usize

The bits that must be zero in order for a *const u8 pointer to be correctly aligned to read vector values.

Required Associated Types§

Source

type Mask: MoveMask

The type of the value returned by Vector::movemask.

This supports abstracting over the specific representation used in order to accommodate different representations in different ISAs.

Required Methods§

Source

fn splat(byte: u8) -> Self

Create a vector with 8-bit lanes with the given byte repeated into each lane.

Source

unsafe fn load_aligned(data: *const u8) -> Self

Read a vector-size number of bytes from the given pointer. The pointer must be aligned to the size of the vector.

§Safety

Callers must guarantee that at least BYTES bytes are readable from data and that data is aligned to a BYTES boundary.

Source

unsafe fn load_unaligned(data: *const u8) -> Self

Read a vector-size number of bytes from the given pointer. The pointer does not need to be aligned.

§Safety

Callers must guarantee that at least BYTES bytes are readable from data.

Source

fn movemask(self) -> Self::Mask

Convert the vector to a mask.

Source

fn cmpeq(self, vector2: Self) -> Self

Compare two vectors for equality.

Source

fn or(self, vector2: Self) -> Self

Bitwise OR of two vectors.

Source

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

Add two vectors.

Source

fn gt(self, vector2: Self) -> Self

Compare two vectors for greater than.

Provided Methods§

Source

fn movemask_will_have_non_zero(self) -> bool

Returns true if and only if Self::movemask would return a mask that contains at least one non-zero bit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Vector for ()

Noop implementation for types that don’t support vectorization.

Source§

const BYTES: usize = 0

Source§

const ALIGN: usize = 0

Source§

type Mask = ()

Source§

fn splat(_byte: u8)

Source§

unsafe fn load_aligned(_data: *const u8)

Source§

unsafe fn load_unaligned(_data: *const u8)

Source§

fn movemask(self) -> <() as Vector>::Mask

Source§

fn cmpeq(self, _vector2: ())

Source§

fn or(self, _vector2: ())

Source§

fn add(self, _vector2: ())

Source§

fn gt(self, _vector2: ())

Source§

impl Vector for __m128i

Source§

const BYTES: usize = 16

Source§

const ALIGN: usize

Source§

type Mask = SensibleMoveMask

Source§

fn splat(byte: u8) -> __m128i

Source§

unsafe fn load_aligned(data: *const u8) -> __m128i

Source§

unsafe fn load_unaligned(data: *const u8) -> __m128i

Source§

fn movemask(self) -> <__m128i as Vector>::Mask

Source§

fn cmpeq(self, vector2: __m128i) -> __m128i

Source§

fn or(self, vector2: __m128i) -> __m128i

Source§

fn add(self, vector2: __m128i) -> __m128i

Source§

fn gt(self, vector2: __m128i) -> __m128i

Source§

impl Vector for __m256i

Source§

const BYTES: usize = 32

Source§

const ALIGN: usize

Source§

type Mask = SensibleMoveMask

Source§

fn splat(byte: u8) -> __m256i

Source§

unsafe fn load_aligned(data: *const u8) -> __m256i

Source§

unsafe fn load_unaligned(data: *const u8) -> __m256i

Source§

fn movemask(self) -> <__m256i as Vector>::Mask

Source§

fn cmpeq(self, vector2: __m256i) -> __m256i

Source§

fn or(self, vector2: __m256i) -> __m256i

Source§

fn add(self, vector2: __m256i) -> __m256i

Source§

fn gt(self, vector2: __m256i) -> __m256i

Implementors§