Skip to content

Commit

Permalink
Merge branch 'storage/phmap_upd'
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed Jan 19, 2022
2 parents 643827e + 62c5307 commit a7e767d
Show file tree
Hide file tree
Showing 9 changed files with 995 additions and 524 deletions.
185 changes: 86 additions & 99 deletions external/parallel_hashmap/btree.h

Large diffs are not rendered by default.

944 changes: 684 additions & 260 deletions external/parallel_hashmap/phmap.h

Large diffs are not rendered by default.

54 changes: 29 additions & 25 deletions external/parallel_hashmap/phmap_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ using common_type_t = typename std::common_type<T...>::type;
template <typename T>
using underlying_type_t = typename std::underlying_type<T>::type;

template <typename T>
using result_of_t = typename std::result_of<T>::type;
template< class F, class... ArgTypes>
#if PHMAP_HAVE_CC17
using invoke_result_t = typename std::invoke_result_t<F, ArgTypes...>;
#else
using invoke_result_t = typename std::result_of<F(ArgTypes...)>::type;
#endif

namespace type_traits_internal {

Expand Down Expand Up @@ -413,7 +417,7 @@ inline void AssertHashEnabled
// hash_policy_traits
// -----------------------------------------------------------------------------
namespace phmap {
namespace container_internal {
namespace priv {

// Defines how slots are initialized/destroyed/moved.
template <class Policy, class = void>
Expand Down Expand Up @@ -577,7 +581,7 @@ struct hash_policy_traits
}
};

} // namespace container_internal
} // namespace priv
} // namespace phmap

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1299,7 +1303,7 @@ constexpr bool HasRebindAlloc(...) {
}

template <typename T, typename U>
constexpr bool HasRebindAlloc(typename T::template rebind<U>::other*) {
constexpr bool HasRebindAlloc(typename std::allocator_traits<T>::template rebind_alloc<U>*) {
return true;
}

Expand Down Expand Up @@ -1523,7 +1527,7 @@ struct allocator_traits
template <typename A, typename... Args>
static auto construct_impl(int, A& a, // NOLINT(runtime/references)
Args&&... args)
-> decltype(a.construct(std::forward<Args>(args)...)) {
-> decltype(std::allocator_traits<A>::construct(a, std::forward<Args>(args)...)) {
std::allocator_traits<A>::construct(a, std::forward<Args>(args)...);
}

Expand All @@ -1534,7 +1538,7 @@ struct allocator_traits

template <typename A, typename T>
static auto destroy_impl(int, A& a, // NOLINT(runtime/references)
T* p) -> decltype(a.destroy(p)) {
T* p) -> decltype(std::allocator_traits<A>::destroy(a, p)) {
std::allocator_traits<A>::destroy(a, p);
}
template <typename T>
Expand Down Expand Up @@ -2706,7 +2710,7 @@ struct hash<phmap::optional<T> >
// common.h
// -----------------------------------------------------------------------------
namespace phmap {
namespace container_internal {
namespace priv {

template <class, class = void>
struct IsTransparent : std::false_type {};
Expand Down Expand Up @@ -2827,7 +2831,7 @@ template <typename Policy, typename PolicyTraits, typename Alloc,
typename = void>
class node_handle : public node_handle_base<PolicyTraits, Alloc>
{
using Base = typename node_handle::node_handle_base;
using Base = node_handle_base<PolicyTraits, Alloc>;

public:
using value_type = typename PolicyTraits::value_type;
Expand All @@ -2851,7 +2855,7 @@ class node_handle<Policy, PolicyTraits, Alloc,
phmap::void_t<typename Policy::mapped_type>>
: public node_handle_base<PolicyTraits, Alloc>
{
using Base = typename node_handle::node_handle_base;
using Base = node_handle_base<PolicyTraits, Alloc>;

public:
using key_type = typename Policy::key_type;
Expand Down Expand Up @@ -2916,7 +2920,7 @@ struct InsertReturnType
NodeType node;
};

} // namespace container_internal
} // namespace priv
} // namespace phmap


Expand Down Expand Up @@ -3138,8 +3142,8 @@ class Span
static const size_type npos = ~(size_type(0));

constexpr Span() noexcept : Span(nullptr, 0) {}
constexpr Span(pointer array, size_type length) noexcept
: ptr_(array), len_(length) {}
constexpr Span(pointer array, size_type lgth) noexcept
: ptr_(array), len_(lgth) {}

// Implicit conversion constructors
template <size_t N>
Expand Down Expand Up @@ -3686,7 +3690,7 @@ constexpr Span<const T> MakeConstSpan(const T (&array)[N]) noexcept {
#endif

namespace phmap {
namespace container_internal {
namespace priv {

// A type wrapper that instructs `Layout` to use the specific alignment for the
// array. `Layout<..., Aligned<T, N>, ...>` has exactly the same API
Expand Down Expand Up @@ -4157,7 +4161,7 @@ class Layout : public internal_layout::LayoutType<sizeof...(Ts), Ts...>
: internal_layout::LayoutType<sizeof...(Ts), Ts...>(sizes...) {}
};

} // namespace container_internal
} // namespace priv
} // namespace phmap

// ---------------------------------------------------------------------------
Expand All @@ -4173,7 +4177,7 @@ class Layout : public internal_layout::LayoutType<sizeof...(Ts), Ts...>
#endif // _MSC_VER

namespace phmap {
namespace container_internal {
namespace priv {

template <typename... Ts>
class CompressedTuple;
Expand Down Expand Up @@ -4273,7 +4277,7 @@ struct PHMAP_INTERNAL_COMPRESSED_TUPLE_DECLSPEC
// To access the members, use member .get<N>() function.
//
// Eg:
// phmap::container_internal::CompressedTuple<int, T1, T2, T3> value(7, t1, t2,
// phmap::priv::CompressedTuple<int, T1, T2, T3> value(7, t1, t2,
// t3);
// assert(value.get<0>() == 7);
// T1& t1 = value.get<1>();
Expand Down Expand Up @@ -4325,12 +4329,12 @@ class PHMAP_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTuple
template <>
class PHMAP_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTuple<> {};

} // namespace container_internal
} // namespace priv
} // namespace phmap


namespace phmap {
namespace container_internal {
namespace priv {

#ifdef _MSC_VER
#pragma warning(push)
Expand Down Expand Up @@ -4416,7 +4420,7 @@ inline void SanitizerUnpoisonObject(const T* object) {
SanitizerUnpoisonMemoryRegion(object, sizeof(T));
}

} // namespace container_internal
} // namespace priv
} // namespace phmap


Expand Down Expand Up @@ -4530,7 +4534,7 @@ inline T& ts_unchecked_read(T& v) PHMAP_NO_THREAD_SAFETY_ANALYSIS {

} // namespace thread_safety_analysis

namespace container_internal {
namespace priv {

namespace memory_internal {

Expand Down Expand Up @@ -4743,7 +4747,7 @@ struct map_slot_policy
}
};

} // namespace container_internal
} // namespace priv
} // phmap


Expand Down Expand Up @@ -5133,6 +5137,8 @@ class LockableImpl<phmap::NullMutex>: public phmap::NullMutex
};
#endif

#endif // BOOST_THREAD_SHARED_MUTEX_HPP

// --------------------------------------------------------------------------
// std::shared_mutex support (read and write lock support)
// --------------------------------------------------------------------------
Expand All @@ -5152,9 +5158,7 @@ class LockableImpl<phmap::NullMutex>: public phmap::NullMutex
using UniqueLocks = typename Base::WriteLocks;
using UpgradeToUnique = typename Base::DoNothing; // we already have unique ownership
};
#endif

#endif // PHMAP_HAS_BOOST_THREAD_MUTEXES
#endif // PHMAP_HAVE_SHARED_MUTEX


} // phmap
Expand Down
18 changes: 9 additions & 9 deletions external/parallel_hashmap/phmap_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64(uint64_t n) {
return (int)(63 - result);
}
return 64;
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && !defined(__clang__)
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
unsigned long result = 0; // NOLINT(runtime/int)
if ((n >> 32) && _BitScanReverse(&result, (unsigned long)(n >> 32))) {
Expand All @@ -297,7 +297,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros64(uint64_t n) {
return 63 - result;
}
return 64;
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
// Use __builtin_clzll, which uses the following instructions:
// x86: bsr
// ARM64: clz
Expand All @@ -324,13 +324,13 @@ PHMAP_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32Slow(uint64_t n) {
}

PHMAP_BASE_INTERNAL_FORCEINLINE int CountLeadingZeros32(uint32_t n) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
unsigned long result = 0; // NOLINT(runtime/int)
if (_BitScanReverse(&result, n)) {
return (int)(31 - result);
}
return 32;
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
// Use __builtin_clz, which uses the following instructions:
// x86: bsr
// ARM64: clz
Expand Down Expand Up @@ -361,19 +361,19 @@ PHMAP_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64Slow(uint64_t n)
}

PHMAP_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero64(uint64_t n) {
#if defined(_MSC_VER) && defined(_M_X64)
#if defined(_MSC_VER) && !defined(__clang__) && defined(_M_X64)
unsigned long result = 0; // NOLINT(runtime/int)
_BitScanForward64(&result, n);
return (int)result;
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && !defined(__clang__)
unsigned long result = 0; // NOLINT(runtime/int)
if (static_cast<uint32_t>(n) == 0) {
_BitScanForward(&result, (unsigned long)(n >> 32));
return result + 32;
}
_BitScanForward(&result, (unsigned long)n);
return result;
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
static_assert(sizeof(unsigned long long) == sizeof(n), // NOLINT(runtime/int)
"__builtin_ctzll does not take 64-bit arg");
return __builtin_ctzll(n);
Expand All @@ -394,11 +394,11 @@ PHMAP_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32Slow(uint32_t n)
}

PHMAP_BASE_INTERNAL_FORCEINLINE int CountTrailingZerosNonZero32(uint32_t n) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
unsigned long result = 0; // NOLINT(runtime/int)
_BitScanForward(&result, n);
return (int)result;
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
static_assert(sizeof(int) == sizeof(n),
"__builtin_ctz does not take 32-bit arg");
return __builtin_ctz(n);
Expand Down
25 changes: 20 additions & 5 deletions external/parallel_hashmap/phmap_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#endif



// -----------------------------------------------------------------------------
// Compiler Feature Checks
// -----------------------------------------------------------------------------
Expand All @@ -119,6 +120,14 @@
#define PHMAP_HAVE_BUILTIN(x) 0
#endif

#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || __cplusplus >= 201703
#define PHMAP_HAVE_CC17 1
#else
#define PHMAP_HAVE_CC17 0
#endif

#define PHMAP_BRANCHLESS 1

// ----------------------------------------------------------------
// Checks whether `std::is_trivially_destructible<T>` is supported.
// ----------------------------------------------------------------
Expand Down Expand Up @@ -304,8 +313,7 @@

// #pragma message(PHMAP_VAR_NAME_VALUE(_MSVC_LANG))

#if defined(_MSC_VER) && _MSC_VER >= 1910 && \
((defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || __cplusplus >= 201703)
#if defined(_MSC_VER) && _MSC_VER >= 1910 && PHMAP_HAVE_CC17
// #define PHMAP_HAVE_STD_ANY 1
#define PHMAP_HAVE_STD_OPTIONAL 1
#define PHMAP_HAVE_STD_VARIANT 1
Expand All @@ -314,7 +322,7 @@
#endif
#endif

#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || __cplusplus >= 201703
#if PHMAP_HAVE_CC17
#define PHMAP_HAVE_SHARED_MUTEX 1
#endif

Expand All @@ -330,6 +338,13 @@
#define PHMAP_INTERNAL_MSVC_2017_DBG_MODE
#endif

// ---------------------------------------------------------------------------
// Checks whether wchar_t is treated as a native type
// (MSVC: /Zc:wchar_t- treats wchar_t as unsigned short)
// ---------------------------------------------------------------------------
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
#define PHMAP_HAS_NATIVE_WCHAR_T
#endif

// -----------------------------------------------------------------------------
// Sanitizer Attributes
Expand Down Expand Up @@ -610,7 +625,7 @@
#endif

#ifndef PHMAP_HAVE_SSSE3
#ifdef __SSSE3__
#if defined(__SSSE3__) || defined(__AVX2__)
#define PHMAP_HAVE_SSSE3 1
#else
#define PHMAP_HAVE_SSSE3 0
Expand All @@ -633,7 +648,7 @@
// ----------------------------------------------------------------------
// constexpr if
// ----------------------------------------------------------------------
#if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703)
#if PHMAP_HAVE_CC17
#define PHMAP_IF_CONSTEXPR(expr) if constexpr ((expr))
#else
#define PHMAP_IF_CONSTEXPR(expr) if ((expr))
Expand Down
Loading

0 comments on commit a7e767d

Please sign in to comment.