fix Issue 13474 - Discard excess precision for float and double (x87)#6247
Merged
andralex merged 1 commit intodlang:masterfrom Nov 10, 2016
Merged
fix Issue 13474 - Discard excess precision for float and double (x87)#6247andralex merged 1 commit intodlang:masterfrom
andralex merged 1 commit intodlang:masterfrom
Conversation
Contributor
|
35e4116 to
6db2246
Compare
Contributor
|
I'm very happy to see this. This addresses the biggest problem I've had with developing floating point code in D. Because this extra precision exists on some platforms but not others, I did not find any way of writing code which works for all three of x87 runtime, non-x87 runtime, and CTFE. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The following code:
The body of which, when optimized, looks like:
Or, in x87 instructions:
The algorithm relies on rounding to double precision of the
(x-t)calculation. The only way to get the x87 to do that is to actually assign it to memory. But the compiler optimizes away the assignment to memory, because it is substantially slower.The 64 bit code does not have this problem, because the code gen looks like:
It's doing the same optimization, but the result is rounded to double because the XMM registers are doubles.
Note that the following targets generate x87 code, not XMM code:
because it is not guaranteed that the target has XMM registers. I suspect we don't really care about the floating point performance on those targets, but we do care that the code gives expected results.
This fix is to disable optimizing away the assignment to y for x87 code gen targets. The resulting code is: