pub trait ShuffleExt: Sealed {
type Indices;
type Output;
// Required methods
fn shuffle(self, indices: Self::Indices) -> Self::Output;
fn shuffle_zeroing(self, indices: Self::Indices) -> Self::Output;
fn shuffle_wrapping(self, indices: Self::Indices) -> Self::Output;
}Expand description
An extension trait implemented for arrays of SIMD vectors, which provides shuffling from multiple input vectors.
§Example
use wide::{f32x4, ShuffleExt, u32x4};
let simd_a = f32x4::new([0.0, 1.0, 2.0, 3.0]);
let simd_b = f32x4::new([100.0, 101.0, 102.0, 103.0]);
// Here, indices `0..4` map to `simd_a`, and indices `4..8` map to `simd_b`
let from_two_vectors = [simd_a, simd_b].shuffle(u32x4::new([2, 3, 4, 5]));
assert_eq!(from_two_vectors, f32x4::new([2.0, 3.0, 100.0, 101.0]));Required Associated Types§
Required Methods§
Sourcefn shuffle(self, indices: Self::Indices) -> Self::Output
fn shuffle(self, indices: Self::Indices) -> Self::Output
Returns a SIMD vector whose elements are selected from multiple input
vectors using the corresponding runtime indices.
If N is the number of elements in each vector, indices in the range
0..N select values from self[0], indices in the range N..N * 2
select values from self[1], etc.
If an index is out of bounds (greater than or equal to N * INPUTS), the
corresponding result element is unspecified.
§Example
use wide::{f32x4, ShuffleExt, u32x4};
let simd_a = f32x4::new([0.0, 1.0, 2.0, 3.0]);
let simd_b = f32x4::new([100.0, 101.0, 102.0, 103.0]);
// Here, indices `0..4` map to `simd_a`, and indices `4..8` map to `simd_b`
let from_two_vectors = [simd_a, simd_b].shuffle(u32x4::new([2, 3, 4, 5]));
assert_eq!(from_two_vectors, f32x4::new([2.0, 3.0, 100.0, 101.0]));§Type-specific guarantees
For all 8-bit types, it is guaranteed that for out of bounds indices, either zero is returned or the index wraps around, non-deterministically (unlike other types, which can return arbitrary values).
Sourcefn shuffle_zeroing(self, indices: Self::Indices) -> Self::Output
fn shuffle_zeroing(self, indices: Self::Indices) -> Self::Output
Returns a SIMD vector whose elements are selected from multiple input
vectors using the corresponding runtime indices.
If N is the number of elements in each vector, indices in the range
0..N select values from self[0], indices in the range N..N * 2
select values from self[1], etc.
If an index is out of bounds (greater than or equal to N * INPUTS), the
corresponding result element is the number zero.
§Example
use wide::{f32x4, ShuffleExt, u32x4};
let simd_a = f32x4::new([0.0, 1.0, 2.0, 3.0]);
let simd_b = f32x4::new([100.0, 101.0, 102.0, 103.0]);
// Here, indices `0..4` map to `simd_a`, and indices `4..8` map to `simd_b`
let from_two_vectors = [simd_a, simd_b].shuffle_zeroing(u32x4::new([2, 3, 100, 5]));
assert_eq!(from_two_vectors, f32x4::new([2.0, 3.0, 0.0, 101.0]));Sourcefn shuffle_wrapping(self, indices: Self::Indices) -> Self::Output
fn shuffle_wrapping(self, indices: Self::Indices) -> Self::Output
Returns a SIMD vector whose elements are selected from multiple input
vectors using the corresponding runtime indices.
If N is the number of elements in each vector, indices in the range
0..N select values from self[0], indices in the range N..N * 2
select values from self[1], etc.
Indices are wrapped by N * INPUTS.
§Example
use wide::{f32x4, ShuffleExt, u32x4};
let simd_a = f32x4::new([0.0, 1.0, 2.0, 3.0]);
let simd_b = f32x4::new([100.0, 101.0, 102.0, 103.0]);
// Here, indices `0..4` map to `simd_a`, and indices `4..8` map to `simd_b`
let from_two_vectors = [simd_a, simd_b].shuffle_wrapping(u32x4::new([2, 3, 9, 5]));
assert_eq!(from_two_vectors, f32x4::new([2.0, 3.0, 1.0, 101.0]));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".