-
Notifications
You must be signed in to change notification settings - Fork 23
Add dynamic swizzles for 128-bit u8/i8 vectors #265
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1165,6 +1165,14 @@ impl Simd for Fallback { | |
| .simd_into(self) | ||
| } | ||
| #[inline(always)] | ||
| fn swizzle_dyn_i8x16(self, a: i8x16<Self>, idxs: u8x16<Self>) -> i8x16<Self> { | ||
| let mut dest = [Default::default(); 16]; | ||
| for (i, idx) in idxs.val.0.iter().copied().enumerate() { | ||
| dest[i] = a.val.0.get(idx as usize).copied().unwrap_or(0); | ||
| } | ||
| dest.simd_into(self) | ||
| } | ||
| #[inline(always)] | ||
| fn reinterpret_u8_i8x16(self, a: i8x16<Self>) -> u8x16<Self> { | ||
| a.bitcast() | ||
| } | ||
|
|
@@ -1768,6 +1776,14 @@ impl Simd for Fallback { | |
| result.simd_into(self) | ||
| } | ||
| #[inline(always)] | ||
| fn swizzle_dyn_u8x16(self, a: u8x16<Self>, idxs: u8x16<Self>) -> u8x16<Self> { | ||
| let mut dest = [Default::default(); 16]; | ||
| for (i, idx) in idxs.val.0.iter().copied().enumerate() { | ||
| dest[i] = a.val.0.get(idx as usize).copied().unwrap_or(0); | ||
| } | ||
| dest.simd_into(self) | ||
| } | ||
| #[inline(always)] | ||
|
Comment on lines
+1779
to
+1786
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| fn widen_u8x16(self, a: u8x16<Self>) -> u16x16<Self> { | ||
| [ | ||
| a[0usize] as u16, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,11 @@ pub trait SimdCvtFloat<T: Seal>: Seal { | |
| fn float_from(x: T) -> Self; | ||
| } | ||
|
|
||
| /// Dynamic swizzle for byte vectors. | ||
| pub trait SimdSwizzleDyn<S: Simd>: SimdBase<S> + Seal { | ||
| fn swizzle_dyn(self, idxs: crate::u8x16<S>) -> Self; | ||
| } | ||
|
|
||
|
Comment on lines
+159
to
+163
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way this trait is defined locks us into u8x16 vectors for indices. Making it more general later is a semver-breaking change. Something like
|
||
| /// Concatenation of two SIMD vectors. | ||
| /// | ||
| /// This is implemented on all vectors 256 bits and lower, producing vectors of up to 512 bits. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback implementations are usually manually unrolled so that platforms we don't support via intrinsics would have a better shot at autovectorization, see e.g.
fearless_simd/fearless_simd/src/generated/fallback.rs
Lines 1009 to 1114 in df33f0c
I'd prefer to have this fully unrolled style applied here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately, instead of
get().unwrap_or(0)I would preferget((idx % 16) as usize )which should be easier for the compiler to autovectorize and matches the current x86 behavior. But that's ultimately up to you, I'm not going to block this PR on that.