Does AMOSWAP.D write the new value or old value to rd?
rd receives the old value. AMOSWAP.D first reads the old 64-bit memory value into rd, then writes the 64-bit rs2 value to memory.
RV64 atomic 64-bit doubleword swap: rd returns the old memory value, while memory receives the 64-bit value from rs2
The following semantics assume the target region supports this AMO width and operation and the access succeeds. AMOSWAP.D performs an atomic read-modify-write on the 64-bit doubleword addressed by rs1: it reads the old memory doubleword into rd and then writes the 64-bit value from rs2 back to the same address. It is an RV64 A/Zaamo instruction and does not use an LR/SC reservation; aq/rl add ordering only in the accessed memory or I/O address domain, and ordering across both domains still needs FENCE. rs2 uses its pre-execution value; rd=x0 discards only the old-value register writeback, while the memory operation still occurs.
Shows A / Zaamo doubleword atomic field decode, aq/rl ordering bits, a memory read, and RMW state update.
A / Zaamo-extension doubleword atomic instructions use a 32-bit encoding; the animation starts by splitting the fields.
Assumes the region supports this AMO and the access succeeds. Shows the operation, old-value return, memory update and aq/rl ordering in the accessed domain. Steps are a teaching sequence; access faults, CPU cache coherence, pipelines and timing are not modeled.
AMOSWAP.D is a 64-bit atomic swap: on successful access with rd≠x0, rd gets the old memory doubleword before the swap, and memory gets the 64-bit rs2 value. It is not an LR/SC sequence and does not write the new value to rd.
Successful 64-bit access example: a2=0x1000, old memory=5, a1=3; amoswap.d a0, a1, (a2) returns a0=5 and updates memory to 3. The address is naturally aligned and the region supports this AMO.
Successful 64-bit access example: a2=0x1000, old memory=5, a1=3; amoswap.d a0, a1, (a2) returns a0=5 and updates memory to 3. The address is naturally aligned and the region supports this AMO.
rd receives the old value. AMOSWAP.D first reads the old 64-bit memory value into rd, then writes the 64-bit rs2 value to memory.
No. AMOSWAP.D is a single AMO read-modify-write instruction and does not depend on LR/SC reservation state.