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

miri: implement some llvm.x86.sse.* intrinsics and add tests #2989

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

eduardosm
Copy link
Contributor

PR moved from rust-lang/rust#113932.

Implements LLVM intrisics needed to run most SSE functions from core::arch::x86{,_64}.

Also adds miri tests for those functions (mostly copied from core_arch tests).

r? @RalfJung

The first commit is the same that the commit in the PR I had opened in the Rust repository. I addressed review comments in additional commits to make it easier to review. I also fixed formatting and clippy warnings.

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2023

Error: The feature assign is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

This looks very good, thanks a lot for all the comments. :) I left a bunch of notes, mostly minor.

I can't actually tell if these implementations are correct, I'll just have to trust you on that and wait for bug reports otherwise. ;)

One thing that might be useful is to briefly establish some terminology at the top of sse.rs. In particular "ss" and "ps" seem to be very common and I have no idea what these are for.

src/shims/foreign_items.rs Outdated Show resolved Hide resolved
src/shims/foreign_items.rs Outdated Show resolved Hide resolved
src/shims/intrinsics/mod.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
tests/pass/intrinsics-x86-sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Show resolved Hide resolved
src/shims/x86/sse.rs Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Aug 8, 2023

@eduardosm so through this PR I became aware of nontemporal_store, which led to rust-lang/rust#114582, and getcsr/setcsr, which led to rust-lang/stdarch#1454... which other hideous monsters are lurking in stdarch?^^

@RalfJung
Copy link
Member

RalfJung commented Aug 8, 2023

Please never merge master into your PR, and only rebase when there are conflicts or it is needed to resolve CI failures (which might be the case here due to the operand_deref rename).

@eduardosm
Copy link
Contributor Author

eduardosm commented Aug 8, 2023

Please never merge master into your PR, and only rebase when there are conflicts or it is needed to resolve CI failures (which might be the case here due to the operand_deref rename).

I was avoiding force-pushing so everything appears as new commits to make it easier to review. I was planning on squashing everything together at the end.

@RalfJung
Copy link
Member

RalfJung commented Aug 8, 2023

Yeah, keeping it in new commits is definitely appreciated, even across the rebase.

I guess the merge commits don't hurt if we remember to squash-before-merge.

src/shims/x86/sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
src/shims/x86/sse.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

I've added a commit that moves the entire "multiply by (1+err)" logic into the helper function, makes it much more clear what's going on IMO. I wonder if it wouldn't be easier to just XOR all but the first 11 or 12 bits of the mantissa with random garbage, but I don't know how to do that with apfloat so 🤷 .

LGTM, thanks a lot for enduring the review! Can you please squash?

Implements LLVM intrisics needed to run most SSE functions from `core::arch::x86{,_64}`.

Also adds miri tests for those functions (mostly copied from core_arch tests).
@eduardosm
Copy link
Contributor Author

Squashed! Thanks for the thorough review :)

@RalfJung
Copy link
Member

RalfJung commented Aug 11, 2023

This test failure here is concerning: https://github.com/rust-lang/miri/actions/runs/5832262620/job/15817332780

This failed here. Is it possible that the tests are expecting more precision from RCP/RSQRT than they provide?

@eduardosm
Copy link
Contributor Author

This test failure here is concerning: https://github.com/rust-lang/miri/actions/runs/5832262620/job/15817332780

This failed here. Is it possible that the tests are expecting more precision from RCP/RSQRT than they provide?

Nah, that's because it was calculating sqrt(x) instead of 1/sqrt(x).

miri/src/shims/x86/sse.rs

Lines 531 to 539 in 31ed6d0

FloatUnaryOp::Rsqrt => {
let op = op.to_scalar().to_u32()?;
// FIXME using host floats
let sqrt = Single::from_bits(f32::from_bits(op).sqrt().to_bits().into());
// Apply a relative error with a magnitude on the order of 2^-12 to simulate the
// inaccuracy of RSQRT.
let res = apply_random_float_error(this, sqrt, -12);
Ok(Scalar::from_f32(res))
}

I fixed it before squashing.

@RalfJung
Copy link
Member

Nah, that's because it was calculating sqrt(x) instead of 1/sqrt(x).

Oh, I screwed up then. oops Thanks for taking care of it!

@RalfJung
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 11, 2023

📌 Commit 16a4a9f has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 11, 2023

⌛ Testing commit 16a4a9f with merge c6bd71a...

@bors
Copy link
Contributor

bors commented Aug 11, 2023

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing c6bd71a to master...

@bors bors merged commit c6bd71a into rust-lang:master Aug 11, 2023
@eduardosm eduardosm deleted the x86-intrinsics branch August 11, 2023 14:57
bors added a commit that referenced this pull request Aug 11, 2023
Add checked float-to-int helper function

As discussed in #2989 (comment)
RalfJung pushed a commit to RalfJung/rust that referenced this pull request Aug 17, 2023
bors added a commit that referenced this pull request Sep 12, 2023
Implement some `llvm.x86.sse2.*` intrinsics and add tests

Continuation of #2989 with SSE2 intrinsics.

Thankfully, a significant amount of SSE2 functions use `simd_*` intrinsics, which are already implemented in Miri.
RalfJung pushed a commit to RalfJung/rust that referenced this pull request Sep 12, 2023
Implement some `llvm.x86.sse2.*` intrinsics and add tests

Continuation of rust-lang/miri#2989 with SSE2 intrinsics.

Thankfully, a significant amount of SSE2 functions use `simd_*` intrinsics, which are already implemented in Miri.
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.

4 participants