bitwise: slight improvements to documentation
This commit is contained in:
parent
b0311f9cd4
commit
6bcbaeb98e
26
bitwise.hpp
26
bitwise.hpp
@ -18,24 +18,37 @@
|
|||||||
|
|
||||||
namespace cruft {
|
namespace cruft {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Rotate `value` left by `magnitude` bits.
|
||||||
|
///
|
||||||
|
/// `magnitude` must not be greater than the bit count of `value`.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T
|
constexpr T
|
||||||
rotatel [[gnu::pure]] (const T value, std::size_t magnitude)
|
rotatel [[gnu::pure]] (const T value, std::size_t magnitude)
|
||||||
{
|
{
|
||||||
|
CHECK_LE (magnitude, sizeof (value) * 8);
|
||||||
|
|
||||||
return (value << magnitude) | (value >> (sizeof (value) * 8 - magnitude));
|
return (value << magnitude) | (value >> (sizeof (value) * 8 - magnitude));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///------------------------------------------------------------------------
|
||||||
|
/// Rotate `value` right by `magnitude` bits.
|
||||||
|
///
|
||||||
|
/// `magnitude` must not be greater than the bit count of `value`.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T
|
constexpr T
|
||||||
rotater [[gnu::pure]] (const T value, std::size_t magnitude)
|
rotater [[gnu::pure]] (const T value, std::size_t magnitude)
|
||||||
{
|
{
|
||||||
|
CHECK_LE (magnitude, sizeof (value) * 8);
|
||||||
|
|
||||||
return (value >> magnitude) | (value << (sizeof (value) * 8 - magnitude));
|
return (value >> magnitude) | (value << (sizeof (value) * 8 - magnitude));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// adapted from 'bit twiddling hacks'
|
/// Reverse the order of bits in the supplied value.
|
||||||
|
///
|
||||||
|
/// Adapted from 'bit twiddling hacks'
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr
|
constexpr
|
||||||
std::enable_if_t<std::is_integral<T>::value, T>
|
std::enable_if_t<std::is_integral<T>::value, T>
|
||||||
@ -56,7 +69,9 @@ namespace cruft {
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// adapted from 'bit twiddling hacks'
|
/// Reverse the order of bits in the supplied value.
|
||||||
|
///
|
||||||
|
/// Adapted from 'bit twiddling hacks'
|
||||||
template <>
|
template <>
|
||||||
constexpr
|
constexpr
|
||||||
uint8_t
|
uint8_t
|
||||||
@ -67,6 +82,7 @@ namespace cruft {
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Calculates the number of bits that are set.
|
||||||
constexpr unsigned
|
constexpr unsigned
|
||||||
popcount (unsigned t)
|
popcount (unsigned t)
|
||||||
{
|
{
|
||||||
@ -74,7 +90,8 @@ namespace cruft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
///------------------------------------------------------------------------
|
||||||
|
/// Calculates the number of bits that are set.
|
||||||
constexpr unsigned long
|
constexpr unsigned long
|
||||||
popcount (unsigned long t)
|
popcount (unsigned long t)
|
||||||
{
|
{
|
||||||
@ -82,7 +99,8 @@ namespace cruft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
///------------------------------------------------------------------------
|
||||||
|
/// Calculates the number of bits that are set.
|
||||||
constexpr unsigned long long
|
constexpr unsigned long long
|
||||||
popcount (unsigned long long t)
|
popcount (unsigned long long t)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user