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

TZCNT counts the zero bits below the lowest set bit, which is that bit’s index: for 0x28 it gives 3. For a zero source it returns the operand size, 16, 32 or 64, and sets CF, so every input has a defined result. Code walks the set bits of a mask with it: TZCNT for the index of the lowest one, BLSR to clear that bit, and again until the mask is 0.

TZCNT and BSF

TZCNT is encoded as BSF with an F3 prefix, and a processor without BMI1 ignores the prefix and runs BSF. Both give the same index for a nonzero source; they part for zero and in the flags:

SourceTZCNTBSF
nonzerothe index; CF = 0, ZF = 1 if it is 0the index; ZF = 0
zerothe operand size; CF = 1, ZF = 0the destination unchanged; ZF = 1

Both vendors’ manuals now say that BSF leaves the destination unchanged; Intel’s adds that some older processors clear bits 63:32 of a 64-bit register for a 32-bit BSF.

Compilers use the shared encoding. Without -mbmi, GCC 14 and Clang 23 at -O2 compile __builtin_ctz(x), which C leaves undefined for 0, to rep bsf: TZCNT on processors with BMI1, BSF on the others, and the same result for every nonzero x. For x ? __builtin_ctz(x) : 32, Clang loads 32 into the destination first, which TZCNT returns and BSF keeps; GCC adds a TEST and a CMOVE. With -mbmi both emit one TZCNT. Code that tests ZF after rep bsf to catch a zero source, however, gets different answers on the two kinds of processors.

LZCNT is different

The trick does not carry over to LZCNT and BSR. BSR returns the index of the highest set bit, LZCNT the number of zeros above it, which for 32 bits is 31 minus that index; a processor without LZCNT runs its encoding as BSR and returns the other number. Without -mlzcnt, both compilers therefore compile __builtin_clz to BSR and an XOR with 31, not to rep bsr.

TZCNT belongs to BMI1, part of x86-64-v3; APX adds an EVEX form and one that leaves the flags unchanged (NF).

In the optimization guide

What the optimization guide says about TZCNT, 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).

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.

Zen 5

Forms

Every encoding of TZCNT that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
TZCNT r16/32/64, m16/32/64 TZCNT_GPRv_MEMvF3 0F BC /rBMI1
TZCNT r16/32/64, r16/32/64 TZCNT_GPRv_GPRvF3 0F BC /rBMI1
TZCNT r16/32/64, r16/32/64 TZCNT_GPRv_GPRv_APXEVEX.LLZ.NP.MAP4.SCALABLE F4 /rAPX_F + BMI1
TZCNT r16/32/64, m16/32/64 TZCNT_GPRv_MEMv_APXEVEX.LLZ.NP.MAP4.SCALABLE F4 /rAPX_F + BMI1
TZCNT r16/32/64, r16/32/64 NF TZCNT_GPRv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE F4 /r NF=1APX_F + APX_NCI_NDD_NF + BMI1
TZCNT r16/32/64, m16/32/64 NF TZCNT_GPRv_MEMv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE F4 /r NF=1APX_F + APX_NCI_NDD_NF + BMI1

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 / 1.33p1353 / 0.33p1353 / 0.33p135
Zen6 / 0.5ALU0 ALU1 ALU2 ALU32 / 0.5ALU0 ALU1 ALU2 ALU32 / 0.5ALU0 ALU1 ALU2 ALU3
Zen 36 / 0.5ALU1 ALU22 / 1ALU0 ALU1 ALU2 ALU32 / 0.5ALU1 ALU2
Zen 45 / 0.5ALU1 ALU21 / 0.25ALU0 ALU1 ALU2 ALU31 / 0.5ALU1 ALU2
Jaguar5 / 1ALU0 ALU12 / 1ALU0 ALU12 / 1ALU0 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 >> i & 1:
        break
    n += 1                       # the 0 bits below the lowest 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 BMI1, a processor runs the legacy encoding (F3 0F BC) as BSF

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
TZCNT r16/32/64, r/m16/32/64
r16/32/64explicitwrite
r/m16/32/64explicitread
RFLAGSimplicitwrite
TZCNT 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
BMI1

BMI1
CPUID.(EAX=07H,ECX=0):EBX[3] BMI1

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, Zen 3, Zen 4, Zen 5, Zen 6

Note: XED's Piledriver adds TBM and FMA to Bulldozer but not BMI1, and its Zen chips inherit that gap; GCC's -march=bdver2 and later and -march=znver1 and later include BMI1.

APX_F_BMI1

APX_F + BMI1
CPUID.(EAX=07H,ECX=1):EDX[21] APX_F
CPUID.(EAX=07H,ECX=0):EBX[3] BMI1

Nova Lake, Diamond Rapids
APX_F_BMI1_N3

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

Same as APX_F_BMI1

More BMI1 instructions

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 2B, page 4-731 (TZCNT)
  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)

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.