GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc Performance Win

Adds __builtin_bitreverse{8,16,32,64} builtins.

GCC now provides built-in functions for bit reversal of 8, 16, 32, and 64-bit integers, potentially optimized for specific targets.

GCC now includes __builtin_bitreverse{8,16,32,64} built-in functions for reversing the order of bits in integer types. These builtins will be optimized for specific targets, such as ARM (RBIT instruction) and x86 with GFNI (vgf2p8affineqb instruction) in future work. The patch adds the builtins, handles constant folding, and adds documentation and test cases.

In Details

This commit introduces new built-in functions for bit reversal, integrated into GCC's middle-end and back-end. The changes involve modifications to builtin-types.def, builtins.def, builtins.cc, fold-const-call.cc, fold-const.cc, optabs.def, optabs.cc, tree-ssa-ccp.cc, and tree-ssa-phiopt.cc, adding new built-in function definitions and handling their expansion, constant folding, and optimization. The expand_bitreverse function in optabs.cc is responsible for expanding the builtins into target-specific instructions.

For Context

GCC's built-in functions provide direct access to common operations, often optimized for specific hardware. Bit reversal is an operation that reverses the order of bits in an integer (e.g., 0b101 becomes 0b101). These built-ins provide a portable and potentially efficient way to perform bit reversal, as the compiler can use specialized hardware instructions if available. This can be useful in cryptography, signal processing, and other domains.

Filed Under: builtinsbit manipulationoptimization