diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 0d48c911..89d79dae 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -261,12 +261,20 @@ private: 0xF8F8F8F8u,0xF9F9F9F9u,0xFAFAFAFAu,0xFBFBFBFBu,0xFCFCFCFCu,0xFDFDFDFDu,0xFEFEFEFEu,0xFFFFFFFFu, }; +#if defined(__MSVC_RUNTIME_CHECKS) + return (int)word[hash&0xffu]; +#else return (int)word[(unsigned char)hash]; +#endif } inline static unsigned char reduced_hash(std::size_t hash) { +#if defined(__MSVC_RUNTIME_CHECKS) + return match_word(hash)&0xffu; +#else return (unsigned char)match_word(hash); +#endif } inline unsigned char& at(std::size_t pos) @@ -517,7 +525,11 @@ struct group15 std::size_t pos=reinterpret_cast(pc)%sizeof(group15); group15 *pg=reinterpret_cast(pc-pos); boost::uint64_t x=((pg->m[0])>>pos)&0x000100010001ull; +#if defined(__MSVC_RUNTIME_CHECKS) + boost::uint32_t y=(x|(x>>15)|(x>>30))&0xffffffffu; +#else boost::uint32_t y=static_cast(x|(x>>15)|(x>>30)); +#endif return !pg->is_not_overflowed(y); }; @@ -532,7 +544,11 @@ struct group15 inline int match_occupied()const { boost::uint64_t x=m[0]|m[1]; +#if defined(__MSVC_RUNTIME_CHECKS) + boost::uint32_t y=(x|(x>>32))&0xffffffffu; +#else boost::uint32_t y=static_cast(x|(x>>32)); +#endif y|=y>>16; return y&0x7FFF; } @@ -567,7 +583,11 @@ private: 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, }; +#if defined(__MSVC_RUNTIME_CHECKS) + return table[hash&0xffu]; +#else return table[(unsigned char)hash]; +#endif } inline void set_impl(std::size_t pos,std::size_t n) @@ -994,6 +1014,7 @@ void swap_if(T&,T&){} inline void prefetch(const void* p) { + (void) p; #if defined(BOOST_GCC)||defined(BOOST_CLANG) __builtin_prefetch((const char*)p); #elif defined(BOOST_UNORDERED_SSE2) diff --git a/include/boost/unordered/detail/prime_fmod.hpp b/include/boost/unordered/detail/prime_fmod.hpp index 885c071b..4c538487 100644 --- a/include/boost/unordered/detail/prime_fmod.hpp +++ b/include/boost/unordered/detail/prime_fmod.hpp @@ -117,9 +117,15 @@ namespace boost { #if defined(BOOST_UNORDERED_FCA_HAS_64B_SIZE_T) std::size_t sizes_under_32bit = inv_sizes32_len; if (BOOST_LIKELY(size_index < sizes_under_32bit)) { +#if defined(__MSVC_RUNTIME_CHECKS) + return fast_modulo( + boost::uint32_t(hash & 0xffffffffu) + boost::uint32_t(hash >> 32), + inv_sizes32[size_index], boost::uint32_t(sizes[size_index])); +#else return fast_modulo( boost::uint32_t(hash) + boost::uint32_t(hash >> 32), inv_sizes32[size_index], boost::uint32_t(sizes[size_index])); +#endif } else { return positions[size_index - sizes_under_32bit](hash); } diff --git a/test/unordered/prime_fmod_tests.cpp b/test/unordered/prime_fmod_tests.cpp index ba0f92d4..2094bc57 100644 --- a/test/unordered/prime_fmod_tests.cpp +++ b/test/unordered/prime_fmod_tests.cpp @@ -21,8 +21,7 @@ void macros_test() BOOST_ERROR("std::numeric_limits::digits >= 64, but " "BOOST_UNORDERED_FCA_HAS_64B_SIZE_T is not defined"); #endif - } - else { + } else { #if defined(BOOST_UNORDERED_FCA_HAS_64B_SIZE_T) BOOST_ERROR("std::numeric_limits::digits < 64, but " "BOOST_UNORDERED_FCA_HAS_64B_SIZE_T is defined"); @@ -155,7 +154,7 @@ void get_remainder_test() for (std::size_t i = 0; i < 1000000u; ++i) { boost::uint64_t f = rng(); - boost::uint32_t d = static_cast(rng()); + boost::uint32_t d = rng() & 0xffffffffu; boost::uint64_t r1 = boost::unordered::detail::prime_fmod_size<>::get_remainder(f, d); @@ -180,14 +179,14 @@ void modulo_test() boost::detail::splitmix64 rng; for (std::size_t i = 0; i < 1000000u; ++i) { - std::size_t hash = static_cast(rng()); + std::size_t hash = static_cast(-1) & rng(); for (std::size_t j = 0; j < sizes_len; ++j) { std::size_t h = hash; #if defined(BOOST_UNORDERED_FCA_HAS_64B_SIZE_T) if (sizes[j] <= UINT_MAX) { - h = boost::uint32_t(h) + boost::uint32_t(h >> 32); + h = boost::uint32_t(h & 0xffffffffu) + boost::uint32_t(h >> 32); } #endif std::size_t p1 =