Why does SC.W write 0 to rd on success?
SC.W uses rd as a status-result register. The official semantics define 0 for success and nonzero for failure, letting software decide whether to exit or retry the LR/SC loop.
Atomically conditionally store a 32-bit word if the reservation is valid; success writes memory and rd=0, failure leaves memory unchanged and rd nonzero
SC.W takes the low 32 bits of rs2 as the candidate store value and writes it to the address in rs1 only if the reservation from the most recent LR.W is still valid and the reservation set contains the target bytes. On success, rd receives zero; on failure, memory is not written and rd receives a nonzero failure code. Whether it succeeds or fails, SC.W invalidates the current hart reservation.
Shows A-extension word atomic field decode, aq/rl ordering bits, memory read, and RMW state update.
A-extension word 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.
SC.W is the decision point in an LR/SC sequence: it is not an unconditional store. On success it writes memory and writes 0 to rd; on failure memory remains unchanged and rd receives a nonzero failure code.
Understand this scenario with real code like «sc.w.rl t0, a1, (a0) # try store a1 to *a0 with release ordering, t0=0 on success».
SC.W uses rd as a status-result register. The official semantics define 0 for success and nonzero for failure, letting software decide whether to exit or retry the LR/SC loop.
No. On failure, SC.W does not perform the memory write; it only writes a nonzero failure code to rd and invalidates the current reservation.