Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add examples for shift_elements_{left, right} and rotate_elements_{left, right} #452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ where
/// Rotates the vector such that the first `OFFSET` elements of the slice move to the end
/// while the last `self.len() - OFFSET` elements move to the front. After calling `rotate_elements_left`,
/// the element previously at index `OFFSET` will become the first element in the slice.
/// ```
/// # #![feature(portable_simd)]
/// # use core::simd::Simd;
/// let a = Simd::from_array([0, 1, 2, 3]);
/// let x = a.rotate_elements_left::<3>();
/// assert_eq!(x.to_array(), [3, 0, 1, 2]);
///
/// let y = a.rotate_elements_left::<7>();
/// assert_eq!(y.to_array(), [3, 0, 1, 2]);
/// ```
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn rotate_elements_left<const OFFSET: usize>(self) -> Self {
Expand All @@ -238,6 +248,16 @@ where
/// Rotates the vector such that the first `self.len() - OFFSET` elements of the vector move to
/// the end while the last `OFFSET` elements move to the front. After calling `rotate_elements_right`,
/// the element previously at index `self.len() - OFFSET` will become the first element in the slice.
/// ```
/// # #![feature(portable_simd)]
/// # use core::simd::Simd;
/// let a = Simd::from_array([0, 1, 2, 3]);
/// let x = a.rotate_elements_right::<3>();
/// assert_eq!(x.to_array(), [1, 2, 3, 0]);
///
/// let y = a.rotate_elements_right::<7>();
/// assert_eq!(y.to_array(), [1, 2, 3, 0]);
/// ```
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn rotate_elements_right<const OFFSET: usize>(self) -> Self {
Expand All @@ -261,6 +281,16 @@ where

/// Shifts the vector elements to the left by `OFFSET`, filling in with
/// `padding` from the right.
/// ```
/// # #![feature(portable_simd)]
/// # use core::simd::Simd;
/// let a = Simd::from_array([0, 1, 2, 3]);
/// let x = a.shift_elements_left::<3>(255);
/// assert_eq!(x.to_array(), [3, 255, 255, 255]);
///
/// let y = a.shift_elements_left::<7>(255);
/// assert_eq!(y.to_array(), [255, 255, 255, 255]);
/// ```
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn shift_elements_left<const OFFSET: usize>(self, padding: T) -> Self {
Expand All @@ -283,6 +313,16 @@ where

/// Shifts the vector elements to the right by `OFFSET`, filling in with
/// `padding` from the left.
/// ```
/// # #![feature(portable_simd)]
/// # use core::simd::Simd;
/// let a = Simd::from_array([0, 1, 2, 3]);
/// let x = a.shift_elements_right::<3>(255);
/// assert_eq!(x.to_array(), [255, 0, 1, 2]);
///
/// let y = a.shift_elements_right::<7>(255);
/// assert_eq!(y.to_array(), [255, 255, 255, 255]);
/// ```
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn shift_elements_right<const OFFSET: usize>(self, padding: T) -> Self {
Expand Down
Loading