-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-pass | ||
#![feature(const_fn_transmute)] | ||
|
||
const fn make_nans() -> (f64, f64, f32, f32) { | ||
let nan1: f64 = unsafe { std::mem::transmute(0x7FF0_0001_0000_0001u64) }; | ||
let nan2: f64 = unsafe { std::mem::transmute(0x7FF0_0000_0000_0001u64) }; | ||
|
||
let nan1_32 = nan1 as f32; | ||
let nan2_32 = nan2 as f32; | ||
|
||
(nan1, nan2, nan1_32, nan2_32) | ||
} | ||
|
||
static NANS: (f64, f64, f32, f32) = make_nans(); | ||
|
||
fn main() { | ||
let (nan1, nan2, nan1_32, nan2_32) = NANS; | ||
|
||
assert!(nan1.is_nan()); | ||
assert!(nan2.is_nan()); | ||
|
||
assert!(nan1_32.is_nan()); | ||
assert!(nan2_32.is_nan()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.