-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mono][mini] Interlocked.CompareExchange and Interlocked.Exchange int…
…rinsics for small types and enums (#106660) Only arm64, amd64 and WebAssembly. Interpreter, JIT and LLVM AOT. No x86 or arm32. The complication for the 8- and 16-bit operands is that the .NET operand stack is 32-bit. so we have to zero- or sign-extend the inputs and output. I ended up following the same approach as clang: zero-extend "expected" value and then sign-extend the return value of the CAS. One nice consequence is that the LLVM support is essentially free. --- Also this PR makes the intrinsic apply to types that have byte/int/long as the underlying type (bool, enums) not just when the type is literally in the signature --- Also implement interp and jiterp intrinsic for Exchange(int) - this was not available previously. --- Related to #105335 Related to #93488 * [mono][mini][arm64] Interlocked.CompareExchange for byte/sbyte * [sample] fixup HelloWorld to work with full aot * [mini][llvm] support OP_ATOMIC_CAS_U1 * [mini][amd64] support OP_ATOMIC_CAS_U1 * [mini][wasm] support OP_ATOMIC_CAS_U1 in LLVM AOT * make intrinsic must-expand on arm64,amd64,wasm on mono * [interp] MINT_MONO_CMPXCHG_U1 also add mono_atomic_cas_u8 utility function * [mini] CompareExchange(i16/u16) * [mono] must expand CompareExchange(i16/u16) * [interp] Interlocked.CompareExchange(u16/i16) * [mini] zext unsigned CAS results for small types * [interp] signed small CAS ops * [amd64] fixup 8- and 16-bit cmpxchg encoding * fixup u16 win32 atomic * Interlocked.Exchange u1/i1/u2/i2 interp,llvm,amd64,arm64 * [amd64] give u2 CMPXCHG and XCHG one more byte for the 16-bit addressing prefix * If jiterpreter is engaged before the thread is fully initialized, just fail to allocate a table index and generate a warning. This shouldn't happen in prod anyway * Implement cmpxchg atomics natively in jiterpreter * Remove unnecessary jiterp cas helpers * Do cmpxchg result fixups as needed * Add runtime option for jiterpreter atomics * Implement atomic exchanges in the jiterpreter * Interlocked.Exchange(int) for interp and jiterp --------- Co-authored-by: Katelyn Gadd <kg@luminance.org>
- Loading branch information
1 parent
df2d213
commit 86b58ee
Showing
24 changed files
with
711 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.