Extensions
Forms
14 (14 Legacy)
Data
Intel XED v2026.08.23

TEST ANDs its operands, sets the flags from the result and discards it: it is to AND what CMP is to SUB. It has two everyday uses:

  • Zero and sign. test rax, rax sets ZF when RAX is 0 and SF when it is negative, so JZ, JNZ, JS and JNS can follow it. Every condition code then gives the same answer as after cmp rax, 0, since both leave CF and OF clear, and TEST needs no immediate byte. GCC 14 and Clang 23 at -O2 compile both x == 0 and x < 0 to test rdi, rdi and a branch.
  • Bits. test reg, mask sets ZF when none of the bits in the mask is set, so JNZ means “any of them is”. For a single bit whose number is in a register, BT copies that bit to CF instead.

APX’s CTESTscc is TEST under a condition, as CCMPscc is CMP under one.

The immediate

TEST has no form with a sign-extended 8-bit immediate, which CMP, AND and the other arithmetic instructions have: its immediate is as wide as the operand, up to 32 bits. When the mask fits in the low byte, a byte operand is shorter, and Clang 23 compiles if (x & 8) to test dil, 8, four bytes, where test edi, 8 would take six.

Parity

PF reflects only the low 8 bits of the result, as it does after the arithmetic and logical instructions in general, so test eax, eax followed by JP says nothing about the parity of all 32 bits. Folding the halves together with XOR first, as GCC and Clang do for __builtin_parity, or a POPCNT, gives that.

The /1 encodings

TEST with an immediate is F6 /0 or F7 /0. XED decodes the same opcodes with /1 in ModRM.reg as TEST too, and marks those forms undocumented: AMD’s opcode map lists TEST under both /0 and /1, while Intel’s leaves /1 empty. Zen 5 ran the /1 forms recorded here exactly as the /0 ones.

In the optimization guide

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

Front end

  • Macro-fusion: Intel’s cores since Sandy Bridge (Skylake) fuse test and and with any conditional branch; cmp, add and sub with branches on the equal, unsigned and signed comparisons, but not on the sign, parity or overflow flag alone; and inc and dec only with branches on equality and the signed comparisons.
  • Macro-fusion: AMD’s Zen 3 to Zen 5 fuse more: cmp, test, add, sub, and, or, xor, inc and dec with any conditional branch, except that on Zen 3 and Zen 4 inc and dec do not fuse with a branch that reads the carry flag, which Intel’s cores do not fuse either (Zen 5, Zen 4, Zen 3). sources differ
  • Macro-fusion: With a memory operand, Intel’s Sandy Bridge to Skylake do not fuse an instruction that also has an immediate, while AMD’s Zen 3 and Zen 4 still fuse cmp and test unless a displacement comes with the immediate or the address is relative to RIP. sources differ
  • Macro-fusion: On Intel’s cores the choice of instruction decides fusion more often, so Intel prefers test to cmp for a comparison with zero, as test fuses with every condition.

Bulldozer to Excavator

  • Branches: A cmp or test directly followed by a conditional branch fuses into one op, unless the compare uses a RIP-relative address or has a displacement as well as an immediate; no other instruction fuses. sources differ

Haswell and Broadwell

  • Front end: CMP, ADD and SUB fuse with a following conditional jump that tests carry, zero, or a signed or unsigned comparison; INC and DEC only with one that tests zero or a signed comparison; TEST and AND with any.

Ice Lake to Rocket Lake

  • Front end: A cmp, add, sub, inc or dec fuses with a following jump on zero, carry or an unsigned or signed comparison, and test or and with any conditional jump; or, xor, adc, sbb, shifts and js, jo and jp never fuse.

Sandy Bridge and Ivy Bridge

  • Front end: Sandy Bridge widens macro-fusion from Nehalem’s CMP and TEST to also fuse ADD, SUB, AND, INC and DEC with a following conditional branch, fusing when the first instruction’s first operand is a register and its second operand, if any, is an immediate, a register or memory that is not RIP-relative; the pair does not fuse only when the first instruction ends on the last byte of a 64-byte line and the branch begins the next line’s first byte.

Skylake to Cooper Lake

  • Front end: test and and fuse with any following conditional jump; cmp, add and sub with the jumps on equality and on the unsigned and signed comparisons, but not with js, jp or jo and their inverses; inc and dec only with those on equality and the signed comparisons.

Zen and Zen+

  • Integer execution: Only a cmp or test directly followed by a conditional branch fuses into one macro-op, and not when it has a displacement together with an immediate, or an address relative to RIP; no other arithmetic or logic instruction fuses.

Zen 2

  • Integer execution: Only a cmp or test followed by a conditional branch fuses into one macro-op, not one with a displacement together with an immediate or an address relative to RIP; the arithmetic and logic instructions that fuse on Zen 3 do not.

Zen 3

  • Integer execution: A cmp, test, add, sub, inc, dec, and, or or xor followed by a conditional branch becomes one macro-op, also with a memory operand, unless it carries a displacement together with an immediate, addresses relative to RIP or makes the pair longer than 15 bytes; inc and dec do not fuse with a branch on the carry flag, and jrcxz never fuses.

Zen 4

  • Integer execution: A cmp, test, add, sub, inc, dec, and, or or xor followed by a conditional branch becomes one macro-op, also with a memory operand, unless it carries a displacement together with an immediate, addresses relative to RIP or makes the pair longer than 15 bytes; inc and dec do not fuse with a branch on the carry flag.

Zen 5

  • Integer execution: A cmp, test, add, sub, inc, dec, and, or or xor followed by a conditional branch becomes one macro-op, also with a memory operand, within limits on the sizes of its displacement and immediate.

Forms

Every encoding of TEST that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
TEST m8, imm8 TEST_MEMb_IMMb_F6r0F6 /0 ibBase instruction set
TEST r8, imm8 TEST_GPR8_IMMb_F6r0F6 /0 ibBase instruction set
TEST m8, imm8 undocumented TEST_MEMb_IMMb_F6r1F6 /1 ibBase instruction set
TEST r8, imm8 undocumented TEST_GPR8_IMMb_F6r1F6 /1 ibBase instruction set
TEST m16/32/64, imm16/32 TEST_MEMv_IMMz_F7r0F7 /0 iw/idBase instruction set
TEST r16/32/64, imm16/32 TEST_GPRv_IMMz_F7r0F7 /0 iw/idBase instruction set
TEST m16/32/64, imm16/32 undocumented TEST_MEMv_IMMz_F7r1F7 /1 iw/idBase instruction set
TEST r16/32/64, imm16/32 undocumented TEST_GPRv_IMMz_F7r1F7 /1 iw/idBase instruction set
TEST m8, r8 TEST_MEMb_GPR884 /rBase instruction set
TEST r8, r8 TEST_GPR8_GPR884 /rBase instruction set
TEST m16/32/64, r16/32/64 TEST_MEMv_GPRv85 /rBase instruction set
TEST r16/32/64, r16/32/64 TEST_GPRv_GPRv85 /rBase instruction set
TEST AL, imm8 TEST_AL_IMMbA8 ibBase instruction set
TEST rAX, imm16/32 TEST_OrAX_IMMzA9 iw/idBase instruction set

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.
Modelm8, imm8
m16, imm16
m32, imm32
m64, imm32
m8, r8
m16, r16
m32, r32
m64, r64
r8, imm8
r32, imm32
r64, imm32
r8, r8
r16, r16
r32, r32
r64, r64
AL, imm8
rAX, imm32
r16, imm16
rAX, imm16
Sandy Bridge6 / 0.5p0151 / 0.33p0151 / 0.33p015
Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake6 / 0.5p01561 / 0.25p01561 / 0.25p0156
Alder Lake, Sapphire Rapids7 / 0.33p0 p1 p5 p6 p112 / 0.2p0 p1 p5 p6 p111 / 0.2p0 p1 p5 p6 p11
Lunar Lake7 / 0.33p0123452 / 0.17p0123451 / 0.33p135
Bonnell1 / 1p01 / 0.5p011 / 0.5p01
Silvermont4 / 1IEC0 IEC1 MEC1 / 0.5IEC0 IEC11 / 0.5IEC0 IEC1
Piledriver5 / 1.5EX0 EX11 / 1EX0 EX11 / 1EX0 EX1
Zen5 / 0.5ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 2, Zen 3, Zen 45 / 0.33ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 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.

r = src1 & sext(src2)            # as AND, but nothing is written
of = cf = 0
sf = msb(r)
zf = r == 0
pf = parity(r)
af = UNDEFINED

Run on AMD Zen 5 (EPYC 9645): 224 cases.

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
TEST r/m8, imm8 TEST r/m16/32/64, imm16/32
r/m8/16/32/64explicitread
imm8/16/32explicitread
RFLAGSimplicitwrite
TEST r/m8, r8 TEST r/m16/32/64, r16/32/64
r/m8/16/32/64explicitread
r8/16/32/64explicitread
RFLAGSimplicitwrite
TEST AL, imm8 TEST rAX, imm16/32
AL, rAXexplicitread
imm8/16/32explicitread
RFLAGSimplicitwrite

Flags

M modified, 0 cleared, U undefined; blank: not affected. How to read.
OFSFZFAFPFCF
All forms
0MMUM0

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
I86

No CPUID bit: part of the base instruction set.

Every x86-64 processor in XED’s model and Zen 3 to Zen 6

More General-purpose instructions

All 109 General-purpose 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-721 (TEST)
  5. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 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.