From eaa754622d4cd49567d25f595dffd1d83f7109cf Mon Sep 17 00:00:00 2001 From: Nicola Cabiddu Date: Tue, 5 Mar 2024 15:23:51 +0000 Subject: [PATCH] please windows builder warnings + x86 --- src/realm/array_direct.hpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/realm/array_direct.hpp b/src/realm/array_direct.hpp index ab011903627..5b2013f60e4 100644 --- a/src/realm/array_direct.hpp +++ b/src/realm/array_direct.hpp @@ -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(where); + return 64; +#elif defined(_WIN32) + if (_BitScanForward(&where, static_cast(vector))) + return static_cast(where); + if (_BitScanForward(&where, static_cast(vector >> 32))) + return static_cast(where + 32); + return 64; #else - int lz = __builtin_ctzll(vector); + where = __builtin_ctzll(vector); + return static_cast(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;