Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions inc/zoo/swar/SWAR.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ constexpr auto horizontalEquality(SWAR<NBits, T> left, SWAR<NBits, T> right) {
return left.m_v == right.m_v;
}

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sold on promoting this to the main header of swar.
This really seems to be an artifact of the "regressive" direction of "associative iteration", it does not cohere enough to the SWAR library itself.


#if ZOO_USE_LEASTNBITSMASK
Expand Down
6 changes: 2 additions & 4 deletions inc/zoo/swar/associative_iteration.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ constexpr auto multiplication_OverflowUnsafe_SpecificBitCount(
};

auto halver = [](auto counts) {
auto msbCleared = counts & ~S{S::MostSignificantBit};
return S{msbCleared.value() << 1};
return swar::consumeMSB(counts);
};

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

auto halver = [](auto counts) {
auto msbCleared = counts & ~S{S::MostSignificantBit};
return S{static_cast<T>(msbCleared.value() << 1)};
return swar::consumeMSB(counts);
};

return associativeOperatorIterated_regressive(
Expand Down
Loading