bitwise: add word halving query

This commit is contained in:
Danny Robson 2020-11-03 15:32:47 +10:00
parent 8f5604dde6
commit e1f18edacf

View File

@ -149,6 +149,29 @@ namespace cruft {
} }
///////////////////////////////////////////////////////////////////////////
namespace bits {
inline constexpr std::tuple<u32, u32> halve (u64 val)
{
return { val >> 32, val & 0xffffffff };
}
//-------------------------------------------------------------------------
inline constexpr std::tuple<u16, u16> halve (u32 val)
{
return { val >> 16, val & 0xffff };
}
//-------------------------------------------------------------------------
inline constexpr std::tuple<u08, u08> halve (u16 val)
{
return { val >> 8, val & 0xff };
}
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// returns the integral value composed of the bits from `val' in the /// returns the integral value composed of the bits from `val' in the
/// inclusive range [lo, hi]. /// inclusive range [lo, hi].