Instruction
PDEP
Deposits the low bits of the source at the bit positions selected by a mask, clearing the others.
PDEP scatters the low bits of its source to the positions of the 1 bits of a mask, in order: bit 0 of the source goes to the lowest 1 of the mask, bit 1 to the next one, and so on. Every position where the mask has a 0 is cleared, and source bits beyond the mask’s number of ones are dropped. Depositing 0b101 into the mask 0xF0 gives 0x50. PEXT does the reverse, gathering the bits at the mask’s positions into the low bits, so PEXT of PDEP(x, m) with the same mask m gives back the low bits of x, as many as m has ones.
Operand order
In Intel syntax the source comes second and the mask third:
pdep rax, rbx, rcx deposits RBX into the places of RCX, and only
the mask may be in memory. The intrinsics _pdep_u32(src, mask) and
_pdep_u64(src, mask) take them in the same order. There are 32- and
64-bit forms, no 16-bit one, and no flag changes.
Uses
- The index of the n-th set bit of x, counting from 0: deposit the
single bit
1 << ninto the mask x and count the trailing zeros. GCC 14 and Clang 23 at -O2 compile_tzcnt_u64(_pdep_u64(1ULL << n, x))to SHLX, PDEP and TZCNT; if x has n or fewer set bits, the result is 64. - Interleaving:
_pdep_u64(x, 0x5555555555555555)spreads x over the even bits and_pdep_u64(y, 0xAAAAAAAAAAAAAAAA)y over the odd ones; their OR is the Morton code of the point (x, y). - Widening a bit mask: PDEP of an 8-bit mask into 0x0101010101010101 puts each bit at the bottom of its own byte, and a multiplication by 0xFF turns each byte into 0x00 or 0xFF.
Neither compiler finds PDEP in plain C.
Speed differs between processors
Intel’s optimization manual lists PDEP with MUL and IMUL among the instructions of the one “slow integer” unit of Golden Cove (Table 2-4). AMD’s Zen 5 guide says that Zen 5 runs PDEP and PEXT natively in three of its ALUs, three per cycle with a latency of three cycles, and tells software that chooses between code for fast and slow PDEP to take the fast code there (Section 2.10.2).
PDEP belongs to BMI2, part of x86-64-v3; APX adds an EVEX form that reaches its new registers.
In the optimization guide
What the optimization guide says about PDEP, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Golden Cove and Raptor Cove
- Integer execution: Port 1 alone runs the slower integer operations: multiplication, PDEP and PEXT,
popcnt,bsr,crc32and the double shifts with an immediate count, which LLVM’s models give a latency of three cycles and one per cycle.
Skylake to Cooper Lake
- Integer execution: Port 1 alone runs integer multiplication, PDEP and PEXT,
popcnt,lzcnt,tzcnt,bsf,bsrand the double shifts, with a latency of three cycles and one a cycle in LLVM’s models, as on Golden Cove.
Zen and Zen+
- Integer execution: PDEP and PEXT are microcoded, in AMD’s spreadsheet and in LLVM’s model, though the core supports BMI2; code with a choice uses shifts and masks instead.
Zen 2
- Integer execution: PDEP and PEXT are microcoded, as in LLVM’s model, though CPUID reports BMI2; Zen 3 runs them on an ALU in three cycles.
Zen 3
- Integer execution: PDEP and PEXT run natively on ALU 1, one per cycle with a latency of three cycles; code with a separate path for processors where they are slow, such as Zen 2, should take the fast path.
Zen 4
- Integer execution: PDEP and PEXT run natively on one ALU, one per cycle with a latency of three cycles, against three per cycle on Zen 5; code with a separate path for processors where they are slow should take the fast path.
Zen 5
- Integer execution: PDEP and PEXT run natively, three per cycle with a latency of three cycles; code with a separate path for processors where they are slow should take the fast path.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
PDEP r32, r32, m32
PDEP_GPR32d_GPR32d_MEMd | VEX.LZ.F2.0F38.W0 F5 /r | BMI2 |
PDEP r32, r32, r32
PDEP_GPR32d_GPR32d_GPR32d | VEX.LZ.F2.0F38.W0 F5 /r | BMI2 |
PDEP r64, r64, m64 64-bit mode only
PDEP_GPR64q_GPR64q_MEMq | VEX.LZ.F2.0F38.W1 F5 /r | BMI2 |
PDEP r64, r64, r64 64-bit mode only
PDEP_GPR64q_GPR64q_GPR64q | VEX.LZ.F2.0F38.W1 F5 /r | BMI2 |
PDEP r32, r32, r32
PDEP_GPR32i32_GPR32i32_GPR32i32_APX | EVEX.LLZ.F2.0F38.W0 F5 /r | APX_F + BMI2 |
PDEP r32, r32, m32
PDEP_GPR32i32_GPR32i32_MEMi32_APX | EVEX.LLZ.F2.0F38.W0 F5 /r | APX_F + BMI2 |
PDEP r64, r64, r64
PDEP_GPR64i64_GPR64i64_GPR64i64_APX | EVEX.LLZ.F2.0F38.W1 F5 /r | APX_F + BMI2 |
PDEP r64, r64, m64
PDEP_GPR64i64_GPR64i64_MEMi64_APX | EVEX.LLZ.F2.0F38.W1 F5 /r | APX_F + BMI2 |
Latency and throughput
| Model | r32, r32, m32r64, r64, m64 | r32, r32, r32r64, r64, r64 |
|---|---|---|
| Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake, Alder Lake, Sapphire Rapids | 8 / 1p1 | 3 / 1p1 |
| Lunar Lake | 7 / 1.33p135 | 3 / 1p135 |
| Zen, Zen 2 | 100 / 0.25 | 100 / 0.25 |
| Zen 3, Zen 4 | 5 / 0.33ALU0 ALU1 ALU2 ALU3 | 3 / 1ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
s = src.read()
m = mask.read()
r = 0
k = 0 # the next bit of src, from bit 0 up
for i in range(OSIZE):
if m >> i & 1:
r |= (s >> k & 1) << i # to the place of the next 1 bit of mask
k += 1
dest.write(r) # a 32-bit register: bits 63:32 cleared
Run on AMD Zen 5 (EPYC 9645): 36 cases. The APX forms were not run: none of these processors has APX.
Operands
| Operand | Kind | Action |
|---|---|---|
PDEP r32, r32, r/m32 PDEP r64, r64, r/m64 64-bit mode only | ||
r32/64 | explicit | write |
r32/64 | explicit | read |
r/m32/64 | explicit | read |
Flags
None: XED records no flag that the forms test or change.
Exceptions
The exception class is XED's name for the set of exception conditions that a form follows. How to read.
- VEX forms
- none in XED
- EVEX forms
APX-EVEX-BMI
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to PDEP, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.
| Intrinsic | Compiles to |
|---|---|
_pdep_u32
unsigned int _pdep_u32(unsigned int __X, unsigned int __Y) |
|
_pdep_u64
unsigned long long _pdep_u64(unsigned long long __X, unsigned long long __Y) |
|
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 |
|---|---|---|
BMI2 | BMI2 | Haswell, Broadwell, Skylake, Comet Lake, Cannon Lake, Ice Lake (client), Tiger Lake, Alder Lake, Arrow Lake, Panther Lake, Nova Lake, Skylake-SP, Cascade Lake, Cooper Lake, Ice Lake (server), Sapphire Rapids, Emerald Rapids, Granite Rapids, Diamond Rapids, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6 |
APX_F_BMI2 | APX_F + BMI2 | Nova Lake, Diamond Rapids |
More BMI2 instructions
More APX 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. - Clang's x86 intrinsic headers, LLVM 23.1.2 (commit
85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them. - 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 2B, page 4-282 (PDEP)
- Intel Advanced Performance Extensions (Intel APX) Architecture Specification, revision 9.0 (355828-009, August 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, 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 intrinsics and their signatures come from Clang and the timings from LLVM's scheduling models, both part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.