AMOCAS.W
Atomic Compare and Swap Word
AMOCAS.W rd, rs2, (rs1)
Atomically compares memory at rs1 with rd; if equal, writes rs2 to memory. Returns original value in rd.
Encoding
Binary Layout
00101
31:27
aq
26
rl
25
rs2
24:20
rs1
19:15
010
14:12
rd
11:7
0101111
6:0
Operands
-
rd
Dest/Compare -
rs2
Swap Value -
rs1
Address
Example
AMOCAS.W t0, a1, a0
Related
Across architectures
Atomic Compare and Swap : how x86, ARM, RISC-V, and PowerISA each do this.
More in Zacas
Reference
View in RISC-V Unprivileged ISA Specification ↗
RISC-V ISA Manual
Description
AMOCAS.W (Zacas) atomically compares the word at the address in rs1 with rs1 (the compare value), and if equal, writes rs2 to that address. The original value is returned in rd.
Operation
atomic { if(M[rs1]==R[rd]) M[rs1]=R[rs2]; R[rd]=M[rs1]; }