What does VFIRST.M return when no set bit is found?
It returns -1 in integer register rd.
Find the lowest-numbered active set mask bit and write integer rd
VFIRST.M finds the lowest-numbered active set element in the vs2 source mask and writes that element index to integer register rd; if none is found, it writes -1. It still writes -1 when vl=0, and raises an illegal-instruction exception when vstart is nonzero.
Starts from OP-V encoding fields, then shows how VFIRST.M finds the lowest-numbered active set bit, or writes -1 when none is found.
The teaching model fixes vstart=0. VFIRST.M raises an illegal-instruction exception for nonzero vstart; on the normal path it still writes -1 to rd when VL=0.
vfirst.m uses OP-V encoding; the vs1 field is fixed to 10001, 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 integer rd writeback. It does not model pipelines, caches, or timing.
VFIRST.M is a mask-to-scalar search instruction: the result is the lowest-numbered active set-bit index, or -1 when none is found.
rd selects integer x0–x31 or an ABI name; vs2 is one mask register v0–v31, with one bit per element independent of SEW/LMUL.
The assembly vm operand is optional v0.t; omitting it means vm=1. With vm=0 only elements with v0[i]=1 participate.
Find the lowest active index i<vl with vs2[i]=1; no match, including vl=0, writes -1 to rd. rd=x0 discards writeback.
Require V, enabled vector state, and valid vector configuration. vstart must be 0; a nonzero value raises illegal instruction, and traps report vstart=0.
Assume V/VS enabled, supported e32,m1, vstart=0, VLMAX≥4, a0=4 and v8 bits 0101 in lane order 0..3. The unmasked example gives a1=1; adding v0.t with v0 bits 1011 gives a1=3. No active set bit, or vl=0, gives -1.
Assume V/VS enabled, supported e32,m1, vstart=0, VLMAX≥4, a0=4 and v8 bits 0101 in lane order 0..3. The unmasked example gives a1=1; adding v0.t with v0 bits 1011 gives a1=3. No active set bit, or vl=0, gives -1.
It returns -1 in integer register rd.
No. With vm=0, positions whose v0.t bit is 0 do not participate, even if the vs2 bit is 1.