Skip to content

Commit

Permalink
Fix missing _BitScanForward64 on Windows x86
Browse files Browse the repository at this point in the history
Fixes #220.
  • Loading branch information
foonathan committed Jan 7, 2025
1 parent 0bce9a7 commit 21728ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/lexy/_detail/swar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ constexpr std::size_t swar_find_difference(swar_int lhs, swar_int rhs)

#if defined(__GNUC__)
auto bit_idx = __builtin_ctzll(mask);
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && defined(_WIN64)
unsigned long bit_idx;
if (!_BitScanForward64(&bit_idx, mask))
bit_idx = 64;
_BitScanForward64(&bit_idx, mask);
#elif defined(_MSC_VER)
unsigned long bit_idx = 0;
if (!_BitScanForward(&bit_idx, static_cast<std::uint32_t>(mask))
&& _BitScanForward(&bit_idx, mask >> 32))
bit_idx += 32;
#else
# error "unsupported compiler; please file an issue"
#endif
Expand Down
1 change: 1 addition & 0 deletions tests/lexy/detail/swar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TEST_CASE("swar_find_difference")
CHECK(swar_find_difference<char>(a, a) == 8);
CHECK(swar_find_difference<char>(a, A) == 0);
CHECK(swar_find_difference<char>(abc, aBc) == 1);
CHECK(swar_find_difference<char>(0x1'FFFF'FFFF, 0x2'FFFF'FFFF) == 4);
}

TEST_CASE("swar_has_zero")
Expand Down

0 comments on commit 21728ab

Please sign in to comment.