-
Notifications
You must be signed in to change notification settings - Fork 12
Plural right shift #91
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
base: master
Are you sure you want to change the base?
Changes from all commits
e82dbdd
54f30a3
657f659
a872b5c
8398c2f
d87f9c1
0740d8b
d8011c9
ad5ca7a
2b37cf8
26a5494
ca23a82
df27e45
54fdc03
a5b9ccb
9cd7c83
9e52623
a43259d
1e98db4
123c37c
65d03a0
91ffbaf
49dc069
98565d4
0fa63bd
0207738
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#ifndef ZOO_SWAR_ASSOCIATIVE_ITERATION_H | ||
#define ZOO_SWAR_ASSOCIATIVE_ITERATION_H | ||
|
||
#include "zoo/meta/BitmaskMaker.h" | ||
#include "zoo/swar/SWAR.h" | ||
#include <cstdint> | ||
|
||
//#define ZOO_DEVELOPMENT_DEBUGGING | ||
#ifdef ZOO_DEVELOPMENT_DEBUGGING | ||
|
@@ -260,7 +262,8 @@ template<int NB, typename B> | |
constexpr auto makeLaneMaskFromMSB(SWAR<NB, B> input) { | ||
using S = SWAR<NB, B>; | ||
auto msb = input & S{S::MostSignificantBit}; | ||
auto msbCopiedToLSB = S{msb.value() >> (NB - 1)}; | ||
B val = msb.value() >> (NB - 1); | ||
auto msbCopiedToLSB = S{val}; | ||
Comment on lines
+265
to
+266
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. Why this change? |
||
return impl::makeLaneMaskFromMSB_and_LSB(msb, msbCopiedToLSB); | ||
} | ||
|
||
|
@@ -392,8 +395,13 @@ template< | |
typename CountHalver | ||
> | ||
constexpr auto associativeOperatorIterated_regressive( | ||
Base base, Base neutral, IterationCount count, IterationCount forSquaring, | ||
Operator op, unsigned log2Count, CountHalver ch | ||
Base base, | ||
Base neutral, | ||
IterationCount count, | ||
IterationCount forSquaring, | ||
Operator op, | ||
unsigned log2Count, | ||
CountHalver ch | ||
) { | ||
auto result = neutral; | ||
if(!log2Count) { return result; } | ||
|
@@ -419,10 +427,12 @@ constexpr auto multiplication_OverflowUnsafe_SpecificBitCount( | |
|
||
auto halver = [](auto counts) { | ||
auto msbCleared = counts & ~S{S::MostSignificantBit}; | ||
return S{msbCleared.value() << 1}; | ||
T res = msbCleared.value() << 1; | ||
return S{res}; | ||
Comment on lines
+430
to
+431
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. Why so many unnecessary changes? 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. was getting seemingly random type errors. 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. will try and resolve |
||
}; | ||
|
||
multiplier = S{multiplier.value() << (NB - ActualBits)}; | ||
T val = multiplier.value() << (NB - ActualBits); | ||
multiplier = S{val}; | ||
return associativeOperatorIterated_regressive( | ||
multiplicand, S{0}, multiplier, S{S::MostSignificantBit}, operation, | ||
ActualBits, halver | ||
|
@@ -483,6 +493,34 @@ constexpr auto exponentiation_OverflowUnsafe_SpecificBitCount( | |
); | ||
} | ||
|
||
/** Transforms a binary number into it's unary representation (in binary). | ||
* E.g. 0b0011 (3) -> 0b0111 | ||
* It seems that getting the lane width exactly is overflowy */ | ||
template <typename S> | ||
constexpr auto binaryToUnary_Plural(S input) { | ||
constexpr auto two = S{meta::BitmaskMaker<typename S::type, 2, S::NBits>::value}; | ||
constexpr auto one = S::LeastSignificantBit; | ||
constexpr auto max_size = S::LeastSignificantLaneMask; | ||
typename S::type v = exponentiation_OverflowUnsafe_SpecificBitCount<S::NBits>(two, input).value() - one; | ||
return S{v}; | ||
} | ||
|
||
template <typename S> | ||
constexpr auto rightShift_Plural(S input, S shifts) { | ||
auto minimumMask = ~binaryToUnary_Plural(shifts); | ||
auto inputMasked = input.value() & minimumMask.value(); | ||
|
||
typename S::type result = 0; | ||
for (int i = 0; i < S::Lanes; i++) { | ||
auto laneMask = S::laneMask(i); | ||
auto currentShiftAmount = shifts.at(i); | ||
auto masked = inputMasked & laneMask; | ||
auto shifted = masked >> currentShiftAmount; | ||
result |= shifted; | ||
} | ||
return S{result}; | ||
} | ||
|
||
template<int NB, typename T> | ||
constexpr auto multiplication_OverflowUnsafe( | ||
SWAR<NB, T> multiplicand, | ||
|
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.
?