Instruction
BT
Copies the bit that a register or immediate offset selects in a register or memory operand into CF; a register offset can reach beyond a memory operand.
- Extensions
- Forms
- 4 (4 Legacy)
- Data
- Intel XED v2026.08.23
BT copies one bit of its first operand into CF, where JC, JNC, SETC,
CMOVC or ADC can use it. BTS, BTR and
BTC copy the bit the same way and then set, clear or flip
it. Clang 23 at -O2 compiles if (x & (1ULL << n)) on a 64-bit x to
bt rdi, rsi and a CMOVAE, and the test of a fixed bit 40 to
bt rdi, 40, which spares it a 10-byte MOV of the mask. GCC 14 tests
such bits with shifts and ANDs, but sets and clears bit n of a register
with BTS and BTR.
How far the offset reaches
On a register, the bit number is taken modulo the operand size, 16, 32 or 64, and an immediate does the same on memory, so it selects a bit within the operand itself.
A register offset on a memory operand is different. The address then
marks only bit 0 of a bit string, and the offset is a signed number,
not masked, that can select a bit far below or above it: up to 2^63
bits either way with a 64-bit offset. The processor reads the 2, 4 or 8
bytes, by operand size, that hold the bit. This site’s Zen 5 ran cases
reaching 64 bytes below and above the address, so bt [rdi], rsi tests
bit RSI of a whole array at RDI.
Cautions
- The access is wider than the bit. It covers a word of the operand’s size around the bit, so near memory-mapped I/O, or at the edge of mapped memory, Intel’s and AMD’s manuals advise a MOV and a BT on the register instead.
- Speed. The instruction table that comes with AMD’s Zen 5 guide
lists BT with a memory operand and a register offset as microcoded,
while the register and immediate forms are single macro-ops. Neither
compiler uses it at -O2: for
(a[n / 64] >> (n % 64)) & 1, both load the word with a MOV, and Clang then runsbt rcx, rsion the register. - No LOCK. BT only reads, and a LOCK prefix raises #UD; the atomic test-and-modify forms are LOCK BTS, LOCK BTR and LOCK BTC.
BT leaves ZF as it was, so code cannot use the zero flag to learn the bit; the flags table shows the others.
In the optimization guide
What the optimization guide says about BT, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Out of order
- Partial register and flag writes: Some instructions write only part of the flags:
incanddecleave the carry flag as it was, andbtleaves the zero flag.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
BT m16/32/64, imm8
BT_MEMv_IMMb | 0F BA /4 ib | Base instruction set |
BT r16/32/64, imm8
BT_GPRv_IMMb | 0F BA /4 ib | Base instruction set |
BT m16/32/64, r16/32/64
BT_MEMv_GPRv | 0F A3 /r | Base instruction set |
BT r16/32/64, r16/32/64
BT_GPRv_GPRv | 0F A3 /r | Base instruction set |
Latency and throughput
| Model | m16, imm8m32, imm8m64, imm8 | r16, imm8r32, imm8r64, imm8r16, r16r32, r32 | m16, r16m32, r32 | m64, r64 | r64, r64 |
|---|---|---|---|---|---|
| Sandy Bridge | 6 / 0.5p05 | 1 / 0.5p05 | 9 / 1p015 | 9 / 1p015 | 1 / 0.5p05 |
| Haswell | 6 / 0.5p06 | 1 / 0.5p06 | 1 / 2.5 | 1 / 2.5 | 1 / 0.5p06 |
| Broadwell, Skylake, Skylake-SP, Ice Lake | 6 / 0.5p06 | 1 / 0.5p06 | 6 / 0.5p0156 | 6 / 0.5p0156 | 1 / 0.5p06 |
| Alder Lake, Sapphire Rapids | 6 / 1p1 | 1 / 1p1 | 11 / 1.8p0 p1 p5 p6 p11 | 10 / 1.6p0 p1 p5 p6 p11 | 3 / 1p1 |
| Lunar Lake | 6 / 0.33p135 | 1 / 0.33p135 | 11 / 1.5p012345 | 10 / 1.33p012345 | 3 / 1p1 |
| Bonnell | 1 / 1p0 | 1 / 1p1 | 9 / 4.5p1 | 9 / 4.5p1 | 1 / 1p1 |
| Silvermont | 4 / 1IEC0 IEC1 MEC | 1 / 1IEC0 IEC1 | 4 / 1IEC0 IEC1 MEC | 4 / 1IEC0 IEC1 MEC | 1 / 1IEC0 IEC1 |
| Piledriver | 5 / 1.5EX0 EX1 | 1 / 1EX0 EX1 | 5 / 3.5EX0 EX1 | 5 / 3.5EX0 EX1 | 1 / 1EX0 EX1 |
| Zen | 5 / 0.5ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 | 5 / 0.5ALU0 ALU1 ALU2 ALU3 | 5 / 0.5ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 2 | 5 / 0.33ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 | 5 / 0.33ALU0 ALU1 ALU2 ALU3 | 5 / 0.33ALU0 ALU1 ALU2 ALU3 | 1 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 3, Zen 4 | 5 / 0.5ALU1 ALU2 | 1 / 0.5ALU1 ALU2 | 5 / 0.5ALU1 ALU2 | 5 / 0.5ALU1 ALU2 | 1 / 0.5ALU1 ALU2 |
| Jaguar | 4 / 1ALU0 ALU1 | 1 / 0.5ALU0 ALU1 | 4 / 1ALU0 ALU1 | 4 / 1ALU0 ALU1 | 1 / 0.5ALU0 ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
BT r/m16/32/64, imm8 BT r16/32/64, r16/32/64n = bit & (OSIZE - 1) # the offset, modulo the operand size
cf = base >> n & 1
of = sf = af = pf = UNDEFINED # ZF keeps its value
Run on AMD Zen 5 (EPYC 9645): 84 cases.
BT m16/32/64, r16/32/64n = signed(bit) # not masked: bit n can lie far below
# or above the operand
a = base.address + n // OSIZE * (OSIZE // 8) # the OSIZE bits that
cf = load(a, OSIZE) >> n % OSIZE & 1 # hold it
of = sf = af = pf = UNDEFINED # ZF keeps its value
Run on AMD Zen 5 (EPYC 9645): 51 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
BT r/m16/32/64, imm8 | ||
r/m16/32/64 | explicit | read |
imm8 | explicit | read |
RFLAGS | implicit | write |
BT r/m16/32/64, r16/32/64 | ||
r/m16/32/64 | explicit | read |
r16/32/64 | explicit | read |
RFLAGS | implicit | write |
Flags
| OF | SF | AF | PF | CF |
|---|---|---|---|---|
| All forms | ||||
| U | U | U | U | M |
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.
| ISA set | CPUID | Processors |
|---|---|---|
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
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-112 (BT)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- 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.