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

LZCNT counts the zero bits above the highest set bit of its source: for the 32-bit value 0x28 it gives 26. A zero source returns the operand size, 16, 32 or 64, and sets CF, so every input has a defined result, and ZF is set when the count is 0, that is, when the top bit is set. It is the counterpart of TZCNT, which counts from the bottom.

Availability

AMD’s manual files LZCNT under ABM, its advanced bit manipulation, and both vendors report it with the same bit, CPUID.80000001H:ECX[5]; it belongs to x86-64-v3. Its encoding, F3 0F BD, is BSR with an F3 prefix, and a processor without LZCNT runs it as BSR, which returns the index of the highest set bit instead of the number of zeros above it: 5 instead of 26 for 0x28. AMD’s manual therefore tells software to check the CPUID bit before using it. For the same reason, GCC 14 and Clang 23 at -O2 do not emit LZCNT for the baseline: __builtin_clz(x) becomes BSR and an XOR with 31.

With -mlzcnt

Allowed LZCNT, both compilers turn __builtin_clz(x) into an LZCNT, and so, since the zero case is now defined, x ? __builtin_clz(x) : 32 and __builtin_clzg(x, 32). GCC puts an xor eax, eax before the LZCNT of __builtin_clz, Clang does not. The bit width of x, 32 - __builtin_clz(x), becomes mov eax, 32, LZCNT and SUB, and the leading ones of x are the leading zeros of ~x, a NOT and an LZCNT.

Other forms

AVX-512CD counts per element: VPLZCNTD and VPLZCNTQ; Intel’s optimization manual builds permute controls with them in its conflict-detection examples. APX adds an EVEX form of LZCNT and one that leaves the flags unchanged (NF). The instruction table of AMD’s Zen 5 guide lists LZCNT as one macro-op with a latency of one cycle.

In the optimization guide

What the optimization guide says about LZCNT, 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

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.

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.

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.

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 LZCNT that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
LZCNT r16/32/64, m16/32/64 LZCNT_GPRv_MEMvF3 0F BD /rLZCNT
LZCNT r16/32/64, r16/32/64 LZCNT_GPRv_GPRvF3 0F BD /rLZCNT
LZCNT r16/32/64, r16/32/64 LZCNT_GPRv_GPRv_APXEVEX.LLZ.NP.MAP4.SCALABLE F5 /rAPX_F + LZCNT
LZCNT r16/32/64, m16/32/64 LZCNT_GPRv_MEMv_APXEVEX.LLZ.NP.MAP4.SCALABLE F5 /rAPX_F + LZCNT
LZCNT r16/32/64, r16/32/64 NF LZCNT_GPRv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE F5 /r NF=1APX_F + APX_NCI_NDD_NF + LZCNT
LZCNT r16/32/64, m16/32/64 NF LZCNT_GPRv_MEMv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE F5 /r NF=1APX_F + APX_NCI_NDD_NF + LZCNT

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
Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake, Alder Lake, Sapphire Rapids8 / 1p13 / 1p13 / 1p1
Lunar Lake7 / 1p13 / 1p13 / 1p1
Piledriver6 / 2EX02 / 2EX02 / 2EX0
Zen6 / 0.5ALU0 ALU1 ALU2 ALU32 / 0.25ALU0 ALU1 ALU2 ALU32 / 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):
    if s >> (OSIZE - 1 - i) & 1:
        break
    n += 1                       # the 0 bits above the highest 1 bit
if not nf:                       # NF=1 (APX) leaves the flags as they were
    cf = s == 0                  # and then n is OSIZE
    zf = n == 0
    of = sf = af = pf = UNDEFINED
dest.write(n)                    # a 32-bit register: bits 63:32 cleared
# without LZCNT (AMD's ABM), a processor runs the legacy encoding
# (F3 0F BD) as BSR

Run on AMD Zen 5 (EPYC 9645): 78 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
LZCNT r16/32/64, r/m16/32/64
r16/32/64explicitwrite
r/m16/32/64explicitread
RFLAGSimplicitwrite
LZCNT r16/32/64, r/m16/32/64 NF
r16/32/64explicitwrite
r/m16/32/64explicitread

Flags

M modified, U undefined; blank: not affected. How to read.
OFSFZFAFPFCF
NF forms
Not affected
Other forms
UUMUUM

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

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
LZCNT

LZCNT
CPUID.80000001H:ECX[5] LZCNT

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, 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_LZCNT

APX_F + LZCNT
CPUID.(EAX=07H,ECX=1):EDX[21] APX_F
CPUID.80000001H:ECX[5] LZCNT

Nova Lake, Diamond Rapids
APX_F_LZCNT_N3

APX_F + APX_NCI_NDD_NF + LZCNT
CPUID.(EAX=07H,ECX=1):EDX[21] APX_F
CPUID.(EAX=29H,ECX=0):EBX[0] APX_NCI_NDD_NF
CPUID.80000001H:ECX[5] LZCNT

Same as APX_F_LZCNT

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. LLVM 23.1.2's x86 scheduling models (commit 85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them.
  4. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-578 (LZCNT)
  5. Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
  6. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
  7. Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
  8. Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP

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 timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.