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

Spurious NaNs produced by trig functions with valid inputs on Windows GNU toolchains #65658

Closed
novacrazy opened this issue Oct 21, 2019 · 4 comments
Labels
C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@novacrazy
Copy link

I'm unsure what the root cause of this is, and have been unable to reproduce it in a minimal project for many months, but every so often trig functions such as sin/cos/sin_cos will produce NaN values on perfectly valid inputs, only when using the Windows GNU toolchains.

In a project I have these lines:

let (sin_phi, cos_phi) = phi.sin_cos();

assert!(!sin_phi.is_nan(), "SIN {} {}", sin_phi, phi);
assert!(!cos_phi.is_nan(), "COS {} {}", cos_phi, phi);

which panics with this message:

thread 'main' panicked at 'SIN NaN -0.044661168'

on nightly-x86_64-pc-windows-gnu (1.40.0-nightly (3a9abe3f0 2019-10-15))

The program is complex but deterministic, and produces no such issues on the Windows MSVC toolchains.

This occurs with no RUSTFLAGS, and with the Cargo.toml config of:

[profile.dev]
debug = true
opt-level = 3
incremental = false
debug-assertions = true
codegen-units = 32
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 21, 2019
@mati865
Copy link
Contributor

mati865 commented Oct 21, 2019

Related to #53254

@mati865
Copy link
Contributor

mati865 commented Oct 22, 2019

@novacrazy does your code use MMX instructions or packed_simd crate?

Discussion on Zulip about #53254 revealed this happens when using mingw libm and MMX instructions. I suspect this is the same case.

@novacrazy
Copy link
Author

Yes, phi is a plain f32, but it is constructed from SIMD operations including .sum() (simd_reduce_add_unordered?) and .extract() (simd_extract) from the packed_simd crate.

@mati865
Copy link
Contributor

mati865 commented Oct 22, 2019

Then it's the same as #53254 and I think there is no point in keeping it open.

This is (mostly?) packed_simd bug and should be fixed there, upstream tracking issue: rust-lang/packed_simd#72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows-gnu Toolchain: GNU, Operating system: Windows T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants