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
Atomically loads the 32-bit value at the address in rs1 and compares it with the 32-bit value in rd (the low 32 bits on RV64). If they are bitwise equal it stores the value in rs2 to that address. The value loaded from memory is always written to rd (sign-extended on RV64).
Operation
atomic { temp = M[R[rs1]]; if (temp == R[rd]) M[R[rs1]] = R[rs2]; R[rd] = temp; }