Does AMOSWAP.W write the new value or old value to rd?
rd receives the old 32-bit value from memory before the swap, sign-extended to XLEN. The low 32 bits of rs2 are the new value written to memory.
Atomically swap a 32-bit word: read the old memory value into rd and write the low 32 bits of rs2 back to the same address
AMOSWAP.W performs an atomic read-modify-write on the 32-bit word addressed by rs1: it reads the old memory value, sign-extends it into rd, and writes the low 32 bits of rs2 back to the same address. It does not use an LR/SC reservation; the aq/rl bits only affect ordering of this atomic memory operation relative to other memory operations in the same address domain.
Shows A / Zaamo word atomic field decode, aq/rl ordering bits, a memory read, and RMW state update.
A / Zaamo-extension word 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.W writes the pre-swap old memory value to rd, while memory receives the low 32 bits of rs2. It is a single AMO read-modify-write operation, not an LR/SC loop.
Successful 32-bit access example: a2=0x1000, old memory=5, a1=3; amoswap.w 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 32-bit value from memory before the swap, sign-extended to XLEN. The low 32 bits of rs2 are the new value written to memory.
No. AMOSWAP.W is an independent AMO read-modify-write instruction and does not depend on an LR/SC reservation.