Skip to content

Convert x86/sse41.rs intrinsics to const generics - #1026

Merged
Amanieu merged 2 commits into
rust-lang:masterfrom
lqd:const_generics_3_electric_boogalee
Mar 1, 2021
Merged

Convert x86/sse41.rs intrinsics to const generics#1026
Amanieu merged 2 commits into
rust-lang:masterfrom
lqd:const_generics_3_electric_boogalee

Conversation

@lqd

@lqd lqd commented Feb 28, 2021

Copy link
Copy Markdown
Member

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:

As 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 ?

@rust-highfive

Copy link
Copy Markdown

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

Comment thread crates/core_arch/src/macros.rs Outdated
// out of range.
pub(crate) struct ValidateConstImm8<const imm8: i32>();
// out of 8-bit range.
pub(crate) struct ValidateConstImm8<const imm8: i32>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lqd lqd Mar 1, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread crates/core_arch/src/x86/macros.rs Outdated
@lqd
lqd force-pushed the const_generics_3_electric_boogalee branch from 3fc29a8 to c934f5f Compare March 1, 2021 00:33
@Amanieu
Amanieu merged commit c0cca91 into rust-lang:master Mar 1, 2021
@lqd
lqd deleted the const_generics_3_electric_boogalee branch March 3, 2021 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants