From patchwork Fri Feb 1 21:04:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 217585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 857512C007A for ; Sat, 2 Feb 2013 08:04:59 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360357499; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=73zX5xOmh2FEOIN662Fl4GEX9as=; b=HDuUjTD4rHTyq91 MOsgi5koW52I+DtqjI770Wf5wYAPEd2MeYnYaSCrR958ET43azK4IRB3zob/CBqq zIqOu2ZhuNcAsngS/B5j7qQhn/UMyylI6tNQZtEKI5D1mpZGK//N0K+lTddxId/X LweRcJTaP2hFjKOb6MCUr9jhp4rY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:X-Forwarded-Message-Id:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=VpKxzGvJGjXmZR0LDOgOajmSMun1DT0aS+pJhzESRmZZYlr62TNecm1ImMvUAM ElQ7Q4zSSne+BbUybpsuV6KnzaCG9HZctcfOyAfj7ApPGkx9+8yPpNthcUhHSryO JsbDJr8dNfXd2DqM9h/516Fejrd7jGe4mbLPpD9Ibr91c=; Received: (qmail 23541 invoked by alias); 1 Feb 2013 21:04:41 -0000 Received: (qmail 23523 invoked by uid 22791); 1 Feb 2013 21:04:40 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_SPAMHAUS_DROP, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-we0-f170.google.com (HELO mail-we0-f170.google.com) (74.125.82.170) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Feb 2013 21:04:33 +0000 Received: by mail-we0-f170.google.com with SMTP id z53so3396302wey.29 for ; Fri, 01 Feb 2013 13:04:31 -0800 (PST) X-Received: by 10.194.239.167 with SMTP id vt7mr2265161wjc.33.1359752671438; Fri, 01 Feb 2013 13:04:31 -0800 (PST) Received: from localhost.localdomain (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by mx.google.com with ESMTPS id bw9sm5682054wib.5.2013.02.01.13.04.29 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Feb 2013 13:04:30 -0800 (PST) Message-ID: <510C2DDD.2060908@gmail.com> Date: Fri, 01 Feb 2013 22:04:29 +0100 From: =?ISO-8859-1?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120829 Thunderbird/15.0 MIME-Version: 1.0 To: "libstdc++@gcc.gnu.org" , gcc-patches , Paolo Carlini Subject: Fwd: Re: Export _Prime_rehash_policy symbols References: <510C29B0.4040601@gmail.com> In-Reply-To: <510C29B0.4040601@gmail.com> X-Forwarded-Message-Id: <510C29B0.4040601@gmail.com> 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 Test successful so attached patch applied. 2013-02-01 François Dumont * include/bits/hashtable_policy.h (_Prime_rehash_policy::_M_next_bkt) (_Prime_rehash_policy::_M_need_rehash): Move definition... * src/c++11/hashtable_c++0x.cc: ... here. * src/shared/hashtable-aux.cc: Remove c++config.h include. * config/abi/gnu.ver (GLIBCXX_3.4.18): Export _Prime_rehash_policy symbols. François On 01/30/2013 11:12 AM, Paolo Carlini wrote: > ... before committing, please double check that we aren't breaking > |--enable-symvers=|gnu-versioned-namespace, wouldn't be the first time > that we do that and we notice only much later. At minimum build with > it and run the testsuite. > > Paolo. Index: include/bits/hashtable_policy.h =================================================================== --- include/bits/hashtable_policy.h (revision 195557) +++ include/bits/hashtable_policy.h (working copy) @@ -369,7 +369,8 @@ // Return a bucket count appropriate for n elements std::size_t - _M_bkt_for_elements(std::size_t __n) const; + _M_bkt_for_elements(std::size_t __n) const + { return __builtin_ceil(__n / (long double)_M_max_load_factor); } // __n_bkt is current bucket count, __n_elt is current element count, // and __n_ins is number of elements to be inserted. Do we need to @@ -397,77 +398,6 @@ mutable std::size_t _M_next_resize; }; - extern const unsigned long __prime_list[]; - - // XXX This is a hack. There's no good reason for any of - // _Prime_rehash_policy's member functions to be inline. - - // Return a prime no smaller than n. - inline std::size_t - _Prime_rehash_policy:: - _M_next_bkt(std::size_t __n) const - { - // Optimize lookups involving the first elements of __prime_list. - // (useful to speed-up, eg, constructors) - static const unsigned char __fast_bkt[12] - = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; - - if (__n <= 11) - { - _M_next_resize - = __builtin_ceil(__fast_bkt[__n] - * (long double)_M_max_load_factor); - return __fast_bkt[__n]; - } - - const unsigned long* __next_bkt - = std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, - __n); - _M_next_resize - = __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor); - return *__next_bkt; - } - - // Return the smallest integer p such that alpha p >= n, where alpha - // is the load factor. - inline std::size_t - _Prime_rehash_policy:: - _M_bkt_for_elements(std::size_t __n) const - { return __builtin_ceil(__n / (long double)_M_max_load_factor); } - - // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. - // If p > __n_bkt, return make_pair(true, p); otherwise return - // make_pair(false, 0). In principle this isn't very different from - // _M_bkt_for_elements. - - // The only tricky part is that we're caching the element count at - // which we need to rehash, so we don't have to do a floating-point - // multiply for every insertion. - - inline std::pair - _Prime_rehash_policy:: - _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, - std::size_t __n_ins) const - { - if (__n_elt + __n_ins >= _M_next_resize) - { - long double __min_bkts = (__n_elt + __n_ins) - / (long double)_M_max_load_factor; - if (__min_bkts >= __n_bkt) - return std::make_pair(true, - _M_next_bkt(std::max(__builtin_floor(__min_bkts) + 1, - __n_bkt * _S_growth_factor))); - else - { - _M_next_resize - = __builtin_floor(__n_bkt * (long double)_M_max_load_factor); - return std::make_pair(false, 0); - } - } - else - return std::make_pair(false, 0); - } - // Base classes for std::_Hashtable. We define these base classes // because in some cases we want to do different things depending on // the value of a policy class. In some cases the policy class Index: src/shared/hashtable-aux.cc =================================================================== --- src/shared/hashtable-aux.cc (revision 195557) +++ src/shared/hashtable-aux.cc (working copy) @@ -1,6 +1,6 @@ // std::__detail and std::tr1::__detail definitions -*- C++ -*- -// Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007-2013 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -22,8 +22,6 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . -#include - namespace __detail { _GLIBCXX_BEGIN_NAMESPACE_VERSION Index: src/c++11/hashtable_c++0x.cc =================================================================== --- src/c++11/hashtable_c++0x.cc (revision 195557) +++ src/c++11/hashtable_c++0x.cc (working copy) @@ -1,6 +1,6 @@ // std::__detail definitions -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007-2013 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -22,13 +22,76 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . -#include - #if __cplusplus < 201103L # error "hashtable_c++0x.cc must be compiled with -std=gnu++0x" #endif +#include +#include +#include + namespace std _GLIBCXX_VISIBILITY(default) { #include "../shared/hashtable-aux.cc" -} // namespace // namespace std + +namespace __detail +{ + _GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Return a prime no smaller than n. + std::size_t + _Prime_rehash_policy::_M_next_bkt(std::size_t __n) const + { + // Optimize lookups involving the first elements of __prime_list. + // (useful to speed-up, eg, constructors) + static const unsigned char __fast_bkt[12] + = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; + + if (__n <= 11) + { + _M_next_resize = + __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor); + return __fast_bkt[__n]; + } + + const unsigned long* __next_bkt = + std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n); + _M_next_resize = + __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor); + return *__next_bkt; + } + + // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. + // If p > __n_bkt, return make_pair(true, p); otherwise return + // make_pair(false, 0). In principle this isn't very different from + // _M_bkt_for_elements. + + // The only tricky part is that we're caching the element count at + // which we need to rehash, so we don't have to do a floating-point + // multiply for every insertion. + + std::pair + _Prime_rehash_policy:: + _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, + std::size_t __n_ins) const + { + if (__n_elt + __n_ins >= _M_next_resize) + { + long double __min_bkts = (__n_elt + __n_ins) + / (long double)_M_max_load_factor; + if (__min_bkts >= __n_bkt) + return std::make_pair(true, + _M_next_bkt(std::max(__builtin_floor(__min_bkts) + 1, + __n_bkt * _S_growth_factor))); + + _M_next_resize + = __builtin_floor(__n_bkt * (long double)_M_max_load_factor); + return std::make_pair(false, 0); + } + else + return std::make_pair(false, 0); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace __detail +} // namespace std Index: config/abi/pre/gnu.ver =================================================================== --- config/abi/pre/gnu.ver (revision 195557) +++ config/abi/pre/gnu.ver (working copy) @@ -1,7 +1,6 @@ ## Linker script for GNU versioning (GNU ld 2.13.91+ only.) ## -## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -## 2011, 2012 Free Software Foundation, Inc. +## Copyright (C) 2002-2013 Free Software Foundation, Inc. ## ## This file is part of the GNU ISO C++ Library. This library is free ## software; you can redistribute it and/or modify it under the @@ -1334,6 +1333,7 @@ extern "C++" { std::random_device::*; + std::__detail::_Prime_rehash_policy::*; }; # std::this_thread::__sleep_for