From patchwork Tue Oct 10 22:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp177243vqb; Tue, 10 Oct 2023 15:40:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvQrSF3m4SVYaY3dWTMlcyLO/HDujeRAqNgLx/JOxAyTbGitxiXR351p0Hauj2imWTcjWY X-Received: by 2002:a17:906:76d4:b0:9a1:e994:3440 with SMTP id q20-20020a17090676d400b009a1e9943440mr17473951ejn.4.1696977624673; Tue, 10 Oct 2023 15:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977624; cv=none; d=google.com; s=arc-20160816; b=yZRNYKpIyQhbovUA4Tluu34umJ22mCK1+X4LGVzUJt26tjfmNchNra/O6W1W1a6iPn ZqRpdFvQLSdlKp3LAaBZQBLBuFm2gID/1qxFr9Fvv0SNgHjcvOSPb68ueZurWYftcNte zJ6+QhoVsW35mGZeDkzebLCmB7ny9ASzV3XVNkLm1q75LKTwu1aZqZl+YNLWA3e58sek zL3HkDYtKFdFdsNb57QLxuHiN9N7s+AsgpBcvhAUjSifAFobIXi91hTBXiMRjFiYnfSS t8mSCNLZ+LxAPfW+pSsLqcUlMEmkjkzvJifzGe7mA8nzkwU/mgu8JLjpsY+bDKQcXAMX cIbw== 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=orDMc8xG2zQ7QNjJXh/5ECn8heU+MmGvisqZyfbv4DGm1r2Zb6tG9brfrBUANO5yn2 0+iXfjhsAbLadnYG89bywohhnF52du27cqb5nkCMQGZH0gbuB0f6zmZVNKR3lygvmBYA Z4EbY5itmUx69TpGu5qeNuz1jhEjkZrKqFkq91QxfJRs3FPzqYCQIi4xynwmE+nrl33M QBqR2Ledls5O5ChNua+ijADCKtjlRXYBoyUe6lQTeev0+z5HceOVDZFSKYwmSnzVswyY kngYrIA8+WriV49bI8WTdwcM9Dkv7sGDs994tuI3kkr+NC0GoMwHBDNRIvekXz9n2UOc XWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jwuoYbKz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l15-20020a1709066b8f00b0099cd371dd90si5520655ejr.928.2023.10.10.15.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:40:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jwuoYbKz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 E83D6388A02F for ; Tue, 10 Oct 2023 22:34:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E83D6388A02F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977249; 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=jwuoYbKzQTi2ddaBi0kRLmhK60H48iwUsHOSEAsDby9A+O8K7CIzOe0/f3spguB/H 6PUF0n8FnFCp9mAKaPq+S7q3SDmjL0o4U/gFrR1LH8FfMoth9GqEnRokgDZKxdU7Yv vAGyBF6BVaLXb1HWxIyr+eoHfweVrv8AQL7LlpBA= 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 F3B6D3888C4A; Tue, 10 Oct 2023 22:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3B6D3888C4A 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 (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMJTAE030629; Tue, 10 Oct 2023 22:33:24 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnay8u6u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:33:23 +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 39AMXAuE023205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:33:10 -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 39AMFOUb024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:33:09 -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 v16 24/39] libstdc++: Optimize is_function trait performance Date: Tue, 10 Oct 2023 15:10:15 -0700 Message-ID: <20231010221520.3680267-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: x-NCrzkJcl8nP8dVkYOHxkreJr5u3C1W X-Proofpoint-GUID: x-NCrzkJcl8nP8dVkYOHxkreJr5u3C1W 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_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 clxscore=1034 mlxlogscore=583 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997392552534413 X-GMAIL-MSGID: 1779410009866787403 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