From patchwork Fri Sep 2 13:31:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 113139 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 80482B6F7F for ; Fri, 2 Sep 2011 23:32:49 +1000 (EST) Received: (qmail 8745 invoked by alias); 2 Sep 2011 13:32:47 -0000 Received: (qmail 8722 invoked by uid 22791); 2 Sep 2011 13:32:46 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Sep 2011 13:32:21 +0000 Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p82DW7jO025929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 2 Sep 2011 13:32:09 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p82DW6BN026860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Sep 2011 13:32:07 GMT Received: from abhmt117.oracle.com (abhmt117.oracle.com [141.146.116.69]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p82DW0YV003464; Fri, 2 Sep 2011 08:32:00 -0500 Received: from [192.168.1.4] (/79.47.211.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 02 Sep 2011 06:32:00 -0700 Message-ID: <4E60DACE.3070302@oracle.com> Date: Fri, 02 Sep 2011 15:31:58 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Improve std::bitset::all X-IsSubscribed: yes 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 Hi, tested x86_64-linux multilib, a nice improvement joint work with Marc. Mainline only of course. Thanks, Paolo. ///////////////////////// 2011-09-02 Paolo Carlini Marc Glisse * include/std/bitset (_Base_bitset<>::_M_are_all_aux): Remove. (_Base_bitset<>::_M_are_all): Add. (bitset<>::all): Use the latter, improve implementation. Index: include/std/bitset =================================================================== --- include/std/bitset (revision 178463) +++ include/std/bitset (working copy) @@ -185,15 +185,17 @@ return true; } - size_t - _M_are_all_aux() const _GLIBCXX_NOEXCEPT - { - for (size_t __i = 0; __i < _Nw - 1; __i++) - if (_M_w[__i] != ~static_cast<_WordT>(0)) - return 0; - return ((_Nw - 1) * _GLIBCXX_BITSET_BITS_PER_WORD - + __builtin_popcountl(_M_hiword())); - } + template + bool + _M_are_all() const _GLIBCXX_NOEXCEPT + { + for (size_t __i = 0; __i < _Nw - 1; __i++) + if (_M_w[__i] != ~static_cast<_WordT>(0)) + return false; + return _M_hiword() == (~static_cast<_WordT>(0) + >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD + - _Nb)); + } bool _M_is_any() const _GLIBCXX_NOEXCEPT @@ -460,9 +462,11 @@ _M_is_equal(const _Base_bitset<1>& __x) const _GLIBCXX_NOEXCEPT { return _M_w == __x._M_w; } - size_t - _M_are_all_aux() const _GLIBCXX_NOEXCEPT - { return __builtin_popcountl(_M_w); } + template + bool + _M_are_all() const _GLIBCXX_NOEXCEPT + { return _M_w == (~static_cast<_WordT>(0) + >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); } bool _M_is_any() const _GLIBCXX_NOEXCEPT @@ -605,9 +609,10 @@ _M_is_equal(const _Base_bitset<0>&) const _GLIBCXX_NOEXCEPT { return true; } - size_t - _M_are_all_aux() const _GLIBCXX_NOEXCEPT - { return 0; } + template + bool + _M_are_all() const _GLIBCXX_NOEXCEPT + { return true; } bool _M_is_any() const _GLIBCXX_NOEXCEPT @@ -1312,7 +1317,7 @@ */ bool all() const _GLIBCXX_NOEXCEPT - { return this->_M_are_all_aux() == _Nb; } + { return this->template _M_are_all<_Nb>(); } /** * @brief Tests whether any of the bits are on.