Message ID | 20230612222515.20102-7-kmatsui@cs.washington.edu |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp171056vqr; Mon, 12 Jun 2023 15:33:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XRzCkp3N7r8E9SwlzVKnloEy6aLmHoqAewcwYEz+kZ+ohas1dBjk2pK4741RY48N0p71B X-Received: by 2002:a05:6402:51ca:b0:514:b3b5:59b2 with SMTP id r10-20020a05640251ca00b00514b3b559b2mr6390639edd.20.1686609211898; Mon, 12 Jun 2023 15:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686609211; cv=none; d=google.com; s=arc-20160816; b=vfdICQyJlP4I/3YtPVtB+ZYoJXVom2Am/LtGwmaVqXRahpc5ceRsnkhtzQg8pFjpKe b9aI5G7pSUWCbOCQmuCvsqdlm2ZWRGIZsLmjjuXEdaWzG/1sDuBpENzRkLn9SaM1ACy0 dJCuag2NGsBfViGrvdkDB+KQ8l3Xz9MBjoyuKV1cYysX/0ZyTaTEWGpiUfBF5mKCEABn 2ced5Ghuh1akSvTylDbFMtOhSsuQZAqTRQsvwk3e71dPP/1VugxVTkvqpjK6AhxRODEG Bantfa9iksMwApAbauq/9ZjUW2g8m8xTOZO9bHvWFPj/ldmLtSJY8oRy4XCulhbeFL7G y1Yg== 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=3F6E7Ar7FzRfGYCHjGpVogyzZ7uhCr+X1uV3LSDRiqI=; b=TKWnlMUPYKZvIKk4s8mczC3a2T9+P3nQx/qNS09Vv9Qo+pJXGF2oHiS33v4KWPzORZ VC5bnTRemD+FcJFcUlDY965Te6+NXU9OLDgQIzdoc0jHZLRvT8bxaxzUPacRLzK1ECRW b4TznEvbsvfMqUDsynCHZy+UvpjctqNkKcFb0woC3D9TwfZ0O7FipV+IUhZDHOufsc0I c5UgEld1/lF9L66bnKG5CGL5B0nKBTQQNJPsOjIZOHpdGw6KhrqL1A9NH7/UOzrlnzJg NgTOD+WDvThOxahgWsL2sUdfYEC4Pw43v5EkNWg6GxWoy5BXfa3i48292hpVvpUxU3zB T7Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=H4mQ0XUK; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e23-20020a170906081700b0097668bb795asi3038092ejd.312.2023.06.12.15.33.31 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 15:33:31 -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=H4mQ0XUK; 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 14A76385660A for <ouuuleilei@gmail.com>; Mon, 12 Jun 2023 22:32:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14A76385660A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686609151; bh=3F6E7Ar7FzRfGYCHjGpVogyzZ7uhCr+X1uV3LSDRiqI=; 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=H4mQ0XUKn99sX9WpyfJmcAtqLCHV+jv3PfCNwny91XgL3q7lwOEp34tj4bAAjKp2Y Kyhp4Un5Cvvv+5A5RoSbeiYimrziT8mD2TvN0U1Y32YDLNsdaoR5Pt7lTg5xMIghIp 2abuVVJ5U0X5gs8qoJwCN9sOyvtKYUfzz/pyC0GY= 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 9654B3856DE6; Mon, 12 Jun 2023 22:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9654B3856DE6 Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35CMAs5f014544; Mon, 12 Jun 2023 22:30:39 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3r661w39q9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jun 2023 22:30:39 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 35CMUZuD012538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Jun 2023 15:30:35 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.234]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 35CMPHWv012136 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 12 Jun 2023 15:30:35 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui <kmatsui@cs.washington.edu> Subject: [PATCH v5 6/6] libstdc++: make std::is_object dispatch to new built-in traits Date: Mon, 12 Jun 2023 15:22:31 -0700 Message-ID: <20230612222515.20102-7-kmatsui@cs.washington.edu> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612222515.20102-1-kmatsui@cs.washington.edu> References: <20230611024657.42846-1-kmatsui@cs.washington.edu> <20230612222515.20102-1-kmatsui@cs.washington.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: QUnpvuSOJLfSCcFRFFEK5plF8Zy6TC9b X-Proofpoint-ORIG-GUID: QUnpvuSOJLfSCcFRFFEK5plF8Zy6TC9b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-12_16,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 phishscore=0 priorityscore=1501 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=911 malwarescore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306120193 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Ken Matsui via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Ken Matsui <kmatsui@cs.washington.edu> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761403850642973368?= X-GMAIL-MSGID: =?utf-8?q?1768537940484647329?= |
Series |
c++, libstdc++: get std::is_object to dispatch to new built-in traits
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Ken Matsui
June 12, 2023, 10:22 p.m. UTC
This patch gets std::is_object to dispatch to new built-in traits,
__is_function, __is_reference, and __is_void.
libstdc++-v3/ChangeLog:
* include/std/type_traits (is_object): Use new built-in traits,
__is_function, __is_reference, and __is_void.
(__is_object): Define this built-in-like macro.
(is_object_v): Use built-in traits through the build-in-like macro.
Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu>
---
libstdc++-v3/include/std/type_traits | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
Comments
On 13/06/2023 00:22, Ken Matsui via Libstdc++ wrote: > This patch gets std::is_object to dispatch to new built-in traits, > __is_function, __is_reference, and __is_void. > > libstdc++-v3/ChangeLog: > * include/std/type_traits (is_object): Use new built-in traits, > __is_function, __is_reference, and __is_void. > (__is_object): Define this built-in-like macro. > (is_object_v): Use built-in traits through the build-in-like macro. > > Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu> > --- > libstdc++-v3/include/std/type_traits | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits > index 780fcc00135..93335f94385 100644 > --- a/libstdc++-v3/include/std/type_traits > +++ b/libstdc++-v3/include/std/type_traits > @@ -682,11 +682,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { }; > > /// is_object > +#if __has_builtin(__is_function) && __has_builtin(__is_reference) \ > + && __has_builtin(__is_void) > + > +#define __is_object(_Tp) \ > + (!(__is_function(_Tp) || __is_reference(_Tp) || __is_void(_Tp))) Is this evaluation order random ? Are all those builtin functions performances equivalent ? I would have felt that __is_void is the simplest/fastest cause only for 'void' so would have put it first. > + > + template<typename _Tp> > + struct is_object > + : public __bool_constant<__is_object(_Tp)> > + { }; > +#else > template<typename _Tp> > struct is_object > : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, > is_void<_Tp>>>::type > { }; > +#endif > > template<typename> > struct is_member_pointer; > @@ -3235,8 +3247,15 @@ template <typename _Tp> > inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; > template <typename _Tp> > inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; > + > +#ifdef __is_object > +template <typename _Tp> > + inline constexpr bool is_object_v = __is_object(_Tp); > +#else > template <typename _Tp> > inline constexpr bool is_object_v = is_object<_Tp>::value; > +#endif > + > template <typename _Tp> > inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; > template <typename _Tp>
On Tue, Jun 13, 2023 at 10:10 PM François Dumont <frs.dumont@gmail.com> wrote: > > > On 13/06/2023 00:22, Ken Matsui via Libstdc++ wrote: > > This patch gets std::is_object to dispatch to new built-in traits, > > __is_function, __is_reference, and __is_void. > > > > libstdc++-v3/ChangeLog: > > * include/std/type_traits (is_object): Use new built-in traits, > > __is_function, __is_reference, and __is_void. > > (__is_object): Define this built-in-like macro. > > (is_object_v): Use built-in traits through the build-in-like macro. > > > > Signed-off-by: Ken Matsui <kmatsui@cs.washington.edu> > > --- > > libstdc++-v3/include/std/type_traits | 19 +++++++++++++++++++ > > 1 file changed, 19 insertions(+) > > > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits > > index 780fcc00135..93335f94385 100644 > > --- a/libstdc++-v3/include/std/type_traits > > +++ b/libstdc++-v3/include/std/type_traits > > @@ -682,11 +682,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > { }; > > > > /// is_object > > +#if __has_builtin(__is_function) && __has_builtin(__is_reference) \ > > + && __has_builtin(__is_void) > > + > > +#define __is_object(_Tp) \ > > + (!(__is_function(_Tp) || __is_reference(_Tp) || __is_void(_Tp))) > > Is this evaluation order random ? Are all those builtin functions > performances equivalent ? > > I would have felt that __is_void is the simplest/fastest cause only for > 'void' so would have put it first. This particular order is derived from the original implementation: ``` template<typename _Tp> struct is_object : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, is_void<_Tp>>>::type { }; ``` From what I can see, it appears there shouldn't be any disparities in performance based on these implementations in /gcc/cp/semantics.cc: ``` + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_VOID: + return VOID_TYPE_P (type1); ``` VOID_TYPE_P: gcc/tree.h ``` /* Nonzero if this type is the (possibly qualified) void type. */ #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE) ``` > > + > > + template<typename _Tp> > > + struct is_object > > + : public __bool_constant<__is_object(_Tp)> > > + { }; > > +#else > > template<typename _Tp> > > struct is_object > > : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, > > is_void<_Tp>>>::type > > { }; > > +#endif > > > > template<typename> > > struct is_member_pointer; > > @@ -3235,8 +3247,15 @@ template <typename _Tp> > > inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; > > template <typename _Tp> > > inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; > > + > > +#ifdef __is_object > > +template <typename _Tp> > > + inline constexpr bool is_object_v = __is_object(_Tp); > > +#else > > template <typename _Tp> > > inline constexpr bool is_object_v = is_object<_Tp>::value; > > +#endif > > + > > template <typename _Tp> > > inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; > > template <typename _Tp>
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 780fcc00135..93335f94385 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,11 +682,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if __has_builtin(__is_function) && __has_builtin(__is_reference) \ + && __has_builtin(__is_void) + +#define __is_object(_Tp) \ + (!(__is_function(_Tp) || __is_reference(_Tp) || __is_void(_Tp))) + + template<typename _Tp> + struct is_object + : public __bool_constant<__is_object(_Tp)> + { }; +#else template<typename _Tp> struct is_object : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template<typename> struct is_member_pointer; @@ -3235,8 +3247,15 @@ template <typename _Tp> inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template <typename _Tp> inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; + +#ifdef __is_object +template <typename _Tp> + inline constexpr bool is_object_v = __is_object(_Tp); +#else template <typename _Tp> inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template <typename _Tp> inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template <typename _Tp>