Home/Instructions/Wait for Interrupt
WFI

RISC-V WFI Instruction Details

Instruction ManualI-type

Wait-for-interrupt hint: an implementation may stall the hart until an interrupt may need service; a legal implementation may also treat it as NOP.

Instruction Syntax

wfi
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.
PrivilegedSystem & Privileged

Instruction Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

WFI uses opcode 1110011 (0x73), funct3 000, funct12 000100000101. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 1110011 (0x73)
funct3: 000 (0x0)
funct12: 000100000101 (0x105)

Instruction Behavior

WFI informs the implementation that the current hart may be stalled until an interrupt might need service. If a locally enabled interrupt is already pending or later becomes pending, the trap is taken on a following instruction; implementations may also resume for any reason, so software must handle WFI returning as if it were a NOP. WFI is available in all privileged modes; U-mode availability and trapping when TW=1 are governed by the privileged specification.

Quick Understanding & Search Notes

WFI is a system-level instruction defined by the privileged architecture. This page covers architectural semantics only, not platform firmware policy.

Execution permission, trap type, and state restoration depend on privilege level, relevant CSR bits, and extension presence.
Executing at an unsupported privilege level or without the required extension raises the specified exception.

Common Usage Scenarios

Idle loop power saving

Understand this scenario with real code like «wfi # Wait for interrupt».

Low-power waiting

Understand this scenario with real code like «wfi # Wait for interrupt».

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

WFI is a hint; an implementation may avoid stalling and return as a NOP.
WFI can resume for locally enabled pending interrupts even when global interrupt-enable bits are clear.
If the wake event does not cause a trap, execution continues after WFI; software usually rechecks conditions and loops.

FAQ

Is it a normal user-mode instruction?

No. These instructions are constrained by privilege level and extension support; user-mode legality must follow the privileged rules.

Does it replace ordinary memory fences?

No. Address translation, instruction fetch, and data-memory ordering use different fence/invalidation instructions.