35template<
typename T>
inline constexpr int bitsofval(
const T& val)
36{ (void) val;
return sizeof(T) * 8; }
49template<ShiftOpRHS TW
idth,
typename TIntegral>
50requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
53 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
54 return TIntegral(~(TUnsigned(~TUnsigned(0)) << TWidth) );
67template<ShiftOpRHS TW
idth,
typename TIntegral>
68requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
69constexpr TIntegral
LowerMask() {
return TIntegral(~TIntegral(0)); }
84template<
typename TIntegral>
85requires std::integral<TIntegral>
88 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
89 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
90 return TIntegral(~(TUnsigned(~TUnsigned(0)) << width ));
105template<ShiftOpRHS TW
idth,
typename TIntegral>
106requires ( std::is_integral<TIntegral>::value && TWidth <
bitsof(TIntegral) )
109 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
110 return TIntegral((TUnsigned(~TUnsigned(0)) << TWidth));
122template<ShiftOpRHS TW
idth,
typename TIntegral>
123requires ( std::is_integral<TIntegral>::value && TWidth >=
bitsof(TIntegral) )
139template<
typename TIntegral>
140requires std::integral<TIntegral>
143 "Requested mask width wider than integral: {} >= {}", width,
bitsof(TIntegral) )
144 using TUnsigned=
typename std::make_unsigned<TIntegral>::type;
145 return TIntegral( (TUnsigned(~TUnsigned(0)) << width) );
162template<ShiftOpRHS TW
idth,
typename TIntegral>
163requires std::integral<TIntegral>
165 if constexpr ( TWidth >=
bitsof(TIntegral) )
182template<
typename TIntegral>
183requires std::integral<TIntegral>
196template<
typename TIntegral>
197requires std::integral<TIntegral>
200 static_assert(
bitsof(TIntegral) <= 128,
"Integrals larger than 128 are not supported.");
201 if constexpr (
bitsof(TIntegral) == 32)
return 5;
202 if constexpr (
bitsof(TIntegral) == 64)
return 7;
203 if constexpr (
bitsof(TIntegral) == 8)
return 3;
204 if constexpr (
bitsof(TIntegral) == 16)
return 4;
213template<
typename TIntegral>
214requires std::integral<TIntegral>
216{
return std::popcount(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) ); }
230template<
typename TIntegral>
231requires std::integral<TIntegral>
232constexpr int CLZ( TIntegral value ) {
233 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
235 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
237 return std::countl_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
249template<
typename TIntegral>
250requires std::integral<TIntegral>
251constexpr int CLZ0( TIntegral value) {
269template<
typename TIntegral>
270requires std::integral<TIntegral>
271constexpr int CTZ( TIntegral value ) {
273 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
274 return std::countr_zero(
static_cast<typename std::make_unsigned<TIntegral>::type
>( value ) );
286template<
typename TIntegral>
287requires std::integral<TIntegral>
288constexpr int CTZ0( TIntegral value ) {
312template<
typename TIntegral>
313requires std::integral<TIntegral>
314constexpr int MSB( TIntegral value) {
315 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
317 "Illegal value 0 passed to MSB(). Use MSB0() if 0 values need to be handled." )
330template<
typename TIntegral>
331requires std::integral<TIntegral>
332constexpr 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)