From patchwork Tue Oct 10 09:46:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp91814vqb; Tue, 10 Oct 2023 03:23:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmo3qphI5o/8O/1pujdzdooiZ+uRuXl5jnMOSduVSDOGPy4azl3weai1f415PH+Ytc3wX7 X-Received: by 2002:a17:906:5193:b0:9ae:5848:3f8e with SMTP id y19-20020a170906519300b009ae58483f8emr16768029ejk.49.1696933401949; Tue, 10 Oct 2023 03:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696933401; cv=none; d=google.com; s=arc-20160816; b=jFlAvJeDEcydCDlMKzHGOF/49CLHz25IP2iqpidZ6ebTQg6aSeUD/qC1ZrPBV1aJjM LMardFUKsdtqItKd2l1ieQ1mMenVw01NzwRxBfTyK1omXk4OvLKIJHmNpZ4T+gCooRLk J+0MlA3xY13f3OgXDyGOqFZV9zGuidEmwxIDGbYD8EMWEldn0Mc+1JEt6UsqLONOUozy ZE5XXmCEq6umE7Y1y9+jgLniJaWBStnYqz6fJ7dP8c+Ud8OXKQEzsnu7CpQN+lbl0sYg D8MZ4X7ESI6rjHRQBp7K1LWpHGk4+Djnfaoc48S8ZM8yNH+PtJb2nYXCvG68cDNVegHa nXaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to: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 :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HRC2efzrwRCP0neJuFs5hiVgLelvolSgQyZFivA1qPnnBvDPoY13EHMuw6mKJc9gLi 1pzjRpuxO0JveTbUwCMLP4Dm8hx5BkrtoBpN3vuvED+Ae4yKxv7yeoo9NBwtGJngHNU/ 64/fJg7zrYuKxqFtRiGwqCfU7Ld8JMSEDVCEcGss7HLCcOLbIU/cFxKBQCXQHP4Se+Lu xGXPfig/pNRYyx19NFd+U5R0UvBcPYoqqMs+6oBTKQqvyYuf+55vxqwYj1ROWO8wklHQ uw7o28QPRNAHpxQj8Qo/kMFJe3ZruyLPmGvJOFqNpopP55v1Exc5RDk+oUi+t7VD07Bx q6Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sf7GBNU0; 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 nc16-20020a1709071c1000b009ba088b5841si3737512ejc.1054.2023.10.10.03.23.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 03:23:21 -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=Sf7GBNU0; 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 68BCE3BF90E0 for ; Tue, 10 Oct 2023 10:09:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68BCE3BF90E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932576; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Sf7GBNU0A4AjvQFE7oiEto/EBDNMRtHLVedd2O3MP/16ajPQGt3TG8Ul0Ko8+CmbX 5s4zRhwZv0ba5/lwRZy9hBruT3duqPeznCjg9Ugbrk6P7MsGy4Rur+1OZERQAQJLAc RkWh/vlO4qHXsM/5WvGwOzLd7PrL9TWL/cvYwJYw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id CAECA3888839; Tue, 10 Oct 2023 10:08:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAECA3888839 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A9Ys4N014102; Tue, 10 Oct 2023 10:08:32 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhk2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:08:32 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA8I9b004613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:08:18 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTU014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:08:18 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 24/39] libstdc++: Optimize is_function trait performance Date: Tue, 10 Oct 2023 02:46:38 -0700 Message-ID: <20231010095229.3364786-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2oHVPXHjq23RpEUuAPL9DoSKcLdi21lo X-Proofpoint-ORIG-GUID: 2oHVPXHjq23RpEUuAPL9DoSKcLdi21lo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=583 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997392552534413 X-GMAIL-MSGID: 1779363638907845467 This patch optimizes the performance of the is_function trait by dispatching to the new __is_function built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..bd57488824b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3269,8 +3276,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template