Skip to content

Commit 2214ac8

Browse files
committed
add consume msb
1 parent 2302504 commit 2214ac8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

inc/zoo/swar/SWAR.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ constexpr auto horizontalEquality(SWAR<NBits, T> left, SWAR<NBits, T> right) {
258258
return left.m_v == right.m_v;
259259
}
260260

261+
template <int NBits, typename T>
262+
constexpr static auto consumeMSB(SWAR<NBits, T> s) noexcept {
263+
using S = SWAR<NBits, T>;
264+
auto msbCleared = s & ~S{S::MostSignificantBit};
265+
return S{static_cast<T>(msbCleared.value() << 1)};
266+
}
261267

262268

263269
#if ZOO_USE_LEASTNBITSMASK

inc/zoo/swar/associative_iteration.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ constexpr auto multiplication_OverflowUnsafe_SpecificBitCount(
396396
};
397397

398398
auto halver = [](auto counts) {
399-
auto msbCleared = counts & ~S{S::MostSignificantBit};
400-
return S{msbCleared.value() << 1};
399+
return swar::consumeMSB(counts);
401400
};
402401

403402
auto shifted = S{multiplier.value() << (NB - ActualBits)};
@@ -539,8 +538,7 @@ constexpr auto saturatingExponentiation(
539538
};
540539

541540
auto halver = [](auto counts) {
542-
auto msbCleared = counts & ~S{S::MostSignificantBit};
543-
return S{static_cast<T>(msbCleared.value() << 1)};
541+
return swar::consumeMSB(counts);
544542
};
545543

546544
return associativeOperatorIterated_regressive(

0 commit comments

Comments
 (0)