From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com [IPv6:2607:f8b0:4864:20::e34]) by sourceware.org (Postfix) with ESMTPS id AE4FA385840B for ; Mon, 16 Oct 2023 20:22:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE4FA385840B 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE4FA385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::e34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697487779; cv=none; b=eTLlb1ZHiAHEIX6VKvsvdR01ICd2+ChCPjbor+sbeSOkKGxy82peS5pi6jqx35AIqnY2E6G5vIbrQ4aBfRNOfI8fTcsPGzDlOnaU4L0aQshlwXR92ykPqplbKMITvc09jf/SODwIrR6TuyAv24MAStWSUHL9Dnoof/KW0Bq4Ztg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697487779; c=relaxed/simple; bh=X10SCintgtECiEohBy+jhVaAHaeybbMG6MPvO4blRs0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KIDkQWHl5Sf2hqFgf+BuE6f/sO2ayrZAmvFdgpQdt3oeIogvF/zqgXe3c7/61Xz77kXfkcyv5S3gS1HjjBTEfbpG8c0h57gFX9P7DX7NIiTQGL/IGDXvBpd9pq/rwhBZuyxNMmkI+uLl9A7xEFnJUij9s4+itbqxaDbwcK2pP7U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-457c82cd837so1339729137.2 for ; Mon, 16 Oct 2023 13:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1697487776; x=1698092576; darn=gcc.gnu.org; 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=7lHb8x/kgjcZErdGMjKYofTuwc5TrF7auQ7oLeK/jdw=; b=WJCjV7Z9l8oNeRGFEiDOGBEbTHvpvt/NYGnz0jeiyP6pv/rsubKiczGXGlwtTAK9GG xyQLIG2eTr0AJB3HrODCryQ81UyMJrD6sJfkqAPOL7LMKxR4RoeKYfZSVeWOg60iJkx9 N1wSAq6to3+GfYYGavsqkTsRdG3isI/iI3ohI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697487776; x=1698092576; 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=7lHb8x/kgjcZErdGMjKYofTuwc5TrF7auQ7oLeK/jdw=; b=Kd9i4O6PfIWb8oeDDhLl6fEFt+EUke6S7bk4snzQZa8c/tnQ9D2kaxcbX6EPHMyIyL Yxu/vpX45P+dU9D6xD4WsiSzBgWFfi1xECWd3AuGyb8Qx1NiMTdMIPCzFNkKVC4xXnKW beuaQob2wAeqZ8H6lRf5swJfvUQ6zdFawVukmuG+G8ZL+QB8OfOeqShtS6UjsevAsACN DKp++Q/Yo/dWv1iaslLY1j4PBUZPm7RgrU2jLfxfwgmhbCHW8/TNrXQG0jTfv5BDxMMh hNFT7Or8a8g08gadTCgcT19jOwWO6wv2cR0Q9YQsYLEShoN6w+5zN4Z7gVmD31lb30Bx S4tw== X-Gm-Message-State: AOJu0YxQD4GB0Mp4TBpqRyxlzawKa8X9pfiAhF2nmnNobAP769DMxb0b mX6Dv1ragciFcHir52z+nTrhPP35or99jGJhlxYRhc0yuD3DsYJg+ng= X-Google-Smtp-Source: AGHT+IE5SA7ola/oNC9aaAnUIerb4LXoYsXDhvyVXTSTCdbz8/F+rhPM8DJzHZpIXD4Ll9uuttx9hwWyCt7JtGEViRA= X-Received: by 2002:a67:c085:0:b0:457:f117:b752 with SMTP id x5-20020a67c085000000b00457f117b752mr436701vsi.12.1697487775701; Mon, 16 Oct 2023 13:22:55 -0700 (PDT) MIME-Version: 1.0 References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-31-kmatsui@gcc.gnu.org> <981886ec-3213-1a02-a471-2594ee024e8f@idea> In-Reply-To: <981886ec-3213-1a02-a471-2594ee024e8f@idea> From: Ken Matsui Date: Mon, 16 Oct 2023 13:22:19 -0700 Message-ID: Subject: Re: [PATCH v20 30/40] libstdc++: Optimize is_pointer trait performance To: Patrick Palka Cc: Ken Matsui , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, Jonathan Wakely Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.0 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 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 Mon, Oct 16, 2023 at 9:36=E2=80=AFAM Patrick Palka w= rote: > > On Sun, 15 Oct 2023, Ken Matsui wrote: > > > This patch optimizes the performance of the is_pointer trait by dispatc= hing to > > the new __is_pointer built-in trait. > > > > libstdc++-v3/ChangeLog: > > > > * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer > > built-in trait. > > * include/std/type_traits (is_pointer): Likewise. Optimize its > > implementation. > > (is_pointer_v): Likewise. > > > > Co-authored-by: Jonathan Wakely > > Signed-off-by: Ken Matsui > > --- > > libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ > > libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- > > 2 files changed, 44 insertions(+), 8 deletions(-) > > > > diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3= /include/bits/cpp_type_traits.h > > index 4312f32a4e0..cd5ce45951f 100644 > > --- a/libstdc++-v3/include/bits/cpp_type_traits.h > > +++ b/libstdc++-v3/include/bits/cpp_type_traits.h > > @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) > > // > > // Pointer types > > // > > +#if __has_builtin(__is_pointer) > > Why not _GLIBCXX_USE_BUILTIN_TRAIT? LGTM besides this. > Oops, thank you for pointing this out :) > > + template > > + struct __is_pointer : __truth_type<__is_pointer(_Tp)> > > + { > > + enum { __value =3D __is_pointer(_Tp) }; > > + }; > > Nice :D > Yeees! But I thought this might be very confusing for someone who does not know the new built-in behavior. > > +#else > > template > > struct __is_pointer > > { > > @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) > > enum { __value =3D 1 }; > > typedef __true_type __type; > > }; > > +#endif > > > > // > > // An arithmetic type is an integer type or a floating point type > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/includ= e/std/type_traits > > index 9c56d15c0b7..3acd843f2f2 100644 > > --- a/libstdc++-v3/include/std/type_traits > > +++ b/libstdc++-v3/include/std/type_traits > > @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > : public true_type { }; > > #endif > > > > - template > > - struct __is_pointer_helper > > + /// is_pointer > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > > + template > > + struct is_pointer > > + : public __bool_constant<__is_pointer(_Tp)> > > + { }; > > +#else > > + template > > + struct is_pointer > > : public false_type { }; > > > > template > > - struct __is_pointer_helper<_Tp*> > > + struct is_pointer<_Tp*> > > : public true_type { }; > > > > - /// is_pointer > > template > > - struct is_pointer > > - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type > > - { }; > > + struct is_pointer<_Tp* const> > > + : public true_type { }; > > + > > + template > > + struct is_pointer<_Tp* volatile> > > + : public true_type { }; > > + > > + template > > + struct is_pointer<_Tp* const volatile> > > + : public true_type { }; > > +#endif > > > > /// is_lvalue_reference > > template > > @@ -3254,8 +3268,22 @@ template > > inline constexpr bool is_array_v<_Tp[_Num]> =3D true; > > #endif > > > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > > +template > > + inline constexpr bool is_pointer_v =3D __is_pointer(_Tp); > > +#else > > template > > - inline constexpr bool is_pointer_v =3D is_pointer<_Tp>::value; > > + inline constexpr bool is_pointer_v =3D false; > > +template > > + inline constexpr bool is_pointer_v<_Tp*> =3D true; > > +template > > + inline constexpr bool is_pointer_v<_Tp* const> =3D true; > > +template > > + inline constexpr bool is_pointer_v<_Tp* volatile> =3D true; > > +template > > + inline constexpr bool is_pointer_v<_Tp* const volatile> =3D true; > > +#endif > > + > > template > > inline constexpr bool is_lvalue_reference_v =3D false; > > template > > -- > > 2.42.0 > > > > >