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

BTR copies one bit of its first operand into CF and then clears that bit. It is BTS with the opposite write: the bit is chosen as BT chooses it, ZF stays as it was, and with LOCK on a memory operand the read, the clear and the write back are one atomic operation. CF then says whether this BTR was the one that cleared the bit, which makes it a test-and-clear: a thread can claim a slot marked free by a set bit, or consume a pending-event bit, and know that no other thread got the same one.

From C

GCC 14 and Clang 23 at -O2 compile __atomic_fetch_and(p, ~(1UL << 40), __ATOMIC_SEQ_CST) & (1UL << 40) to lock btr qword ptr [rdi], 40 and a SETC (Clang prints it setb), and the same with a bit number n in a register to and esi, 63 and lock btr qword ptr [rdi], rsi: the AND stays because a memory operand does not take the offset modulo 64. Without the test of the old bit, both emit lock and with a mask instead.

On a register, x & ~(1UL << n) becomes btr rax, rsi. For a constant bit above 31, such as 40 or the sign bit 63, GCC writes btr rax, 40, while Clang loads the inverted mask with a 10-byte MOVABS and ANDs it, since an AND immediate holds at most 32 bits, sign-extended.

Clearing a bit in memory

Neither compiler uses BTR on plain memory. For a[n / 64] &= ~(1UL << (n % 64)), GCC builds the mask with a shift and a NOT, and Clang with mov rax, -2 and rol rax, cl, rotating the one zero into place, before an AND to memory. The instruction table of AMD’s Zen 5 guide lists every memory form of BTR as microcoded and the register forms as 2 macro-ops.

Things to know

  • Not the lowest bit. To clear the lowest set bit, whichever it is, BLSR does it without a bit number.
  • Undefined flags. OF, SF, AF and PF are undefined; Zen 5 left them as they were in all 168 recorded cases.

Forms

Every encoding of BTR that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
BTR m16/32/64, imm8 BTR_MEMv_IMMb0F BA /6 ibBase instruction set
BTR r16/32/64, imm8 BTR_GPRv_IMMb0F BA /6 ibBase instruction set
BTR m16/32/64, r16/32/64 BTR_MEMv_GPRv0F B3 /rBase instruction set
BTR r16/32/64, r16/32/64 BTR_GPRv_GPRv0F B3 /rBase instruction set
LOCK BTR m16/32/64, imm8 BTR_LOCK_MEMv_IMMb0F BA /6 ibBase instruction set
LOCK BTR m16/32/64, r16/32/64 BTR_LOCK_MEMv_GPRv0F B3 /rBase 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.
Modelm16, imm8
m32, imm8
m64, imm8
BTR m16, imm8
BTR m32, imm8
BTR m64, imm8
r16, imm8
r32, imm8
r64, imm8
r16, r16
r32, r32
m16, r16
m32, r32
BTR m16, r16
BTR m32, r32
m64, r64
BTR m64, r64
r64, r64
Sandy Bridge7 / 1p051 / 0.5p059 / 1p0159 / 1p0151 / 0.5p05
Haswell7 / 1p061 / 0.5p061 / 2.751 / 2.751 / 0.5p06
Broadwell, Skylake, Skylake-SP6 / 1p061 / 0.5p066 / 1p01566 / 1p01561 / 0.5p06
Ice Lake6 / 0.5p061 / 0.5p066 / 0.5p01566 / 0.5p01561 / 0.5p06
Alder Lake, Sapphire Rapids12 / 1p11 / 1p118 / 1.6p0 p1 p5 p6 p1117 / 1.4p0 p1 p5 p6 p113 / 1p1
Lunar Lake12 / 0.5p1351 / 0.33p13518 / 1.33p01234517 / 1.17p0123453 / 1p1
Bonnell2 / 1p11 / 1p111 / 5.5p111 / 5.5p11 / 1p1
Silvermont4 / 2IEC0 IEC1 MEC1 / 1IEC0 IEC14 / 2IEC0 IEC1 MEC4 / 2IEC0 IEC1 MEC1 / 1IEC0 IEC1
Piledriver7 / 21EX0 EX12 / 1EX0 EX17 / 22EX0 EX17 / 22EX0 EX12 / 1EX0 EX1
Zen6 / 0.5ALU0 ALU1 ALU2 ALU32 / 0.25ALU0 ALU1 ALU2 ALU36 / 0.5ALU0 ALU1 ALU2 ALU36 / 0.5ALU0 ALU1 ALU2 ALU32 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 26 / 0.33ALU0 ALU1 ALU2 ALU32 / 0.25ALU0 ALU1 ALU2 ALU36 / 0.33ALU0 ALU1 ALU2 ALU36 / 0.33ALU0 ALU1 ALU2 ALU32 / 0.25ALU0 ALU1 ALU2 ALU3
Zen 3, Zen 47 / 0.67ALU1 ALU22 / 1ALU1 ALU27 / 0.67ALU1 ALU27 / 0.67ALU1 ALU22 / 1ALU1 ALU2
Jaguar6 / 1ALU0 ALU11 / 0.5ALU0 ALU16 / 1ALU0 ALU16 / 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.

BTR r/m16/32/64, imm8 BTR r16/32/64, r16/32/64 LOCK BTR m16/32/64, imm8
n = bit & (OSIZE - 1)            # the offset, modulo the operand size
v = dest.read()                  # with LOCK: one atomic read-modify-write
cf = v >> n & 1
of = sf = af = pf = UNDEFINED    # ZF keeps its value
dest.write(v & ~(1 << n))        # a 32-bit register: bits 63:32 cleared

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

BTR m16/32/64, r16/32/64 LOCK BTR m16/32/64, r16/32/64
n = signed(bit)                  # not masked: bit n can lie far below
                                 # or above the operand
a = dest.address + n // OSIZE * (OSIZE // 8)   # the OSIZE bits that
v = load(a, OSIZE)                             # hold it; with LOCK,
cf = v >> n % OSIZE & 1                        # read and written as one
of = sf = af = pf = UNDEFINED    # ZF keeps its value
store(a, OSIZE, v & ~(1 << n % OSIZE))

Run on AMD Zen 5 (EPYC 9645): 69 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
BTR r/m16/32/64, imm8 LOCK BTR m16/32/64, imm8
r/m16/32/64explicitread, write
imm8explicitread
RFLAGSimplicitwrite
BTR r/m16/32/64, r16/32/64 LOCK BTR m16/32/64, r16/32/64
r/m16/32/64explicitread, write
r16/32/64explicitread
RFLAGSimplicitwrite

Flags

M modified, U undefined; blank: not affected. How to read.
OFSFAFPFCF
All forms
UUUUM

Attributes

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

Memory forms without LOCK
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
I386

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 2A, page 3-116 (BTR)
  5. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
  6. 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.