Convert x86/sse41.rs intrinsics to const generics - #1026
Merged
Conversation
|
r? @Amanieu (rust-highfive has picked a reviewer for you, use r? to override) |
Amanieu
reviewed
Feb 28, 2021
| // out of range. | ||
| pub(crate) struct ValidateConstImm8<const imm8: i32>(); | ||
| // out of 8-bit range. | ||
| pub(crate) struct ValidateConstImm8<const imm8: i32>; |
Member
There was a problem hiding this comment.
It might be worth making this generic over the bit width:
struct ValidateConstImm8<const imm i32, const bits: i32>The check would then be:
let _ = 1 / ((imm >= 0 && imm < (1 << bits)) as usize);Then we can simply define macros referring to a single instance of this struct. These macros should ideally be in the generic macros.rs instead of the arch-specific one.
Member
Author
There was a problem hiding this comment.
good idea, that should be enough for most of the other constify_imms analogues. (the other design has the advantage of encoding the immediate width in its name, and the expression shows up in the const error message, but a single struct will be better)
Amanieu
reviewed
Feb 28, 2021
lqd
force-pushed
the
const_generics_3_electric_boogalee
branch
from
March 1, 2021 00:33
3fc29a8 to
c934f5f
Compare
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.
This PR updates the x86 SSE 4.1 intrinsics to use const generics.
Of note, some of these made an effort to test the masking/clamping of the constify immediates macros, testing with both in-range and out-of-range values in:
_mm_extract_ps: _mm_extract_ps(a, 5) on a 2-bit immediate_mm_extract_epi8: _mm_extract_epi8(a, 19) on a 4-bit immediate_mm_extract_epi32: _mm_extract_epi32(a, 5) on a 2-bit immediate_mm_insert_epi8: _mm_insert_epi8(a, 32, 17) on a 4-bit immediate_mm_insert_epi32: _mm_insert_epi32(a, 32, 5) on a 2-bit immediateAs discussed with Amanieu on zulip, I've made such out-of-range immediates errors with static assertions, and changed the tests in these cases. Opinions are welcome.
I've noticed our previous PRs were squashed when merged, so I didn't make a commit per intrinsic this time. Of course, I can do so if it would be helpful for the review ?