tetl 0.1.0
Embedded Template Library
|
Bit manipulation functions. More...
Enumerations | |
enum struct | endian { little = __ORDER_LITTLE_ENDIAN__ , big = __ORDER_BIG_ENDIAN__ , native = __BYTE_ORDER__ } |
Indicates the endianness of all scalar types. If all scalar types are little-endian, endian::native equals endian::little . If all scalar types are big-endian, endian::native equals endian::big . More... | |
Functions | |
template<typename To, typename From> requires detail::bitcastable<To, From> | |
constexpr auto | bit_cast (From const &src) noexcept -> To |
Obtain a value of type To by reinterpreting the object representation of from. Every bit in the value representation of the returned To object is equal to the corresponding bit in the object representation of from. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | bit_ceil (UInt x) noexcept -> UInt |
Calculates the smallest integral power of two that is not smaller than x. If that value is not representable in UInt, the behavior is undefined. Call to this function is permitted in constant evaluation only if the undefined behavior does not occur. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | bit_floor (UInt x) noexcept -> UInt |
If x is not zero, calculates the largest integral power of two that is not greater than x. If x is zero, returns zero. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | bit_width (UInt x) noexcept -> int |
If x is not zero, calculates the number of bits needed to store the value x, that is, 1+⌊log2(x)⌋. If x is zero, returns zero. | |
template<integral Int> | |
constexpr auto | byteswap (Int val) noexcept -> Int |
Reverses the bytes in the given integer value n. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | countl_one (UInt x) noexcept -> int |
Returns the number of consecutive 1 ("one") bits in the value of x, starting from the most significant bit ("left"). | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | countl_zero (UInt x) noexcept -> int |
Returns the number of consecutive 0 bits in the value of x, starting from the most significant bit ("left"). | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | countr_one (UInt x) noexcept -> int |
Returns the number of consecutive 1 bits in the value of x, starting from the least significant bit ("right"). | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | countr_zero (UInt x) noexcept -> int |
Returns the number of consecutive 0 bits in the value of x, starting from the least significant bit ("right"). | |
template<etl::size_t Pos, etl::builtin_unsigned_integer UInt> | |
constexpr auto | flip_bit (UInt word) noexcept -> UInt |
Flip bit at position Pos. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | flip_bit (UInt word, UInt pos) noexcept -> UInt |
Flip bit at position pos . | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | has_single_bit (UInt x) noexcept -> bool |
Checks if x is an integral power of two. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | popcount (UInt val) noexcept -> int |
Returns the number of 1 bits in the value of x. | |
template<etl::size_t Pos, etl::builtin_unsigned_integer UInt> | |
constexpr auto | reset_bit (UInt word) noexcept -> UInt |
Reset bit at position Pos. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | reset_bit (UInt word, UInt pos) noexcept -> UInt |
Reset bit at position pos . | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | rotl (UInt t, int s) noexcept -> UInt |
Computes the result of bitwise left-rotating the value of x by s positions. This operation is also known as a left circular shift. | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | rotr (UInt t, int s) noexcept -> UInt |
Computes the result of bitwise right-rotating the value of x by s positions. This operation is also known as a right circular shift. | |
template<etl::size_t Pos, etl::builtin_unsigned_integer UInt> | |
constexpr auto | set_bit (UInt word) noexcept -> UInt |
Set bit at position Pos | |
template<etl::size_t Pos, etl::builtin_unsigned_integer UInt> | |
constexpr auto | set_bit (UInt word, bool value) noexcept -> UInt |
Set bit at position Pos to value . | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | set_bit (UInt word, UInt pos) noexcept -> UInt |
Set bit at position pos . | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | set_bit (UInt word, UInt pos, bool value) -> UInt |
Set bit at position pos to value . | |
template<etl::size_t Pos, etl::builtin_unsigned_integer UInt> | |
constexpr auto | test_bit (UInt word) noexcept -> bool |
Test bit at position Pos | |
template<etl::builtin_unsigned_integer UInt> | |
constexpr auto | test_bit (UInt word, UInt pos) noexcept -> bool |
Test bit at position pos . | |
Bit manipulation functions.
|
strong |
Indicates the endianness of all scalar types. If all scalar types are little-endian, endian::native
equals endian::little
. If all scalar types are big-endian, endian::native
equals endian::big
.
https://en.cppreference.com/w/cpp/types/endian
Enumerator | |
---|---|
little | |
big | |
native |
|
constexprnoexcept |
Obtain a value of type To by reinterpreting the object representation of from. Every bit in the value representation of the returned To object is equal to the corresponding bit in the object representation of from.
The values of padding bits in the returned To object are unspecified. If there is no value of type To corresponding to the value representation produced, the behavior is undefined. If there are multiple such values, which value is produced is unspecified. This overload only participates in overload resolution if sizeof(To) == sizeof(From) and both To and From are TriviallyCopyable types.
|
nodiscardconstexprnoexcept |
Calculates the smallest integral power of two that is not smaller than x. If that value is not representable in UInt, the behavior is undefined. Call to this function is permitted in constant evaluation only if the undefined behavior does not occur.
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
If x is not zero, calculates the largest integral power of two that is not greater than x. If x is zero, returns zero.
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
If x is not zero, calculates the number of bits needed to store the value x, that is, 1+⌊log2(x)⌋. If x is zero, returns zero.
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Reverses the bytes in the given integer value n.
etl::byteswap participates in overload resolution only if Int satisfies integral, i.e., Int is an integer type. The program is ill-formed if Int has padding bits.
|
nodiscardconstexprnoexcept |
Returns the number of consecutive 1 ("one") bits in the value of x, starting from the most significant bit ("left").
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Returns the number of consecutive 0 bits in the value of x, starting from the most significant bit ("left").
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Returns the number of consecutive 1 bits in the value of x, starting from the least significant bit ("right").
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Returns the number of consecutive 0 bits in the value of x, starting from the least significant bit ("right").
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Flip bit at position Pos.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
|
nodiscardconstexprnoexcept |
Flip bit at position pos
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
pos
must be a valid bit-index for UInt
|
nodiscardconstexprnoexcept |
Checks if x is an integral power of two.
This overload only participates in overload resolution if T is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Returns the number of 1 bits in the value of x.
This overload only participates in overload resolution if UInt is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
|
nodiscardconstexprnoexcept |
Reset bit at position Pos.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
|
nodiscardconstexprnoexcept |
Reset bit at position pos
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
pos
must be a valid bit-index for UInt
|
constexprnoexcept |
Computes the result of bitwise left-rotating the value of x by s positions. This operation is also known as a left circular shift.
|
constexprnoexcept |
Computes the result of bitwise right-rotating the value of x by s positions. This operation is also known as a right circular shift.
|
nodiscardconstexprnoexcept |
Set bit at position Pos
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
|
nodiscardconstexprnoexcept |
Set bit at position Pos
to value
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
|
nodiscardconstexprnoexcept |
Set bit at position pos
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
pos
must be a valid bit-index for UInt
|
nodiscardconstexpr |
Set bit at position pos
to value
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
pos
must be a valid bit-index for UInt
|
nodiscardconstexprnoexcept |
Test bit at position Pos
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
|
nodiscardconstexprnoexcept |
Test bit at position pos
.
https://stackoverflow.com/questions/47981/how-to-set-clear-and-toggle-a-single-bit
pos
must be a valid bit-index for UInt