-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Backport LLVM apfloat commit to rustc_apfloat #77368
Conversation
Backports LLVM commit: llvm/llvm-project@e34bd1e Fixes rust-lang#69532
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, this is pretty clearly still wrong... Disappointing... I'll try and file an upstream bug about it when I have more time :(.
Can you remove the Fixes comment? This will fix the listed issue in one case, but not all. See #69532 (comment) for more details. |
Do you have a concrete example that it will not fix? Another testcase would be good. |
Hmmm I think we should wait until this LLVM MR that @thomcc linked to is merged: https://reviews.llvm.org/D88238 Then we can backport that. I'm not sure I agree with the suggestion to change usage sites, pointed out by @thomcc here, because the one they refer to mainly concerns floating point parsing of LLVM IR. LLVM has hexadecimal "raw" ways to specify float literals with some type inferrence, but in Rust you can only specify floats by their decimal fraction. |
Now the commit has made it to LLVM master. r? @varkor |
// don't currently do it. You're really supposed to get | ||
// an invalid operation signal at runtime, but nobody does that. | ||
status = Status::OK; | ||
// Convert of sNaN creates qNaN and raises an exception (invalid op). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what "raises an exception" means here, but wouldn't this mean the cast fails when run in Miri?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the purpose of signaling NaNs. Quoting Wikipedia:
Signaling NaNs, or sNaNs, are special forms of a NaN that, when consumed by most operations, should raise the invalid operation exception and then, if appropriate, be "quieted" into a qNaN that may then propagate.
This is precisely what we (and LLVM) do here :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my understanding that this is generally not implemented, i.e., sNaNs behave like qNaNs with modern compilers on modern hardware? But maybe I misunderstood.
Given that your new testcases passes, it does not seem like this "exception" actually does anything in Miri though, so I guess it's okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah by default trapping is off, but it can be enabled by e.g. feenableexcept
. If trapping is off, only some exception flags are set in a specific "status word" register, readable by e.g. _statusfp on Windows (couldn't find the unix analog).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On x86, it's the fstsw
instruction.
Backports LLVM commit: [APFloat] convert SNaN to QNaN in convert() and raise Invalid signal llvm/llvm-project@149f5b5 SNaN to QNaN conversion also matches what my Intel x86_64 hardware does.
@bors r+ |
📌 Commit d010809 has been approved by |
…as-schievink Rollup of 8 pull requests Successful merges: - rust-lang#77072 (Minor `hash_map` doc adjustments + item attribute orderings) - rust-lang#77368 (Backport LLVM apfloat commit to rustc_apfloat) - rust-lang#77445 (BTreeMap: complete the compile-time test_variance test case) - rust-lang#77504 (Support vectors with fewer than 8 elements for simd_select_bitmask) - rust-lang#77513 (Change DocFragments from enum variant fields to structs with a nested enum) - rust-lang#77518 (Only use Fira Sans for the first `td` in item lists) - rust-lang#77521 (Move target feature whitelist from cg_llvm to cg_ssa) - rust-lang#77525 (Enable RenameReturnPlace MIR optimization on mir-opt-level >= 2) Failed merges: r? `@ghost`
Backports LLVM commit: llvm/llvm-project@e34bd1e
Fixes #69532