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.129.124]) by sourceware.org (Postfix) with ESMTPS id CEB2B386D639 for ; Thu, 4 Jan 2024 22:16:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEB2B386D639 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 CEB2B386D639 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704406601; cv=none; b=o+mne2HVCA/MgnjOfI6NkKtroBVml2Ya7odJEUX8bASuRoEkOnzG6S7JPE8v5xnSZHA1Vlv1VGMfTrSWG/aFCN8N4O0V8z7FF6A2ivkG6EiazSVxs9Fj+cNX03J4hqq5onF0EYRk+VtWq0E1a6/nnjuiaYpuC28SswvIMnGE+J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704406601; c=relaxed/simple; bh=KKl46+Wi89WjOsx0eUVnyBdEZmI4hJIlAiZzt+qqqU4=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=xq3i5lyprvAMAkLtjgCoQbvsIJbH/5zEUOTNT8m8fQQWK+cRiYTkiXOTyL30sv6Kuj5xe65HxX1PokSTZcYLwU/amLewGkx+xlnHlxzeQddqm7Ye52NAvekJvLZ5Oh254NZ00KSec/7nGhCThXFSiVQrlt7NcV4GKmYkm29hBPw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704406599; 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=kY7JGTZdU2zmkRlm9rjZnxM7Wk6K7u2/G5oB8Pkev5Q=; b=D2ktz7b3eSOz7pqPk1BllZeTi0KinGuPjAa45RDHKmHYVTCsCt+Xpt0U2/6fOtKXgRXRIG Y35BNdOPsgiCcIXnK5Z8HIOg9T43yk0q0DILFljvzwCN0s85GX84fSCHWKuTDxPC7J6MNy C0DOSBRaBqdbg61xtqE5DbgzYVXbjus= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-biB8Z6DgOZeairKbOTh8iA-1; Thu, 04 Jan 2024 17:16:38 -0500 X-MC-Unique: biB8Z6DgOZeairKbOTh8iA-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3bbac3d23f8so1023408b6e.0 for ; Thu, 04 Jan 2024 14:16:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704406597; x=1705011397; 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=kY7JGTZdU2zmkRlm9rjZnxM7Wk6K7u2/G5oB8Pkev5Q=; b=IeAhHMECC6qRE765h7ZYsD80jf6P3642U8a9P7eHh5p2+e1ZfDkM/2QX9hBxYSs+c3 62jVcDOO0TU0Hp2tgHHqLxISxS/lmVIGQ6TS0nWzjxHOGflcY4YO+hxLiDM532g2PhHx jT0Kc+v1g1EEJVo5g0eLAD8/CypMo8a2bOqaPLKa9TKOJbI8z2JYyaVp2jV/pYK5K5W7 olMtq5tIfdfC3rLdk8xT++e+Mtwq3/VGty8Jr0WS1qEV64s5ROzYSLq2NlLJA5LpxMgB 3msHjQ8kScpWLeUk2l189+8UgIljzv9Wdm5Ug212QVHJO+dxEe+9+ApWtClwaka7gf/N 2syQ== X-Gm-Message-State: AOJu0Yx0Dao3AWNSGEypSB/HVoDOy9U0GIW+l2xXLKuLP19ayuXKKUdn N3PP1KnTyIznV1/sPBt1/tGtyt9M9G4vKp4ryPzAd3YYtAXMeIRi81YzdRcUq6TbyceUDXQkuUR Siubpe8pXqrFaZnmRiOzAT6Y= X-Received: by 2002:a05:6808:20a1:b0:3ba:f:526c with SMTP id s33-20020a05680820a100b003ba000f526cmr1438059oiw.66.1704406597522; Thu, 04 Jan 2024 14:16:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEORuaRRauq3+U+TfTuf5Cs2pLcEDuC4LhOwYxAZwnA62cA1WsqVRoqY5lIF3+qy9bFehmHHQ== X-Received: by 2002:a05:6808:20a1:b0:3ba:f:526c with SMTP id s33-20020a05680820a100b003ba000f526cmr1438054oiw.66.1704406597311; Thu, 04 Jan 2024 14:16:37 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id o12-20020a056214108c00b00680ca85b06fsm129448qvr.31.2024.01.04.14.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 14:16:36 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 4 Jan 2024 17:16:36 -0500 (EST) To: Patrick Palka cc: Ken Matsui , 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: <8f87b635-c957-d4b6-f0b3-5d1378ad1dc6@idea> Message-ID: <34832a51-4920-465e-f4d1-53f0795a1261@idea> References: <20231223220432.712093-1-kmatsui@gcc.gnu.org> <20231223220432.712093-7-kmatsui@gcc.gnu.org> <8f87b635-c957-d4b6-f0b3-5d1378ad1dc6@idea> 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=-16.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_H4,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 Thu, 4 Jan 2024, Patrick Palka wrote: > 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. By the way, a related optimization might be to optimize __remove_cv_t via the built-in (related since the current fallback implementation is in terms of __remove_cv_t). This should be safe since the alias template isn't used in any function signature, so it's never mangled. > > > +#endif > > + > > template > > inline constexpr bool is_lvalue_reference_v = false; > > template > > -- > > 2.43.0 > > > > >