Long is not long enough for a long long
authorChristopher Dykes <cdykes@fb.com>
Fri, 1 Jul 2016 01:11:51 +0000 (18:11 -0700)
committerFacebook Github Bot 8 <facebook-github-bot-8-bot@fb.com>
Fri, 1 Jul 2016 01:24:13 +0000 (18:24 -0700)
Summary: Thus `1UL << 63 == 0` which is not the intended behavior.

Reviewed By: yfeldblum

Differential Revision: D3478480

fbshipit-source-id: a31dba7f5a503be2b34a4cb66bc7039076f158a0

folly/detail/FingerprintPolynomial.h
folly/detail/SlowFingerprint.h
folly/test/BitsTest.cpp
folly/test/GroupVarintTest.cpp
folly/test/RandomBenchmark.cpp

index 588ae7574efd5f5b03ea4d56f993d56af8f667fd..fd927dcbd3e0cec0c7461999124b73f0185912a3 100644 (file)
@@ -57,7 +57,7 @@ class FingerprintPolynomial {
 
   // Multiply by X.  The actual degree must be < DEG.
   void mulX() {
-    CHECK_EQ(0, val_[0] & (1UL<<63));
+    CHECK_EQ(0, val_[0] & (1ULL<<63));
     uint64_t b = 0;
     for (int i = size()-1; i >= 0; i--) {
       uint64_t nb = val_[i] >> 63;
@@ -91,8 +91,8 @@ class FingerprintPolynomial {
   //   the binary representation of A, left shift by 1,
   //   XOR p if a_(k-1) == 1
   void mulXmod(const FingerprintPolynomial<DEG>& p) {
-    bool needXOR = (val_[0] & (1UL<<63));
-    val_[0] &= ~(1UL<<63);
+    bool needXOR = (val_[0] & (1ULL<<63));
+    val_[0] &= ~(1ULL<<63);
     mulX();
     if (needXOR) {
       add(p);
@@ -112,7 +112,7 @@ class FingerprintPolynomial {
     DCHECK_LE(k, DEG);
     int word_offset = (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.
index 1bbbda61bba607853482f4f209047ca26b7b8a78..9e0b276ab6f28affaedff9ca8c92eebdcc497fe2 100644 (file)
@@ -76,7 +76,7 @@ class SlowFingerprint {
   void updateLSB(uint64_t val, int bits) {
     val <<= (64-bits);
     for (; bits != 0; --bits) {
-      updateBit(val & (1UL << 63));
+      updateBit(val & (1ULL << 63));
       val <<= 1;
     }
   }
index b5cf43be600cb1a0b7d1759505ca26984d52642b..d277f9d82a9fc0c59a01a1318ba30dd70b3c3998 100644 (file)
@@ -107,7 +107,7 @@ TEST(Bits, FindLastSet) {
   EXPECT_EQ(1024, nextPowTwoFunc(513u));                          \
   EXPECT_EQ(1024, nextPowTwoFunc(777u));                          \
   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));        \
 }
 
index 102c2f35924c73b8b7bf546da4be333a92d00de1..fa3bc117beea59f621fd0be6b041939559891f43 100644 (file)
@@ -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,
   // 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* p = GroupVarint32::encode(start, a, b, c, d);
   EXPECT_EQ((void*)(start + size), (void*)p);
index cc17e5ee2ad9fe6e9030c429fb83b9281618f1c0..14a0edb3d5e822d3408c15ebbc7506ee8bf249a7 100644 (file)
@@ -63,7 +63,7 @@ BENCHMARK(RandomDouble) { doNotOptimizeAway(Random::randDouble01()); }
 BENCHMARK(Random32) { doNotOptimizeAway(Random::rand32()); }
 BENCHMARK(Random32Num) { doNotOptimizeAway(Random::rand32(100)); }
 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)); }
 
 int main(int argc, char** argv) {