VIOTA.M

RISC-V VIOTA.M Instruction Details

Instruction ManualR-type

Count set bits in the source mask before each element and write the prefix count to integer vector vd.

Instruction Syntax

viota.m vd, vs2, 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 PermutationMask Operations

Instruction Behavior

VIOTA.M is a RISC-V V mask prefix-count instruction. For each active element i, it counts set elements in source mask vs2 with index less than i and writes the count to vd. It is commonly used for compaction, scatter indexing, or deriving compact indices from a mask.

Quick Understanding & Search Notes

VIOTA.M outputs how many matching bits appear before each position; it does not include the current bit itself.

vs2 is the source mask; output vd is an integer vector with element width determined by current SEW.
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

Sparse Indexing

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0 # v12[i]=count of zeros before i».

Compress Helper

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0 # v12[i]=count of zeros before i».

Conditional Gather

Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0 # v12[i]=count of zeros before 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

Input vs2 is mask register (bit vector); output vd is data vector (SEW-bit elements).
Prefix count covers indices 0 to i-1 (exclusive); for an active element 0, the count is 0.
Commonly used to derive compact indices for masked scatter or compaction sequences.

FAQ

How does VIOTA.M handle masking?

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