@@ -5,55 +5,67 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
55///
66/// A new vector is constructed by specifying the the lanes of the source vector or vectors to use.
77///
8- /// When shuffling one vector, the indices of the result vector are indicated by a `const` array
8+ /// When swizzling one vector, the indices of the result vector are indicated by a `const` array
99/// of `usize`, like [`Swizzle`].
10- /// When shuffling two vectors, the indices are indicated by a `const` array of [`Which`], like
10+ /// When swizzling two vectors, the indices are indicated by a `const` array of [`Which`], like
1111/// [`Swizzle2`].
1212///
1313/// # Examples
1414/// ## One source vector
1515/// ```
1616/// # #![feature(portable_simd)]
17- /// # use core_simd::{Simd, simd_shuffle };
17+ /// # use core_simd::{Simd, simd_swizzle };
1818/// let v = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
19- /// let v = simd_shuffle!(v, [3, 0, 1, 2]);
20- /// assert_eq!(v.to_array(), [3., 0., 1., 2.]);
19+ ///
20+ /// // Keeping the same size
21+ /// let r = simd_swizzle!(v, [3, 0, 1, 2]);
22+ /// assert_eq!(r.to_array(), [3., 0., 1., 2.]);
23+ ///
24+ /// // Changing the number of lanes
25+ /// let r = simd_swizzle!(v, [3, 1]);
26+ /// assert_eq!(r.to_array(), [3., 1.]);
2127/// ```
2228///
2329/// ## Two source vectors
2430/// ```
2531/// # #![feature(portable_simd)]
26- /// # use core_simd::{Simd, simd_shuffle , Which};
32+ /// # use core_simd::{Simd, simd_swizzle , Which};
2733/// use Which::*;
2834/// let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
2935/// let b = Simd::<f32, 4>::from_array([4., 5., 6., 7.]);
30- /// let v = simd_shuffle!(a, b, [First(0), First(1), Second(2), Second(3)]);
31- /// assert_eq!(v.to_array(), [0., 1., 6., 7.]);
36+ ///
37+ /// // Keeping the same size
38+ /// let r = simd_swizzle!(a, b, [First(0), First(1), Second(2), Second(3)]);
39+ /// assert_eq!(r.to_array(), [0., 1., 6., 7.]);
40+ ///
41+ /// // Changing the number of lanes
42+ /// let r = simd_swizzle!(a, b, [First(0), Second(0)]);
43+ /// assert_eq!(r.to_array(), [0., 4.]);
3244/// ```
3345#[ macro_export]
34- macro_rules! simd_shuffle {
46+ macro_rules! simd_swizzle {
3547 {
3648 $vector: expr, $index: expr $( , ) ?
3749 } => {
3850 {
3951 use $crate:: simd:: Swizzle ;
40- struct Shuffle ;
41- impl Swizzle <{ $index . len ( ) } , { $index. len( ) } > for Shuffle {
52+ struct SwizzleImpl ;
53+ impl < const LANES : usize > Swizzle <LANES , { $index. len( ) } > for SwizzleImpl {
4254 const INDEX : [ usize ; { $index. len( ) } ] = $index;
4355 }
44- Shuffle :: swizzle( $vector)
56+ SwizzleImpl :: swizzle( $vector)
4557 }
4658 } ;
4759 {
4860 $first: expr, $second: expr, $index: expr $( , ) ?
4961 } => {
5062 {
5163 use $crate:: simd:: { Which , Swizzle2 } ;
52- struct Shuffle ;
53- impl Swizzle2 <{ $index . len ( ) } , { $index. len( ) } > for Shuffle {
64+ struct SwizzleImpl ;
65+ impl < const LANES : usize > Swizzle2 <LANES , { $index. len( ) } > for SwizzleImpl {
5466 const INDEX : [ Which ; { $index. len( ) } ] = $index;
5567 }
56- Shuffle :: swizzle2( $first, $second)
68+ SwizzleImpl :: swizzle2( $first, $second)
5769 }
5870 }
5971}
0 commit comments