Extensions
Forms
6 (2 Legacy, 4 EVEX)
Data
Intel XED v2026.08.23

POPCNT counts the bits that are set in its source, the population count or Hamming weight. It answers how many members a bitset has, and after an XOR how many bits two words differ in: Clang 23 at -O2, allowed POPCNT, compiles __builtin_popcountl(a ^ b) to xor rdi, rsi and popcnt rax, rdi. The lowest bit of the count is the parity of the whole operand, which the parity flag cannot give, since PF covers only the low byte of a result; with POPCNT available, GCC 14 and Clang 23 compile __builtin_parity to POPCNT and an AND with 1.

Availability

POPCNT has a CPUID bit of its own, CPUID.01H:ECX[23], apart from SSE4.2’s. Among Intel’s processors Nehalem had it first, among AMD’s K10, as the list below shows, and it belongs to x86-64-v2, not to the x86-64 baseline. A compiler targeting the baseline therefore cannot emit it: for __builtin_popcount, GCC 14 calls __popcountdi2 in its support library, and Clang 23 inlines some fifteen instructions, shifts, masks, additions and a multiplication. With -mpopcnt or -march=x86-64-v2, both emit a single POPCNT.

A processor without POPCNT raises #UD for its encoding, F3 0F B8. That is unlike TZCNT and LZCNT, whose F3-prefixed encodings older processors run as BSF and BSR, giving results that may differ.

Other forms

For counting in vectors, AVX-512 has per-element versions: VPOPCNTB and VPOPCNTW in AVX512_BITALG, VPOPCNTD and VPOPCNTQ in AVX512_VPOPCNTDQ. APX adds an EVEX form of POPCNT itself and one that leaves the flags unchanged (NF).

In the optimization guide

What the optimization guide says about POPCNT, a line per claim. Each links to the claim in the guide, with its sources and where they differ.

Out of order

  • Zeroing and dependency-breaking idioms: Some instructions that overwrite their whole destination still wait for its old value, a flaw of particular cores: LLVM’s tunings mark popcnt from Sandy Bridge to the Skylake family and lzcnt and tzcnt on Haswell, AMD names tzcnt and three BMI1 instructions on some versions of Zen 5, and Intel several AVX-512 permutations and multiplications on Golden Cove (Skylake, Zen 5, Golden Cove).

Bulldozer to Excavator

  • Integer execution: POPCNT and LZCNT, new with Family 15h, beat any sequence that does their work: POPCNT takes 4 cycles, 6 with 64-bit operands, and starts every 2 or 4 cycles, and LZCNT is a double instruction of 2 cycles. sources differ

Crestmont and Gracemont

  • Integer execution: LLVM treats popcnt on these cores as waiting for its destination’s old value.

Golden Cove and Raptor Cove

  • Integer execution: Port 1 alone runs the slower integer operations: multiplication, PDEP and PEXT, popcnt, bsr, crc32 and the double shifts with an immediate count, which LLVM’s models give a latency of three cycles and one per cycle.

Haswell and Broadwell

  • Integer execution and bypass: LLVM’s tuning marks POPCNT, LZCNT and TZCNT on both cores as waiting for whatever last wrote the register they overwrite, though they never use its value, as on Skylake.

Ice Lake to Rocket Lake

Jaguar and Puma

  • Integer execution: LZCNT and POPCNT take one cycle on either ALU and TZCNT two, while BSF and BSR are microcoded, of seven and eight macro-ops and 4 and 5 cycles, so the newer instructions are the better choice where the zero case allows.

Silvermont to Goldmont Plus

Skylake to Cooper Lake

  • Integer execution: Port 1 alone runs integer multiplication, PDEP and PEXT, popcnt, lzcnt, tzcnt, bsf, bsr and the double shifts, with a latency of three cycles and one a cycle in LLVM’s models, as on Golden Cove.
  • Integer execution: popcnt waits for the old value of its destination register, which it overwrites; compilers tuning for these cores zero the destination first to break the chain.

Tremont

  • Integer execution: Three ALU ports run simple integer operations, three a cycle; shifts go to port 00 only, and multiplication, division, popcnt, crc32 and the bit operations to port 01 only.
  • Integer execution: LLVM’s tuning for Tremont, as for Goldmont Plus, does not make popcnt wait for its destination register’s old value, which its Goldmont tuning does.

Zen and Zen+

  • Integer execution: BSF and BSR are six macro-ops with a latency of three and four cycles, while LZCNT and POPCNT are one macro-op of one cycle and TZCNT two of two cycles. sources differ

Zen 2

  • Integer execution: BSF and BSR are six macro-ops with a latency of three and four cycles, while LZCNT and POPCNT are one macro-op of one cycle and TZCNT two; LLVM’s model agrees.

Forms

Every encoding of POPCNT that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
POPCNT r16/32/64, m16/32/64 POPCNT_GPRv_MEMvF3 0F B8 /rPOPCNT
POPCNT r16/32/64, r16/32/64 POPCNT_GPRv_GPRvF3 0F B8 /rPOPCNT
POPCNT r16/32/64, r16/32/64 POPCNT_GPRv_GPRv_APXEVEX.LLZ.NP.MAP4.SCALABLE 88 /rAPX_F + POPCNT
POPCNT r16/32/64, m16/32/64 POPCNT_GPRv_MEMv_APXEVEX.LLZ.NP.MAP4.SCALABLE 88 /rAPX_F + POPCNT
POPCNT r16/32/64, r16/32/64 NF POPCNT_GPRv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 88 /r NF=1APX_F + APX_NCI_NDD_NF + POPCNT
POPCNT r16/32/64, m16/32/64 NF POPCNT_GPRv_MEMv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 88 /r NF=1APX_F + APX_NCI_NDD_NF + POPCNT

Latency and throughput

What the scheduling models of LLVM 23.1.2 give for each form, not measurements: latency / reciprocal throughput in cycles, the ports under them. A row is a model, or models that agree; a dash, a form that its processors lack. Memory forms: latency from the address, ports without the load and store units. Which processors each model covers.
Modelr16, m16
r32, m32
r64, m64
r16, r16r32, r32
r64, r64
Sandy Bridge9 / 1p13 / 1p13 / 1p1
Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake, Alder Lake, Sapphire Rapids8 / 1p13 / 1p13 / 1p1
Lunar Lake7 / 0.33p1353 / 0.33p1353 / 0.33p135
Silvermont6 / 1IEC0 MEC3 / 1IEC03 / 1IEC0
Piledriver8 / 2EX0 EX14 / 2EX0 EX14 / 2EX0 EX1
Zen5 / 0.5ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 25 / 0.33ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 3, Zen 45 / 0.33ALU0 ALU1 ALU2 ALU31 / 1ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Jaguar4 / 1ALU0 ALU11 / 0.5ALU0 ALU11 / 0.5ALU0 ALU1

Operation

What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.

s = src.read()
n = 0
for i in range(OSIZE):
    n += s >> i & 1              # count the 1 bits
if not nf:                       # NF=1 (APX) leaves the flags as they were
    of = sf = af = pf = cf = 0
    zf = s == 0
dest.write(n)                    # a 32-bit register: bits 63:32 cleared

Run on AMD Zen 5 (EPYC 9645) and an Intel processor under KVM (model hidden): 138 cases. The APX forms were not run: none of these processors has APX.

Operands

What each form reads and writes, as Intel XED records it: the operands of its syntax, in order, and the implicit ones that the syntax does not name. How to read.
OperandKindAction
POPCNT r16/32/64, r/m16/32/64
r16/32/64explicitwrite
r/m16/32/64explicitread
RFLAGSimplicitwrite
POPCNT r16/32/64, r/m16/32/64 NF
r16/32/64explicitwrite
r/m16/32/64explicitread

Flags

M modified, 0 cleared; blank: not affected. How to read.
OFSFZFAFPFCF
NF forms
Not affected
Other forms
00M000

Exceptions

The exception class is XED's name for the set of exception conditions that a form follows. How to read.

Legacy forms
none in XED
EVEX forms
APX-EVEX-INT

Intrinsics

The C intrinsics of Clang 23.1.2 that compile to POPCNT, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.

IntrinsicCompiles to
_mm_popcnt_u32 int _mm_popcnt_u32(unsigned int __A)

POPCNT r16/32/64, r16/32/64 Legacy -mpopcnt

_mm_popcnt_u64 long long _mm_popcnt_u64(unsigned long long __A)

POPCNT r16/32/64, r16/32/64 Legacy -mpopcnt

CPUID and processors

Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.

CPUID requirements and processors of the XED ISA sets above. Alternatives are separated by “or”; processors follow XED’s chip model, whose AMD processors end with Zen 2, and the CPU data of this site for Zen 3 to Zen 6.
ISA setCPUIDProcessors
POPCNT

POPCNT
CPUID.01H:ECX[23] POPCNT

Nehalem, Westmere, Sandy Bridge, Ivy Bridge, Haswell, Broadwell, Skylake, Comet Lake, Cannon Lake, Ice Lake (client), Tiger Lake, Alder Lake, Arrow Lake, Panther Lake, Nova Lake, Skylake-SP, Cascade Lake, Cooper Lake, Ice Lake (server), Sapphire Rapids, Emerald Rapids, Granite Rapids, Diamond Rapids, Silvermont, Goldmont, Goldmont Plus, Tremont, Snow Ridge, Lakefield, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, K10 (Family 10h), Bulldozer, Piledriver, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6
APX_F_POPCNT

APX_F + POPCNT
CPUID.(EAX=07H,ECX=1):EDX[21] APX_F
CPUID.01H:ECX[23] POPCNT

Nova Lake, Diamond Rapids
APX_F_POPCNT_N3

APX_F + APX_NCI_NDD_NF + POPCNT
CPUID.(EAX=07H,ECX=1):EDX[21] APX_F
CPUID.(EAX=29H,ECX=0):EBX[0] APX_NCI_NDD_NF
CPUID.01H:ECX[23] POPCNT

Same as APX_F_POPCNT

More APX instructions

All 88 APX instructions

Sources

  1. Intel XED v2026.08.23 (commit 0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model.
  2. The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s -march feature sets and AMD’s Processor Programming References, which the page of each processor cites.
  3. Clang's x86 intrinsic headers, LLVM 23.1.2 (commit 85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them.
  4. LLVM 23.1.2's x86 scheduling models (commit 85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them.
  5. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-405 (POPCNT)
  6. Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
  7. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)

The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The intrinsics and their signatures come from Clang and the timings from LLVM's scheduling models, both part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.