Macro packed_simd_2::shuffle
source · [−]macro_rules! shuffle {
($vec0:expr, $vec1:expr, [$l0:expr, $l1:expr]) => { ... };
($vec0:expr, $vec1:expr, [$l0:expr, $l1:expr, $l2:expr, $l3:expr]) => { ... };
($vec0:expr, $vec1:expr,
[$l0:expr, $l1:expr, $l2:expr, $l3:expr,
$l4:expr, $l5:expr, $l6:expr, $l7:expr]) => { ... };
($vec0:expr, $vec1:expr,
[$l0:expr, $l1:expr, $l2:expr, $l3:expr,
$l4:expr, $l5:expr, $l6:expr, $l7:expr,
$l8:expr, $l9:expr, $l10:expr, $l11:expr,
$l12:expr, $l13:expr, $l14:expr, $l15:expr]) => { ... };
($vec0:expr, $vec1:expr,
[$l0:expr, $l1:expr, $l2:expr, $l3:expr,
$l4:expr, $l5:expr, $l6:expr, $l7:expr,
$l8:expr, $l9:expr, $l10:expr, $l11:expr,
$l12:expr, $l13:expr, $l14:expr, $l15:expr,
$l16:expr, $l17:expr, $l18:expr, $l19:expr,
$l20:expr, $l21:expr, $l22:expr, $l23:expr,
$l24:expr, $l25:expr, $l26:expr, $l27:expr,
$l28:expr, $l29:expr, $l30:expr, $l31:expr]) => { ... };
($vec0:expr, $vec1:expr,
[$l0:expr, $l1:expr, $l2:expr, $l3:expr,
$l4:expr, $l5:expr, $l6:expr, $l7:expr,
$l8:expr, $l9:expr, $l10:expr, $l11:expr,
$l12:expr, $l13:expr, $l14:expr, $l15:expr,
$l16:expr, $l17:expr, $l18:expr, $l19:expr,
$l20:expr, $l21:expr, $l22:expr, $l23:expr,
$l24:expr, $l25:expr, $l26:expr, $l27:expr,
$l28:expr, $l29:expr, $l30:expr, $l31:expr,
$l32:expr, $l33:expr, $l34:expr, $l35:expr,
$l36:expr, $l37:expr, $l38:expr, $l39:expr,
$l40:expr, $l41:expr, $l42:expr, $l43:expr,
$l44:expr, $l45:expr, $l46:expr, $l47:expr,
$l48:expr, $l49:expr, $l50:expr, $l51:expr,
$l52:expr, $l53:expr, $l54:expr, $l55:expr,
$l56:expr, $l57:expr, $l58:expr, $l59:expr,
$l60:expr, $l61:expr, $l62:expr, $l63:expr]) => { ... };
($vec:expr, [$($l:expr),*]) => { ... };
}
Expand description
Shuffles vector elements.
This macro returns a new vector that contains a shuffle of the elements in
one (shuffle!(vec, [indices...])
) or two (shuffle!(vec0, vec1, [indices...])
) input vectors.
The type of vec0
and vec1
must be equal, and the element type of the
resulting vector is the element type of the input vector.
The number of indices
must be a power-of-two in range [0, 64)
, since
currently, the largest vector supported by the library has 64 lanes. The
length of the resulting vector equals the number of indices provided.
The indices must be in range [0, M * N)
where M
is the number of input
vectors (1
or 2
) and N
is the number of lanes of the input vectors.
The indices i
in range [0, N)
refer to the i
-th element of vec0
,
while the indices in range [N, 2*N)
refer to the i - N
-th element of
vec1
.
Examples
Shuffling elements of two vectors:
// Shuffle allows reordering the elements:
let x = i32x4::new(1, 2, 3, 4);
let y = i32x4::new(5, 6, 7, 8);
let r = shuffle!(x, y, [4, 0, 5, 1]);
assert_eq!(r, i32x4::new(5, 1, 6, 2));
// The resulting vector can als be smaller than the input:
let r = shuffle!(x, y, [1, 6]);
assert_eq!(r, i32x2::new(2, 7));
// Or larger:
let r = shuffle!(x, y, [1, 3, 4, 2, 1, 7, 2, 2]);
assert_eq!(r, i32x8::new(2, 4, 5, 3, 2, 8, 3, 3));
// At most 2 * the number of lanes in the input vector.
Shuffling elements of one vector:
// Shuffle allows reordering the elements of a vector:
let x = i32x4::new(1, 2, 3, 4);
let r = shuffle!(x, [2, 1, 3, 0]);
assert_eq!(r, i32x4::new(3, 2, 4, 1));
// The resulting vector can be smaller than the input:
let r = shuffle!(x, [1, 3]);
assert_eq!(r, i32x2::new(2, 4));
// Equal:
let r = shuffle!(x, [1, 3, 2, 0]);
assert_eq!(r, i32x4::new(2, 4, 3, 1));
// Or larger:
let r = shuffle!(x, [1, 3, 2, 2, 1, 3, 2, 2]);
assert_eq!(r, i32x8::new(2, 4, 3, 3, 2, 4, 3, 3));
// At most 2 * the number of lanes in the input vector.