-
Notifications
You must be signed in to change notification settings - Fork 13.3k
u64 to f32 conversion is inaccurate on Windows 32bit #59787
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
Comments
@llvm/issue-subscribers-backend-x86 |
Here's a patch to use library call for Windows instead of the broken inline expansion.
|
I also tried |
-mfpmath=sse No clue why -msse/-msse2 doesn't imply that. It doesn't affect ABI, it still passes arguments on stack and return in x87. |
-mno-x87 is not correctly implemented and is poorly tested. It was added after a lot of code was written and a lot of that hasn’t been updated. There’s no sse2 instruction that can do unsigned 64-bit integer to float on a 32 bit target. So we use x87. But the algorithm only works if x87 is configured for full precision. If not it rounds incorrectly. |
MSVC has the same problem: https://godbolt.org/z/4sbn8dq1T |
MSVC x86 does not seem to produce different results depending on whether or not it has sign, so it is less likely to be an issue. It might be better to just match MSVC's behavior than to use library calls, even though we lose a tiny bit of precision. |
Fixed in a6e3027 |
I'm going to revert the patch. It broke Chrome and Halide builds. I'm going to look at modifying PC in FPCW on the fly. |
Fixed again in 11fb09e |
On Windows, the x87 control word has a different default value than on other platforms. This not only introduces floating point precision issues, but also results in inconsistent behavior with other platforms. I tried to avoid using x87 by adding the
-msse2
option when compiling for Windows 32bit, but the compiler still generates binaries using only x87.The code below outputs differently on Windows 32bit than on other platforms:
rust-lang/rust#105626
The text was updated successfully, but these errors were encountered: