Skip to content

Commit

Permalink
Cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed May 25, 2021
1 parent badb6ee commit cbe157b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
6 changes: 3 additions & 3 deletions include/ewah/boolarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ template <class uword = uint32_t> class BoolArray {
void set(const size_t pos) {
if (pos >= sizeinbits)
padWithZeroes(pos + 1);
buffer[pos / wordinbits] |= (static_cast<uword>(1) << (pos % wordinbits));
buffer[pos / wordinbits] |= static_cast<uword>((static_cast<uword>(1) << (pos % wordinbits)));
}

/**
Expand Down Expand Up @@ -215,7 +215,7 @@ template <class uword = uint32_t> class BoolArray {
size_t upto = out.buffer.size() < ba.buffer.size() ? out.buffer.size()
: ba.buffer.size();
for (size_t i = 0; i < upto; ++i)
out.buffer[i] = buffer[i] & (~ba.buffer[i]);
out.buffer[i] = static_cast<uword>(buffer[i] & (~ba.buffer[i]));
for (size_t i = upto; i < out.buffer.size(); ++i)
out.buffer[i] = buffer[i];
out.clearBogusBits();
Expand Down Expand Up @@ -434,7 +434,7 @@ template <class uword = uint32_t> class BoolArray {
void clearBogusBits() {
if ((sizeinbits % wordinbits) != 0) {
const uword maskbogus =
(static_cast<uword>(1) << (sizeinbits % wordinbits)) - 1;
static_cast<uword>((static_cast<uword>(1) << (sizeinbits % wordinbits)) - 1);
buffer[buffer.size() - 1] &= maskbogus;
}
}
Expand Down
42 changes: 21 additions & 21 deletions include/ewah/ewah-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ template <class uword> class EWAHBoolArraySetBitForwardIterator {
}
wordPosition++; // point to first literal word
wordLength =
wordPosition + RunningLengthWord<uword>::getNumberOfLiteralWords(rlw);
static_cast<uword>(wordPosition + RunningLengthWord<uword>::getNumberOfLiteralWords(rlw));
}

inline bool moveToNext() {
Expand All @@ -212,7 +212,7 @@ template <class uword> class EWAHBoolArraySetBitForwardIterator {
if (runningHasNext())
return;
} else {
uword t = word & (~word + 1);
uword t = static_cast<uword>(word & (~word + 1));
answer = literalPosition + countOnes((uword)(t - 1));
word ^= t;
}
Expand Down Expand Up @@ -308,7 +308,7 @@ template <class uword> void EWAHBoolArray<uword>::inplace_logicalnot() {
if (sizeinbits % wordinbits != 0) {
RunningLengthWord<uword> rlw(buffer[lastrlw]);
const uword maskbogus =
(static_cast<uword>(1) << (sizeinbits % wordinbits)) - 1;
static_cast<uword>((static_cast<uword>(1) << (sizeinbits % wordinbits)) - 1);
if (rlw.getNumberOfLiteralWords() > 0) { // easy case
buffer[lastrlw + 1 + rlw.getNumberOfLiteralWords() - 1] &= maskbogus;
} else {
Expand Down Expand Up @@ -439,7 +439,7 @@ void EWAHBoolArray<uword>::logicalnot(EWAHBoolArray &x) const {
x.fastaddStreamOfEmptyWords(!rlw.getRunningBit(),
rlw.getRunningLength() - 1);
const uword maskbogus =
(static_cast<uword>(1) << (this->sizeinbits % wordinbits)) - 1;
static_cast<uword>((static_cast<uword>(1) << (this->sizeinbits % wordinbits)) - 1);
x.addLiteralWord(maskbogus);
break;
} else {
Expand All @@ -458,9 +458,9 @@ void EWAHBoolArray<uword>::logicalnot(EWAHBoolArray &x) const {
}
const uword maskbogus =
(this->sizeinbits % wordinbits != 0)
? (static_cast<uword>(1) << (this->sizeinbits % wordinbits)) - 1
? static_cast<uword>((static_cast<uword>(1) << (this->sizeinbits % wordinbits)) - 1)
: ~static_cast<uword>(0);
x.addLiteralWord((~dw[rlw.getNumberOfLiteralWords() - 1]) & maskbogus);
x.addLiteralWord(static_cast<uword>((~dw[rlw.getNumberOfLiteralWords() - 1]) & maskbogus));
break;
}
}
Expand Down Expand Up @@ -744,7 +744,7 @@ bool EWAHBoolArray<uword>::operator==(const EWAHBoolArray &x) const {
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k)
Expand Down Expand Up @@ -862,7 +862,7 @@ void EWAHBoolArray<uword>::appendSetBits(container &out,
for (uword k = 0; k < rlwlw; ++k) {
uword currentword = buffer[pointer];
while (currentword != 0) {
uint64_t t = currentword & -currentword;
uword t = static_cast<uword>(currentword & (~currentword+1));
uint32_t r = numberOfTrailingZeros(t);
out.push_back(currentoffset + r);
currentword ^= t;
Expand Down Expand Up @@ -1005,7 +1005,7 @@ size_t EWAHBoolArray<uword>::addStreamOfDirtyWords(const uword *v,
if (NumberOfLiteralWords + number <=
RunningLengthWord<uword>::largestliteralcount) {
RunningLengthWord<uword>::setNumberOfLiteralWords(
rlw, NumberOfLiteralWords + number);
rlw, static_cast<uword>(NumberOfLiteralWords + number));
buffer[lastRLW] = rlw;
sizeinbits += number * wordinbits;
buffer.insert(buffer.end(), v, v + number);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ void EWAHBoolArray<uword>::fastaddStreamOfDirtyWords(const uword *v,
if (NumberOfLiteralWords + number <=
RunningLengthWord<uword>::largestliteralcount) {
RunningLengthWord<uword>::setNumberOfLiteralWords(
rlw, NumberOfLiteralWords + number);
rlw, static_cast<uword>(NumberOfLiteralWords + number));
buffer[lastRLW] = rlw;
for (size_t i = 0; i < number; ++i)
buffer.push_back(v[i]);
Expand Down Expand Up @@ -1072,7 +1072,7 @@ size_t EWAHBoolArray<uword>::addStreamOfNegatedDirtyWords(const uword *v,
if (NumberOfLiteralWords + number <=
RunningLengthWord<uword>::largestliteralcount) {
RunningLengthWord<uword>::setNumberOfLiteralWords(
rlw, NumberOfLiteralWords + number);
rlw, static_cast<uword>(NumberOfLiteralWords + number));
buffer[lastRLW] = rlw;
sizeinbits += number * wordinbits;
for (size_t k = 0; k < number; ++k)
Expand Down Expand Up @@ -1218,7 +1218,7 @@ void EWAHBoolArray<uword>::logicalor(const EWAHBoolArray &a,
predator.discardRunningWordsWithReload();
}

const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ size_t EWAHBoolArray<uword>::logicalorcount(const EWAHBoolArray &a) const {
predator.discardRunningWordsWithReload();
}

const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ void EWAHBoolArray<uword>::logicalxor(const EWAHBoolArray &a,
predator.getRunningLength() - index);
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k)
Expand Down Expand Up @@ -1356,7 +1356,7 @@ size_t EWAHBoolArray<uword>::logicalxorcount(const EWAHBoolArray &a) const {

predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1406,7 +1406,7 @@ void EWAHBoolArray<uword>::logicaland(const EWAHBoolArray &a,
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1469,11 +1469,11 @@ void EWAHBoolArray<uword>::logicalandnot(const EWAHBoolArray &a,
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
container.addWord(rlwi.getLiteralWordAt(k) & ~rlwj.getLiteralWordAt(k));
container.addWord(static_cast<uword>(rlwi.getLiteralWordAt(k) & ~rlwj.getLiteralWordAt(k)));
}
rlwi.discardLiteralWordsWithReload(nbre_literal);
rlwj.discardLiteralWordsWithReload(nbre_literal);
Expand Down Expand Up @@ -1524,7 +1524,7 @@ size_t EWAHBoolArray<uword>::logicalandnotcount(const EWAHBoolArray &a) const {
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1567,7 +1567,7 @@ size_t EWAHBoolArray<uword>::logicalandcount(const EWAHBoolArray &a) const {
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down Expand Up @@ -1608,7 +1608,7 @@ bool EWAHBoolArray<uword>::intersects(const EWAHBoolArray &a) const {
}
predator.discardRunningWordsWithReload();
}
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
const uword nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),
rlwj.getNumberOfLiteralWords());
if (nbre_literal > 0) {
for (size_t k = 0; k < nbre_literal; ++k) {
Expand Down
14 changes: 7 additions & 7 deletions include/ewah/runninglengthword.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
size_t pd = getNumberOfLiteralWords();
if (pd > 0)
return true;
discardFirstWordsWithReload(pl + pd);
discardFirstWordsWithReload(static_cast<uword>(pl + pd));
}
return false;
}
Expand All @@ -352,7 +352,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
if (index + RunningLength > max) {
const size_t offset = max - index;
container.fastaddStreamOfEmptyWords(getRunningBit(), offset);
RunningLength -= offset;
RunningLength = static_cast<uword>(RunningLength - offset);
return max;
}
container.fastaddStreamOfEmptyWords(getRunningBit(), RunningLength);
Expand All @@ -361,7 +361,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
const size_t offset = max - index;
writeLiteralWords(offset, container);
RunningLength = 0;
NumberOfLiteralWords -= offset;
NumberOfLiteralWords = static_cast<uword>(NumberOfLiteralWords - offset);
return max;
}
writeLiteralWords(NumberOfLiteralWords, container);
Expand Down Expand Up @@ -389,7 +389,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
}
if (pd > 0)
return true;
discardFirstWordsWithReload(pl + pd);
discardFirstWordsWithReload(static_cast<uword>(pl + pd));
}
return false;
}
Expand All @@ -411,7 +411,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
pd = max - index;
}
writeNegatedLiteralWords(pd, container);
discardFirstWordsWithReload(pl + pd);
discardFirstWordsWithReload(static_cast<uword>(pl + pd));
index += pd;
}
return index;
Expand All @@ -432,7 +432,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
}
if (pd > 0)
return true;
discardFirstWordsWithReload(pl + pd);
discardFirstWordsWithReload(static_cast<uword>(pl + pd));
index += pd;
}
return false;
Expand Down Expand Up @@ -532,7 +532,7 @@ template <class uword = uint32_t> class BufferedRunningLengthWord {
size_t toDiscard = x > NumberOfLiteralWords ? NumberOfLiteralWords : x;
NumberOfLiteralWords =
static_cast<uword>(NumberOfLiteralWords - toDiscard);
x -= toDiscard;
x = static_cast<uword>(x - toDiscard);
if ((x > 0) || (size() == 0)) {
if (!next())
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function(add_cpp_test TEST_NAME)
if(NOT MSVC)
target_compile_options(
${TEST_NAME} PUBLIC
-Werror -Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings
-Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings
-Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion
)
endif()
Expand Down
19 changes: 11 additions & 8 deletions tests/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,14 +1454,17 @@ template <class uword> bool dataindexingtest(std::string path) {
return true;
}

typedef struct {
EWAHBoolArray<uint32_t> gpr[32][4];
} vcpu_ctx;

typedef struct {
vcpu_ctx vcpu;
void *uval;
} thread_ctx_t;
struct vcpu_ctx {
EWAHBoolArray<uint32_t> gpr[32][4]{};
};

struct thread_ctx_t {
thread_ctx_t() = default;
thread_ctx_t(const thread_ctx_t& t) = delete;
thread_ctx_t& operator=(const thread_ctx_t&) = delete;
vcpu_ctx vcpu{};
void *uval{nullptr};
};

bool funnytest() {
cout << "[funnytest] checking funnytest" << endl;
Expand Down

0 comments on commit cbe157b

Please sign in to comment.