Antkeeper
0.0.1
|
Bitwise math. More...
Functions | |
template<class T > | |
constexpr T | compress (T x) noexcept |
Compresses the even bits of a value into the lower half, then clears the upper half. More... | |
template<class T > | |
constexpr int | count (T x) noexcept |
Returns the number of set bits in a value, known as a population count or Hamming weight. More... | |
template<class T > | |
constexpr T | crossover (T a, T b, int i) noexcept |
Performs a single-point crossover between two values. More... | |
template<class T > | |
constexpr T | crossover_n (T a, T b, T mask) noexcept |
Performs an n-point crossover between two values. More... | |
template<class T > | |
constexpr T | deposit (T x, T mask) noexcept |
Reads bits from the least significant bits of a value and returns them in the positions marked by a mask. More... | |
template<class T > | |
constexpr T | desegregate (T x) noexcept |
Interleaves bits of the lower and upper halves of a value. More... | |
template<class T > | |
constexpr int | difference (T x, T y) noexcept |
Returns the number of differing bits between two values, known as Hamming distance. More... | |
template<class T > | |
constexpr T | expand (T x) noexcept |
Moves bits from the lower half of a value to occupy all even bits, and clears all odd bits. More... | |
template<class T > | |
constexpr T | extract (T x, T mask) noexcept |
Reads bits from a value in the positions marked by a mask and returns them in the least significant bits. More... | |
template<class T > | |
constexpr T | flip (T x, int i) noexcept |
Flips a single bit in a value. More... | |
template<class T , class U = T> | |
constexpr U | interleave (T a, T b) noexcept |
Returns a value with even bits containing the first value's lower half, and odd bits containing the second value's lower half. More... | |
template<class T > | |
constexpr T | merge (T a, T b, T mask) noexcept |
Merges the bits of two values using a bit mask. More... | |
template<class T > | |
constexpr T | parity (T x) noexcept |
Returns the parity of a value. More... | |
template<class T > | |
constexpr T | segregate (T x) noexcept |
Segregates the odd and even bits of a value. More... | |
template<class T > | |
constexpr T | swap_adjacent (T x) noexcept |
Swaps the each odd bit with its following even bit. More... | |
std::uint16_t | swap16 (std::uint16_t x) noexcept |
Swaps the byte order of an unsigned 16-bit number. More... | |
std::int16_t | swap16 (std::int16_t x) noexcept |
Swaps the byte order of a signed 16-bit number. More... | |
std::uint32_t | swap32 (std::uint32_t x) noexcept |
Swaps the byte order of an unsigned 32-bit number. More... | |
std::int32_t | swap32 (std::int32_t x) noexcept |
Swaps the byte order of a signed 32-bit number. More... | |
std::uint64_t | swap64 (std::uint64_t x) noexcept |
Swaps the byte order of an unsigned 64-bit number. More... | |
std::int64_t | swap64 (std::int64_t x) noexcept |
Swaps the byte order of a signed 64-bit number. More... | |
Bitwise math.
|
constexprnoexcept |
Compresses the even bits of a value into the lower half, then clears the upper half.
x | Value to compress. |
Definition at line 193 of file bit-math.hpp.
|
constexprnoexcept |
Returns the number of set bits in a value, known as a population count or Hamming weight.
x | Value to count. |
x
. Definition at line 211 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Performs a single-point crossover between two values.
a | First value. |
b | Second value. |
i | Index of the crossover point. |
Definition at line 220 of file bit-math.hpp.
|
constexprnoexcept |
Performs an n-point crossover between two values.
a | First value. |
b | Second value. |
mask | Bit mask with set bits marking crossover points. |
Definition at line 227 of file bit-math.hpp.
|
constexprnoexcept |
Reads bits from the least significant bits of a value and returns them in the positions marked by a mask.
x | Value from which bits should be read. |
mask | Bit mask indicating where bits should be deposited. |
x
in the positions marked by mask
. Definition at line 265 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Interleaves bits of the lower and upper halves of a value.
x | Value to desegregate. |
x
interleaved with bits from the lower half. Definition at line 241 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Returns the number of differing bits between two values, known as Hamming distance.
x | First value. |
y | Second value. |
y
. Definition at line 280 of file bit-math.hpp.
|
constexprnoexcept |
Moves bits from the lower half of a value to occupy all even bits, and clears all odd bits.
x | Value to expand. |
Definition at line 247 of file bit-math.hpp.
|
constexprnoexcept |
Reads bits from a value in the positions marked by a mask and returns them in the least significant bits.
x | Value from which bits should be read. |
mask | Bit mask indicating which bits to extract. |
x
from the positions marked by mask
in the least significant bits. Definition at line 286 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Flips a single bit in a value.
x | Value to modify. |
i | Index of the bit to flip. |
x
with one bit flipped. Definition at line 301 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Returns a value with even bits containing the first value's lower half, and odd bits containing the second value's lower half.
a | First value. |
b | Second value. |
a
and b
interleaved. Definition at line 307 of file bit-math.hpp.
|
inlineconstexprnoexcept |
Merges the bits of two values using a bit mask.
a | First value. |
b | Second value. |
mask | Bit mask with zeros where bits from a should be used, and ones where bits from b should be used. |
Definition at line 313 of file bit-math.hpp.
|
constexprnoexcept |
Returns the parity of a value.
x | Value to test. |
1
if an odd number of bits are set, 0
otherwise. Definition at line 319 of file bit-math.hpp.
|
constexprnoexcept |
Segregates the odd and even bits of a value.
x | Value to segregate. |
x
in the lower half, and odd bits in the upper half. Definition at line 334 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of a signed 16-bit number.
Definition at line 353 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of an unsigned 16-bit number.
Definition at line 348 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of a signed 32-bit number.
Definition at line 364 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of an unsigned 32-bit number.
Definition at line 358 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of a signed 64-bit number.
Definition at line 377 of file bit-math.hpp.
|
noexcept |
Swaps the byte order of an unsigned 64-bit number.
Definition at line 370 of file bit-math.hpp.
|
constexprnoexcept |
Swaps the each odd bit with its following even bit.
x | Value in which adjacent bits should be swap. |
x
with adjacent bits swapped. Definition at line 343 of file bit-math.hpp.