Skip to content

Commit

Permalink
Add tests, make public
Browse files Browse the repository at this point in the history
  • Loading branch information
sammysheep committed Sep 27, 2024
1 parent c7d9ad8 commit 55b4b74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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,
{
Expand Down
18 changes: 18 additions & 0 deletions crates/core_simd/tests/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ fn rotate() {
assert_eq!(a.rotate_elements_right::<5>().to_array(), [4, 1, 2, 3]);
}

#[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() {
Expand Down

0 comments on commit 55b4b74

Please sign in to comment.