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
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 bits affect memory ordering only.
Shows A-extension doubleword atomic field decode, aq/rl ordering bits, memory read, and RMW state update.
A-extension doubleword atomic instructions use a 32-bit encoding; the animation starts by splitting the fields.
This animation shows ISA-visible atomic read-modify-write, compare-and-swap, LR/SC reservation state, and ordering bits, not any specific CPU cache-coherence implementation, pipeline, or timing.
AMOSWAP.D is a 64-bit atomic swap: 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.
Understand this scenario with real code like «amoswap.d.aq t0, t1, (a0) # t0 = old 64-bit *a0; *a0 = t1».
Understand this scenario with real code like «amoswap.d.aq t0, t1, (a0) # t0 = old 64-bit *a0; *a0 = t1».
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.