Repository navigation
Add mask casting using From - #440
Merged
Merged
Conversation
Shnatsel
approved these changes
Nov 12, 2026
Shnatsel
left a comment
Contributor
There was a problem hiding this comment.
The API seems reasonable. Things like enabling code generic over element type can be layered on top of this later.
The tests and the generated code are reasonable.
I didn't have the time to review the generator code in detail. Cleanup recommendations from an LLM are included below for your reference, feel free to disregard if you think they're not helpful.
LLM recommendations
generic_impl_mask_casts(is_trait_definition: bool, …)— the bool is opaque. Rename it (emit_docs) and/or have the helper emit#[inline(always)]itself, somk_simd_trait.rs's awkward#( #[inline(always)] #mask_casts )*repetition goes away and both call sites look the same.generic_mask_cast(body) vsgeneric_impl_mask_casts(list) are easy to confuse;mask_cast_body/mask_cast_methodswould read better.generic_mask_castsynthesizes intermediateVecTypes (scalar_bits / 2,* 2). That's valid today because the mask type ladder is gapless, but adebug_assert!(SIMD_TYPES.contains(&new_from_ty))or a comment would document the assumption and fail loudly if the ladder ever changes.- Optionally, the
Levelhook could be modeled asfn mask_cast_is_noop(&self) -> bool(defaultfalse) so the trait generator owns body generation andmk_x86.rsdoesn't have to emit whole method bodies. Not required.
Contributor
Author
|
I implemented LLM suggestions 1 and 2, because they were quite good, but the rest didn't make much sense. I also changed one abstraction a little, so the code should be a bit cleaner now. |
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.
Related to #439.
I implemented casting between masks with an equal number of lanes. This makes compatible mask conversions very easy for users. Example:
Under the hood, this is implemented using the existing
Simd::{combine,narrow,split,widen}_maskNxMon all platforms except AVX512 where same-lane-count mask conversion is trivial.The code in
fearless_simd_genis a bit out there, because I couldn't easily hook into existing systems .