pub macro simd_swizzle {
    ($vector : expr, $index : expr $(,) ?) => { ... },
    ($first : expr, $second : expr, $index : expr $(,) ?) => { ... },
}
🔬 This is a nightly-only experimental API. (portable_simd #86656)
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.]);
Run

Two 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