Accept canonical NaN in BFloat16 explicit conversions on WASM - #132307
Merged
pavelsavara merged 1 commit intoAug 14, 2026
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-numerics |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates BFloat16 explicit-conversion tests to be robust on WASM engines that canonicalize NaN payloads (notably V8), while still preserving bit-strict validation on platforms that retain NaN payloads.
Changes:
- Removes the prior WASM+Mono-only skip that dropped NaN test cases from the conversion test data.
- On WASM, allows the conversion result to match either the exact expected NaN payload or the canonical NaN bit pattern (with sign preserved) for
float/double→BFloat16explicit conversions.
tannergooding
approved these changes
Aug 14, 2026
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.
Applies the same fix as #130706 (which handled
HalfTests.ExplicitConversion_FromSingle) to the twoBFloat16explicit conversion tests:ExplicitConversion_FromSingleandExplicitConversion_FromDouble.The software
float/double->BFloat16conversions route the value throughabs/min/max/add(f32.*/f64.*on WASM). The WebAssembly spec permits (but doesn't require) host engines to canonicalize NaN payloads on those ops, and the V8 engine used on the CI Helix queues does, so the bit-strict NaN cases don't round-trip there. Arch-native targets (and payload-preserving WASM engines) are unaffected.Previously the NaN cases were skipped entirely via
if (PlatformDetection.IsMonoRuntime && PlatformDetection.IsWasm && ...) continue;. That gate only fires on Mono, so once the browser CoreCLR work (#129634) started running these tests on CoreCLR+WASM they began failing on V8 withAssert.Equal() ... Expected: NaN / Actual: NaN(payloads differ). Dropping all NaN coverage on WASM also loses the sign-bit check, which is preserved (carried through the integer ALU).Instead, this removes the skip and, on WASM only, accepts the canonical result (
sign | 0x7FC0forBFloat16) in place of the exact expected payload:So the NaN cases now actually run on WASM for both Mono and CoreCLR, and the bit-strict
AssertEqualstays in effect for all other targets.Tracked in #103347.
Note
This PR was prepared with the assistance of GitHub Copilot.