Implement Interlocked for small types.#92974
Conversation
Implements Interlocked.CompareExchange/Exchange for byte/sbyte/short/ushort. Uses an intrinsic on CoreCLR x64 and ARM64 and fallbacks for other platforms. Fixes dotnet#64658.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, 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: @mangod9 Issue DetailsImplements Interlocked.CompareExchange/Exchange for byte/sbyte/short/ushort. Uses an intrinsic on CoreCLR x64 and ARM64 and fallbacks for other platforms. Fixes #64658.
|
I've checked that earlier, it calls into a Additionally, on arm32 it gives such warning: |
|
It is a problem with Other operations are implemented using If
|
|
I've opened a new issue to track this as this PR doesn't introduce the issue: #97452. |
|
|
It does not introduce it, but it makes the problem worse. Could you please replace the new uses of |
As I've noted in that issue, those other APIs also use helper calls so I'd assume they have the same issue. |
Diff results for #92974Throughput diffsThroughput diffs for linux/x64 ran on windows/x64Overall (+0.00% to +0.02%)
MinOpts (+0.01% to +0.03%)
FullOpts (+0.00% to +0.01%)
Throughput diffs for windows/x64 ran on windows/x64Overall (-0.01% to -0.00%)
MinOpts (-0.02% to +0.00%)
FullOpts (-0.01% to -0.00%)
Details here Throughput diffs for linux/x64 ran on linux/x64Overall (-0.03% to -0.01%)
MinOpts (-0.07% to -0.04%)
FullOpts (-0.02% to -0.01%)
Details here Throughput diffs for windows/x86 ran on windows/x86Overall (+0.00% to +0.01%)
MinOpts (+0.01% to +0.02%)
FullOpts (+0.00% to +0.01%)
Details here |
Diff results for #92974Throughput diffsThroughput diffs for linux/x64 ran on windows/x64Overall (+0.00% to +0.01%)
MinOpts (+0.01% to +0.02%)
FullOpts (+0.00% to +0.01%)
Details here Throughput diffs for linux/x64 ran on linux/x64Overall (-0.02%)
MinOpts (-0.05%)
FullOpts (-0.02%)
Details here |
Diff results for #92974Throughput diffsThroughput diffs for linux/x64 ran on linux/x64Overall (-0.03% to -0.01%)
MinOpts (-0.07% to -0.04%)
FullOpts (-0.02% to -0.01%)
Details here |
Diff results for #92974Throughput diffsThroughput diffs for linux/x64 ran on windows/x64Overall (+0.00% to +0.01%)
MinOpts (+0.01% to +0.03%)
FullOpts (+0.00% to +0.01%)
Throughput diffs for windows/x64 ran on windows/x64Overall (-0.01% to -0.00%)
MinOpts (-0.02% to +0.00%)
FullOpts (-0.01% to -0.00%)
Details here Throughput diffs for windows/x86 ran on windows/x86Overall (+0.00% to +0.01%)
MinOpts (+0.01% to +0.02%)
FullOpts (+0.00% to +0.01%)
Details here Throughput diffs for linux/x64 ran on linux/x64Overall (-0.03% to -0.01%)
MinOpts (-0.07% to -0.04%)
FullOpts (-0.02% to -0.01%)
Details here |
|
@jkotas I think the arm32 atomic helper issue should be fixed in a separate PR (I can take a look at using the safe LLVM helpers later today) so this should be ready to merge. |
What was this bug? |
|
/azp run runtime-coreclr outerloop, runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 2 pipeline(s). |
A missing cast to |
jkotas
left a comment
There was a problem hiding this comment.
Thank you for making this happen!
| public static int CompareExchange(ref int location1, int value, int comparand) | ||
| { | ||
| #if TARGET_X86 || TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64 | ||
| return CompareExchange(ref location1, value, comparand); |
There was a problem hiding this comment.
This is a self-referential "must expand" intrinsic now.
Implements Interlocked.CompareExchange/Exchange for byte/sbyte/short/ushort.
Uses an intrinsic on CoreCLR x64 and ARM64 and fallbacks for other platforms.
Fixes #64658.