WRS.STO

RISC-V WRS.STO Instruction Details

Instruction ManualI-type

Wait on reservation set with short timeout

Instruction Syntax

wrs.sto
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
ZawrsCache & Sync

Instruction Behavior

Like WRS.NTO but stall duration bounded by implementation-defined short timeout (10-100x cache miss latency). Part of Zawrs.

Quick Understanding & Search Notes

WRS.STO is a Zawrs wait-on-reservation-set instruction used with a prior LR reservation, allowing the hart to temporarily stall while waiting for a store to the reserved location.

A prior LR must establish a reservation set containing the target bytes; the instruction has no address operand.
WRS.STO bounds the stall by an implementation-defined short timeout.
The instructions are available in all privilege modes, but WRS.NTO is affected by the mstatus.TW rule.

Common Usage Scenarios

Cache & Hints

Understand this scenario with real code like «lr.w x10, (x11) ; wrs.sto ; bne x10, x12, retry».

Device & IO

Understand this scenario with real code like «lr.w x10, (x11) ; wrs.sto ; bne x10, x12, retry».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Must be used with a reservation set established by a prior LR.
The short-timeout duration is implementation-defined and must not be documented as a fixed cycle count.
Returning from the wait does not mean the condition is satisfied; software must reload and test the shared state.

FAQ

Can WRS.STO replace LR/SC?

No. It only waits for events related to an existing reservation set; synchronization algorithms still need LR/SC, AMO, or CAS operations to update state.

Will WRS.STO always sleep until memory changes?

No. The spec allows an implementation to occasionally terminate the stall for any reason, so software must re-check the condition in a loop.