mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
73 lines
3.5 KiB
Plaintext
73 lines
3.5 KiB
Plaintext
Bit
|
|
Utility functions for manipulating binary numbers.
|
|
A reverse engineered version of C++20's and C++23's <bit> header.
|
|
|
|
ETL_CONSTEXPR14 = constexpr for C++14 or above
|
|
____________________________________________________________________________________________________
|
|
bit_cast
|
|
template <typename TDestination, typename TSource>>
|
|
ETL_CONSTEXPR14 TDestination bit_cast(const TSource& source) ETL_NOEXCEPT
|
|
Returns a value of type TDestination by reinterpreting the TSource object.
|
|
____________________________________________________________________________________________________
|
|
byteswap
|
|
template <typename T>
|
|
ETL_CONSTEXPR14 T byteswap(T n) ETL_NOEXCEPT
|
|
Reverses the bytes in n.
|
|
____________________________________________________________________________________________________
|
|
has_single_bit
|
|
template <typename T>
|
|
ETL_CONSTEXPR14 bool has_single_bit(T n) ETL_NOEXCEPT
|
|
Checks if n is a power of two, or has one bit set.
|
|
____________________________________________________________________________________________________
|
|
bit_ceil
|
|
template <typename T>
|
|
ETL_CONSTEXPR14 T bit_ceil(T n);
|
|
Calculates the smallest power of two, that is not smaller than n.
|
|
____________________________________________________________________________________________________
|
|
bit_floor
|
|
template <typename T>
|
|
ETL_CONSTEXPR14 T bit_floor(T n) ETL_NOEXCEPT
|
|
Calculates the smallest power of two, that is not greater than n.
|
|
____________________________________________________________________________________________________
|
|
bit_width
|
|
template <typename T>
|
|
ETL_CONSTEXPR14 T bit_width(T n) ETL_NOEXCEPT
|
|
If n is not 0, calculates the number of bits needed to store it.
|
|
If n is 0, then the result is 0.
|
|
____________________________________________________________________________________________________
|
|
rotl
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 T rotl(T value, int n) ETL_NOEXCEPT
|
|
Computes a left circular shift of value by n.
|
|
____________________________________________________________________________________________________
|
|
rotr
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 T rotr(T value, int n) ETL_NOEXCEPT
|
|
Computes a right circular shift of value by n.
|
|
____________________________________________________________________________________________________
|
|
countl_zero
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 int countl_zero(T value) ETL_NOEXCEPT
|
|
Returns the number of consecutive 0 bits in n, starting from the most significant bit (left).
|
|
____________________________________________________________________________________________________
|
|
countl_one
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 int countl_one(T value) ETL_NOEXCEPT
|
|
Returns the number of consecutive 1 bits in n, starting from the most significant bit (left).
|
|
____________________________________________________________________________________________________
|
|
countr_zero
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 int countr_zero(T value) ETL_NOEXCEPT
|
|
Returns the number of consecutive 0 bits in n, starting from the least significant bit (right).
|
|
____________________________________________________________________________________________________
|
|
countr_one
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 int countr_one(T value) ETL_NOEXCEPT
|
|
Returns the number of consecutive 1 bits in n, starting from the least significant bit (right).
|
|
____________________________________________________________________________________________________
|
|
popcount
|
|
template <typename T>
|
|
ETL_NODISCARD ETL_CONSTEXPR14 int popcount(T value) ETL_NOEXCEPT
|
|
Counts the number of 1 bits in an unsigned integer.
|
|
|