rust-lang / stdarch

Rust's standard library vendor-specific APIs and run-time feature detection
https://doc.rust-lang.org/stable/core/arch/
Apache License 2.0
601 stars 267 forks source link

non-temporal stores: document interaction with Rust memory model #1534

Closed RalfJung closed 7 months ago

RalfJung commented 7 months ago

This is my proposed alternative to https://github.com/rust-lang/stdarch/pull/1457. It builds on the model I sketched here.

Changing the docs alone is not sufficient IMO, we also should stop using LLVM's non-temporal hint as LLVM passes do not properly take into account the non-standard nature of non-temporal stores. Originally I thought these all have to become inline assembly, but now I noticed that some of these operations are using different LLVM intrinsics:

    #[link_name = "llvm.x86.sse4a.movnt.sd"]
    fn movntsd(x: *mut f64, y: __m128d);
    #[link_name = "llvm.x86.sse4a.movnt.ss"]
    fn movntss(x: *mut f32, y: __m128);

Do these intrinsics exist for the other operations as well, e.g. for movntps? I found llvm.x86.avx.movnt.ps.256 but ofc for the SSE intrinsic we'd want the 128bit version of that. If that exists, using those might be better than using inline assembly? Though of course if LLVM passes treat these intrinsics like regular stores, that would still be wrong.

rustbot commented 7 months ago

r? @Amanieu

rustbot has assigned @Amanieu. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

RalfJung commented 7 months ago

CI failures seem unrelated to this PR.