forked from rust-lang/portable-simd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#360 from rust-lang/shift-scalar
Add scalar shifts
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Shift operations uniquely typically only have a scalar on the right-hand side. | ||
// Here, we implement shifts for scalar RHS arguments. | ||
|
||
use crate::simd::{LaneCount, Simd, SupportedLaneCount}; | ||
|
||
macro_rules! impl_splatted_shifts { | ||
{ impl $trait:ident :: $trait_fn:ident for $ty:ty } => { | ||
impl<const N: usize> core::ops::$trait<$ty> for Simd<$ty, N> | ||
where | ||
LaneCount<N>: SupportedLaneCount, | ||
{ | ||
type Output = Self; | ||
fn $trait_fn(self, rhs: $ty) -> Self::Output { | ||
self.$trait_fn(Simd::splat(rhs)) | ||
} | ||
} | ||
|
||
impl<const N: usize> core::ops::$trait<&$ty> for Simd<$ty, N> | ||
where | ||
LaneCount<N>: SupportedLaneCount, | ||
{ | ||
type Output = Self; | ||
fn $trait_fn(self, rhs: &$ty) -> Self::Output { | ||
self.$trait_fn(Simd::splat(*rhs)) | ||
} | ||
} | ||
|
||
impl<'lhs, const N: usize> core::ops::$trait<$ty> for &'lhs Simd<$ty, N> | ||
where | ||
LaneCount<N>: SupportedLaneCount, | ||
{ | ||
type Output = Simd<$ty, N>; | ||
fn $trait_fn(self, rhs: $ty) -> Self::Output { | ||
self.$trait_fn(Simd::splat(rhs)) | ||
} | ||
} | ||
|
||
impl<'lhs, const N: usize> core::ops::$trait<&$ty> for &'lhs Simd<$ty, N> | ||
where | ||
LaneCount<N>: SupportedLaneCount, | ||
{ | ||
type Output = Simd<$ty, N>; | ||
fn $trait_fn(self, rhs: &$ty) -> Self::Output { | ||
self.$trait_fn(Simd::splat(*rhs)) | ||
} | ||
} | ||
}; | ||
{ $($ty:ty),* } => { | ||
$( | ||
impl_splatted_shifts! { impl Shl::shl for $ty } | ||
impl_splatted_shifts! { impl Shr::shr for $ty } | ||
)* | ||
} | ||
} | ||
|
||
// In the past there were inference issues when generically splatting arguments. | ||
// Enumerate them instead. | ||
impl_splatted_shifts! { i8, i16, i32, i64, isize, u8, u16, u32, u64, usize } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters