-
Notifications
You must be signed in to change notification settings - Fork 92
swizzle_dyn: 64 byte swizzle_dyn for AVX2 #480
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
Open
87flowers
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
87flowers:avx2_pshufb512
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -80,6 +80,8 @@ where | |
}; | ||
transize(swizzler, self, idxs) | ||
} | ||
#[cfg(all(target_feature = "avx2", not(target_feature = "avx512vbmi")))] | ||
64 => transize(avx2_pshufb512, self, idxs), | ||
// Notable absence: avx512bw pshufb shuffle | ||
#[cfg(all(target_feature = "avx512vl", target_feature = "avx512vbmi"))] | ||
64 => { | ||
|
@@ -171,6 +173,61 @@ unsafe fn avx2_pshufb(bytes: Simd<u8, 32>, idxs: Simd<u8, 32>) -> Simd<u8, 32> { | |
} | ||
} | ||
|
||
/// The above function but for 64 bytes | ||
/// | ||
/// # Safety | ||
/// This requires AVX2 to work | ||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
#[target_feature(enable = "avx2")] | ||
#[allow(unused)] | ||
#[inline] | ||
#[allow(clippy::let_and_return)] | ||
unsafe fn avx2_pshufb512(bytes: Simd<u8, 64>, idxs: Simd<u8, 64>) -> Simd<u8, 64> { | ||
use crate::simd::cmp::SimdPartialOrd; | ||
#[cfg(target_arch = "x86")] | ||
use core::arch::x86; | ||
#[cfg(target_arch = "x86_64")] | ||
use core::arch::x86_64 as x86; | ||
use x86::_mm256_blendv_epi8 as avx2_blend; | ||
use x86::_mm256_permute2x128_si256 as avx2_cross_shuffle; | ||
use x86::_mm256_shuffle_epi8 as avx2_half_pshufb; | ||
let high = Simd::splat(64u8); | ||
// SAFETY: Caller promised AVX2 | ||
unsafe { | ||
let half_swizzler = |bytes0: Simd<u8, 32>, bytes1: Simd<u8, 32>, idxs: Simd<u8, 32>| { | ||
let mask0 = idxs << 2; | ||
let mask1 = idxs << 3; | ||
|
||
let lolo0 = avx2_cross_shuffle::<0x00>(bytes0.into(), bytes0.into()); | ||
let hihi0 = avx2_cross_shuffle::<0x11>(bytes0.into(), bytes0.into()); | ||
let lolo0 = avx2_half_pshufb(lolo0, idxs.into()); | ||
let hihi0 = avx2_half_pshufb(hihi0, idxs.into()); | ||
let x = avx2_blend(lolo0, hihi0, mask1.into()); | ||
|
||
let lolo1 = avx2_cross_shuffle::<0x00>(bytes1.into(), bytes1.into()); | ||
let hihi1 = avx2_cross_shuffle::<0x11>(bytes1.into(), bytes1.into()); | ||
let lolo1 = avx2_half_pshufb(lolo1, idxs.into()); | ||
let hihi1 = avx2_half_pshufb(hihi1, idxs.into()); | ||
let y = avx2_blend(lolo1, hihi1, mask1.into()); | ||
|
||
avx2_blend(x, y, mask0.into()) | ||
}; | ||
|
||
let bytes0 = bytes.extract::<0, 32>(); | ||
let bytes1 = bytes.extract::<32, 32>(); | ||
let idxs0 = idxs.extract::<0, 32>(); | ||
let idxs1 = idxs.extract::<32, 32>(); | ||
|
||
let z0 = half_swizzler(bytes0, bytes1, idxs0); | ||
let z1 = half_swizzler(bytes0, bytes1, idxs1); | ||
|
||
// SAFETY: Concatenation of two 32-element vectors to one 64-element vector | ||
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. this says what your doing, what it should say is why it's safe to use |
||
let z = mem::transmute::<[Simd<u8, 32>; 2], Simd<u8, 64>>([z0.into(), z1.into()]); | ||
|
||
idxs.simd_lt(high).select(z, Simd::splat(0u8)) | ||
} | ||
} | ||
|
||
/// This sets up a call to an architecture-specific function, and in doing so | ||
/// it persuades rustc that everything is the correct size. Which it is. | ||
/// This would not be needed if one could convince Rust that, by matching on N, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
you should probably add more safety comments, e.g. answer why is the
transmute
sound?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.
Added one for the
transmute
. Can't really think of anywhere else where its required.