-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use Unsafe.BitCast for Interlocked.{Compare}Exchange of float/double #87166
Conversation
Tagging subscribers to this area: @mangod9 Issue DetailsCodegen for coreclr: private static float x;
private static int i;
public float Variable(float a, float b) => Interlocked.CompareExchange(ref x, a, b);
public float Constant() => Interlocked.CompareExchange(ref x, 1.0f, 2.0f);
public float IntField() => Interlocked.CompareExchange(ref Unsafe.As<int, float>(ref i), 1.0f, 2.0f);
I don't know how to see codegen for mono/nativeaot, but as long as they implement
|
/// <param name="comparand">The value that is compared to the value at <paramref name="location1"/>.</param> | ||
/// <returns>The original value in <paramref name="location1"/>.</returns> | ||
/// <exception cref="NullReferenceException">The address of <paramref name="location1"/> is a null pointer.</exception> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
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.
AggressiveInlining wasn't shown necessary in my first explorations, added just for consistency with uint/ulong ones.
Codegen for ARM64: public float Constant() => Interlocked.CompareExchange(ref x, 1.0f, 2.0f);
public int ConstantInteger() => Interlocked.CompareExchange(ref i, 1, 2);
I don't really understand ARM asm, but since the patterns are almost the same, I think there's no issue. |
The mono changes look ok. |
I'd check codegen for x86/arm32 for the double one. |
Double codegen for x86:
The call to CompareExchange isn't inlined, since it's an FCall? |
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.
Thank you
CI is not feeling well
yes, that's expected |
|
Codegen for coreclr:
I don't know how to see codegen for mono/nativeaot, but as long as they implement
Unsafe.As/BitCast
correctly this would be very simple.