WRS.NTO

RISC-V WRS.NTO Instruction Details

Instruction ManualI-type

Wait on reservation set with no timeout

Instruction Syntax

wrs.nto

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=000000001101, rs1=00000, funct3=000, rd=00000, opcode=1110011.

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

Outside M, TW=1 causes an illegal-instruction exception on noncompletion within an implementation-specific bounded time. In VS/VU, TW=0 and VTW=1 cause a virtual-instruction exception on the same noncompletion condition.

ZawrsCache & Sync

Instruction Encoding

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

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

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

Instruction Behavior

May temporarily stall a hart while its LR-established reservation set is valid and no pending interrupt is observed, even if disabled. An implementation may occasionally end the stall for any reason.

Quick Understanding & Search Notes

WRS.NTO is a Zawrs wait-on-reservation-set instruction: a hart can temporarily stall while its reservation set is valid and no pending interrupt is observed; 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.NTO has no short timeout, but can end on a store to the reservation set, an observed interrupt, or an implementation choice.
The instructions are available in all privilege modes. WRS.NTO has a bounded-time illegal-instruction rule outside M mode with mstatus.TW=1; in VS/VU modes, mstatus.TW=0 plus hstatus.VTW=1 instead gives a virtual-instruction exception.

Common Usage Scenarios

Polling an LR reservation set

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=000000001101, 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; there is no built-in short timeout. The implementation may occasionally complete for any reason; software must recheck its condition.
  • Outside M, TW=1 causes an illegal-instruction exception on noncompletion within an implementation-specific bounded time. In VS/VU, TW=0 and VTW=1 cause a virtual-instruction exception on the same noncompletion condition.

Pitfalls / Common Confusions

To wait for a memory location to be written, first use LR to establish a reservation set that includes its bytes.
With mstatus.TW=1, WRS.NTO outside M mode raises an illegal-instruction exception if it does not complete within an implementation-specific bounded time. In VS/VU modes, with mstatus.TW=0 and hstatus.VTW=1, the same noncompletion causes a virtual-instruction exception.
There is no short-timeout guarantee, but the implementation can still end the wait because of a store to the reservation set, an interrupt, or its own choice; software must re-check the condition in a loop.

FAQ

Can WRS.NTO 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.NTO always sleep until memory changes?

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