From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 90CC8385840C for ; Thu, 4 Jan 2024 22:07:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90CC8385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90CC8385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704406025; cv=none; b=KlH5r551Mt9W6zarZ+awms62+Jqhw0Nnt59ujcuj0K6COWKCjd3juXVq4sb+oxQ2iLsL7qtK83qOR6OkwCGJ7kZuW5sdCPrnlmM+BVWRu2xmH+OVtOwZautA7vre7re10qE5W4KXbmz9u/kjWl4SUEHaBv6QEHosgjbG5fIMVoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704406025; c=relaxed/simple; bh=k6dxSboeemfiRjJUiWwafCU7L+nyHtFBsDeNLyG0SaM=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=ON1MFjzNqcvCqhaYldf+5cdUURPmG48qYq8YYbFHlLsaxGw/ZZRv9URc810YCEdPMoNd8Xw55CdCO+TOjzekxcfNCFVVJRUYLM3V86GDchlD4xJtgcUMzDwwP+PN0WxG5iLoQrqwH2LLjGqRzVFjzzmtqKmiOSWKZdDnJ31zzME= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704406023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DCPbk/DZJZdTalgjiInH/KOlxYG9cU4Klg+LnnK+Le0=; b=cFNy1eZ8mKrM/zhectoTVhheT5d2SHZKsA/5P5WYwVX4HCcXOXXq2lw/D/Cb9LyChzr33C LTSARxjoPS8DVGRTxJ8Ao1gQM+IDaCUK9GVj0qt0SsWZ+ctLaQTbEj4s5hNWvnx75BnaqW W7GkBzyNqRZU2IDcG/Tc6JoCB10dv3Y= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-u2aLFX3XPYedcYqxeI-z8Q-1; Thu, 04 Jan 2024 17:06:56 -0500 X-MC-Unique: u2aLFX3XPYedcYqxeI-z8Q-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-680dbcd297aso11829086d6.0 for ; Thu, 04 Jan 2024 14:06:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704406016; x=1705010816; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DCPbk/DZJZdTalgjiInH/KOlxYG9cU4Klg+LnnK+Le0=; b=MkQuL+pxqOX7e1X/ZE+qL7y3yfk4w7mz4XGMOxFojB/OfvaTB9GUmHiHd+cQ2gGzAd UV952PkmyTLuLMxlivK814uXGQsHr20SFkpL3jME6SiA4Yr33FNIv4yPaDwRfK5L6lbW 1vm3velN5O0xfrJy9WynoHNQKZa2iC7Wd66yVsG0lGnBNq/aXrH44c66bPUx/nxVZkNc 3yK0oCqAKG3Q0cFS0TIawl5PMn5W2a4pcDW4+y/0X1Y7bu7/sEovqrQws7ndNu8a+7EV 9AXdWoo8iCku52wYBZzBekAQCjik4G/D+eu1mhTda7eUuOzHm+dYgFKWWbPdDJz5bQif +b3g== X-Gm-Message-State: AOJu0YyNbR/aWboJEv0XPAp5iIFHY4YjcsY6CY1r2J+PRsHqHgLE77kt ROZ++t4x7gTot9HYC7UJAByUe+LJ+dlMhgCGTjODI1SHOn1Kh3KsJE41TIjDEOII5PY9RFAtH2+ gQk4OJ0+Uw3IHyc+9uBRTOLg= X-Received: by 2002:a05:620a:470f:b0:781:623d:5544 with SMTP id bs15-20020a05620a470f00b00781623d5544mr1455980qkb.8.1704406016225; Thu, 04 Jan 2024 14:06:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9xkggmOuuR6qD6dCwoQML/N/yopgCs4K4PwT1sIHR6fvS8qjd2Grcav4ZNRDI21px/OdmLw== X-Received: by 2002:a05:620a:470f:b0:781:623d:5544 with SMTP id bs15-20020a05620a470f00b00781623d5544mr1455970qkb.8.1704406015922; Thu, 04 Jan 2024 14:06:55 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id t3-20020a05620a0b0300b0077fafe70b34sm114931qkg.113.2024.01.04.14.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 14:06:55 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 4 Jan 2024 17:06:54 -0500 (EST) To: Ken Matsui cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, Jonathan Wakely Subject: Re: [PATCH v2 6/8] libstdc++: Optimize std::is_pointer compilation performance In-Reply-To: <20231223220432.712093-7-kmatsui@gcc.gnu.org> Message-ID: <8f87b635-c957-d4b6-f0b3-5d1378ad1dc6@idea> References: <20231223220432.712093-1-kmatsui@gcc.gnu.org> <20231223220432.712093-7-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-15.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Sat, 23 Dec 2023, Ken Matsui wrote: > This patch optimizes the compilation performance of std::is_pointer > by dispatching 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. Optimize its implementation. > * include/std/type_traits (is_pointer): Likewise. > (is_pointer_v): Likewise. > > Co-authored-by: Jonathan Wakely > Signed-off-by: Ken Matsui > --- > libstdc++-v3/include/bits/cpp_type_traits.h | 29 ++++++++++++++ > libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- > 2 files changed, 65 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..c348df97f72 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 _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > + template > + struct __is_pointer : __truth_type<_IsPtr> > + { > + enum { __value = _IsPtr }; > + }; > +#else > template > struct __is_pointer > { > @@ -377,6 +384,28 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) > typedef __true_type __type; > }; > > + template > + struct __is_pointer<_Tp* const> > + { > + enum { __value = 1 }; > + typedef __true_type __type; > + }; > + > + template > + struct __is_pointer<_Tp* volatile> > + { > + enum { __value = 1 }; > + typedef __true_type __type; > + }; > +#endif > + > + template > + struct __is_pointer<_Tp* const volatile> > + { > + enum { __value = 1 }; > + typedef __true_type __type; > + }; > + > // > // An arithmetic type is an integer type or a floating point type > // > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits > index 30b0778e58a..d53911b2fa0 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 > @@ -3252,8 +3266,22 @@ template > inline constexpr bool is_array_v<_Tp[_Num]> = true; > #endif > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > +template > + inline constexpr bool is_pointer_v = __is_pointer(_Tp); > +#else > template > - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; > + inline constexpr bool is_pointer_v = false; > +template > + inline constexpr bool is_pointer_v<_Tp*> = true; > +template > + inline constexpr bool is_pointer_v<_Tp* const> = true; > +template > + inline constexpr bool is_pointer_v<_Tp* volatile> = true; > +template > + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; Is this fallback implementation faster than the current implementation? LGTM if so. > +#endif > + > template > inline constexpr bool is_lvalue_reference_v = false; > template > -- > 2.43.0 > >