Commit 389ce43b authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 8

Long is not long enough for a long long

Summary: Thus `1UL << 63 == 0` which is not the intended behavior.

Reviewed By: yfeldblum

Differential Revision: D3478480

fbshipit-source-id: a31dba7f5a503be2b34a4cb66bc7039076f158a0
parent 788ab800
...@@ -57,7 +57,7 @@ class FingerprintPolynomial { ...@@ -57,7 +57,7 @@ class FingerprintPolynomial {
// Multiply by X. The actual degree must be < DEG. // Multiply by X. The actual degree must be < DEG.
void mulX() { void mulX() {
CHECK_EQ(0, val_[0] & (1UL<<63)); CHECK_EQ(0, val_[0] & (1ULL<<63));
uint64_t b = 0; uint64_t b = 0;
for (int i = size()-1; i >= 0; i--) { for (int i = size()-1; i >= 0; i--) {
uint64_t nb = val_[i] >> 63; uint64_t nb = val_[i] >> 63;
...@@ -91,8 +91,8 @@ class FingerprintPolynomial { ...@@ -91,8 +91,8 @@ class FingerprintPolynomial {
// the binary representation of A, left shift by 1, // the binary representation of A, left shift by 1,
// XOR p if a_(k-1) == 1 // XOR p if a_(k-1) == 1
void mulXmod(const FingerprintPolynomial<DEG>& p) { void mulXmod(const FingerprintPolynomial<DEG>& p) {
bool needXOR = (val_[0] & (1UL<<63)); bool needXOR = (val_[0] & (1ULL<<63));
val_[0] &= ~(1UL<<63); val_[0] &= ~(1ULL<<63);
mulX(); mulX();
if (needXOR) { if (needXOR) {
add(p); add(p);
...@@ -112,7 +112,7 @@ class FingerprintPolynomial { ...@@ -112,7 +112,7 @@ class FingerprintPolynomial {
DCHECK_LE(k, DEG); DCHECK_LE(k, DEG);
int word_offset = (DEG - k) / 64; int word_offset = (DEG - k) / 64;
int bit_offset = 63 - (DEG - k) % 64; int bit_offset = 63 - (DEG - k) % 64;
val_[word_offset] ^= (1UL << bit_offset); val_[word_offset] ^= (1ULL << bit_offset);
} }
// Set the highest 8 bits to val. // Set the highest 8 bits to val.
......
...@@ -76,7 +76,7 @@ class SlowFingerprint { ...@@ -76,7 +76,7 @@ class SlowFingerprint {
void updateLSB(uint64_t val, int bits) { void updateLSB(uint64_t val, int bits) {
val <<= (64-bits); val <<= (64-bits);
for (; bits != 0; --bits) { for (; bits != 0; --bits) {
updateBit(val & (1UL << 63)); updateBit(val & (1ULL << 63));
val <<= 1; val <<= 1;
} }
} }
......
...@@ -107,7 +107,7 @@ TEST(Bits, FindLastSet) { ...@@ -107,7 +107,7 @@ TEST(Bits, FindLastSet) {
EXPECT_EQ(1024, nextPowTwoFunc(513u)); \ EXPECT_EQ(1024, nextPowTwoFunc(513u)); \
EXPECT_EQ(1024, nextPowTwoFunc(777u)); \ EXPECT_EQ(1024, nextPowTwoFunc(777u)); \
EXPECT_EQ(1ul << 31, nextPowTwoFunc((1ul << 31) - 1)); \ EXPECT_EQ(1ul << 31, nextPowTwoFunc((1ul << 31) - 1)); \
EXPECT_EQ(1ul << 32, nextPowTwoFunc((1ul << 32) - 1)); \ EXPECT_EQ(1ull << 32, nextPowTwoFunc((1ull << 32) - 1)); \
EXPECT_EQ(1ull << 63, nextPowTwoFunc((1ull << 62) + 1)); \ EXPECT_EQ(1ull << 63, nextPowTwoFunc((1ull << 62) + 1)); \
} }
......
...@@ -60,7 +60,7 @@ void testGroupVarint32(uint32_t a, uint32_t b, uint32_t c, uint32_t d, ...) { ...@@ -60,7 +60,7 @@ void testGroupVarint32(uint32_t a, uint32_t b, uint32_t c, uint32_t d, ...) {
// ssse3 decoding requires that the source buffer have length >= 17, // ssse3 decoding requires that the source buffer have length >= 17,
// so that it can read 128 bits from &start[1] via _mm_loadu_si128. // so that it can read 128 bits from &start[1] via _mm_loadu_si128.
foundBytes.resize(std::max(size + 4, 17UL)); foundBytes.resize(std::max<size_t>(size + 4, 17UL));
char* start = &(foundBytes.front()); char* start = &(foundBytes.front());
char* p = GroupVarint32::encode(start, a, b, c, d); char* p = GroupVarint32::encode(start, a, b, c, d);
EXPECT_EQ((void*)(start + size), (void*)p); EXPECT_EQ((void*)(start + size), (void*)p);
......
...@@ -63,7 +63,7 @@ BENCHMARK(RandomDouble) { doNotOptimizeAway(Random::randDouble01()); } ...@@ -63,7 +63,7 @@ BENCHMARK(RandomDouble) { doNotOptimizeAway(Random::randDouble01()); }
BENCHMARK(Random32) { doNotOptimizeAway(Random::rand32()); } BENCHMARK(Random32) { doNotOptimizeAway(Random::rand32()); }
BENCHMARK(Random32Num) { doNotOptimizeAway(Random::rand32(100)); } BENCHMARK(Random32Num) { doNotOptimizeAway(Random::rand32(100)); }
BENCHMARK(Random64) { doNotOptimizeAway(Random::rand64()); } BENCHMARK(Random64) { doNotOptimizeAway(Random::rand64()); }
BENCHMARK(Random64Num) { doNotOptimizeAway(Random::rand64(100ul << 32)); } BENCHMARK(Random64Num) { doNotOptimizeAway(Random::rand64(100ull << 32)); }
BENCHMARK(Random64OneIn) { doNotOptimizeAway(Random::oneIn(100)); } BENCHMARK(Random64OneIn) { doNotOptimizeAway(Random::oneIn(100)); }
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment