Extensions
Forms
60 (24 Legacy, 36 EVEX)
Data
Intel XED v2026.08.23

SUB subtracts its source from its destination and sets the flags from the difference, the same flags that CMP sets without writing anything. CF is the borrow, set when the destination is below the source as unsigned numbers, and OF the signed overflow, so one SUB answers both questions:

  • __builtin_sub_overflow on two unsigned longs compiles, in GCC 14 and Clang 23 at -O2, to sub rdi, rsi and setb al, and on two longs to the same SUB and seto al.
  • For the saturating a > b ? a - b : 0, Clang subtracts once and keeps the difference with cmovae only when there was no borrow; GCC adds a separate CMP.

Immediates

An 8-bit immediate is sign-extended and reaches from -128 to 127, so 128 does not fit but -128 does. Both compilers exploit the asymmetry: *p += 128 on a long becomes sub qword ptr [rdi], -128 (4 bytes) instead of an ADD with a 32-bit immediate (7 bytes), and *p -= 128 becomes add qword ptr [rdi], -128. In registers they compute x - 128 with an LEA, which can write a different register.

SUB has no reversed form, so 10 - x takes mov eax, 10 and sub rax, rdi. The stack pointer is a frequent destination: a function that needs a frame reserves it with sub rsp and an immediate (see stack frames).

Zeroing and fusion

SUB of a register from itself gives 0, and Intel’s Optimization Reference Manual (Section 3.5.1.7) and AMD’s guide for Zen 5 (Section 2.9.2) list it beside XOR as an idiom that does not wait for the register’s old value; compilers use the XOR. A SUB followed by a conditional jump can be fused into one operation: Intel’s Table 3-1 (Sandy Bridge) allows it for the carry, zero, above and signed conditions but not for O, S and P, and AMD lists SUB among the instructions that fuse on Zen 5 (Section 2.9.3).

Atomic subtraction

With LOCK, SUB subtracts from memory atomically. Both compilers use lock sub for an atomic_fetch_sub whose result is unused; when the old value is needed, they negate the operand and use XADD, and when only reaching 0 matters, they test ZF after lock sub (GCC) or DEC (Clang).

In the optimization guide

What the optimization guide says about SUB, 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: xor eax, eax and sub eax, eax give zero whatever EAX held, and every core here recognizes them as it renames: the result needs no execution unit and does not wait for the old value, so the idiom also ends any chain through the register.
  • Move elimination: Golden Cove goes further: Agner Fog found that adding a small constant to a register sometimes takes no time, and LLVM’s model gives add and sub of an 8-bit immediate to a 64-bit register no micro-op at all (Golden Cove).

Golden Cove and Raptor Cove

  • Integer execution: Register-to-register moves and zeroing idioms are handled when micro-ops are renamed, and adding a small constant to a register sometimes takes no cycle either.

Skylake to Cooper Lake

  • Integer execution: xor, sub and the vector pxor, xorps, pandn, psub and pcmpgt of a register with itself zero it without an execution unit, four a cycle, for 32-bit and 64-bit and all vector registers.

Forms

Every encoding of SUB that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
SUB m8, imm8 SUB_MEMb_IMMb_80r580 /5 ibBase instruction set
SUB r8, imm8 SUB_GPR8_IMMb_80r580 /5 ibBase instruction set
SUB m16/32/64, imm16/32 SUB_MEMv_IMMz81 /5 iw/idBase instruction set
SUB r16/32/64, imm16/32 SUB_GPRv_IMMz81 /5 iw/idBase instruction set
SUB m8, imm8 not in 64-bit mode SUB_MEMb_IMMb_82r582 /5 ibBase instruction set
SUB r8, imm8 not in 64-bit mode SUB_GPR8_IMMb_82r582 /5 ibBase instruction set
SUB m16/32/64, imm8 SUB_MEMv_IMMb83 /5 ibBase instruction set
SUB r16/32/64, imm8 SUB_GPRv_IMMb83 /5 ibBase instruction set
SUB m8, r8 SUB_MEMb_GPR828 /rBase instruction set
SUB r8, r8 SUB_GPR8_GPR8_2828 /rBase instruction set
SUB m16/32/64, r16/32/64 SUB_MEMv_GPRv29 /rBase instruction set
SUB r16/32/64, r16/32/64 SUB_GPRv_GPRv_2929 /rBase instruction set
SUB r8, r8 SUB_GPR8_GPR8_2A2A /rBase instruction set
SUB r8, m8 SUB_GPR8_MEMb2A /rBase instruction set
SUB r16/32/64, r16/32/64 SUB_GPRv_GPRv_2B2B /rBase instruction set
SUB r16/32/64, m16/32/64 SUB_GPRv_MEMv2B /rBase instruction set
SUB AL, imm8 SUB_AL_IMMb2C ibBase instruction set
SUB rAX, imm16/32 SUB_OrAX_IMMz2D iw/idBase instruction set
LOCK SUB m8, imm8 SUB_LOCK_MEMb_IMMb_80r580 /5 ibBase instruction set
LOCK SUB m16/32/64, imm16/32 SUB_LOCK_MEMv_IMMz81 /5 iw/idBase instruction set
LOCK SUB m8, imm8 not in 64-bit mode SUB_LOCK_MEMb_IMMb_82r582 /5 ibBase instruction set
LOCK SUB m16/32/64, imm8 SUB_LOCK_MEMv_IMMb83 /5 ibBase instruction set
LOCK SUB m8, r8 SUB_LOCK_MEMb_GPR828 /rBase instruction set
LOCK SUB m16/32/64, r16/32/64 SUB_LOCK_MEMv_GPRv29 /rBase instruction set
SUB r8, r8 SUB_GPR8i8_GPR8i8_APXEVEX.LLZ.NP.MAP4.WIG 28 /r
EVEX.LLZ.NP.MAP4.WIG 2A /r
APX_F
SUB m8, r8 SUB_MEMi8_GPR8i8_APXEVEX.LLZ.NP.MAP4.WIG 28 /rAPX_F
SUB r8, r8 NF SUB_GPR8i8_GPR8i8_APX_N3EVEX.LLZ.NP.MAP4.WIG 28 /r NF=1
EVEX.LLZ.NP.MAP4.WIG 2A /r NF=1
APX_F + APX_NCI_NDD_NF
SUB m8, r8 NF SUB_MEMi8_GPR8i8_APX_N3EVEX.LLZ.NP.MAP4.WIG 28 /r NF=1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, r16/32/64, imm8 NDD NF optional SUB_GPRv_GPRv_IMM8_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ib ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, m16/32/64, imm8 NDD NF optional SUB_GPRv_MEMv_IMM8_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ib ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r8, r8, r8 NDD NF optional SUB_GPR8i8_GPR8i8_GPR8i8_APX_N3EVEX.LLZ.NP.MAP4.WIG 28 /r ND=1 NF=0/1
EVEX.LLZ.NP.MAP4.WIG 2A /r ND=1 NF=0/1
APX_F + APX_NCI_NDD_NF
SUB r8, m8, r8 NDD NF optional SUB_GPR8i8_MEMi8_GPR8i8_APX_N3EVEX.LLZ.NP.MAP4.WIG 28 /r ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, r16/32/64 SUB_GPRv_GPRv_APXEVEX.LLZ.NP.MAP4.SCALABLE 29 /r
EVEX.LLZ.NP.MAP4.SCALABLE 2B /r
APX_F
SUB m16/32/64, r16/32/64 SUB_MEMv_GPRv_APXEVEX.LLZ.NP.MAP4.SCALABLE 29 /rAPX_F
SUB r16/32/64, r16/32/64 NF SUB_GPRv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 29 /r NF=1
EVEX.LLZ.NP.MAP4.SCALABLE 2B /r NF=1
APX_F + APX_NCI_NDD_NF
SUB m16/32/64, r16/32/64 NF SUB_MEMv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 29 /r NF=1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, r16/32/64, r16/32/64 NDD NF optional SUB_GPRv_GPRv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 29 /r ND=1 NF=0/1
EVEX.LLZ.NP.MAP4.SCALABLE 2B /r ND=1 NF=0/1
APX_F + APX_NCI_NDD_NF
SUB r16/32/64, m16/32/64, r16/32/64 NDD NF optional SUB_GPRv_MEMv_GPRv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 29 /r ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r8, m8 SUB_GPR8i8_MEMi8_APXEVEX.LLZ.NP.MAP4.WIG 2A /rAPX_F
SUB r8, m8 NF SUB_GPR8i8_MEMi8_APX_N3EVEX.LLZ.NP.MAP4.WIG 2A /r NF=1APX_F + APX_NCI_NDD_NF
SUB r8, r8, m8 NDD NF optional SUB_GPR8i8_GPR8i8_MEMi8_APX_N3EVEX.LLZ.NP.MAP4.WIG 2A /r ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, m16/32/64 SUB_GPRv_MEMv_APXEVEX.LLZ.NP.MAP4.SCALABLE 2B /rAPX_F
SUB r16/32/64, m16/32/64 NF SUB_GPRv_MEMv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 2B /r NF=1APX_F + APX_NCI_NDD_NF
SUB r8, r8, imm8 NDD NF optional SUB_GPR8i8_GPR8i8_IMM8_APX_N3EVEX.LLZ.NP.MAP4.WIG 80 /5 ib ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r8, m8, imm8 NDD NF optional SUB_GPR8i8_MEMi8_IMM8_APX_N3EVEX.LLZ.NP.MAP4.WIG 80 /5 ib ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, r16/32/64, m16/32/64 NDD NF optional SUB_GPRv_GPRv_MEMv_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 2B /r ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r8, imm8 SUB_GPR8i8_IMM8_APXEVEX.LLZ.NP.MAP4.WIG 80 /5 ibAPX_F
SUB m8, imm8 SUB_MEMi8_IMM8_APXEVEX.LLZ.NP.MAP4.WIG 80 /5 ibAPX_F
SUB r8, imm8 NF SUB_GPR8i8_IMM8_APX_N3EVEX.LLZ.NP.MAP4.WIG 80 /5 ib NF=1APX_F + APX_NCI_NDD_NF
SUB m8, imm8 NF SUB_MEMi8_IMM8_APX_N3EVEX.LLZ.NP.MAP4.WIG 80 /5 ib NF=1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, imm16/32 SUB_GPRv_IMMz_APXEVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/idAPX_F
SUB m16/32/64, imm16/32 SUB_MEMv_IMMz_APXEVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/idAPX_F
SUB r16/32/64, imm16/32 NF SUB_GPRv_IMMz_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/id NF=1APX_F + APX_NCI_NDD_NF
SUB m16/32/64, imm16/32 NF SUB_MEMv_IMMz_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/id NF=1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, r16/32/64, imm16/32 NDD NF optional SUB_GPRv_GPRv_IMMz_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/id ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, m16/32/64, imm16/32 NDD NF optional SUB_GPRv_MEMv_IMMz_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 81 /5 iw/id ND=1 NF=0/1APX_F + APX_NCI_NDD_NF
SUB r16/32/64, imm8 SUB_GPRv_IMM8_APXEVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ibAPX_F
SUB m16/32/64, imm8 SUB_MEMv_IMM8_APXEVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ibAPX_F
SUB r16/32/64, imm8 NF SUB_GPRv_IMM8_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ib NF=1APX_F + APX_NCI_NDD_NF
SUB m16/32/64, imm8 NF SUB_MEMv_IMM8_APX_N3EVEX.LLZ.NP.MAP4.SCALABLE 83 /5 ib NF=1APX_F + APX_NCI_NDD_NF

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
m8, r8
SUB m8, imm8
SUB m8, r8
r8, imm8
r16, imm16
r32, imm32
r64, imm32
r16, imm8
r32, imm8
r8, r8
r16, r16
r32, r32
r64, r64
m16, imm16
m32, imm32
m64, imm32
m16, imm8
m32, imm8
m64, imm8
m16, r16
m32, r32
m64, r64
SUB m16, imm16
SUB m32, imm32
SUB m64, imm32
SUB m16, imm8
SUB m32, imm8
SUB m64, imm8
SUB m16, r16
SUB m32, r32
SUB m64, r64
r64, imm8r8, m8
r16, m16
r32, m32
r64, m64
AL, imm8
rAX, imm16
rAX, imm32
Sandy Bridge7 / 1p0151 / 0.33p0157 / 1p0151 / 0.33p0156 / 0.5p0151 / 0.33p015
Haswell, Broadwell, Skylake, Skylake-SP7 / 1p01561 / 0.25p01567 / 1p01561 / 0.25p01566 / 0.5p01561 / 0.25p0156
Ice Lake7 / 0.5p01561 / 0.25p01567 / 0.5p01561 / 0.25p01566 / 0.5p01561 / 0.25p0156
Alder Lake, Sapphire Rapids13 / 0.5p0 p1 p5 p6 p111 / 0.2p0 p1 p5 p6 p1112 / 0.5p0 p1 p5 p6 p111 / 06 / 0.33p0 p1 p5 p6 p111 / 0.2p0 p1 p5 p6 p11
Lunar Lake13 / 0.5p0123451 / 0.33p13512 / 0.67p1351 / 06 / 0.33p0123451 / 0.33p135
Bonnell1 / 1p01 / 0.5p011 / 1p01 / 0.5p011 / 1p01 / 0.5p01
Silvermont5 / 2IEC0 IEC1 MEC1 / 0.5IEC0 IEC15 / 2IEC0 IEC1 MEC1 / 0.5IEC0 IEC14 / 1IEC0 IEC1 MEC1 / 0.5IEC0 IEC1
Piledriver6 / 2EX0 EX11 / 1EX0 EX16 / 2EX0 EX11 / 1EX0 EX15 / 1.5EX0 EX11 / 1EX0 EX1
Zen5 / 0.5ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU35 / 0.5ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU35 / 0.5ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 25 / 0.33ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU35 / 0.33ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU35 / 0.33ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 3, Zen 46 / 0.67ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU36 / 0.67ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU35 / 0.33ALU0 ALU1 ALU2 ALU31 / 1ALU0 ALU1 ALU2 ALU3
Jaguar6 / 1ALU0 ALU11 / 0.5ALU0 ALU16 / 1ALU0 ALU11 / 0.5ALU0 ALU14 / 1ALU0 ALU11 / 0.5ALU0 ALU1

Operation

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

All forms but the NDD forms
a = dest.read()                  # with LOCK: one atomic read-modify-write
b = sext(src)                    # an immediate is sign-extended to OSIZE
if not nf:                       # NF=1 (APX) leaves the flags as they were
    flags = sub_flags(a, b)
dest.write(a - b)                # a 32-bit register: bits 63:32 cleared

Run on AMD Zen 5 (EPYC 9645) and an Intel processor under KVM (model hidden): 832 cases. The APX forms were not run: none of these processors has APX. The forms that 64-bit mode lacks were not run: the probe runs in 64-bit mode.

NDD forms
a = src1.read()
b = sext(src2)                   # an immediate is sign-extended to OSIZE
if not nf:                       # NF=1 leaves the flags as they were
    flags = sub_flags(a, b)
dest.write(a - b)                # the new destination: bits 63:OSIZE
                                 # cleared, even for 8 and 16 bits

Not run on a processor: 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
SUB r/m8, imm8 SUB r/m16/32/64, imm16/32 SUB r/m16/32/64, imm8 LOCK SUB m8, imm8 LOCK SUB m16/32/64, imm16/32 LOCK SUB m16/32/64, imm8
r/m8/16/32/64explicitread, write
imm8/16/32explicitread
RFLAGSimplicitwrite
SUB r/m8, r8 SUB r/m16/32/64, r16/32/64 LOCK SUB m8, r8 LOCK SUB m16/32/64, r16/32/64
r/m8/16/32/64explicitread, write
r8/16/32/64explicitread
RFLAGSimplicitwrite
SUB r8, r/m8 SUB r16/32/64, r/m16/32/64
r8/16/32/64explicitread, write
r/m8/16/32/64explicitread
RFLAGSimplicitwrite
SUB AL, imm8 SUB rAX, imm16/32
AL, rAXexplicitread, write
imm8/16/32explicitread
RFLAGSimplicitwrite
SUB r/m8, r8 NF SUB r/m16/32/64, r16/32/64 NF
r/m8/16/32/64explicitread, write
r8/16/32/64explicitread
SUB r8, r/m8, imm8 NDD NF optional SUB r16/32/64, r/m16/32/64, imm8 NDD NF optional SUB r16/32/64, r/m16/32/64, imm16/32 NDD NF optional
r8/16/32/64explicitwrite
r/m8/16/32/64explicitread
imm8/16/32explicitread
RFLAGSimplicitwrite (NF=0)
SUB r8, r/m8, r8 NDD NF optional SUB r16/32/64, r/m16/32/64, r16/32/64 NDD NF optional
r8/16/32/64explicitwrite
r/m8/16/32/64explicitread
r8/16/32/64explicitread
RFLAGSimplicitwrite (NF=0)
SUB r8, m8 NF SUB r16/32/64, m16/32/64 NF
r8/16/32/64explicitread, write
m8/16/32/64explicitread
SUB r8, r8, m8 NDD NF optional SUB r16/32/64, r16/32/64, m16/32/64 NDD NF optional
r8/16/32/64explicitwrite
r8/16/32/64explicitread
m8/16/32/64explicitread
RFLAGSimplicitwrite (NF=0)
SUB r/m8, imm8 NF SUB r/m16/32/64, imm16/32 NF SUB r/m16/32/64, imm8 NF
r/m8/16/32/64explicitread, write
imm8/16/32explicitread

Flags

M modified; blank: not affected. With NF=1, the forms with optional NF leave the flags unchanged. How to read.
WhenOFSFZFAFPFCF
NF forms
Not affected
NDD forms
NF=0MMMMMM
Other forms
MMMMMM

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

Attributes

What else XED records about the forms. How to read.

SUB m8, imm8 SUB m8, r8 SUB m16/32/64, imm16/32 SUB m16/32/64, imm8 SUB m16/32/64, r16/32/64
accepts a LOCK prefix
LOCK forms
locked: atomic read-modify-write; accepts XACQUIRE; accepts XRELEASE

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
APX_F

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

Nova Lake, Diamond Rapids
APX_F_N3

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

Same as APX_F

More General-purpose instructions

All 109 General-purpose 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-685 (SUB)
  5. Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
  6. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
  7. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
  8. Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)
  9. 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.