CPOP
Population Count
CPOP rd, rs1
Counts the number of set bits (1s) in the register.
Encoding
Binary Layout
011000000010
31:20
rs1
19:15
001
14:12
rd
11:7
0010011
6:0
Operands
-
rd
Destination register (integer) -
rs1
Source
Example
CPOP x10, x11
// Hamming weight calculation.
Related
Across architectures
Population Count : how x86, ARM, RISC-V, and PowerISA each do this.
More in Zbb
Reference
View in RISC-V Unprivileged ISA Specification ↗
RISC-V ISA Manual
Description
CPOP counts the number of set bits (population count / Hamming weight) in rs1 and writes the count to rd.
Operation
R[rd] = count_set_bits(R[rs1]);