Skip to content

[RISC-V] Zacas support for Interlocked.CompareExchange #137345

In review

Description

@equmagg

Interlocked.CompareExchange intrinsics currently use lr/sc retry loop sequences, processors supporting Zacas could lagely benefit from using amocas.w and amocas.d.

Admittedly, hardware support is currently lacking, but considering the importance of CAS operations as a building block for synchronization and concurrent algorithms, preemptive support seems justified. Zacas is also required to represent 128-bit CAS, which is not currently exposed, but may unblock work in the future, as it allows for a genuine cmpxchg16b emulation on RISC-V.
There is also a precedent with OpenJDK supporting it, as well as a precedent in the JIT for introducing ISA support before hardware validation.
I find it useful personally in VM/Emulator scenarios as well.

The initial scope would be to cover 32-bit and 64-bit Interlocked.CompareExchange intrinsics. Memory ordering on comparison failure needs special attention, since failed amocas operations do not provide release semantics by themselves.

I have a PR draft with the intial bringup, tested and passing with QEMU locally and I would love to contribute.
I would appreciate feedback on the scope and general direction
cc @am11 @filipnavara

Activity

  1. added
    untriaged
    on Nov 11, 2026
  2. added
    area-CodeGen-coreclr
    on Nov 11, 2026
  3. dotnet-policy-service commented on Nov 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. added
    arch-riscv
    on Nov 11, 2026
  5. removed
    untriaged
    on Nov 25, 2026
  6. added this to the 12.0.0 milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

arch-riscvarea-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions