35template<
typename T>
inline constexpr int bitsofval(
const T& val)
36{ (void) val;
return sizeof(T) * 8; }
52template<ShiftOpRHS TW
idth,
typename TIntegral>
55template<ShiftOpRHS TW
idth,
typename TIntegral>
56requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
59 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
60 return TIntegral(~(TUnsigned(~TUnsigned(0)) << TWidth) );
64template<ShiftOpRHS TW
idth,
typename TIntegral>
65requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
66constexpr TIntegral
LowerMask() {
return TIntegral(~TIntegral(0)); }
82template<
typename TIntegral>
83requires std::integral<TIntegral>
86 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
87 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
88 return TIntegral(~(TUnsigned(~TUnsigned(0)) << width ));
105template<ShiftOpRHS TW
idth,
typename TIntegral>
106requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
109template<ShiftOpRHS TW
idth,
typename TIntegral>
110requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
113 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
114 return TIntegral((TUnsigned(~TUnsigned(0)) << TWidth));
117template<ShiftOpRHS TW
idth,
typename TIntegral>
118requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
119constexpr TIntegral
UpperMask() {
return TIntegral(0); }
134template<
typename TIntegral>
135requires std::integral<TIntegral>
138 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
139 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
140 return TIntegral( (TUnsigned(~TUnsigned(0)) << width) );
157template<ShiftOpRHS TW
idth,
typename TIntegral>
158requires std::integral<TIntegral>
160 if constexpr ( TWidth >=
bitsof(TIntegral) )
177template<
typename TIntegral>
178requires std::integral<TIntegral>
191template<
typename TIntegral>
192requires std::integral<TIntegral>
195 static_assert(
bitsof(TIntegral) <= 128,
"Integrals larger than 128 are not supported.");
196 if constexpr (
bitsof(TIntegral) == 32)
return 5;
197 if constexpr (
bitsof(TIntegral) == 64)
return 7;
198 if constexpr (
bitsof(TIntegral) == 8)
return 3;
199 if constexpr (
bitsof(TIntegral) == 16)
return 4;
208template<
typename TIntegral>
209requires std::integral<TIntegral>
211{
return std::popcount(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) ); }
225template<
typename TIntegral>
226requires std::integral<TIntegral>
227constexpr int CLZ( TIntegral value ) {
228 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
230 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
232 return std::countl_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
244template<
typename TIntegral>
245requires std::integral<TIntegral>
246constexpr int CLZ0( TIntegral value) {
264template<
typename TIntegral>
265requires std::integral<TIntegral>
266constexpr int CTZ( TIntegral value ) {
268 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
269 return std::countr_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
281template<
typename TIntegral>
282requires std::integral<TIntegral>
283constexpr int CTZ0( TIntegral value ) {
307template<
typename TIntegral>
308requires std::integral<TIntegral>
309constexpr int MSB( TIntegral value) {
310 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
312 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
325template<
typename TIntegral>
326requires std::integral<TIntegral>
327constexpr int MSB0( TIntegral value) {
#define ALIB_ALLOW_INTEGRAL_CONSTANT_OVERFLOW
#define ALIB_POP_ALLOWANCE
#define ALIB_ASSERT_ERROR(cond, domain,...)
constexpr TIntegral LowerMask()
constexpr int Log2OfSize()
constexpr int BitCount(TIntegral value)
constexpr int bitsofval(const T &val)
constexpr int CLZ0(TIntegral value)
constexpr int MSB0(TIntegral value)
constexpr int CTZ(TIntegral value)
constexpr int MSB(TIntegral value)
constexpr int CTZ0(TIntegral value)
constexpr int CLZ(TIntegral value)
constexpr TIntegral LowerBits(TIntegral value)
constexpr TIntegral UpperMask()