VCTZ.V

RISC-V VCTZ.V Instruction Details

Instruction ManualR-type

Vector count trailing zeros: count trailing zero bits in each element

Instruction Syntax

vctz.v vd, vs2, vm
Operand Breakdown
vd: destination vector register group.
vs2/vs1 or scalar source: selected by suffixes such as .vv, .vx, .vi, or .vf.
vm: when present, vm=0 uses v0 as the execution mask and vm=1 is unmasked.
ZvbbVector Bit Manipulation

Instruction Behavior

vctz.v is the Zvbb vector count-trailing-zeros instruction. Counts trailing zeros from the LSB in each element. All-zero returns SEW.

Quick Understanding & Search Notes

VCTZ.V is a Zvbb vector instruction for vector count trailing zeros. This page is checked against the official vector crypto extension and V-extension execution model.

Each element returns the number of trailing zero bits from the least-significant bit; an all-zero element returns SEW.
It follows V-extension vl, vstart, vtype, and optional vm mask rules.

Vector Execution Context

When reading VCTZ.V, 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.

Check vl first

The current vl determines the number of body elements. Typical code executes vsetvli, vsetivli, or vsetvl before this instruction.

Then check vtype

The current vtype supplies SEW, LMUL, tail policy, and mask policy; these affect element width, register-group size, and inactive/tail destination elements.

Then check vm/v0

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.

Official source: RISC-V V Standard Extension for Vector Operations

Common Usage Scenarios

Crypto & Security

Understand this scenario with real code like «vctz.v vd, vs2».

Vector Acceleration

Understand this scenario with real code like «vctz.v vd, vs2».

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

Result is count (0..SEW), not a bit position. All-zero returns SEW.

FAQ

Can VCTZ.V always use a v0.t mask?

It can use the vm mask operand shown in the syntax; omitting it gives the unmasked form.

What determines the element width for VCTZ.V?

The current vtype SEW determines it, subject to any instruction-specific SEW restrictions in the extension.