-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Different NaN behavior with various float functions on beta-vs-stable #139487
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
This commit implements a workaround for rust-lang/rust#139487 which is necessary to have these implementations continue to work on more recent compilers due to the underlying implementation changing.
This commit implements a workaround for rust-lang/rust#139487 which is necessary to have these implementations continue to work on more recent compilers due to the underlying implementation changing.
Related: #139483 |
Is |
If I understand https://float.exposed/0xffa00000 correctly, your float has a payload with the quiet bit not set (i.e., a signaling NaN), and a non-zero payload? So that would make it "not a preferred NaN" and we guarantee nothing about which NaN you get as a result. AFAIK that matches the wasm spec. If you input |
The culprit seems to be https://github.com/rust-lang/libm/blob/cdbf42389e40e15350745cc29e86cd5d93cb2a76/src/math/floorf.rs#L7, specifically https://github.com/rust-lang/libm/blob/cdbf42389e40e15350745cc29e86cd5d93cb2a76/src/math/floorf.rs#L19-L21 The code was refactored in a later version that Note how the new behaviour only occurs in debug builds, release is the same as before. I think @RalfJung is right that this is allowed to be nondeterministic anyways. |
One failing test is this one, notably: (assert_return (invoke "floor" (f32.const -nan:0x200000)) (f32.const nan:arithmetic)) The input Notably this means that the wasm spec disagrees with your Rust's definition in this case. To me that's fine, I don't mind having an extra branch here, but I nevertheless wanted to confirm that it was intended. If the intention is to match the wasm spec on other platforms then this might be a bug, but if the intention is to provide fewer guarantees about nan then this definitely isn't a bug. Also, FWIW, I don't know what's going on with the link you posted. If I click it it seems to redirect to https://float.exposed/0x7fc00000 and doesn't actually show any information about |
@alexcrichton you’re right, I forgot about the whole arithmetic NaN thing. |
Ah, so wasm says that signaling NaNs must be quieted? Seems I forgot about that. Rust indeed does not guarantee this. This is crucial to support e.g. optimizing
That's not the link I posted, but oddly the link I posted seems to redirect to 0x7fc00000. Strange. |
Ok sounds like this is intended behavior, so I'll go ahead and close. And yeah I don't mean to say you pasted the wrong link, I meant that when I clicked the link you posted it sent me to the link that I pasted. I didn't mean to imply that you pasted the link I pasted, I'll try to reword that better next time. |
The test will already fail built against musl :) https://rust.godbolt.org/z/EGqdq816K (musl disregards sNaNs, https://wiki.musl-libc.org/mathematical-library). Glibc is doing the IEEE754-specified behavior of quieting signaling NaNs and raising To meet the wasm spec, intercepting at the next level up is probably the better option anyway given quieting also isn't done by all C libm implementations. |
No worries. :) |
I've run across an upcoming difference in float-related functions such as floor, trunc, ceil, etc, using a beta compiler on
x86_64-unknown-linux-gnu
relative to the stable compiler. Bisection points to rust-lang/compiler-builtins#763 as the regression point so while it seems that changing sources for the function implementations I wanted to confirm that it's expected that a behavior change was desired here as well.One example change is specifically this program:
currently prints
0xffe00000
while the beta compiler prints0xffa00000
.This was discovered through running the WebAssembly test suite in Wasmtime using a beta/nightly compiler instead of a stable compiler, and previously some functions were "just"
the_float.floor()
where now we need NaN checks around them as well. Not a huge issue for us and we're happy to work around it, but I wanted to flag this behavior nonetheless to ensure it's intended.If this is indeed an intended behavior change (which personally I think is totally fine), I'm happy to close this.
cc @tgross35 for the relevance to rust-lang/compiler-builtins#763
The text was updated successfully, but these errors were encountered: