Add mask<->vector conversion methods - #400
Open
valadaptive wants to merge 2 commits into
Open
valadaptive wants to merge 2 commits into
valadaptive wants to merge 2 commits into
Conversation
valadaptive
force-pushed
the
mask-vector-conversion
branch
from
September 27, 2026 09:49
8d75a8e to
6590b49
Compare
Contributor
|
The direction looks good to me, I'll take a closer look later. Thanks! |
valadaptive
force-pushed
the
mask-vector-conversion
branch
from
September 30, 2026 06:58
6590b49 to
d433103
Compare
Contributor
|
We generally try to align with std::simd on naming, because that's what other libs are also doing and it makes porting across the whole ecosystem really easy. But in our case to_simd sounds like it's going to give you the |
Shnatsel
approved these changes
Sep 30, 2026
Shnatsel
left a comment
Contributor
There was a problem hiding this comment.
I've pushed a change to specify more generic bounds, cargo-semver-checks is happy with it. PTAL.
We need to make a call on whether to align with std::simd and call this to_simd or keep the to_vector, I'm OK with either.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #398.
This PR adds methods for converting masks to and from vectors.
The
SimdMasktrait now has anIntsassociated type, which represents the mask's corresponding integer vector type.For AVX-512, these are implemented using
movm_epi[N]andmovepi[N]_mask. For all other instruction sets, the mask types are the same as the integer vector types, so all we have to do is re-wrap them in the proper type.I'm not attached to any of the names here (
Ints,from_vector,to_vector) and am willing to change them if anyone has a better idea.I'm also not sure if we should provide corresponding
from_maskorto_maskfunctions on the corresponding integer vector types; I think that would require adding a newSimdSignedInttype or implementing this functionality for both signed and unsigned int vector types.I also implemented these as associated methods on
SimdMaskbut haven't added any sort of conversion trait. In general, I prefer APIs where the types are concrete if possible (no wide-ranging conversion trait) because it helps with type inference and reduces the number of "turbofish" I have to type out.