Atomic instructions
Type: unprivileged
Zaamo and Zalrsc
| Version | State | Ratified |
|---|---|---|
| 2.1.0 | ratified | 2019-12 |
The atomic-instruction extension, named `A`, contains instructions that atomically read-modify-write memory to support synchronization between multiple RISC-V harts running in the same memory space. The two forms of atomic instruction provided are load-reserved/store-conditional instructions and atomic fetch-and-op memory instructions. Both types of atomic instruction support various memory consistency orderings including unordered, acquire, release, and sequentially consistent semantics. These instructions allow RISC-V to support the RCsc memory consistency model. cite:[Gharachorloo90memoryconsistency]
Note: After much debate, the language community and architecture community appear to have finally settled on release consistency as the standard memory consistency model and so the RISC-V atomic support is built around this model.
The `A` extension comprises instructions provided by the `Zaamo` and `Zalrsc` extensions.
Specifying Ordering of Atomic Instructions
The base RISC-V ISA has a relaxed memory model, with the `FENCE` instruction used to impose additional ordering constraints. The address space is divided by the execution environment into memory and I/O domains, and the `FENCE` instruction provides options to order accesses to one or both of these two address domains.
To provide more efficient support for release consistency cite:[Gharachorloo90memoryconsistency], each atomic instruction has two bits, _aq_ and _rl_, used to specify additional memory ordering constraints as viewed by other RISC-V harts. The bits order accesses to one of the two address domains, memory or I/O, depending on which address domain the atomic instruction is accessing. No ordering constraint is implied to accesses to the other domain, and a FENCE instruction should be used to order across both domains.
If both bits are clear, no additional ordering constraints are imposed on the atomic memory operation. If only the _aq_ bit is set, the atomic memory operation is treated as an _acquire_ access, i.e., no following memory operations on this RISC-V hart can be observed to take place before the acquire memory operation. If only the _rl_ bit is set, the atomic memory operation is treated as a _release_ access, i.e., the release memory operation cannot be observed to take place before any earlier memory operations on this RISC-V hart. If both the _aq_ and _rl_ bits are set, the atomic memory operation is _sequentially consistent_ and cannot be observed to happen before any earlier memory operations or after any later memory operations in the same RISC-V hart and to the same address domain.
amoadd.d — Atomic fetch-and-add doublewordamoadd.d.aq — Atomic fetch-and-add doubleword (acquire)amoadd.d.aqrl — Atomic fetch-and-add doubleword (acquire-release)amoadd.d.rl — Atomic fetch-and-add doubleword (release)amoadd.w — Atomic fetch-and-add wordamoadd.w.aq — Atomic fetch-and-add word (acquire)amoadd.w.aqrl — Atomic fetch-and-add word (acquire-release)amoadd.w.rl — Atomic fetch-and-add word (release)amoand.d — Atomic fetch-and-and doublewordamoand.d.aq — Atomic fetch-and-and doubleword (acquire)amoand.d.aqrl — Atomic fetch-and-and doubleword (acquire-release)amoand.d.rl — Atomic fetch-and-and doubleword (release)amoand.w — Atomic fetch-and-and wordamoand.w.aq — Atomic fetch-and-and word (acquire)amoand.w.aqrl — Atomic fetch-and-and word (acquire-release)amoand.w.rl — Atomic fetch-and-and word (release)amomax.d — Atomic MAX doublewordamomax.d.aq — Atomic MAX doubleword (acquire)amomax.d.aqrl — Atomic MAX doubleword (acquire-release)amomax.d.rl — Atomic MAX doubleword (release)amomax.w — Atomic MAX wordamomax.w.aq — Atomic MAX word (acquire)amomax.w.aqrl — Atomic MAX word (acquire-release)amomax.w.rl — Atomic MAX word (release)amomaxu.d — Atomic MAX unsigned doublewordamomaxu.d.aq — Atomic MAX unsigned doubleword (acquire)amomaxu.d.aqrl — Atomic MAX unsigned doubleword (acquire-release)amomaxu.d.rl — Atomic MAX unsigned doubleword (release)amomaxu.w — Atomic MAX unsigned wordamomaxu.w.aq — Atomic MAX unsigned word (acquire)amomaxu.w.aqrl — Atomic MAX unsigned word (acquire-release)amomaxu.w.rl — Atomic MAX unsigned word (release)amomin.d — Atomic MIN doublewordamomin.d.aq — Atomic MIN doubleword (acquire)amomin.d.aqrl — Atomic MIN doubleword (acquire-release)amomin.d.rl — Atomic MIN doubleword (release)amomin.w — Atomic MIN wordamomin.w.aq — Atomic MIN word (acquire)amomin.w.aqrl — Atomic MIN word (acquire-release)amomin.w.rl — Atomic MIN word (release)amominu.d — Atomic MIN unsigned doublewordamominu.d.aq — Atomic MIN unsigned doubleword (acquire)amominu.d.aqrl — Atomic MIN unsigned doubleword (acquire-release)amominu.d.rl — Atomic MIN unsigned doubleword (release)amominu.w — Atomic MIN unsigned wordamominu.w.aq — Atomic MIN unsigned word (acquire)amominu.w.aqrl — Atomic MIN unsigned word (acquire-release)amominu.w.rl — Atomic MIN unsigned word (release)amoor.d — Atomic fetch-and-or doublewordamoor.d.aq — Atomic fetch-and-or doubleword (acquire)amoor.d.aqrl — Atomic fetch-and-or doubleword (acquire-release)amoor.d.rl — Atomic fetch-and-or doubleword (release)amoor.w — Atomic fetch-and-or wordamoor.w.aq — Atomic fetch-and-or word (acquire)amoor.w.aqrl — Atomic fetch-and-or word (acquire-release)amoor.w.rl — Atomic fetch-and-or word (release)amoswap.d — Atomic SWAP doublewordamoswap.d.aq — Atomic SWAP doubleword (acquire)amoswap.d.aqrl — Atomic SWAP doubleword (acquire-release)amoswap.d.rl — Atomic SWAP doubleword (release)amoswap.w — Atomic SWAP wordamoswap.w.aq — Atomic SWAP word (acquire)amoswap.w.aqrl — Atomic SWAP word (acquire-release)amoswap.w.rl — Atomic SWAP word (release)amoxor.d — Atomic fetch-and-xor doublewordamoxor.d.aq — Atomic fetch-and-xor doubleword (acquire)amoxor.d.aqrl — Atomic fetch-and-xor doubleword (acquire-release)amoxor.d.rl — Atomic fetch-and-xor doubleword (release)amoxor.w — Atomic fetch-and-xor wordamoxor.w.aq — Atomic fetch-and-xor word (acquire)amoxor.w.aqrl — Atomic fetch-and-xor word (acquire-release)amoxor.w.rl — Atomic fetch-and-xor word (release)lr.d — Load Reserved Doublewordlr.d.aq — Load Reserved Doublewordlr.d.aqrl — Load Reserved Doublewordlr.d.rl — Load Reserved Doublewordlr.w — Load Reserved Wordlr.w.aq — Load Reserved Wordlr.w.aqrl — Load Reserved Wordlr.w.rl — Load Reserved Wordsc.d — Store conditional doublewordsc.d.aq — Store conditional doublewordsc.d.aqrl — Store conditional doublewordsc.d.rl — Store conditional doublewordsc.w — Store conditional wordsc.w.aq — Store conditional wordsc.w.aqrl — Store conditional wordsc.w.rl — Store conditional wordVersion af3eaf9+cheriot.f635218
Data from the RISC-V Unified Database, copyright RISC-V International and contributors.
CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.
This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.