ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 1,823 microarchs · 16,083 chips · 105 sources
Arch:
Tier:

wfi

T1 riscv system insn
Wait for interrupt
SourceRISC-V Official Unified Database (riscv-unified-db) (riscv_unified_db)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeRV32/RV64 Sm
RV32 / RV64 (Ratified & Standard Extensions)
License & VersionApache-2.0 / CC-BY-4.0
main
Upstreamhttps://github.com/riscv/riscv-unified-db
Privilegeuser
ExtensionsSm

Summary

Can causes the processor to enter a low-power state until the next interrupt occurs.

Syntax / Encoding

wfi | 00010000010100000000000001110011 (mask=0xffffffff match=0x10500073)

Binary Encodings (1)

WidthFormatBit PatternMask / Match
32RV000100000101000000000000011100110xffffffff / 0x10500073

Reference Notes

Can causes the processor to enter a low-power state until the next interrupt occurs.

<%- if ext?(:H) -%>
The behavior of `wfi` is affected by the `mstatus.TW`
and `hstatus.VTW` bits, as summarized below.

[%autowidth,%footer]
|===
.2+| [.rotate]#`mstatus.TW`# .2+| [.rotate]#`hstatus.VTW`# 4+^.>| `wfi` behavior
h| HS-mode h| U-mode h| VS-mode h| in VU-mode

| 0 | 0 | Wait | Trap (I) | Wait | Trap (V)
| 0 | 1 | Wait | Trap (I) | Trap (V) | Trap (V)
| 1 | - | Trap (I) | Trap (I) | Trap (I) | Trap (I)

6+| Trap (I) - Trap with `Illegal Instruction` code +
Trap (V) - Trap with `Virtual Instruction` code
|===

<%- else -%>
The `wfi` instruction is also affected by `mstatus.TW`, as shown below:

[%autowidth,%footer]
|===
.2+| [.rotate]#`mstatus.TW`# 2+^.>| `wfi` behavior
h| S-mode h| U-mode

| 0 | Wait | Trap (I)
| 1 | Trap (I) | Trap (I)

3+| Trap (I) - Trap with `Illegal Instruction` code
|===

<%- end -%>

When `wfi` is marked as causing a trap above, the implementation is allowed to wait
for an unspecified period of time to see if an interrupt occurs before raising the trap.
That period of time can be zero (_i.e._, `wfi` always causes a trap in the cases identified
above).