Skip to content
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

simd intrinsics: add simd_shuffle_generic and other missing intrinsics #119213

Merged
merged 4 commits into from
Feb 11, 2024

Conversation

RalfJung
Copy link
Member

Also tweak the simd_shuffle docs a bit.

r? @calebzulawski

@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2023

Failed to set assignee to calebzulawski: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 22, 2023
@RalfJung
Copy link
Member Author

r? @workingjubilee

/// Returns a new vector such that element `i` is selected from `xy[IDX[i]]`, where `xy`
/// is the concatenation of `x` and `y`. It is a compile-time error if `IDX[i]` is out-of-bounds
/// of `xy`.
pub fn simd_shuffle_generic<T, U, const IDX: &'static [u32]>(x: T, y: T) -> U;
Copy link
Member

Choose a reason for hiding this comment

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

I haven't seen this intrinsic before 🤔 this is what we need in std::simd

Copy link
Member Author

@RalfJung RalfJung Dec 22, 2023

Choose a reason for hiding this comment

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

It's an experiment to see how far we can get with the current const-generic support. I don't think std::simd can use it yet, that would need generic_const_exprs which is still a highly experimental feature.

Copy link
Member

Choose a reason for hiding this comment

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

it would be nice if we could stabilize a small enough subset of GCE that this sort of thing becomes feasible.

Copy link
Member Author

Choose a reason for hiding this comment

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

From talking with @lcnr that seems pretty far out currently. And in particular reference types in const generics have pretty thorny unsolved theoretical questions as well.

@RalfJung RalfJung changed the title simd intrinsics: add simd_shuffle_generic simd intrinsics: add simd_shuffle_generic and other missing intrinsics Dec 28, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 28, 2023

Failed to set assignee to calebzulawski: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@RalfJung
Copy link
Member Author

I realized there are more intrinsics missing, so I added those as well.

library/core/src/intrinsics/simd.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member Author

@workingjubilee friendly review ping :)

@workingjubilee
Copy link
Member

'sup, sorry about the delay. I had the usual holidays-induced madness and then work on shipping soundness fixes to Rust crates and then a blackout in winter! will take a look this week/after a nap.

@RalfJung
Copy link
Member Author

No worries, I was just making sure this doesn't fall through the cracks. :)

@workingjubilee
Copy link
Member

it seems sometimes I have an interesting interpretation of "this week".

library/core/src/intrinsics/simd.rs Outdated Show resolved Hide resolved
Comment on lines +248 to +249
/// The stores happen in left-to-right order.
/// (This is relevant in case two of the stores overlap.)
Copy link
Member

Choose a reason for hiding this comment

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

( probably not relevant, but fun facts to know and tell: if the machine instruction gets executed, this guarantee also affects the state of the CPU during exception handling. )

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait, exception handles can observe these instructions as non-atomic? Wow.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, on Intel CPUs at least, for most variants of these instructions, the operands (esp. the mask operand) get updated so that continuing with the same operands will complete the operation, completing a single store for each index.

Copy link
Member Author

@RalfJung RalfJung Feb 10, 2024

Choose a reason for hiding this comment

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

What do you mean "get updated"? Does this change the contents of some other register, where the mask operand is stored? I hope it restored the original value when the instruction is done?

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean "get updated"? Does this change the contents of some other register, where the mask operand is stored?

Yes, the mask register.

I hope it restored the original value when the instruction is done?

uhhh probably! 😁

Copy link
Member

Choose a reason for hiding this comment

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

I hope it restored the original value when the instruction is done?

uhhh probably! 😁

nope, it's defined to clear the mask register: https://www.felixcloutier.com/x86/vscatterdps:vscatterdpd:vscatterqps:vscatterqpd

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay... well as long as LLVM takes that into account it's all good.

library/core/src/intrinsics/simd.rs Outdated Show resolved Hide resolved
library/core/src/intrinsics/simd.rs Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2024

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

@workingjubilee
Copy link
Member

cool!

@bors r+

@@ -204,7 +204,7 @@ extern "platform-intrinsic" {
///
/// `T` must be a vector.
///
/// `V` must be a vector with the same element type as `T` and the same length as `IDX`.
/// `U` must be a vector with the same element type as `T` and the same length as `IDX`.
Copy link
Member

Choose a reason for hiding this comment

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

ah, good catch. ^^;

@bors
Copy link
Contributor

bors commented Feb 10, 2024

📌 Commit 3bc490d has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2024
@workingjubilee
Copy link
Member

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - rust-lang#120272 (Suppress suggestions in derive macro)
 - rust-lang#120773 (large_assignments: Allow moves into functions)
 - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates)
 - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic)
 - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - rust-lang#120895 (don't skip coercions for types with errors)
 - rust-lang#120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - rust-lang#120272 (Suppress suggestions in derive macro)
 - rust-lang#120773 (large_assignments: Allow moves into functions)
 - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates)
 - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic)
 - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - rust-lang#120895 (don't skip coercions for types with errors)
 - rust-lang#120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - rust-lang#120272 (Suppress suggestions in derive macro)
 - rust-lang#120773 (large_assignments: Allow moves into functions)
 - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates)
 - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic)
 - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - rust-lang#120895 (don't skip coercions for types with errors)
 - rust-lang#120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - rust-lang#120272 (Suppress suggestions in derive macro)
 - rust-lang#120773 (large_assignments: Allow moves into functions)
 - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates)
 - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic)
 - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - rust-lang#120895 (don't skip coercions for types with errors)
 - rust-lang#120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5f9457c into rust-lang:master Feb 11, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 11, 2024
Rollup merge of rust-lang#119213 - RalfJung:simd_shuffle, r=workingjubilee

simd intrinsics: add simd_shuffle_generic and other missing intrinsics

Also tweak the simd_shuffle docs a bit.

r? `@calebzulawski`
@RalfJung RalfJung deleted the simd_shuffle branch February 11, 2024 20:51
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 25, 2024
…s, r=workingjubilee

Stop using `unsized_const_parameters` in core/std

`feature(unsized_const_parameters)` is an incomplete feature and should not be used by core/std as it makes it can make it significantly harder to evolve the feature. It also just generally opens the possibility of introducing bugs on stable through std's backdoor.

The only usage of this feature in std is the `simd_shuffle_intrinsic` added in rust-lang#119213. It doesn't seem to be used anywhere as far as I can tell so it is removed in this PR. All tests and codegen logic etc have been kept however.

r? `@workingjubilee`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 26, 2024
Rollup merge of rust-lang#128150 - BoxyUwU:std_only_sized_const_params, r=workingjubilee

Stop using `unsized_const_parameters` in core/std

`feature(unsized_const_parameters)` is an incomplete feature and should not be used by core/std as it makes it can make it significantly harder to evolve the feature. It also just generally opens the possibility of introducing bugs on stable through std's backdoor.

The only usage of this feature in std is the `simd_shuffle_intrinsic` added in rust-lang#119213. It doesn't seem to be used anywhere as far as I can tell so it is removed in this PR. All tests and codegen logic etc have been kept however.

r? `@workingjubilee`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants