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] Test TotalOrderIeee754ComparerTests: Fix NFloat - NaN testcases for RISC-V #97340

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,38 @@ public void TotalOrderTestHalf(Half x, Half y, int result)
Assert.Equal(result, Math.Sign(comparer.Compare(x, y)));
}

public static IEnumerable<object[]> NFloatTestData
{
get
{
yield return new object[] { 0.0f, 0.0f, 0 };
yield return new object[] { -0.0f, -0.0f, 0 };
yield return new object[] { 0.0f, -0.0f, 1 };
yield return new object[] { -0.0f, 0.0f, -1 };
yield return new object[] { 0.0f, 1.0f, -1 };
yield return new object[] { float.PositiveInfinity, 1.0f, 1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), float.PositiveInfinity, 1 };
yield return new object[] { float.NaN, float.NaN, 0 };
if (PlatformDetection.IsRiscV64Process) // float->double cast does not preserve NaN payload and sign on RISC-V
{
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, 1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, 1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), 0 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), 0 }; // implementation defined, not part of IEEE 754 totalOrder
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is the desirable/best fix.

The overall preservation of a NaN sign/payload is implementation defined; however, in the face of a NaN with sign and/or payload, IEEE 754 totalOrder describes exact handling/behavior that is required to be followed.

The test was using SingleTestData for simplicity purposes; however in the face of RiscV it is likely better to fix the test to take NFloat and to enumerate bitwise correct values depending on the underlying bitness of the platform. That way encountered NaN with sign/payload (such as from the developer doing a bitcast where RiscV doesn't normalize) can be validated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to enumerate bitwise correct values only for NaN values or for all test values?

else
{
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, -1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, -1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), -1 };
yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; // implementation defined, not part of IEEE 754 totalOrder
}
}
}

[Theory]
[MemberData(nameof(SingleTestData))]
[MemberData(nameof(NFloatTestData))]
public void TotalOrderTestNFloat(float x, float y, int result)
{
var comparer = new TotalOrderIeee754Comparer<NFloat>();
Expand Down
Loading