Home/Instructions/Count Population
CPOP

RISC-V CPOP Instruction Details

Instruction ManualI-type (OP-IMM)

Count set bits (population count)

Instruction Syntax

cpop rd, rs1
Operand Breakdown
rd: x0–x31; receives the count, with writes to x0 discarded.
rs1: all XLEN bits participate; overlap with rd reads the source before writeback.
RV32/RV64, requiring Zbb. There is no immediate operand; imm[11:0]=011000000010 is a fixed instruction selector.
ZbbBit ManipulationInteger Operation

Instruction Behavior

cpop is an RV32/RV64 Zbb instruction that counts the set bits in the XLEN bits of rs1 and writes the count to rd.

CPOP Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
cpop
,
Execution Context

This example uses fixed initial register values and PC=0x2000; instruction fetch succeeds, with no asynchronous interrupt or extra extension checks. Exception branches stop ordinary commit; post-trap PC and handler state are EEI-dependent.

t1(x6)
0x00000014
31..20
19..15
14..12
11..7
6..0
011000000010
fixed imm[11:0]
00110
rs1
001
funct3
00101
rd
0010011
opcode
Execution Data Path
instruction
0x60231293
opcode
0010011 -> OP-IMM
funct3
001 -> CPOP
fixed imm[11:0]
011000000010 -> CPOP selector
rd / rs1
t0(x5) / t1(x6)=0x00000014
fixed imm[11:0]
011000000010 selects CPOP (not an arithmetic immediate)
population count
Not computed
x5
t0(x5) = 0x00003001; pc = 0x00002000
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x60231293
syntax : cpop t0(x5), t1(x6)
Pending result: Not computed
Current architectural state
t0(x5) = 0x00003001; pc = 0x00002000

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Quick Understanding & Search Notes

cpop is an RV32/RV64 Zbb instruction that counts the set bits in the XLEN bits of rs1 and writes the count to rd.

CPOP is an OP-IMM instruction in the Zbb basic bit-manipulation extension and counts the XLEN bits of rs1.
The result range is 0..XLEN.

Common Usage Scenarios

cpop population count

RV32/RV64 Zbb, x11=0x15 (binary 10101): cpop x10, x11 writes x10=3.

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-type (OP-IMM).
  • 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

The result range is 0..XLEN.

FAQ

Does cpop access memory?

No. It reads integer register operands and writes rd only.

How does cpop handle a zero input?

The count is 0. The entire XLEN-bit source register is examined.