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

Implement fcvt_to_uint_sat (f32x4 -> i32x4) for x86 #1822

Closed
wants to merge 4 commits into from

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Jun 4, 2020

This follows from #1821 and should be merged after that PR. [ready to review]

Along the lines of #1820, this adds the necessary legalizations and instructions for enabling the Wasm SIMD spec tests with truncation instructions.

@abrown abrown marked this pull request as ready for review June 4, 2020 17:23
@abrown abrown requested a review from bnjbvr June 4, 2020 17:35
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:meta Everything related to the meta-language. cranelift:wasm labels Jun 4, 2020
@github-actions
Copy link

github-actions bot commented Jun 4, 2020

Subscribe to Label Action

cc @bnjbvr

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:meta", "cranelift:wasm"

Thus the following users have been cc'd because of the following labels:

  • bnjbvr: cranelift

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@bnjbvr bnjbvr removed their request for review June 9, 2020 13:17
@abrown abrown force-pushed the trunc-sat-unsigned branch 2 times, most recently from aa97b48 to 3fb3689 Compare June 19, 2020 19:03
@alexcrichton alexcrichton changed the base branch from master to main June 25, 2020 18:49
cranelift/codegen/meta/src/isa/x86/instructions.rs Outdated Show resolved Hide resolved
cranelift/codegen/meta/src/isa/x86/opcodes.rs Show resolved Hide resolved
cranelift/codegen/src/isa/x86/enc_tables.rs Show resolved Hide resolved
.as_any()
.downcast_ref::<isa::x86::Isa>()
.expect("the target ISA must be x86 at this point");
if x86_isa.isa_flags.use_avx512vl_simd() || x86_isa.isa_flags.use_avx512f_simd() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the rounding semantics of the two alternative implementations equivalent? For the short case, vcvtps2udq, the Intel manual says "When a conversion is inexact, the value returned is rounded according to the rounding control bits in the MXCSR register or the embedded rounding control bits." The slow path appears to use cvtt2si (presumably, really, cvttps2pi), and all the tt variant conversion insns are round-towards-zero: "When a conversion is inexact, a truncated (round toward zero) result is returned."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good point: I had hoped MXCSR would have the right rounding mode but it does not. I added a run filetest that passes with the long sequence and fails with the AVX512 sequence: it looks like the machines running the CI have AVX512 and therefore fail. I started playing around with a new recipe that embeds the rounding control (e.g. EvexContext::RoundingRegToRegFP { rc: EvexRoundingControl::RZ } but this didn't immediately fix the test case (the emitted bytes aren't exactly right) so I will have to play around with this a bit more.

This allows x86 machines with the right AVX features to lower fcvt_to_uint_sat.i32x4 to a single instruction.
This converts an `f32x4` into an `i32x4` (unsigned) with some rounding either by using an AVX512VL/F instruction--VCVTPS2UDQ--or a long sequence of SSE4.1 compatible instructions.
@abrown
Copy link
Contributor Author

abrown commented Jul 7, 2020

Replacing this with #1990--I propose we look at the AVX512 lowering in a separate PR since it may get tricky (and this legalization is already tricky enough).

@abrown abrown closed this Jul 7, 2020
@abrown abrown deleted the trunc-sat-unsigned branch May 17, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:meta Everything related to the meta-language. cranelift:wasm cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants