Feature gate: #![feature(uint_gather_scatter_bits)]
This is a tracking issue for two functions that operate on masked bits: extract_bits consolidates masked bits into the least significant bits of an integer, and deposit_bits distributes bits from the least significant bits of an integer to the bits specified by a mask.
The functions are implemented on unsigned integers and correspond to the hardware instructions known on some platforms as "bit extract" and "bit deposit" (PEXT/PDEP).
Public API
impl uint { pub const fn extract_bits(self, mask: Self) -> Self; pub const fn deposit_bits(self, mask: Self) -> Self; }
Steps / History
- ACP: ACP: Add functions for "compress bits" and "expand bits" to unsigned integers libs-team#695
- Implementation: num: Implement
uint_gather_scatter_bitsfeature for unsigned integers #149097- Additional test for uN::{gather,scatter}_bits #149539
- Implement benchmarks for uN::{gather,scatter}_bits #149610
- Optimized implementation for uN::{gather,scatter}_bits #149663
- rename uN::{gather,scatter}_bits to uN::{extract,deposit}_bits #151669
- Add pext/pdep as aliases for extract_bits/deposit_bits #156606
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- No stabilization before the existence of explicit LLVM support:
As of November 2025, there is currently no LLVM intrinsic to guarantee that the code generated is optimal for the target or generates the target architecture instruction if present and the target feature is specified.This is a roadblock for stabilization. Update(2026-June): LLVM intrinsics are implemented, waiting for next LLVM bump before we can use them. Naming: The libs team prefersThe functions have been renamed according to the libs decision in Tracking Issue forgather/scatter_bitswhile that is at odds with how SIMD instructions use the termsgather/scatter. ACP: Add functions for "compress bits" and "expand bits" to unsigned integers libs-team#695 (comment):...by analogy to SIMD, SIMD gather/scatter allows you to arbitrarily reorder elements (it is a fully-general load/store to independently-determined addresses for each element), whereas SIMD compress/expand does not allow reordering the loaded/stored elements, just inserting/removing elements.
uint_gather_scatter_bits#149069 (comment)