-
Notifications
You must be signed in to change notification settings - Fork 20
Make safe most intrinsics that neither access memory nor impact processor state #243
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
Comments
I don't see anything addressing the safety requirements as documented in
This seems quite confused. Firstly, I don't see any uses of |
@BurntSushi Apologies for the (very) sloppy imprecision here. I meant that they're only accessible when you either specify The way the rest of your stuff reads, I'd be better served making an RFC instead for this as there's lower-level language kinks to work out, so I'll close this ACP. |
I would definitely suggest a pre-RFC first. Firstly because I still don't quite understand these sentences. Secondly, because compile time CPU features is somewhat less compelling (although perhaps that's changing with microarchitecture levels). Thirdly, because |
Proposal
Problem statement
Currently, any time you want to use vector intrinsics directly, you have to resort to
unsafe
blocks. As that's still very much unstable, it's not exactly accessible for most currently. Also, there's features that doesn't cover, like AVX-512's result masking (which saves a lot of instructions in some niche cases).Motivating examples or use cases
I've got this code laying around in an experiment:
None of those
unsafe
blocks are truly dealing with anything unsafe as per the book, the unsafe code guidelines, or the reference manual.#[target_feature]
as appropriate, thus avoiding undefined behavior on that front._mm256_castpd128_pd256
in x86.Solution sketch
For each architecture intrinsics that neither read nor modify memory or persistent processor state, make it safe and wrap the inner contents with an
unsafe
block as needed.For x86-64, this equates to roughly the following:
unsafe
unsafe
as it reads persistent processor state__rdtscp
and_rdtsc
unsafe
as it reads persistent processor stateunsafe
as it interacts with persistent processor stateunsafe
as it interacts with persistent processor stateunsafe
as it interacts with persistent processor state_mm256_cast*128_*256
unsafe
due to its upper half being undefined_mm512_cast*128_*512
unsafe
due to its upper 3/4 being undefined_mm512_cast*256_*512
unsafe
due to its upper half being undefined_mm*_undefined*
unsafe
since they're intentionally supposed to be undefinedbsf
/bsr
instructions don't exist, so they don't need covered)Alternatives
Do nothing and just focus on
std::simd
. This is workable, but see my note on AVX-512's result masking for why this isn't helpful in of itself. (I didn't include an example for that here, but it wouldn't be hard for me to provide one.)Links and related work
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: