From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com [IPv6:2607:f8b0:4864:20::92b]) by sourceware.org (Postfix) with ESMTPS id 838003858CDA for ; Wed, 14 Jun 2023 05:25:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 838003858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.washington.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.washington.edu Received: by mail-ua1-x92b.google.com with SMTP id a1e0cc1a2514c-784f7f7deddso746484241.3 for ; Tue, 13 Jun 2023 22:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1686720335; x=1689312335; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SwwM9EEEreWcRBlfSVyi1/5BFTBtSqpnnYKMtn8CFEs=; b=fBOg3zMQjO9OZVSdKL2z3L1gbyY9PGQaqWHjPrnCrz9NwLFOFVImw3YjYSsnR2px6A OILDL3clj93AQb48W2h8ExoyxC85z7FzcwP+7YFIHVrCAOpp1DPafXsfdJZNiWmpCRpg ZBDERSnlua9z3c+V3Y1i7pPVApRmsdVLNku6w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686720335; x=1689312335; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SwwM9EEEreWcRBlfSVyi1/5BFTBtSqpnnYKMtn8CFEs=; b=K8otzUDrx5ezZ5lydXh1i/n+vyTzPs5ZTepif0NrEk7hhyliffSzTnmUvhhFI+YLqv N6KhfxOv7VbFxPIeIuF885RiYOsoum39LTkommn1fv0kRKzJsgN2WWld7sAqTQnKFR5F 3uX+LKO9bpfKlON/B3U2BFJMjo9VP/T65Z1dR2NWRveC4q8QmGdiTRKeC9225vezA3Wl iClPrLN/NvNrVypdP4C0h5sNIDtw3BI/nN/yQaBAK86umlGGoCuN7q1qQNvd2uuFK0w/ rHj4MsW4pDT2BCCDYQ1Z4qykjgN0t5mO7lhTy1V0KqAmutOQNearFla1KGKTpssNZCkk haDQ== X-Gm-Message-State: AC+VfDwr6jhbmko6q0HzX7KPndDpikpN16ETJZ05k+7my5so9kUinfCS eBt8g9Hp/PHyNoG63QhWWk2d7qLy7yPP1aXLvUNXjQ== X-Google-Smtp-Source: ACHHUZ6/hlpP+c9CbbOH+BuIm7kLvDebPzakxxGD0XMHJTHkB454g7/kmXDo0GF0cSrcweCh+08/3AZ+uC5TDRSfv6w= X-Received: by 2002:a67:e893:0:b0:43c:381d:a04 with SMTP id x19-20020a67e893000000b0043c381d0a04mr7332649vsn.18.1686720334751; Tue, 13 Jun 2023 22:25:34 -0700 (PDT) MIME-Version: 1.0 References: <20230611024657.42846-1-kmatsui@cs.washington.edu> <20230612222515.20102-1-kmatsui@cs.washington.edu> <20230612222515.20102-7-kmatsui@cs.washington.edu> <3dfd9968-ddab-f9cf-7350-23be286f7597@gmail.com> In-Reply-To: <3dfd9968-ddab-f9cf-7350-23be286f7597@gmail.com> From: Ken Matsui Date: Tue, 13 Jun 2023 22:25:24 -0700 Message-ID: Subject: Re: [PATCH v5 6/6] libstdc++: make std::is_object dispatch to new built-in traits To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Tue, Jun 13, 2023 at 10:10=E2=80=AFPM Fran=C3=A7ois Dumont 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 macr= o. > > > > Signed-off-by: Ken Matsui > > --- > > libstdc++-v3/include/std/type_traits | 19 +++++++++++++++++++ > > 1 file changed, 19 insertions(+) > > > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/includ= e/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 struct is_object : public __not_<__or_, 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 =3D=3D FUNCTION_TYPE; + case CPTK_IS_REFERENCE: + return type_code1 =3D=3D 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) =3D=3D VOID_TYPE) ``` > > + > > + template > > + struct is_object > > + : public __bool_constant<__is_object(_Tp)> > > + { }; > > +#else > > template > > struct is_object > > : public __not_<__or_, is_reference<_Tp>, > > is_void<_Tp>>>::type > > { }; > > +#endif > > > > template > > struct is_member_pointer; > > @@ -3235,8 +3247,15 @@ template > > inline constexpr bool is_arithmetic_v =3D is_arithmetic<_Tp>::value= ; > > template > > inline constexpr bool is_fundamental_v =3D is_fundamental<_Tp>::val= ue; > > + > > +#ifdef __is_object > > +template > > + inline constexpr bool is_object_v =3D __is_object(_Tp); > > +#else > > template > > inline constexpr bool is_object_v =3D is_object<_Tp>::value; > > +#endif > > + > > template > > inline constexpr bool is_scalar_v =3D is_scalar<_Tp>::value; > > template