Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
fboemer committed May 7, 2021
1 parent c2346fa commit 2dc1db6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions hexl/util/clang.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ inline uint64_t MultiplyUInt64Hi(uint64_t x, uint64_t y) {
return static_cast<uint64_t>(product >> BitShift);
}

// Returns maximum number of possible significant bits given modulus
inline uint64_t MSB(uint64_t modulus) {
return static_cast<uint64_t>(std::log2l(modulus));
// Returns most-significant bit of the input
inline uint64_t MSB(uint64_t input) {
return static_cast<uint64_t>(std::log2l(input));
}

#define HEXL_LOOP_UNROLL_4 _Pragma("clang loop unroll_count(4)")
Expand Down
6 changes: 3 additions & 3 deletions hexl/util/gcc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ inline uint64_t MultiplyUInt64Hi(uint64_t x, uint64_t y) {
return static_cast<uint64_t>(product >> BitShift);
}

// Returns maximum number of possible significant bits given modulus
inline uint64_t MSB(uint64_t modulus) {
return static_cast<uint64_t>(std::log2l(modulus));
// Returns most-significant bit of the input
inline uint64_t MSB(uint64_t input) {
return static_cast<uint64_t>(std::log2l(input));
}

#define HEXL_LOOP_UNROLL_4 _Pragma("GCC unroll 4")
Expand Down
8 changes: 5 additions & 3 deletions hexl/util/msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ inline uint64_t DivideUInt128UInt64Lo(const uint64_t numerator_hi,
return quotient[0];
}

// Returns maximum number of possible significant bits given modulus
inline uint64_t MSB(uint64_t modulus) {
return static_cast<uint64_t>(floorl(std::log2l(modulus)) - 1);
// Returns most-significant bit of the input
inline uint64_t MSB(uint64_t input) {
unsigned long index{0}; // NOLINT(runtime/int)
_BitScanReverse64(&index, input);
return index;
}

#define HEXL_LOOP_UNROLL_4 \
Expand Down
3 changes: 3 additions & 0 deletions test/test-number-theory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ TEST(NumberTheory, MSB) {
EXPECT_EQ(60ULL, MSB(2305843009213689601)); // 2**61 - 4351
EXPECT_EQ(59ULL, MSB(1152921504606844417)); // 2**60 - 2559
EXPECT_EQ(59ULL, MSB(1152921504606844289)); // 2**60 - 2687
EXPECT_EQ(40ULL, MSB((1ULL << 40) + 1));
EXPECT_EQ(40ULL, MSB(1ULL << 40));
EXPECT_EQ(39ULL, MSB((1ULL << 40) - 1));
EXPECT_EQ(8ULL, MSB(256));
EXPECT_EQ(0ULL, MSB(1));
}
Expand Down

0 comments on commit 2dc1db6

Please sign in to comment.