-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[clr-interp] Add missing MustExpand non vector or hardware intrinsics #119670
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
[clr-interp] Add missing MustExpand non vector or hardware intrinsics #119670
Conversation
…ge and Interlocked.CompareExchange
…tor and hardware intrinsic ones.
…erlocked.Exchange
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.
Pull Request Overview
This pull request adds missing "MustExpand" intrinsics to the .NET CoreCLR interpreter to support non-vector and non-hardware intrinsics that are essential for correct program execution. The changes expand intrinsic support for atomic operations, math functions, and memory barriers.
Key changes include:
- Added 8-bit and 16-bit Interlocked operations (Exchange, CompareExchange) with complex alignment handling
- Implemented Interlocked.ExchangeAdd and memory barrier operations
- Added math intrinsics like Sqrt, MultiplyAddEstimate, ReciprocalEstimate, and ConvertToIntegerNative
- Fixed MustExpand detection to exclude virtual function calls and improved debug output
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/interpexec.cpp | Implements execution logic for new 8/16-bit atomic operations and math sqrt functions |
| src/coreclr/interpreter/intrinsics.cpp | Maps method names to intrinsic identifiers for Sqrt and ExchangeAdd |
| src/coreclr/interpreter/inc/intops.def | Defines new interpreter opcodes for the additional intrinsic operations |
| src/coreclr/interpreter/compiler.h | Updates function signature and adds helper for floating-point conversions |
| src/coreclr/interpreter/compiler.cpp | Contains the main intrinsic compilation logic and MustExpand detection fixes |
Comments suppressed due to low confidence (2)
src/coreclr/interpreter/compiler.cpp:1
- The alignment check
shift & 1is incorrect for 16-bit operations. Sinceshift = ((size_t)dst & 3) * 8, this check verifies if the shift is odd (8 or 24 bits), but 16-bit values should be 2-byte aligned. The correct check should be((size_t)dst & 1) != 0to verify the address is 2-byte aligned.
// Licensed to the .NET Foundation under one or more agreements.
src/coreclr/interpreter/compiler.cpp:1
- The alignment check
shift & 1is incorrect for 16-bit operations. Sinceshift = ((size_t)dst & 3) * 8, this check verifies if the shift is odd (8 or 24 bits), but 16-bit values should be 2-byte aligned. The correct check should be((size_t)dst & 1) != 0to verify the address is 2-byte aligned.
// Licensed to the .NET Foundation under one or more agreements.
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ingMustexpandNonVectorOrHarwareIntrinsics
|
After #119775 this will need to use something other than NO_WAY to get JIT fallback (we want to return CORJIT_SKIPPED) |
…dotnet#119670) Add the missing MustExpand intrinsics that are not related to vector or hardware intrinsics - 8 and 16 bit forms of Interlocked.Exchange - Interlocked.ExchangeAdd - Interlocked.MemoryBarrier - Volatile.WriteBarrier - Double.MultiplyAddEstimate and Single.MultiplyAddEstimate - Double.ConvertToIntegerNative and Single.ConvertToIntegerNative - Math.ReciprocalEstimate and MathF.ReciprocalEstimate - Math.ReciprocalSqrtEstimate and MathF.ReciprocalSqrtEstimate And finally as a bonus a related non must-expand intrinsic - Math.Sqrt and MathF.Sqrt Detect MustExpand correctly. (virtual functions cannot be MustExpand) Also in debug builds, print unconditionally when a MustExpand intrinsic is not expanded, and run the NO_WAY code. (In practice on platforms with a JIT this will fall back to running the JIT to provide the implementation) Collectively, this unblocks use of InterpMode=3 for some tests. Previously some of these tests would stack overflow in InterpMode=3. We may want to revisit some of these implementations (notably MultiplyAddEstimate, ConvertToIntegerNative, ReciprocalEstimate, and ReciprocalSqrtEstimate since their behavior will not necessarily match that of the JIT, but for now this will provide generally functional implementations of all of this.)
Add the missing MustExpand intrinsics that are not related to vector or hardware intrinsics
And finally as a bonus a related non must-expand intrinsic
Detect MustExpand correctly. (virtual functions cannot be MustExpand)
Also in debug builds, print unconditionally when a MustExpand intrinsic is not expanded, and run the NO_WAY code. (In practice on platforms with a JIT this will fall back to running the JIT to provide the implementation)
Collectively, this unblocks use of InterpMode=3 for some tests. Previously some of these tests would stack overflow in InterpMode=3.
We may want to revisit some of these implementations (notably MultiplyAddEstimate, ConvertToIntegerNative, ReciprocalEstimate, and ReciprocalSqrtEstimate since their behavior will not necessarily match that of the JIT, but for now this will provide generally functional implementations of all of this.)