about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-09-23 00:28:07 +0000
committerJubilee <46493976+workingjubilee@users.noreply.github.com>2021-10-11 13:18:59 -0700
commit37797d9c0a7e2f28fec5273399f86edc5cff7ae3 (patch)
tree95ab943139dbd33446d58b606d257327f2cdebb9
parent98e4fcae5aa0080d97901835e8391ec394acfef6 (diff)
downloadrust-37797d9c0a7e2f28fec5273399f86edc5cff7ae3.tar.gz
rust-37797d9c0a7e2f28fec5273399f86edc5cff7ae3.zip
simd_shuffle -> simd_swizzle
-rw-r--r--crates/core_simd/examples/matrix_inversion.rs16
-rw-r--r--crates/core_simd/src/lib.rs2
-rw-r--r--crates/core_simd/src/swizzle.rs42
3 files changed, 36 insertions, 24 deletions
diff --git a/crates/core_simd/examples/matrix_inversion.rs b/crates/core_simd/examples/matrix_inversion.rs
index ee8c477b838..468319325e2 100644
--- a/crates/core_simd/examples/matrix_inversion.rs
+++ b/crates/core_simd/examples/matrix_inversion.rs
@@ -169,16 +169,16 @@ pub fn simd_inv4x4(m: Matrix4x4) -> Option<Matrix4x4> {
     const SHUFFLE13: [Which; 4] = [First(1), First(3), Second(1), Second(3)];
     const SHUFFLE23: [Which; 4] = [First(2), First(3), Second(2), Second(3)];
 
-    let tmp = simd_shuffle!(m_0, m_1, SHUFFLE01);
-    let row1 = simd_shuffle!(m_2, m_3, SHUFFLE01);
+    let tmp = simd_swizzle!(m_0, m_1, SHUFFLE01);
+    let row1 = simd_swizzle!(m_2, m_3, SHUFFLE01);
 
-    let row0 = simd_shuffle!(tmp, row1, SHUFFLE02);
-    let row1 = simd_shuffle!(row1, tmp, SHUFFLE13);
+    let row0 = simd_swizzle!(tmp, row1, SHUFFLE02);
+    let row1 = simd_swizzle!(row1, tmp, SHUFFLE13);
 
-    let tmp = simd_shuffle!(m_0, m_1, SHUFFLE23);
-    let row3 = simd_shuffle!(m_2, m_3, SHUFFLE23);
-    let row2 = simd_shuffle!(tmp, row3, SHUFFLE02);
-    let row3 = simd_shuffle!(row3, tmp, SHUFFLE13);
+    let tmp = simd_swizzle!(m_0, m_1, SHUFFLE23);
+    let row3 = simd_swizzle!(m_2, m_3, SHUFFLE23);
+    let row2 = simd_swizzle!(tmp, row3, SHUFFLE02);
+    let row3 = simd_swizzle!(row3, tmp, SHUFFLE13);
 
     let tmp = (row2 * row3).reverse().rotate_right::<2>();
     let minor0 = row1 * tmp;
diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs
index 55b8be97e0e..1d8cdad8900 100644
--- a/crates/core_simd/src/lib.rs
+++ b/crates/core_simd/src/lib.rs
@@ -18,5 +18,5 @@
 
 #[path = "mod.rs"]
 mod core_simd;
-use self::core_simd::simd;
+pub use self::core_simd::simd;
 pub use simd::*;
diff --git a/crates/core_simd/src/swizzle.rs b/crates/core_simd/src/swizzle.rs
index 5ba9f3dec59..d4702784dc5 100644
--- a/crates/core_simd/src/swizzle.rs
+++ b/crates/core_simd/src/swizzle.rs
@@ -5,43 +5,55 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
 ///
 /// A new vector is constructed by specifying the the lanes of the source vector or vectors to use.
 ///
-/// When shuffling one vector, the indices of the result vector are indicated by a `const` array
+/// When swizzling one vector, the indices of the result vector are indicated by a `const` array
 /// of `usize`, like [`Swizzle`].
-/// When shuffling two vectors, the indices are indicated by a `const` array of [`Which`], like
+/// When swizzling two vectors, the indices are indicated by a `const` array of [`Which`], like
 /// [`Swizzle2`].
 ///
 /// # Examples
 /// ## One source vector
 /// ```
 /// # #![feature(portable_simd)]
-/// # use core_simd::{Simd, simd_shuffle};
+/// # use core_simd::{Simd, simd_swizzle};
 /// let v = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
-/// let v = simd_shuffle!(v, [3, 0, 1, 2]);
-/// assert_eq!(v.to_array(), [3., 0., 1., 2.]);
+///
+/// // Keeping the same size
+/// let r = simd_swizzle!(v, [3, 0, 1, 2]);
+/// assert_eq!(r.to_array(), [3., 0., 1., 2.]);
+///
+/// // Changing the number of lanes
+/// let r = simd_swizzle!(v, [3, 1]);
+/// assert_eq!(r.to_array(), [3., 1.]);
 /// ```
 ///
 /// ## Two source vectors
 /// ```
 /// # #![feature(portable_simd)]
-/// # use core_simd::{Simd, simd_shuffle, Which};
+/// # use core_simd::{Simd, simd_swizzle, Which};
 /// use Which::*;
 /// let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
 /// let b = Simd::<f32, 4>::from_array([4., 5., 6., 7.]);
-/// let v = simd_shuffle!(a, b, [First(0), First(1), Second(2), Second(3)]);
-/// assert_eq!(v.to_array(), [0., 1., 6., 7.]);
+///
+/// // Keeping the same size
+/// let r = simd_swizzle!(a, b, [First(0), First(1), Second(2), Second(3)]);
+/// assert_eq!(r.to_array(), [0., 1., 6., 7.]);
+///
+/// // Changing the number of lanes
+/// let r = simd_swizzle!(a, b, [First(0), Second(0)]);
+/// assert_eq!(r.to_array(), [0., 4.]);
 /// ```
 #[macro_export]
-macro_rules! simd_shuffle {
+macro_rules! simd_swizzle {
     {
         $vector:expr, $index:expr $(,)?
     } => {
         {
             use $crate::simd::Swizzle;
-            struct Shuffle;
-            impl Swizzle<{$index.len()}, {$index.len()}> for Shuffle {
+            struct SwizzleImpl;
+            impl<const LANES: usize> Swizzle<LANES, {$index.len()}> for SwizzleImpl {
                 const INDEX: [usize; {$index.len()}] = $index;
             }
-            Shuffle::swizzle($vector)
+            SwizzleImpl::swizzle($vector)
         }
     };
     {
@@ -49,11 +61,11 @@ macro_rules! simd_shuffle {
     } => {
         {
             use $crate::simd::{Which, Swizzle2};
-            struct Shuffle;
-            impl Swizzle2<{$index.len()}, {$index.len()}> for Shuffle {
+            struct SwizzleImpl;
+            impl<const LANES: usize> Swizzle2<LANES, {$index.len()}> for SwizzleImpl {
                 const INDEX: [Which; {$index.len()}] = $index;
             }
-            Shuffle::swizzle2($first, $second)
+            SwizzleImpl::swizzle2($first, $second)
         }
     }
 }