GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
middle-end Performance Win

Introduce __builtin_bitcompressg and __builtin_bitexpandg builtins

New builtins for std::bit_compress and std::bit_expand optimize bit manipulation operations.

This commit introduces new builtins, __builtin_bitcompressg and __builtin_bitexpandg, to optimize std::bit_compress and std::bit_expand. These builtins leverage target-specific instructions like x86 BMI2’s pext/pdep and SVE2’s bext/bdep for efficient bit manipulation. The implementation involves changes across various GCC components, including documentation, internal functions, and optimization tables.

In Details

This change adds internal functions and optimization tables for __builtin_bitcompressg and __builtin_bitexpandg. These builtins map to hardware instructions like PEXT/PDEP on x86 and BEXT/BDEP on SVE2, aiming to provide efficient implementations for bit manipulation. The implementation touches wide-int.cc and gimple-lower-bitint.cc, interacting with GIMPLE and RTL representations for optimization.

For Context
std::bit_compress
A C++ standard library function template that rearranges bits within a value based on a mask. It's part of the C++20 <bit> header.
std::bit_expand
A C++ standard library function template that expands bits from a value based on a mask. It's part of the C++20 <bit> header.
BMI2
An x86 instruction set extension that includes bit manipulation instructions such as PEXT (parallel bit deposit) and PDEP (parallel bit extract).
SVE2
Scalable Vector Extension 2, an extension to the Arm architecture that provides advanced vector processing capabilities, including bit manipulation instructions.
GIMPLE
GCC's internal three-address intermediate representation, used for high-level optimization passes.
RTL
Register Transfer Language, GCC's internal intermediate representation used for lower-level optimizations and machine code generation.
Filed Under: builtinoptimizationbit manipulation