fence.i
Instruction fence
- Extension
- Zifencei
- XLEN
- RV32 and RV64
- Assembly (riscv-unified-db)
fence.i- Length
- 32-bit
Encoding
| 3120 | 1915 | 1412 | 117 | 62 | 10 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| imm[11:0] | rs1 | 001 | rd | 00011 | 11 | ||||||||||||||||||||||||||
Match 0x0000100f, mask 0x0000707f. Source: fence.i imm12 rs1 14..12=1 rd 6..2=0x03 1..0=3 in riscv-opcodes/extensions/rv_zifencei.
| Field | Bits | riscv-opcodes name |
|---|---|---|
| imm[11:0] | 31:20 | imm12 |
| rs1 | 19:15 | rs1 |
| rd | 11:7 | rd |
Description
The FENCE.I instruction is used to synchronize the instruction and data streams. RISC-V does not guarantee that stores to instruction memory will be made visible to instruction fetches on a RISC-V hart until that hart executes a FENCE.I instruction. A FENCE.I instruction ensures that a subsequent instruction fetch on a RISC-V hart will see any previous data stores already visible to the same RISC-V hart. FENCE.I does not ensure that other RISC-V harts' instruction fetches will observe the local hart's stores in a multiprocessor system. To make a store to instruction memory visible to all RISC-V harts, the writing hart also has to execute a data FENCE before requesting that all remote RISC-V harts execute a FENCE.I.
The unused fields in the FENCE.I instruction, imm[11:0], xs1, and xd, are reserved for finer-grain fences in future extensions. For forward compatibility, base implementations shall ignore these fields, and standard software shall zero these fields.
Note
Because FENCE.I only orders stores with a hart's own instruction fetches, application code should only rely upon FENCE.I if the application thread will not be migrated to a different hart. The EEI can provide mechanisms for efficient multiprocessor instruction-stream synchronization.
Description from riscv-unified-db, reformatted.
Operation
ifence();
Pseudocode in riscv-unified-db’s IDL, quoted unchanged.