35template<
typename T>
inline constexpr int bitsofval(
const T& val)
37 (void) val;
return sizeof(T) * 8;
51template<ShiftOpRHS TW
idth,
typename TIntegral>
52requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
56 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
57 return TIntegral(~(TUnsigned(~TUnsigned(0)) << TWidth) );
70template<ShiftOpRHS TW
idth,
typename TIntegral>
71requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
72constexpr TIntegral
LowerMask() {
return TIntegral(~TIntegral(0)); }
87template<
typename TIntegral>
88requires std::integral<TIntegral>
92 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
93 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
94 return TIntegral(~(TUnsigned(~TUnsigned(0)) << width ));
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));
126template<ShiftOpRHS TW
idth,
typename TIntegral>
127requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
143template<
typename TIntegral>
144requires std::integral<TIntegral>
148 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
149 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
150 return TIntegral( (TUnsigned(~TUnsigned(0)) << width) );
167template<ShiftOpRHS TW
idth,
typename TIntegral>
168requires std::integral<TIntegral>
171 if constexpr ( TWidth >=
bitsof(TIntegral) )
188template<
typename TIntegral>
189requires std::integral<TIntegral>
202template<
typename TIntegral>
203requires std::integral<TIntegral>
207 static_assert(
bitsof(TIntegral) <= 128,
"Integrals larger than 128 are not supported.");
208 if constexpr (
bitsof(TIntegral) == 32)
return 5;
209 if constexpr (
bitsof(TIntegral) == 64)
return 7;
210 if constexpr (
bitsof(TIntegral) == 8)
return 3;
211 if constexpr (
bitsof(TIntegral) == 16)
return 4;
220template<
typename TIntegral>
221requires std::integral<TIntegral>
223{
return std::popcount(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) ); }
237template<
typename TIntegral>
238requires std::integral<TIntegral>
239constexpr int CLZ( TIntegral value )
241 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
243 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
245 return std::countl_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
257template<
typename TIntegral>
258requires std::integral<TIntegral>
259constexpr int CLZ0( TIntegral value)
278template<
typename TIntegral>
279requires std::integral<TIntegral>
280constexpr int CTZ( TIntegral value )
283 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
284 return std::countr_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
296template<
typename TIntegral>
297requires std::integral<TIntegral>
298constexpr int CTZ0( TIntegral value )
323template<
typename TIntegral>
324requires std::integral<TIntegral>
325constexpr int MSB( TIntegral value)
327 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
329 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
342template<
typename TIntegral>
343requires std::integral<TIntegral>
344constexpr int MSB0( TIntegral value)
#define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond, domain,...)
constexpr int Log2OfSize()
constexpr int MSB(TIntegral value)
constexpr int CTZ0(TIntegral value)
constexpr int CLZ(TIntegral value)
constexpr TIntegral LowerBits(TIntegral value)
constexpr int bitsofval(const T &val)
constexpr TIntegral UpperMask()
constexpr int MSB0(TIntegral value)
constexpr int CLZ0(TIntegral value)
constexpr int CTZ(TIntegral value)
constexpr TIntegral LowerMask()
constexpr int BitCount(TIntegral value)