about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/core_simd/src/swizzle.rs4
-rw-r--r--crates/core_simd/tests/swizzle.rs18
2 files changed, 20 insertions, 2 deletions
diff --git a/crates/core_simd/src/swizzle.rs b/crates/core_simd/src/swizzle.rs
index 9fa6a7da8d7..cf1e08aa668 100644
--- a/crates/core_simd/src/swizzle.rs
+++ b/crates/core_simd/src/swizzle.rs
@@ -255,7 +255,7 @@ where
     /// default value (e.g., zero) to the right.
     #[inline]
     #[must_use = "method returns a new vector and does not mutate the original inputs"]
-    fn shift_elements_left<const OFFSET: usize>(self) -> Self
+    pub fn shift_elements_left<const OFFSET: usize>(self) -> Self
     where
         T: Default,
     {
@@ -280,7 +280,7 @@ where
     /// default value (e.g., zero) from the left.
     #[inline]
     #[must_use = "method returns a new vector and does not mutate the original inputs"]
-    fn shift_elements_right<const OFFSET: usize>(self) -> Self
+    pub fn shift_elements_right<const OFFSET: usize>(self) -> Self
     where
         T: Default,
     {
diff --git a/crates/core_simd/tests/swizzle.rs b/crates/core_simd/tests/swizzle.rs
index 522d71439b7..98045fc5c54 100644
--- a/crates/core_simd/tests/swizzle.rs
+++ b/crates/core_simd/tests/swizzle.rs
@@ -50,6 +50,24 @@ fn rotate() {
 
 #[test]
 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+fn shift() {
+    let a = Simd::from_array([1, 2, 3, 4]);
+    assert_eq!(a.shift_elements_left::<0>().to_array(), [1, 2, 3, 4]);
+    assert_eq!(a.shift_elements_left::<1>().to_array(), [2, 3, 4, 0]);
+    assert_eq!(a.shift_elements_left::<2>().to_array(), [3, 4, 0, 0]);
+    assert_eq!(a.shift_elements_left::<3>().to_array(), [4, 0, 0, 0]);
+    assert_eq!(a.shift_elements_left::<4>().to_array(), [0, 0, 0, 0]);
+    assert_eq!(a.shift_elements_left::<5>().to_array(), [0, 0, 0, 0]);
+    assert_eq!(a.shift_elements_right::<0>().to_array(), [1, 2, 3, 4]);
+    assert_eq!(a.shift_elements_right::<1>().to_array(), [0, 1, 2, 3]);
+    assert_eq!(a.shift_elements_right::<2>().to_array(), [0, 0, 1, 2]);
+    assert_eq!(a.shift_elements_right::<3>().to_array(), [0, 0, 0, 1]);
+    assert_eq!(a.shift_elements_right::<4>().to_array(), [0, 0, 0, 0]);
+    assert_eq!(a.shift_elements_right::<5>().to_array(), [0, 0, 0, 0]);
+}
+
+#[test]
+#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
 fn interleave() {
     let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
     let b = Simd::from_array([8, 9, 10, 11, 12, 13, 14, 15]);