VCPOP.M

RISC-V VCPOP.M Instruction Details

Instruction ManualV-type

Count set bits in the active source mask and write the integer result to rd

Instruction Syntax

vcpop.m rd, vs2[, v0.t]
Operand Breakdown
rd is an integer register x0–x31, not a vector destination; vs2 is one source mask register, with one bit per element independent of SEW.
With vm=0, count bits where i<vl, vs2[i]=1 and v0[i]=1; vm=1 uses no execution mask. vs2=v0 is legal, but both inputs must describe the same register contents.
VL=0 still writes count 0; rd=x0 discards the result and leaves x0 zero. vpopc.m remains an assembler alias for compatibility.
Require V, a valid vector configuration, and vstart=0; nonzero vstart raises illegal-instruction, and traps report vstart=0.
VVector Mask Operations

Instruction Behavior

VCPOP.M counts active set elements in the vs2 source mask and writes the count to integer register rd. With vm=0, only elements enabled by v0.t participate.

VCPOP.M Decode And Execute Animation

Starts from OP-V encoding fields, then shows how VCPOP.M counts set bits in the active source mask and writes integer rd.

Instruction input
vcpop.m
Execution context

The teaching model fixes vstart=0. VCPOP.M raises an illegal-instruction exception for nonzero vstart; on the normal path it still writes 0 to rd when VL=0.

Teaching context: SEW=8, LMUL=m1, VLEN=4096, VLMAX=512, vstart=0, valid vtype, and enabled VS; only source mask bits within the selected VL are scanned. Steps are teaching stages, not processor cycles.

OP-V encodingfunct6 | vm | vs2 | vs1=10000 | funct3 | rd | opcode
funct6
010000
vm
0
vs2
01000
vs1
10000
funct3
010
rd
01010
opcode
1010111
lane
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
v8
0
0
1
0
1
0
1
0
0
1
0
0
1
0
0
1
v0.t
1
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
scan
+0
off
+1
+0
+1
+0
off
+0
+0
+1
+0
off
+1
+0
+0
+1
x10
...
Current step

Show OP-V 32-bit encoding fields

vcpop.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 integer rd writeback. It does not model pipelines, caches, or timing.

Quick Understanding & Search Notes

VCPOP.M is an RVV mask-to-scalar instruction: it counts only active set source mask bits and writes integer rd.

The source operand vs2 is interpreted with mask-register layout; each element contributes one mask bit, not a SEW-width integer element.
Only body elements within the current vl are scanned; with vm=0, elements whose v0.t bit is 0 do not participate in the count.
The official text requires vcpop.m to raise an illegal-instruction exception when vstart is nonzero; the animation shows only the normal vstart=0 path.
The result is the number of active set bits and is written to scalar integer register rd; when vl=0, it is 0.

Vector Execution Context

rd is an integer register x0–x31, not a vector destination; vs2 is one source mask register, with one bit per element independent of SEW.

With vm=0, count bits where i<vl, vs2[i]=1 and v0[i]=1; vm=1 uses no execution mask. vs2=v0 is legal, but both inputs must describe the same register contents.

VL=0 still writes count 0; rd=x0 discards the result and leaves x0 zero. vpopc.m remains an assembler alias for compatibility.

Require V, a valid vector configuration, and vstart=0; nonzero vstart raises illegal-instruction, and traps report vstart=0.

The RISC-V Instruction Set Manual, Volume I: Unprivileged Architecture — Version 20260120, Chapter 31

Common Usage Scenarios

Loop Condition

Assume V, valid vector configuration, vl=4 and vstart=0, with v8 bits 1011 and v0 bits 1101 in lane order 0..3. vcpop.m x10,v8,v0.t counts lanes 0 and 3, giving x10=2; unmasked it gives 3.

Mask Density

Assume V, valid vector configuration, vl=4 and vstart=0, with v8 bits 1011 and v0 bits 1101 in lane order 0..3. vcpop.m x10,v8,v0.t counts lanes 0 and 3, giving x10=2; unmasked it gives 3.

Pre-Use Checklist

Syntax Check
  • rd is an integer register x0–x31, not a vector destination; vs2 is one source mask register, with one bit per element independent of SEW.
  • With vm=0, count bits where i<vl, vs2[i]=1 and v0[i]=1; vm=1 uses no execution mask. vs2=v0 is legal, but both inputs must describe the same register contents.
Semantic Check
  • VL=0 still writes count 0; rd=x0 discards the result and leaves x0 zero. vpopc.m remains an assembler alias for compatibility.
  • Require V, a valid vector configuration, and vstart=0; nonzero vstart raises illegal-instruction, and traps report vstart=0.

Pitfalls / Common Confusions

The official mnemonic is vcpop.m; vpopc.m is only an older alias.
A nonzero vstart raises an illegal-instruction exception.
The source is mask register bits, not SEW-width data elements.
With rd=x0, the count is discarded and x0 remains zero.

FAQ

Does VCPOP.M count positions where v0.t is 0?

No. With vm=0, elements whose v0.t bit is 0 are inactive and are not counted; with vm=1, all body elements within vl participate.

Does VCPOP.M write a vector register?

No. VCPOP.M writes the count to integer register rd.