-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add unsigned variants for BitConverter float bit APIs #53784
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
Add unsigned variants for BitConverter float bit APIs #53784
Conversation
Adds DoubleToUInt64Bits, UInt64BitsToDouble, SingleToUInt32Bits, UInt32BitsToSingle, HalfToUInt16Bits and UInt16BitsToHalf. Implementations were based on existing signed integer variants. Convert usages of existing APIs to unsigned variants when appropriate. Fix dotnet#36469
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @tannergooding, @pgovind Issue DetailsAdds DoubleToUInt64Bits, UInt64BitsToDouble, SingleToUInt32Bits, Implementations were based on existing signed integer variants. Convert usages of existing APIs to unsigned variants when appropriate. Fix #36469 The changes build on my machine, but I was unable to run the unit tests, running all of them made the test process hang for 4 hours, so I'm opening this to see what happens on the CI.
|
I'm not quite sure what's going on with the tests failing on linux arm and musl arm & arm64, the values returned by the API seem to be way above the ushort range. Could somebody take a look? |
Btw, on x64 (thus, unrelated to your issue) public static unsafe ulong DoubleToUInt64Bits1(double value)
{
Vector128<ulong> vec = Vector128.CreateScalarUnsafe(value).AsUInt64();
return Sse2.X64.ConvertToUInt64(vec);
} Emits: G_M65487_IG01: ;; offset=0000H
C5F877 vzeroupper
;; bbWeight=1 PerfScore 1.00
G_M65487_IG02: ;; offset=0003H
C4E1F97EC0 vmovd rax, xmm0
;; bbWeight=1 PerfScore 2.00
G_M65487_IG03: ;; offset=0008H
C3 ret
;; bbWeight=1 PerfScore 1.00
; Total bytes of code: 9 @tannergooding any idea why it's |
cc @sandreenko (#47843) |
Looks to be a disassembly issue, its emitted an 8-byte move |
@@ -328,7 +328,7 @@ CVType switch | |||
CV_U4 => (uint)_data, | |||
CV_I8 => _data, | |||
CV_U8 => (ulong)_data, | |||
CV_R4 => BitConverter.Int32BitsToSingle((int)_data), | |||
CV_R4 => BitConverter.UInt32BitsToSingle((uint)_data), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it so that both places in Variant use the same pair of APIs, the unsigned ones.
src/libraries/System.Private.CoreLib/src/System/BitConverter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/BitConverter.cs
Outdated
Show resolved
Hide resolved
Reverted a comment change made in the existing code by mistake.
Use the existing signed methods with a cast, less code with the same codegen.
Corrected the type used in a cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
IIRC, there were a few remaining cases that didn't immediately cast, but which should also be switched to the unsigned ones. We can get them in a follow up PR, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR, LGTM!
Adds DoubleToUInt64Bits, UInt64BitsToDouble, SingleToUInt32Bits,
UInt32BitsToSingle, HalfToUInt16Bits and UInt16BitsToHalf.
Implementations were based on existing signed integer variants.
Convert usages of existing APIs to unsigned variants when appropriate.
Fix #36469
The changes build on my machine, but I was unable to run the unit tests, running all of them made the test process hang for 4 hours, so I'm opening this to see what happens on the CI.