-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Literals Utils #80
Changes from 1 commit
295d602
dbf8115
2327807
7c10d29
0b8b214
e3a802d
7ed6e88
03edd02
0648bb1
0d0a833
33183cd
1cba60e
8aa4ea5
2a383cb
1dc2d89
aabab90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,20 +81,19 @@ struct SWAR { | |
LowerBits = MostSignificantBit - LeastSignificantBit, | ||
MaxUnsignedLaneValue = LeastSignificantLaneMask; | ||
|
||
template <typename U, typename ManipulationFn> | ||
constexpr auto loadIntoLanes(const U (&values)[Lanes], const ManipulationFn&& manipulation) { | ||
template <typename U> | ||
constexpr auto loadIntoLanes(const U (&values)[Lanes]) const noexcept { | ||
auto result = T{0}; | ||
for (auto value : values) { | ||
auto laneValue = manipulation(value); | ||
result = (result << NBits) | laneValue; | ||
result = (result << NBits) | value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blitElement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I this does not quite blit the element, if it will move in an element, it shifts up what it got and then adds to the least significant lane |
||
} | ||
return result; | ||
} | ||
|
||
template <typename Arg, std::size_t N, typename = std::enable_if_t<N == Lanes, int>> | ||
constexpr | ||
SWAR(Literals_t<NBits, T>, const Arg (&values)[N]) | ||
: m_v{loadIntoLanes(values, [](auto x) { return x; })} {} | ||
: m_v{loadIntoLanes(values)} {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May you please indent to multiples of four spaces? |
||
|
||
SWAR() = default; | ||
constexpr explicit SWAR(T v): m_v(v) {} | ||
|
@@ -261,10 +260,8 @@ struct BooleanSWAR: SWAR<NBits, T> { | |
using Base = SWAR<NBits, T>; | ||
|
||
template <std::size_t N> | ||
constexpr BooleanSWAR(Literals_t<NBits, T>, const bool (&values)[N]) : Base{0} { | ||
constexpr auto msbOfFirstLane = T{1} << (NBits - 1); | ||
this->m_v = Base::loadIntoLanes(values, [](auto x) { return x ? msbOfFirstLane : 0; }); | ||
} | ||
constexpr BooleanSWAR(Literals_t<NBits, T>, const bool (&values)[N]) | ||
: Base(Literals<NBits, T>, values) { this->m_v <<= (NBits - 1); } | ||
|
||
// Booleanness is stored in the MSBs | ||
static constexpr auto MaskMSB = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to
from_array
. As the symmetrical operation toto_array
.Also, this is a factory, it ought to be
static
, a class-function, not instance.Actually, we also need a constructor from
std::array
.Apologies for all of the creep, I just think there is a lot of extra value by making
SWAR
a really ergonomic type as opposed to somewhat ergonomic.I dislike that C++ forces you to do a lot of boilerplate, I've never figured out how to make tools to eliminate the work to do the boilerplate.