WRS.STO

RISC-V WRS.STO Instruction Details

Instruction ManualI-type

Wait on reservation set with short timeout

Instruction Syntax

wrs.sto

No explicit operands; requires Zawrs. To wait for a memory store, first use LR to reserve a set containing the target bytes.

32-bit SYSTEM I-type fields: funct12=000000011101, rs1=00000, funct3=000, rd=00000, opcode=1110011.

A stall is possible while the reservation is valid and no pending interrupt is observed; an implementation-defined short timeout bounds it. The implementation may occasionally complete for any reason; software must recheck its condition.

Available in all privilege modes; the WRS.NTO bounded-time TW/VTW exception rules do not apply to WRS.STO.

ZawrsCache & Sync

Instruction Encoding

31..20
funct12
19..15
rs1=x0
14..12
funct3
11..7
rd=x0
6..0
opcode

WRS.STO uses opcode 1110011 (0x73), funct3 000, funct12 000000011101. 32-bit SYSTEM I-type fields: funct12=000000011101, rs1=00000, funct3=000, rd=00000, opcode=1110011.

Format: SYSTEM I-type fields
opcode: 1110011 (0x73)
funct3: 000 (0x0)
funct12: 000000011101 (0x01d)

Instruction Behavior

May temporarily stall a hart while its LR-established reservation set is valid, no pending interrupt is observed, and an implementation-defined short timeout has not elapsed. A timeout, store to the reservation set, interrupt, or implementation-selected end can resume execution.

Quick Understanding & Search Notes

WRS.STO is a Zawrs wait-on-reservation-set instruction: a hart can temporarily stall while its reservation set is valid, no pending interrupt is observed, and the short timeout has not elapsed; LR establishes that reservation set.

To wait for target bytes to be written, LR should first establish a reservation set containing them; 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

Reservation polling with a short timeout

In a polling loop, use LR to establish a reservation set covering the target bytes, then decide from the shared state whether to wait. Reload and test after returning; completion does not prove a target store occurred.

Waiting on shared state

In a polling loop, use LR to establish a reservation set covering the target bytes, then decide from the shared state whether to wait. Reload and test after returning; completion does not prove a target store occurred.

Pre-Use Checklist

Syntax Check
  • No explicit operands; requires Zawrs. To wait for a memory store, first use LR to reserve a set containing the target bytes.
  • 32-bit SYSTEM I-type fields: funct12=000000011101, rs1=00000, funct3=000, rd=00000, opcode=1110011.
Semantic Check
  • A stall is possible while the reservation is valid and no pending interrupt is observed; an implementation-defined short timeout bounds it. The implementation may occasionally complete for any reason; software must recheck its condition.
  • Available in all privilege modes; the WRS.NTO bounded-time TW/VTW exception rules do not apply to WRS.STO.

Pitfalls / Common Confusions

To wait for a memory location to be written, first use LR to establish a reservation set that includes its bytes.
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 waits on a reservation set established by LR; it performs neither the LR load nor the SC conditional store.

Will WRS.STO always sleep until memory changes?

No. An implementation may end the stall for any reason; software must re-check the condition.