bitwise: slight improvements to documentation

This commit is contained in:
Danny Robson 2018-12-15 15:36:28 +11:00
parent b0311f9cd4
commit 6bcbaeb98e

View File

@ -18,24 +18,37 @@
namespace cruft {
///////////////////////////////////////////////////////////////////////////
/// Rotate `value` left by `magnitude` bits.
///
/// `magnitude` must not be greater than the bit count of `value`.
template <typename T>
constexpr T
rotatel [[gnu::pure]] (const T value, std::size_t magnitude)
{
CHECK_LE (magnitude, sizeof (value) * 8);
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>
constexpr T
rotater [[gnu::pure]] (const T value, std::size_t magnitude)
{
CHECK_LE (magnitude, sizeof (value) * 8);
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>
constexpr
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 <>
constexpr
uint8_t
@ -67,6 +82,7 @@ namespace cruft {
///////////////////////////////////////////////////////////////////////////
/// Calculates the number of bits that are set.
constexpr unsigned
popcount (unsigned t)
{
@ -74,7 +90,8 @@ namespace cruft {
}
//-------------------------------------------------------------------------
///------------------------------------------------------------------------
/// Calculates the number of bits that are set.
constexpr unsigned long
popcount (unsigned long t)
{
@ -82,7 +99,8 @@ namespace cruft {
}
//-------------------------------------------------------------------------
///------------------------------------------------------------------------
/// Calculates the number of bits that are set.
constexpr unsigned long long
popcount (unsigned long long t)
{