From patchwork Thu Jul 26 14:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 949693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-482448-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="s1BA1M9s"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41bv231Z1qz9rxx for ; Fri, 27 Jul 2018 00:03:07 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:in-reply-to :references; q=dns; s=default; b=QJMYbVmqnuI/0hse5gKSLL4vtOHydAE kQplahSDZEmaZivjXAeCqcmsGfjcDZm8ckxv8lUhsGwR970AUCPvTxdlRAWq/nhZ /eT2vROxeVLV39q2Pd1z5RH05aeezVDsYybXfWcxIeFeBOFxqoEM1kDFL3qN6x/M xk3/MtGxmlZ0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:in-reply-to :references; s=default; bh=2eZQZrsCeE/w594d8NQcAzRbMRE=; b=s1BA1 M9stag5UbZDXnd7B9ZjXB03iOkzZrmsVEDUvnJtGipb/iD5H0L6Xz6U/7DsJ9sUT V61Rw4nG4MoFQn5e/wuCwTDeIoyeOrX4C/zs9ixCCv8UIfDvFgmN21WDmQ6IICNx aIkyI1ayXdaL/HjLa/0r+tL8UhgdRkE5Ajvb48= Received: (qmail 71927 invoked by alias); 26 Jul 2018 14:02:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 71750 invoked by uid 89); 26 Jul 2018 14:02:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=bucket, __x, sk:_GLIBCX, sk:_glibcx X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Jul 2018 14:02:11 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06D2940216E8; Thu, 26 Jul 2018 14:02:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8F0B21568A1; Thu, 26 Jul 2018 14:02:09 +0000 (UTC) From: jwakely@redhat.com To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 3/8] Modify some library internals to work without Date: Thu, 26 Jul 2018 15:01:52 +0100 Message-Id: <34bf5979aac782b73d56c6627625fb340ffa5dca.1532613690.git.jwakely@redhat.com> In-Reply-To: References: In-Reply-To: References: From: Jonathan Wakely 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. 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 */