2018-07-26 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/hashtable_policy.h (__detail::__clp2): Use faster
+ implementation that doesn't depend on <stdint.h> 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<u16string>, hash<u32string>): Remove dependency on
_GLIBCXX_USE_C99_STDINT_TR1.
#define _HASHTABLE_POLICY_H 1
#include <tuple> // for std::tuple, std::forward_as_tuple
-#include <cstdint> // for std::uint_fast64_t
+#include <limits> // for std::numeric_limits
#include <bits/stl_algobase.h> // for std::min.
namespace std _GLIBCXX_VISIBILITY(default)
{ 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<unsigned long>::digits
+ - __builtin_clzl(__n - 1ul));
}
/// Rehash policy providing power of 2 bucket numbers. Avoids modulo
#endif
#if __cplusplus >= 201103L
-# include <cstdint>
-# ifdef _GLIBCXX_USE_C99_STDINT_TR1
+#include <cstdint>
namespace std _GLIBCXX_VISIBILITY(default)
{
_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<uintptr_t>(__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<unsigned long long>(__ptr);
+#endif
const auto __aligned = (__intptr - 1u + __align) & -__align;
const auto __diff = __aligned - __intptr;
if ((__size + __diff) > __space)
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
-#endif // _GLIBCXX_USE_C99_STDINT_TR1
#endif // C++11
#endif /* _GLIBCXX_MEMORY */