ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 1,823 microarchs · 16,083 chips · 105 sources
Arch:
Tier:

cpop

T1 riscv bitmanip insn
Count set bits
SourceRISC-V Official Unified Database (riscv-unified-db) (riscv_unified_db)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeRV32/RV64 Zbb
RV32 / RV64 (Ratified & Standard Extensions)
License & VersionApache-2.0 / CC-BY-4.0
main
Upstreamhttps://github.com/riscv/riscv-unified-db
Privilegeuser
ExtensionsZbb

Summary

Counts the number of 1's (i.e., set bits) in the source register.

Syntax / Encoding

cpop xd, xs1 | 011000000010xxxxx001xxxxx0010011 (mask=0xfff0707f match=0x60201013)

Cross-Chip Latency & Throughput (11 cores)

MicroarchitectureLatency (cycles)Recip. TPuopsPortsSource
Syntacore SCR7111BMUllvm_sched_models
Tenstorrent Ascalon-X111AscalonFXllvm_sched_models
MIPS P8700 (RISC-V)211p8700IssueAL2llvm_sched_models
SiFive P670 / P600211SiFiveP600MulI2Fllvm_sched_models
SiFive P870 / P80020.51SiFiveP800Mulllvm_sched_models
SpacemiT X10020.251SMTX100_IQllvm_sched_models
SpacemiT X60 (K1)20.51SMX60_IEUllvm_sched_models
Andes 45-Series30.51Andes45ALUllvm_sched_models
SiFive 7-Series (U74)311PipeBllvm_sched_models
XiangShan KunMingHu30.51XSPipeGroupBKUllvm_sched_models
XiangShan NanHu30.51XS2MDUllvm_sched_models

Binary Encodings (1)

WidthFormatBit PatternMask / Match
32RV011000000010xxxxx001xxxxx00100110xfff0707f / 0x60201013

Operands

NameDescription
xs1bits [19:15]
xdbits [11:7]

Reference Notes

Counts the number of 1's (i.e., set bits) in the source register.

.Software Hint
[NOTE]
----
This operations is known as population count, popcount, sideways sum,
bit summation, or Hamming weight.

The GCC builtin function `__builtin_popcount (unsigned int x)` is
implemented by cpop on RV32 and by cpopw on RV64. The GCC builtin
function `__builtin_popcountl (unsigned long x)` for LP64 is
implemented by cpop on RV64.
----