Macro core::simd::simd_swizzle
source · [−]pub macro simd_swizzle {
(
$vector:expr, $index:expr $(,)?
) => { ... },
(
$first:expr, $second:expr, $index:expr $(,)?
) => { ... },
}Expand description
Constructs a new vector by selecting values from the lanes of the source vector or vectors to use.
When swizzling one vector, the indices of the result vector are indicated by a const array
of usize, like Swizzle.
When swizzling two vectors, the indices are indicated by a const array of Which, like
Swizzle2.
Examples
One source vector
let v = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
// Keeping the same size
let r = simd_swizzle!(v, [3, 0, 1, 2]);
assert_eq!(r.to_array(), [3., 0., 1., 2.]);
// Changing the number of lanes
let r = simd_swizzle!(v, [3, 1]);
assert_eq!(r.to_array(), [3., 1.]);RunTwo source vectors
use Which::*;
let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
let b = Simd::<f32, 4>::from_array([4., 5., 6., 7.]);
// Keeping the same size
let r = simd_swizzle!(a, b, [First(0), First(1), Second(2), Second(3)]);
assert_eq!(r.to_array(), [0., 1., 6., 7.]);
// Changing the number of lanes
let r = simd_swizzle!(a, b, [First(0), Second(0)]);
assert_eq!(r.to_array(), [0., 4.]);Run