Check vl first
The current vl determines the number of body elements. Typical code executes vsetvli, vsetivli, or vsetvl before this instruction.
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.
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.
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.
When reading VFIRST.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.vv v0, v8, v9 vfirst.m a0, v0».
Understand this scenario with real code like «vsetvli t0, a0, e32, m1, ta, ma vmseq.vv v0, v8, v9 vfirst.m a0, v0».
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.