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.
RV32/RV64 32-bit store-conditional: success stores data and returns rd=0; failure performs no data store and returns nonzero.
Extension condition: RV32/RV64, requiring Zalrsc or the A extension that includes Zalrsc.
SC.W uses rs1 as the address and rs2's low 32 bits as candidate data. Success stores data and writes zero to rd; failure performs no data store and writes a nonzero code to rd. Success requires a valid reservation from the most recent LR covering the written bytes, but a valid reservation does not guarantee success. Relevant writes by another hart, device writes to LR-accessed bytes, or an intervening SC force failure. Both outcomes invalidate this hart's reservation. SC must pass memory permission checks before retiring; side effects of implicit translation/protection accesses on failure are unspecified. On RV64, SC.W sign-extends its 32-bit status value to XLEN.
Shows A / Zalrsc word atomic field decode, aq/rl ordering bits, reservation and permission checks, and store-conditional state update.
This teaching toggle selects the SC success or failure outcome; success still depends on the most recent LR reservation and other architectural conditions, and a failure code is only guaranteed to be nonzero.
A / Zalrsc-extension word atomic instructions use a 32-bit encoding; the animation starts by splitting the fields.
Assumes successful fetch, a naturally aligned LR/SC-capable region and passed memory permission checks. The toggle chooses a permitted SC success/failure outcome; LR, the reservation set and other hart/device interference are not fully modeled. Failure performs no data store, but implicit translation/protection side effects are unspecified. aq/rl concerns only the accessed memory/I/O domain; steps are a teaching sequence.
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 it performs no data store and rd receives a nonzero failure code.
SC.W supports LR/SC conditional updates; software checks rd for zero/nonzero, and a valid reservation does not guarantee 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.
A failed SC performs no data store, writes nonzero status (discarded for rd=x0), and invalidates the reservation. Side effects of implicit translation/protection accesses are unspecified.