Instruction
BTC
Copies the selected bit of a register or memory operand into CF and then inverts it; with LOCK the memory form is atomic.
- Extensions
- Forms
- 6 (6 Legacy)
- Data
- Intel XED v2026.08.23
BTC copies one bit of its first operand into CF and then inverts that bit. The bit is chosen as BT chooses it, and ZF stays as it was. Of the three bit-modifying siblings it is the least used: BTS sets and BTR clears, and both have obvious uses as locks and claims. Flipping is for toggles: a phase bit that alternates between two buffers, or the sign bit of an integer.
The new value from the old
CF holds the bit as it was, so after BTC the bit as it is now is the
inverse of CF. GCC 14 and Clang 23 at -O2 compile the atomic toggle
__atomic_xor_fetch(p, m, __ATOMIC_SEQ_CST) & m, with m being
1UL << (n & 63), to and esi, 63, lock btc qword ptr [rdi], rsi
and setnc al (Clang prints setae al): the condition is inverted, not
the instruction. With __atomic_fetch_xor, which returns the old value,
they use SETC as for BTS. The AND stays because a memory operand does
not reduce the bit number modulo 64.
On registers
x ^ (1UL << n) becomes btc rax, rsi with both compilers. For the
sign bit of a 64-bit value, x ^ (1UL << 63), GCC emits
btc rax, 63, and Clang a 10-byte MOVABS of the mask and an XOR. For a
32-bit x ^ 0x80000000, both use lea eax, [rdi - 2147483648]: adding
2^31 flips bit 31 too, and LEA writes the result to another register
without touching the flags.
Things to know
- Speed. AMD’s Zen 5 instruction table lists the register forms of BTC as 2 macro-ops and every memory form as microcoded; for plain memory, compilers flip a bit with an XOR to memory instead.
- LOCK is accepted only with a memory destination, and raises #UD on a register.
- Undefined flags. OF, SF, AF and PF are undefined; Zen 5 left them as they were in all 168 recorded cases.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
BTC m16/32/64, imm8
BTC_MEMv_IMMb | 0F BA /7 ib | Base instruction set |
BTC r16/32/64, imm8
BTC_GPRv_IMMb | 0F BA /7 ib | Base instruction set |
BTC m16/32/64, r16/32/64
BTC_MEMv_GPRv | 0F BB /r | Base instruction set |
BTC r16/32/64, r16/32/64
BTC_GPRv_GPRv | 0F BB /r | Base instruction set |
LOCK BTC m16/32/64, imm8
BTC_LOCK_MEMv_IMMb | 0F BA /7 ib | Base instruction set |
LOCK BTC m16/32/64, r16/32/64
BTC_LOCK_MEMv_GPRv | 0F BB /r | Base instruction set |
Latency and throughput
| Model | m16, imm8m32, imm8m64, imm8BTC m16, imm8BTC m32, imm8BTC m64, imm8 | r16, imm8r32, imm8r64, imm8r16, r16r32, r32 | m16, r16m32, r32BTC m16, r16BTC m32, r32 | m64, r64BTC m64, r64 | r64, r64 |
|---|---|---|---|---|---|
| Sandy Bridge | 7 / 1p05 | 1 / 0.5p05 | 9 / 1p015 | 9 / 1p015 | 1 / 0.5p05 |
| Haswell | 7 / 1p06 | 1 / 0.5p06 | 1 / 2.75 | 1 / 2.75 | 1 / 0.5p06 |
| Broadwell, Skylake, Skylake-SP | 6 / 1p06 | 1 / 0.5p06 | 6 / 1p0156 | 6 / 1p0156 | 1 / 0.5p06 |
| Ice Lake | 6 / 0.5p06 | 1 / 0.5p06 | 6 / 0.5p0156 | 6 / 0.5p0156 | 1 / 0.5p06 |
| Alder Lake, Sapphire Rapids | 12 / 1p1 | 1 / 1p1 | 18 / 1.6p0 p1 p5 p6 p11 | 17 / 1.4p0 p1 p5 p6 p11 | 3 / 1p1 |
| Lunar Lake | 12 / 0.5p135 | 1 / 0.33p135 | 18 / 1.33p012345 | 17 / 1.17p012345 | 3 / 1p1 |
| Bonnell | 2 / 1p1 | 1 / 1p1 | 11 / 5.5p1 | 11 / 5.5p1 | 1 / 1p1 |
| Silvermont | 4 / 2IEC0 IEC1 MEC | 1 / 1IEC0 IEC1 | 4 / 2IEC0 IEC1 MEC | 4 / 2IEC0 IEC1 MEC | 1 / 1IEC0 IEC1 |
| Piledriver | 7 / 21EX0 EX1 | 2 / 1EX0 EX1 | 7 / 22EX0 EX1 | 7 / 22EX0 EX1 | 2 / 1EX0 EX1 |
| Zen | 6 / 0.5ALU0 ALU1 ALU2 ALU3 | 2 / 0.25ALU0 ALU1 ALU2 ALU3 | 6 / 0.5ALU0 ALU1 ALU2 ALU3 | 6 / 0.5ALU0 ALU1 ALU2 ALU3 | 2 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 2 | 6 / 0.33ALU0 ALU1 ALU2 ALU3 | 2 / 0.25ALU0 ALU1 ALU2 ALU3 | 6 / 0.33ALU0 ALU1 ALU2 ALU3 | 6 / 0.33ALU0 ALU1 ALU2 ALU3 | 2 / 0.25ALU0 ALU1 ALU2 ALU3 |
| Zen 3, Zen 4 | 7 / 0.67ALU1 ALU2 | 2 / 1ALU1 ALU2 | 7 / 0.67ALU1 ALU2 | 7 / 0.67ALU1 ALU2 | 2 / 1ALU1 ALU2 |
| Jaguar | 6 / 1ALU0 ALU1 | 1 / 0.5ALU0 ALU1 | 6 / 1ALU0 ALU1 | 6 / 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.
BTC r/m16/32/64, imm8 BTC r16/32/64, r16/32/64 LOCK BTC m16/32/64, imm8n = 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.
BTC m16/32/64, r16/32/64 LOCK BTC m16/32/64, r16/32/64n = 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
| Operand | Kind | Action |
|---|---|---|
BTC r/m16/32/64, imm8 LOCK BTC m16/32/64, imm8 | ||
r/m16/32/64 | explicit | read, write |
imm8 | explicit | read |
RFLAGS | implicit | write |
BTC r/m16/32/64, r16/32/64 LOCK BTC m16/32/64, r16/32/64 | ||
r/m16/32/64 | explicit | read, write |
r16/32/64 | explicit | read |
RFLAGS | implicit | write |
Flags
| OF | SF | AF | PF | CF |
|---|---|---|---|---|
| All forms | ||||
| U | U | U | U | M |
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.
| 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-114 (BTC)
- 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.