Skip to content

Commit 37797d9

Browse files
calebzulawskiworkingjubilee
authored andcommitted
simd_shuffle -> simd_swizzle
1 parent 98e4fca commit 37797d9

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

crates/core_simd/examples/matrix_inversion.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ pub fn simd_inv4x4(m: Matrix4x4) -> Option<Matrix4x4> {
169169
const SHUFFLE13: [Which; 4] = [First(1), First(3), Second(1), Second(3)];
170170
const SHUFFLE23: [Which; 4] = [First(2), First(3), Second(2), Second(3)];
171171

172-
let tmp = simd_shuffle!(m_0, m_1, SHUFFLE01);
173-
let row1 = simd_shuffle!(m_2, m_3, SHUFFLE01);
172+
let tmp = simd_swizzle!(m_0, m_1, SHUFFLE01);
173+
let row1 = simd_swizzle!(m_2, m_3, SHUFFLE01);
174174

175-
let row0 = simd_shuffle!(tmp, row1, SHUFFLE02);
176-
let row1 = simd_shuffle!(row1, tmp, SHUFFLE13);
175+
let row0 = simd_swizzle!(tmp, row1, SHUFFLE02);
176+
let row1 = simd_swizzle!(row1, tmp, SHUFFLE13);
177177

178-
let tmp = simd_shuffle!(m_0, m_1, SHUFFLE23);
179-
let row3 = simd_shuffle!(m_2, m_3, SHUFFLE23);
180-
let row2 = simd_shuffle!(tmp, row3, SHUFFLE02);
181-
let row3 = simd_shuffle!(row3, tmp, SHUFFLE13);
178+
let tmp = simd_swizzle!(m_0, m_1, SHUFFLE23);
179+
let row3 = simd_swizzle!(m_2, m_3, SHUFFLE23);
180+
let row2 = simd_swizzle!(tmp, row3, SHUFFLE02);
181+
let row3 = simd_swizzle!(row3, tmp, SHUFFLE13);
182182

183183
let tmp = (row2 * row3).reverse().rotate_right::<2>();
184184
let minor0 = row1 * tmp;

crates/core_simd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
1919
#[path = "mod.rs"]
2020
mod core_simd;
21-
use self::core_simd::simd;
21+
pub use self::core_simd::simd;
2222
pub use simd::*;

crates/core_simd/src/swizzle.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)