From patchwork Fri Sep 15 02:21:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 140052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp767962vqi; Thu, 14 Sep 2023 20:01:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAD4PvFAsb6yumC6d69/utw+5g4UpriF7kbtVjD4LF1f4+cPM452rtKgc6cMofRlUuw4g6 X-Received: by 2002:a05:6512:61:b0:4fa:ad2d:6c58 with SMTP id i1-20020a056512006100b004faad2d6c58mr326710lfo.61.1694746867802; Thu, 14 Sep 2023 20:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746867; cv=none; d=google.com; s=arc-20160816; b=dQpUBZgOPOPTU4y631F5IqaNtwddwFNP3vnn04d+x77SA+dP3sCzOYRZ6WGIOoV1w0 LPgbme/Wp25+TDvzjlnB2+JANteRi3Zop8bRrswwbF+CbOSt/sC4Xe+gb7/i4VfJVi0X +JIHgJdVsfaTqaNwkTZ1dp/9SuvaHlL5bWjVp51RtngzRrpE8JSnuDbOu1+RJbRViQxe Uvy+Rhg//2azwTbNAN9PR8dhb0MdgJQ14am5B6n2BRKK3QLU9p0fb1emJdT06fzbecev qKbRkmcnstngVuFzZdmSFjQbSMpvebavKSolfybJP7/OuUi3FxowQ7xA2q7t6DbOhOYG WadA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=rSJvgnGBlviaZMLMLYI1vrsJ+McHCDW4tY1fI2kkSJ5DKg8YphVhKxQ2ykq4FcdnsX pCQAbkZdgWLy1gcl5ZCC31NN6rBLGQyLzMHwT9siIJ1lVfTGKFfA5rVLD4gE/y9Pdhrj /LfEcfo8uInt0G+a+dlJXkpcwDGhh8xdfckOr0iKxWujKWWzbK/VS46P1fS1VBMvHzM+ I8+FieLuLZRr+gi/V3pf+wWE+klI5YrTOE3R+0LJbfB41H3NCc49iUGPcXjo0zRaj21D JH2OUDYxIjASOWaQzNn5aVhcL/O6kM/u8L3yooS0V2Fi31v26Zh7BjeGV26ND0Hzpr/S /f0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IQVWKeZ2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l7-20020a1709061c4700b009828e8bec17si2531348ejg.531.2023.09.14.20.01.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IQVWKeZ2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23B93384025E for ; Fri, 15 Sep 2023 02:40:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23B93384025E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694745601; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IQVWKeZ2Kq2wflaokCNtYL5RDeCjpQMFz22IS2pxEKxTYzjmgGQs+JYHjclsokWAM +LkmYUxq4YXk3Se1/6S9gqYt7OeJehuXo77fVmFE25vK1gldco2thFXkqx75BIRAkX g7t5vtDQgRSpj3PXbEn6pWDl8ZK5DOcXQsZJaSWE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id C6F743856974; Fri, 15 Sep 2023 02:23:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6F743856974 Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38F2IRNw009901; Fri, 15 Sep 2023 02:23:35 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t4bd8h3nb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Sep 2023 02:23:34 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38F2N6LI032702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Sep 2023 19:23:07 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38F2N6Iu031819 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 14 Sep 2023 19:23:06 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v12 03/40] libstdc++: Optimize is_const trait performance Date: Thu, 14 Sep 2023 19:21:09 -0700 Message-ID: <20230915022305.74083-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230915022305.74083-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> <20230915022305.74083-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7PTSYKS79LnLeWVs5v96mWcvnx3TYac0 X-Proofpoint-GUID: 7PTSYKS79LnLeWVs5v96mWcvnx3TYac0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_02,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 mlxlogscore=841 clxscore=1034 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309150019 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995283749276021 X-GMAIL-MSGID: 1777070891849686530 This patch optimizes the performance of the is_const trait by dispatching to the new __is_const built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __is_const built-in trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..686e38e47c3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,6 +784,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -791,6 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3218,10 +3225,17 @@ template inline constexpr bool is_compound_v = is_compound<_Tp>::value; template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif + template inline constexpr bool is_volatile_v = false; template