From: Jonathan Wakely Date: Thu, 26 Jul 2018 14:02:05 +0000 (+0100) Subject: Modify some library internals to work without X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4957b284f1ac52ce14b15fe3b915d46776d624ec;p=gcc.git Modify some library internals to work without std::__detail::__clp2 used uint_fast32_t and uint_fast64_t without checking _GLIBCXX_USE_C99_STDINT_TR1 which was a potential bug. A simpler implementation based on the new std::__ceil2 code performs better and doesn't depend on types. std::align and other C++11 functions in where unnecessarily missing when _GLIBCXX_USE_C99_STDINT_TR1 was not defined. * include/bits/hashtable_policy.h (__detail::__clp2): Use faster implementation that doesn't depend on types. * include/std/memory (align) [!_GLIBCXX_USE_C99_STDINT_TR1]: Use std::size_t when std::uintptr_t is not usable. [!_GLIBCXX_USE_C99_STDINT_TR1] (pointer_safety, declare_reachable) (undeclare_reachable, declare_no_pointers, undeclare_no_pointers): Define independent of _GLIBCXX_USE_C99_STDINT_TR1. From-SVN: r263003 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 10b1496af81..66ee23d1fc7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2018-07-26 Jonathan Wakely + * include/bits/hashtable_policy.h (__detail::__clp2): Use faster + implementation that doesn't depend on types. + * include/std/memory (align) [!_GLIBCXX_USE_C99_STDINT_TR1]: Use + std::size_t when std::uintptr_t is not usable. + [!_GLIBCXX_USE_C99_STDINT_TR1] (pointer_safety, declare_reachable) + (undeclare_reachable, declare_no_pointers, undeclare_no_pointers): + Define independent of _GLIBCXX_USE_C99_STDINT_TR1. + * include/bits/basic_string.h [!_GLIBCXX_USE_C99_STDINT_TR1] (hash, hash): Remove dependency on _GLIBCXX_USE_C99_STDINT_TR1. diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index 3ff6b14a90f..d7497711071 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -32,7 +32,7 @@ #define _HASHTABLE_POLICY_H 1 #include // for std::tuple, std::forward_as_tuple -#include // for std::uint_fast64_t +#include // for std::numeric_limits #include // for std::min. namespace std _GLIBCXX_VISIBILITY(default) @@ -504,27 +504,15 @@ namespace __detail { return __num & (__den - 1); } }; - /// Compute closest power of 2. - _GLIBCXX14_CONSTEXPR + /// Compute closest power of 2 not less than __n inline std::size_t __clp2(std::size_t __n) noexcept { -#if __SIZEOF_SIZE_T__ >= 8 - std::uint_fast64_t __x = __n; -#else - std::uint_fast32_t __x = __n; -#endif - // Algorithm from Hacker's Delight, Figure 3-3. - __x = __x - 1; - __x = __x | (__x >> 1); - __x = __x | (__x >> 2); - __x = __x | (__x >> 4); - __x = __x | (__x >> 8); - __x = __x | (__x >>16); -#if __SIZEOF_SIZE_T__ >= 8 - __x = __x | (__x >>32); -#endif - return __x + 1; + // Equivalent to return __n ? std::ceil2(__n) : 0; + if (__n < 2) + return __n; + return 1ul << (numeric_limits::digits + - __builtin_clzl(__n - 1ul)); } /// Rehash policy providing power of 2 bucket numbers. Avoids modulo diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory index f3559a91327..9689540fb81 100644 --- a/libstdc++-v3/include/std/memory +++ b/libstdc++-v3/include/std/memory @@ -88,8 +88,7 @@ #endif #if __cplusplus >= 201103L -# include -# ifdef _GLIBCXX_USE_C99_STDINT_TR1 +#include namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -113,7 +112,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void* align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept { +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 const auto __intptr = reinterpret_cast(__ptr); +#else + // Cannot use std::uintptr_t so assume that std::size_t can be used instead. + static_assert(sizeof(size_t) >= sizeof(void*), + "std::size_t must be a suitable substitute for std::uintptr_t"); + const auto __intptr = reinterpret_cast(__ptr); +#endif const auto __aligned = (__intptr - 1u + __align) & -__align; const auto __diff = __aligned - __intptr; if ((__size + __diff) > __space) @@ -147,7 +153,6 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; } _GLIBCXX_END_NAMESPACE_VERSION } // namespace -#endif // _GLIBCXX_USE_C99_STDINT_TR1 #endif // C++11 #endif /* _GLIBCXX_MEMORY */