From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id F35AA385E03D for ; Sat, 6 Jan 2024 05:00:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F35AA385E03D 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 F35AA385E03D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704517231; cv=none; b=YkKD23zjybTOkHhVeujcxzstdQjeqP9Lkpt0vRQRYZexMfATJInARnupBp+eatX9lVIMXOGJR2Ya9zknlgz3jnrbzOsVrDjKO2TbSH3Ja6q7919nEnW6KNWmWfXpjuadhuqbhnZIfHMW9GYfvvrYYT5m6B+DMxAtfWiXDvE264w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704517231; c=relaxed/simple; bh=cW0yxqVXTjSCtTBOyrrlpOWxwKFugUxWz5zJ2hUYbLY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=J9FyJvfJWBRDHqcqGligC0Z0Qw/As6j3wRIPmb+9RRH8LSfdPyeK0MIi1sr1TEU/J+Xn74nVJ67c5UC2i462DLapW+JRUaSN+ltZQhXHsx6J3/LzzCO3yuCGIKstniG33m508/GVoUVcR2aMw0ox4ioXO7ZysimV4cqrNwHI4OI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-781251ed685so21124985a.3 for ; Fri, 05 Jan 2024 21:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1704517228; x=1705122028; 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=zzxqSjly50RCR707XInqaxcbESrHABZ9GfDyttvahPc=; b=kj5rCQcgShuFQO6FraeBh4oronOV4917C3dlnXUmzKcT4Cw0WOuBeWS9SIIdctRquF 4YJhvaf85qp4A2YWltltOsaxcUtE5ewgqC+fsXiup47rIHya5/Nh0ewKygLtbOP4SbM3 +DHBiJ/fycn4kHgrBL5g6vLCRtLnE2BsOaXH0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704517228; x=1705122028; 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=zzxqSjly50RCR707XInqaxcbESrHABZ9GfDyttvahPc=; b=VWTD2WKrWpGKCfxyPer4Xv3Tw3NXj4+j6cGBfdnaLbVTjWqxN/pk3j9OJMJZP9MbYM hBVUK9THDKsuXMq6njx2A0zOHbz0pExm2VQxA5s0ASR3undQ8XXNRJYKE1bTXnjgnkrS oTCz8Q1vPU7KsygHJpAHy1S7VY1+KDWNt0IViOrK3+0qkAXR4tb+sc6gjkVk1PB/KGcf pEff1QQzXxwVCM3hRHnf0KAAvXIsutmQrpVBv9hA4bvW1U/uGAjyG10L5kr68xQGyyaE OrgEIMdAVVBwK9Sk3ShfidJkphP3uwmQ8IHXemVxBWrnNyWoF8fmeA4DVWByjvAVNiml cgpA== X-Gm-Message-State: AOJu0YxxU3oFork+30wvsUZJwgJKOtYk3HHAMPYRa3unW1JrXZ91zLHo PAxDbOiWxnEEA3VaRUkRIuFL2eY4RxiLiwY65+yEFt/Pr4sV X-Google-Smtp-Source: AGHT+IFzjPq4kVfBwW/i1ew/MbalNQ28SZ1m2nqoWyvKsTqjYn300RzS+rxwEvNBQKlHqeIECQ3jgMhKcl3Xty6Z6k8= X-Received: by 2002:a05:620a:6201:b0:781:7ac2:d7d8 with SMTP id ou1-20020a05620a620100b007817ac2d7d8mr508065qkn.100.1704517228290; Fri, 05 Jan 2024 21:00:28 -0800 (PST) MIME-Version: 1.0 References: <20231223220432.712093-1-kmatsui@gcc.gnu.org> <20231223220432.712093-7-kmatsui@gcc.gnu.org> In-Reply-To: From: Ken Matsui Date: Fri, 5 Jan 2024 20:59:52 -0800 Message-ID: Subject: Re: [PATCH v2 6/8] libstdc++: Optimize std::is_pointer compilation performance To: Jonathan Wakely Cc: Ken Matsui , 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=-13.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,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, Jan 4, 2024 at 2:13=E2=80=AFPM Jonathan Wakely = wrote: > > On Sat, 23 Dec 2023 at 22:07, 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 =3D _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 =3D 1 }; > > + typedef __true_type __type; > > + }; > > + > > + template > > + struct __is_pointer<_Tp* volatile> > > + { > > + enum { __value =3D 1 }; > > + typedef __true_type __type; > > + }; > > +#endif > > + > > + template > > + struct __is_pointer<_Tp* const volatile> > > + { > > + enum { __value =3D 1 }; > > + typedef __true_type __type; > > + }; > > Why is this partial specialization outside the #else group? > This is totally my fault. Thank you for pointing this out! > > > + > > // > > // 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 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]> =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.43.0 > > >