Skip to content

Commit

Permalink
Fix MSVC warnings (dup commit greg7mdp/parallel-hashmap@946ebad)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Sep 21, 2024
1 parent c2838fa commit f714be4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions include/gtl/bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,25 @@ GTL_FORCEINLINE uint32_t CountLeadingZeros64Slow(uint64_t n) {
zeroes -= 8, n >>= 8;
if (n >> 4)
zeroes -= 4, n >>= 4;
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
return (uint32_t)("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes);
}

GTL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
#if defined(_MSC_VER) && defined(_M_X64)
// MSVC does not have __buitin_clzll. Use _BitScanReverse64.
unsigned long result = 0; // NOLINT(runtime/int)
if (_BitScanReverse64(&result, n)) {
return (uint32_t)(63 - result);
return static_cast<uint32_t>(63 - result);
}
return 64;
#elif defined(_MSC_VER) && !defined(__clang__)
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
unsigned long result = 0; // NOLINT(runtime/int)
if ((n >> 32) && _BitScanReverse(&result, (unsigned long)(n >> 32))) {
return 31 - result;
return static_cast<uint32_t>(31 - result);
}
if (_BitScanReverse(&result, (unsigned long)n)) {
return 63 - result;
return static_cast<uint32_t>(63 - result);
}
return 64;
#elif defined(__GNUC__) || defined(__clang__)
Expand All @@ -299,9 +299,9 @@ GTL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
if (n == 0) {
return 64;
}
return __builtin_clzll(n);
return static_cast<uint32_t>(__builtin_clzll(n));
#else
return CountLeadingZeros64Slow(n);
return static_cast<uint32_t>(CountLeadingZeros64Slow(n));
#endif
}

Expand Down
12 changes: 10 additions & 2 deletions include/gtl/phmap_dump.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ class BinaryOutputArchive {
ofs_.open(file_path, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
}

~BinaryOutputArchive() = default;
BinaryOutputArchive(const BinaryOutputArchive&) = delete;
BinaryOutputArchive& operator=(const BinaryOutputArchive&) = delete;

bool saveBinary(const void* p, size_t sz) {
ofs_.write(reinterpret_cast<const char*>(p), sz);
ofs_.write(reinterpret_cast<const char*>(p), static_cast<std::streamsize>(sz));
return true;
}

Expand All @@ -206,8 +210,12 @@ class BinaryInputArchive {
public:
BinaryInputArchive(const char* file_path) { ifs_.open(file_path, std::ofstream::in | std::ofstream::binary); }

~BinaryInputArchive() = default;
BinaryInputArchive(const BinaryInputArchive&) = delete;
BinaryInputArchive& operator=(const BinaryInputArchive&) = delete;

bool loadBinary(void* p, size_t sz) {
ifs_.read(reinterpret_cast<char*>(p), sz);
ifs_.read(reinterpret_cast<char*>(p), static_cast<std::streamsize>(sz));
return true;
}

Expand Down

0 comments on commit f714be4

Please sign in to comment.