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

Legalize fmin/fmax with NaN quieting semantics #1821

Closed
wants to merge 12 commits into from

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Jun 4, 2020

This builds on #1820 and should be merged after that PR.

The Wasm SIMD spec defines semantics for fmin and fmax that require runtimes to produce long sequences of instructions. This change adds these long sequences through legalization but also provides an alternate mechansim, using the assert_no_nans flag, for guaranteeing that special NaN handling is not required, thus resulting in a much shorter legalization.

abrown added 12 commits June 3, 2020 16:30
This instruction converts i32x4 to f32x4 in several AVX512 feature sets.
This instruction is necessary for lowering `fcvt_from_uint`.
This converts an `i32x4` into an `f32x4` with some rounding either by using an AVX512VL/F instruction--VCVTUDQ2PS--or a long sequence of SSE4.1 compatible instructions.
The NaN semantics of the Wasm SIMD spec do not closely align to x86's NaN semantics, resulting in generated code with extra instructions, e.g. to quiet NaNs. This flag allows users to assert that floating-point operations will not produce NaNs (for SIMD primarily, but this could be used eventually in a scalar context) so that Cranelift can emit fewer instructions--hopefully faster code.
This reuses the `x86_cvtt2si` instruction since the packed and scalar versions seem to group together well.
With user assertions, use CVTTPS2DQ directly; otherwise, use a lengthy sequence to quiet NaNs and saturate overflow.
Because the Wasm specification semantics for NaN handling in `min` and `max` are not x86-friendly, this legalization allows the user to generate code that is spec-compliant (a long sequence of instructions) or fast (a single instruction), using the `assert_no_nans` flag.
@abrown abrown requested a review from bnjbvr June 4, 2020 17:18
@abrown abrown marked this pull request as ready for review June 4, 2020 17:23
@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.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Same comment as in the other issue for assert_in_bounds; range analysis could get us the same result, although it's not implemented at all in Cranelift, afaik.

@abrown abrown closed this Jun 19, 2020
@abrown abrown deleted the legalize-fmin-fmax branch May 17, 2021 18:25
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