VID.V

RISC-V VID.V Instruction Details

Instruction ManualR-type

Write each active element index i to destination integer vector vd.

Instruction Syntax

vid.v vd, vm
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
VVector PermutationPermutation

Instruction Behavior

VID.V is a RISC-V V element-index generation instruction. For each active element i, it writes the unsigned index value i to vd, starting at 0 and bounded by the current vl.

Quick Understanding & Search Notes

VID.V generates element numbers; it does not read memory or an ordinary source vector.

Index values are generated from current element numbers and written to SEW-width destination elements.
vm=0 uses v0 as the execution mask and vm=1 is unmasked; inactive and tail elements follow the current vma/vta policy.
Often combined with mask comparisons, compression, or indexed memory access.

Common Usage Scenarios

Sequence Gen

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vid.v v1 # v1[i] = i».

Loop Counter

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vid.v v1 # v1[i] = i».

Gather Index

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vid.v v1 # v1[i] = i».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-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

vid.v outputs 0,1,2,... (element position) — not byte offset in register.
vs2 operand is ignored but must be specified. Masked-off positions not written (or agnostically overwritten).

FAQ

How does VID.V handle masking?

With vm=0, v0 selects active elements; with vm=1, all body elements participate. Inactive and tail elements follow the current policies.