@@ -5,55 +5,67 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
5
5
///
6
6
/// A new vector is constructed by specifying the the lanes of the source vector or vectors to use.
7
7
///
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
9
9
/// 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
11
11
/// [`Swizzle2`].
12
12
///
13
13
/// # Examples
14
14
/// ## One source vector
15
15
/// ```
16
16
/// # #![feature(portable_simd)]
17
- /// # use core_simd::{Simd, simd_shuffle };
17
+ /// # use core_simd::{Simd, simd_swizzle };
18
18
/// 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.]);
21
27
/// ```
22
28
///
23
29
/// ## Two source vectors
24
30
/// ```
25
31
/// # #![feature(portable_simd)]
26
- /// # use core_simd::{Simd, simd_shuffle , Which};
32
+ /// # use core_simd::{Simd, simd_swizzle , Which};
27
33
/// use Which::*;
28
34
/// let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
29
35
/// 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.]);
32
44
/// ```
33
45
#[ macro_export]
34
- macro_rules! simd_shuffle {
46
+ macro_rules! simd_swizzle {
35
47
{
36
48
$vector: expr, $index: expr $( , ) ?
37
49
} => {
38
50
{
39
51
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 {
42
54
const INDEX : [ usize ; { $index. len( ) } ] = $index;
43
55
}
44
- Shuffle :: swizzle( $vector)
56
+ SwizzleImpl :: swizzle( $vector)
45
57
}
46
58
} ;
47
59
{
48
60
$first: expr, $second: expr, $index: expr $( , ) ?
49
61
} => {
50
62
{
51
63
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 {
54
66
const INDEX : [ Which ; { $index. len( ) } ] = $index;
55
67
}
56
- Shuffle :: swizzle2( $first, $second)
68
+ SwizzleImpl :: swizzle2( $first, $second)
57
69
}
58
70
}
59
71
}
0 commit comments