Skip to content

Commit

Permalink
please windows builder warnings + x86
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-cab committed Mar 5, 2024
1 parent 382f56d commit 4040fd7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/realm/array_direct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,28 @@ constexpr uint32_t inverse_width[65] = {
65536 * 64 / 61, 65536 * 64 / 62, 65536 * 64 / 63, 65536 * 64 / 64,
};

inline int first_field_marked(int width, uint64_t vector)
inline int countr_zero(unsigned long long vector)
{
#if REALM_WINDOWS
int lz = (int)_tzcnt_u64(vector); // TODO: not clear if this is ok on all platforms
unsigned long where;
#if defined(_WIN64)
if (_BitScanForward64(&where, vector))
return static_cast<int>(where);
return 0;
#elif defined(_WIN32)
if (_BitScanForward(&where, static_cast<unsigned long>(vector)))
return static_cast<int>(where);
else if (_BitScanForward(&where, static_cast<unsigned long>(vector >> 32)))
return static_cast<int>(where + 32);
return 0;
#else
int lz = __builtin_ctzll(vector);
where = __builtin_ctzll(vector);
return static_cast<int>(where);
#endif
}

inline int first_field_marked(int width, uint64_t vector)
{
const auto lz = countr_zero(vector);
int field = (lz * inverse_width[width]) >> 22;
REALM_ASSERT_DEBUG(field == (lz / width));
return field;
Expand Down

0 comments on commit 4040fd7

Please sign in to comment.