Slides for P3104R3
Bit permutations
- Document number:
- P3730R0
- Date:
2025-06-04 - Audience:
- LEWG
- Project:
- ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
- Reply-to:
- Jan Schultke <janschultke@gmail.com>
- Source:
- github.com/Eisenwave/cpp-proposals/blob/master/src/bit-permutations-slides.cow
- →, ↓ : go to the next slide
- ←, ↑ : go to previous slide
Bit permutations
P3104R3
History
-
functions added by P0553R4: Bit operations (C++20)<bit> - simple utilities like
has_single_bit - instruction wrappers like
,rotl
,popcount
, …countl_zero
- simple utilities like
functions added by N3022: Modern Bit Utilities (C23)<stdbit.h> -
P3104R0 continues work on
<bit> - first seen in LEWGI at Tokyo 2024
- removal of some functions requested to increase consensus
- proposal minified twice since then; four function templates remain
Synopsis
is an unsigned integer type".
std :: bit_repeat
- repeats/broadcasts bit pattern with
inlength x - hardware support depends on
(> 0)length
bit_repeat ( 0b **** ' **** ' **** ' 0110 u , 4 ) │ ┌────┬────┬────┤ │ │ │ │== 0b 0110 ' 0110 ' 0110 ' 0110 u
std :: bit_reverse
- reverses the order of bits in
x - supported by
(ARM),rbit
(x86), …bswap
bit_reverse ( 0b 1000 ' 1111 ' 0000 ' 1010 u ) ┌───────────────┘│ ┌─────────────────┘ ││ …== 0b 0101 ' 0000 ' 1111 ' 0001 u
std :: bit_compress
- packs bits of
where the "mask"x
has a one-bit, contiguouslym - supported by
(ARM),bext
(x86)pext
unsigned m = 0b 0001 ' 0010 ' 0000 ' 1000 u ; bit_compress ( 0b ***1 ' **1* ' **** ' 0*** u , m ) │ │ └─┐ │ └────────┐│ └───────────┐││== 0b 0000 ' 0000 ' 0000 ' 0110 u
std :: bit_expand
- opposite of
std :: bit_compress - supported by
(ARM),bdep
(x86)pdep
unsigned m = 0b 0001 ' 0010 ' 0000 ' 1000 u ; bit_expand ( 0b **** ' **** ' **** ' *110 u , m ) ┌────────────┘││ │ ┌─────────┘│ │ │ ┌──┘== 0b 0001 ' 0010 ' 0000 ' 0000 u
_____________________________ < vote SF for bit permootations > ----------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\\ ||----w | || ||