Skip to content

Commit 2dc1db6

Browse files
committed
Fix Windows build
1 parent c2346fa commit 2dc1db6

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

hexl/util/clang.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ inline uint64_t MultiplyUInt64Hi(uint64_t x, uint64_t y) {
5353
return static_cast<uint64_t>(product >> BitShift);
5454
}
5555

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

6161
#define HEXL_LOOP_UNROLL_4 _Pragma("clang loop unroll_count(4)")

hexl/util/gcc.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ inline uint64_t MultiplyUInt64Hi(uint64_t x, uint64_t y) {
5454
return static_cast<uint64_t>(product >> BitShift);
5555
}
5656

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

6262
#define HEXL_LOOP_UNROLL_4 _Pragma("GCC unroll 4")

hexl/util/msvc.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ inline uint64_t DivideUInt128UInt64Lo(const uint64_t numerator_hi,
267267
return quotient[0];
268268
}
269269

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

275277
#define HEXL_LOOP_UNROLL_4 \

test/test-number-theory.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ TEST(NumberTheory, MSB) {
428428
EXPECT_EQ(60ULL, MSB(2305843009213689601)); // 2**61 - 4351
429429
EXPECT_EQ(59ULL, MSB(1152921504606844417)); // 2**60 - 2559
430430
EXPECT_EQ(59ULL, MSB(1152921504606844289)); // 2**60 - 2687
431+
EXPECT_EQ(40ULL, MSB((1ULL << 40) + 1));
432+
EXPECT_EQ(40ULL, MSB(1ULL << 40));
433+
EXPECT_EQ(39ULL, MSB((1ULL << 40) - 1));
431434
EXPECT_EQ(8ULL, MSB(256));
432435
EXPECT_EQ(0ULL, MSB(1));
433436
}

0 commit comments

Comments
 (0)