Macro simd_swizzle

macro simd_swizzle {
    (
        $vector:expr, $index:expr $(,)?
    ) => { ... },
    (
        $first:expr, $second:expr, $index:expr $(,)?
    ) => { ... },
}

Constructs a new SIMD vector by copying elements from selected elements in other vectors.

When swizzling one vector, elements are selected like Swizzle::swizzle.

When swizzling two vectors, elements are selected like Swizzle::concat_swizzle.

Examples

With a single SIMD vector, the const array specifies element indices in that vector:

# #![feature(portable_simd)]
# use core::simd::{u32x2, u32x4, simd_swizzle};
let v = u32x4::from_array([10, 11, 12, 13]);

// Keeping the same size
let r: u32x4 = simd_swizzle!(v, [3, 0, 1, 2]);
assert_eq!(r.to_array(), [13, 10, 11, 12]);

// Changing the number of elements
let r: u32x2 = simd_swizzle!(v, [3, 1]);
assert_eq!(r.to_array(), [13, 11]);

With two input SIMD vectors, the const array specifies element indices in the concatenation of those vectors:

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::{u32x2, u32x4, simd_swizzle};
let a = u32x4::from_array([0, 1, 2, 3]);
let b = u32x4::from_array([4, 5, 6, 7]);

// Keeping the same size
let r: u32x4 = simd_swizzle!(a, b, [0, 1, 6, 7]);
assert_eq!(r.to_array(), [0, 1, 6, 7]);

// Changing the number of elements
let r: u32x2 = simd_swizzle!(a, b, [0, 4]);
assert_eq!(r.to_array(), [0, 4]);