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

[RISC-V] Floating NaN overflow test fix #94168

Conversation

denis-paranichev
Copy link
Contributor

There are differences between results of floating NaN conversions overflow on X64 or ARM64 and RISC-V. As I suppose it is caused by runtime using some sort of flush-to-zero option for X64 and ARM64 which replace such overflowing values with zero.
But RISC-V specification does not provide such option.
Thus I suggest to change expected result of NaN overflow tests on RISC-V.

Part of #84834
cc @gbalykov @t-mustafin @clamp03 @tomeksowi

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 30, 2023
@ghost
Copy link

ghost commented Oct 30, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

There are differences between results of floating NaN conversions overflow on X64 or ARM64 and RISC-V. As I suppose it is caused by runtime using some sort of flush-to-zero option for X64 and ARM64 which replace such overflowing values with zero.
But RISC-V specification does not provide such option.
Thus I suggest to change expected result of NaN overflow tests on RISC-V.

Part of #84834
cc @gbalykov @t-mustafin @clamp03 @tomeksowi

Author: DenisParal
Assignees: -
Labels:

area-System.Numerics

Milestone: -

@denis-paranichev
Copy link
Contributor Author

@dotnet-policy-service agree company="Samsung"

@MichalPetryka
Copy link
Contributor

As I suppose it is caused by runtime using some sort of flush-to-zero option for X64 and ARM64

The runtime does not use the FTZ flags cc @tannergooding

Comment on lines +18 to +21
if(System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.RiscV64)
{
return (byte)0xFF;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're working on moving towards deterministic behavior across platforms: #61885

This is going to necessitate, longer term, that saturation occurs as it is what most newer platforms do and what many specs (like WASM) require. This is also going to necessitate standardizing the behavior for NaN.

For x64, it currently returns a sentinel value 0x8000_0000 (int) or 0x8000_0000_0000_0000 (long) when the output type would overflow or when NaN is given. byte and short therefore currently expect 0 because its truncating the 32 or 64-bit result to 8 or 16-bits.

For Arm64, it saturates and converts NaN to zero. For WASM, it requires saturation and leaves NaN conversion undefined.

We plan on matching Arm64 for the cross platform deterministic behavior here as it is simple and straightforward. It matches the general IEEE 754 guidance that you compute the result as if to infinite precision and unbounded range, and then round to the nearest representable. NaN then logically has no equivalent, so it becoming zero "makes sense" and avoids confusion in other regards.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As such, it would be better if we could ensure the RISC-V implementation adjusts and matches this behavior. The underlying platform specific behavior would then be available in the future for the APIs proposed in the linked issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment, I will try to find the proper solution.

@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Nov 1, 2023
@marek-safar marek-safar removed the arch-riscv Related to the RISC-V architecture label Nov 27, 2023
@denis-paranichev
Copy link
Contributor Author

denis-paranichev commented Dec 6, 2023

#94762 fixes this problem, thus this PR can be closed.

@denis-paranichev denis-paranichev deleted the DenisParal/float-nan-overflow branch December 6, 2023 13:52
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants