Skip to content

Commit 55b4b74

Browse files
committed
Add tests, make public
1 parent c7d9ad8 commit 55b4b74

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

crates/core_simd/src/swizzle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ where
255255
/// default value (e.g., zero) to the right.
256256
#[inline]
257257
#[must_use = "method returns a new vector and does not mutate the original inputs"]
258-
fn shift_elements_left<const OFFSET: usize>(self) -> Self
258+
pub fn shift_elements_left<const OFFSET: usize>(self) -> Self
259259
where
260260
T: Default,
261261
{
@@ -280,7 +280,7 @@ where
280280
/// default value (e.g., zero) from the left.
281281
#[inline]
282282
#[must_use = "method returns a new vector and does not mutate the original inputs"]
283-
fn shift_elements_right<const OFFSET: usize>(self) -> Self
283+
pub fn shift_elements_right<const OFFSET: usize>(self) -> Self
284284
where
285285
T: Default,
286286
{

crates/core_simd/tests/swizzle.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ fn rotate() {
4848
assert_eq!(a.rotate_elements_right::<5>().to_array(), [4, 1, 2, 3]);
4949
}
5050

51+
#[test]
52+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
53+
fn shift() {
54+
let a = Simd::from_array([1, 2, 3, 4]);
55+
assert_eq!(a.shift_elements_left::<0>().to_array(), [1, 2, 3, 4]);
56+
assert_eq!(a.shift_elements_left::<1>().to_array(), [2, 3, 4, 0]);
57+
assert_eq!(a.shift_elements_left::<2>().to_array(), [3, 4, 0, 0]);
58+
assert_eq!(a.shift_elements_left::<3>().to_array(), [4, 0, 0, 0]);
59+
assert_eq!(a.shift_elements_left::<4>().to_array(), [0, 0, 0, 0]);
60+
assert_eq!(a.shift_elements_left::<5>().to_array(), [0, 0, 0, 0]);
61+
assert_eq!(a.shift_elements_right::<0>().to_array(), [1, 2, 3, 4]);
62+
assert_eq!(a.shift_elements_right::<1>().to_array(), [0, 1, 2, 3]);
63+
assert_eq!(a.shift_elements_right::<2>().to_array(), [0, 0, 1, 2]);
64+
assert_eq!(a.shift_elements_right::<3>().to_array(), [0, 0, 0, 1]);
65+
assert_eq!(a.shift_elements_right::<4>().to_array(), [0, 0, 0, 0]);
66+
assert_eq!(a.shift_elements_right::<5>().to_array(), [0, 0, 0, 0]);
67+
}
68+
5169
#[test]
5270
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
5371
fn interleave() {

0 commit comments

Comments
 (0)