Check vl first
The current vl determines the number of body elements. Typical code executes vsetvli, vsetivli, or vsetvl before this instruction.
Counts active set bits in the source mask before each element and writes the prefix count to integer vector vd.
VIOTA.M is the RISC-V V extension mask-iota instruction. For each active body element i, it counts set bits in vs2 at lower indexes that participate in execution, then writes that prefix count to vd[i]. It is commonly used to turn a predicate mask into compact indexes for vcompress, scatter, or indexed-memory data paths.
Starts from OP-V encoding fields, then shows how VIOTA.M writes the number of earlier active set bits into an integer vector.
viota.m uses OP-V encoding; the vs1 field is fixed to 10000, and vs1 is not a syntax operand.
This animation shows only ISA-visible relationships from the official V extension: OP-V field decode, active mask-bit scan within vl, and destination integer-vector writeback. It does not model pipelines, caches, or timing.
VIOTA.M turns a mask into integer indexes by asking each active lane how many selected 1 bits appear before it; the current lane itself is not counted.
When reading VIOTA.M, do not stop at the mnemonic. Official V-extension semantics also depend on the current vl, vtype, and mask state. The suffix and operand form determine whether sources are vector, scalar, or immediate values.
The current vl determines the number of body elements. Typical code executes vsetvli, vsetivli, or vsetvl before this instruction.
The current vtype supplies SEW, LMUL, tail policy, and mask policy; these affect element width, register-group size, and inactive/tail destination elements.
For ordinary vector instructions with vm, vm=0 uses v0 as the execution mask and vm=1 is unmasked. A few forms such as VMERGE use v0 as data-selection input.
Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0, v0.t # active vd[i] = count of earlier active set bits».
Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0, v0.t # active vd[i] = count of earlier active set bits».
Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vi v0, v8, 0 viota.m v12, v0, v0.t # active vd[i] = count of earlier active set bits».
No. The result for lane i counts only active set bits at indexes less than i, so the first active lane can produce 0.
No. vs2 is a mask-bit input, but vd is an integer vector result; each active element receives a SEW-wide prefix count.
No. With vm=0, only elements whose v0.t bit is 1 participate in iota counting and writeback; disabled lanes do not increment later counts.