Does VIOTA.M include the current lane bit in its result?
No. Lane i counts only active set bits at lower indexes, so the first active element receives 0.
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 mask-iota instruction. For each active body element i, it counts enabled set bits in vs2 at lower indexes and writes the prefix count to vd[i]. It can be combined with indexed stores to implement vector compression.
Starts from OP-V encoding fields, then shows how VIOTA.M writes the number of earlier active set bits into an integer vector.
The teaching model fixes vstart=0. VIOTA.M raises an illegal-instruction exception for nonzero vstart and restarts from the beginning after trap return. Results are zero-extended for wider SEW, and only the low SEW bits are retained on overflow.
Teaching context: SEW=32, LMUL=m1, VLEN=4096, VLMAX=128, vstart=0, valid vtype, enabled VS, and ta/ma. At most 64 elements are shown; prefix counts do not exceed 63, so no SEW truncation occurs. x marks masked-off destinations, which may retain old values or become all ones; tails follow ta. VL=0 updates no destinations, including tails; normal completion resets vstart=0.
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.
vd is an SEW-wide integer vector group; vs2 is one mask register with one bit per element. vd cannot overlap vs2, and a masked vd cannot overlap v0.
Syntax is viota.m vd, vs2[, v0.t]; omitting v0.t gives vm=1 and including it gives vm=0. With vs2=v0, source and execution mask must contain identical bits.
Active element i receives the number of enabled set bits in vs2 below index i, excluding the current bit. Zero-extend to SEW, retaining only low SEW bits on overflow.
Require enabled V, valid vtype and vstart=0; nonzero vstart raises illegal-instruction. Traps report vstart=0 and resume from the beginning. VL=0 leaves destinations unchanged; inactive/tail follow vma/vta.
Assume enabled V/VS, valid e32,m1, VLMAX≥4, AVL=4, and vl=4, vstart=0, ta/ma after vsetvli; destination does not overlap source masks. Count earlier enabled set bits: vs2 bits=[1,0,1,1], v0=[1,0,1,1] → vd=[0,agnostic,1,2]. Agnostic elements may retain old values or become all ones, without guaranteed zeros.
Assume enabled V/VS, valid e32,m1, VLMAX≥4, AVL=4, and vl=4, vstart=0, ta/ma after vsetvli; destination does not overlap source masks. Count earlier enabled set bits: vs2 bits=[1,0,1,1], v0=[1,0,1,1] → vd=[0,agnostic,1,2]. Agnostic elements may retain old values or become all ones, without guaranteed zeros.
Assume enabled V/VS, valid e32,m1, VLMAX≥4, AVL=4, and vl=4, vstart=0, ta/ma after vsetvli; destination does not overlap source masks. Count earlier enabled set bits: vs2 bits=[1,0,1,1], v0=[1,0,1,1] → vd=[0,agnostic,1,2]. Agnostic elements may retain old values or become all ones, without guaranteed zeros.
No. Lane i counts only active set bits at lower indexes, so the first active element receives 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.