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 7A05D38618AC for ; Thu, 4 Jan 2024 22:13:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A05D38618AC 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 7A05D38618AC 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=1704406414; cv=none; b=BBMKIY4og2CkOJ+na4Hyr5gjzb4gkJLjzImAlLf032Cboh7QKasB/oUzTeI7hmr1Nst6BovRsYrXi8DEItuBlqVcNBDUvZSBMfEUfWxcb+sO6Fb25SBr9JJbkeZh5V338LBEZlOAQoMPVZjLLim86AQx0CVkg4EfSCsNLLKsCnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704406414; c=relaxed/simple; bh=ebqmJMbIv5t9ESPiFWtctXl2Mb/Pg8XaF8JxGuEjcMw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=eTXaRpdiJKSaSLeigAOUpP06iyoxTBUO1NyY0uwhRKpu7/KImw+exwfUx+UjYvGUj+zWQp683emtINwZqrkVeTqiMk4b0AEkczf4PkRso9WjA/C9XYkWR0xbMpjk3pVWuTzca/TUJ/0Elc2INKHY5KS3v+QHTi8j9OM9gKksgn0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704406410; 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=Yi/kd74MsZK/72hy6a9CUKt596VggklVrA0LwKQ9BtM=; b=d2SH3mUf2/ktgkbRVtR30Rosx13GruepMphHIZaQVptx/uSSaBsXxzbI9AZNiy3lgidkWu 2bndFh0MvLys7KRJoK/XzVz4ZME2k+5ECowoYAHjjP5iyOW1/uMmKVX0ZmOvxBfkDMlKBW zx11i5qIAIqve2nIzaUsj/u02uI6qYk= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-49-JJDgkJeMPMmRA2uuy0uhBw-1; Thu, 04 Jan 2024 17:13:29 -0500 X-MC-Unique: JJDgkJeMPMmRA2uuy0uhBw-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5e8e0c7f9a8so474067b3.0 for ; Thu, 04 Jan 2024 14:13:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704406409; x=1705011209; h=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=Yi/kd74MsZK/72hy6a9CUKt596VggklVrA0LwKQ9BtM=; b=J33P3KjrQw+X9y/tRNmFn5ERzZQP/Nb529Q7yVB1Xtvha998obxe0rxYvRHy6PvnUv QAOad34FGE6iGprXam/fAWQAgOAt6CTRo9b82TR77Zfudn+dHsy/NsZ/6acbqUjusZVU g3JD4tLoGrxCfreYeNedIS1jHfcvjUuySAza1fK9rFPaHDejQPIdhMqYitp5CJg+JSoj omZ1obhT1vu0vTl6kbcLCAAe4ykQmE9NmrVF/TXtfDNLRsOX54xfy6ve7sDmw1gOpts3 25dQI0YH8j3UuTk3XQ2Xd4eTxExCluWtiMJnq3RCq7B0CcOEMtBiVlV61EBZZxsWcRS3 mnig== X-Gm-Message-State: AOJu0YxbYrCfJgihOrNg5mVB/5kR0GtRFzhqu/hquH9TvA+WQ8FbqHc3 QLRUERmV7pWlycSY3f9o5afVjLMfnGv9AKHDQI6WAWVkrikK8yPkQXHGFgung2u9/Rx0epaNk/Y gxYoPw88v+AYnz4C+phaAr8IjTdh3oGqJ+eKrdAA= X-Received: by 2002:a81:48c5:0:b0:5ea:1ea8:9ca1 with SMTP id v188-20020a8148c5000000b005ea1ea89ca1mr939963ywa.43.1704406409004; Thu, 04 Jan 2024 14:13:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfEhz7BtIGHvhUbQLdG9iNO0Amy5Whp26z7851gWkohPnkO+gI0guFwjqDge/xWDYQ77ORQu1QwU411ZBrO5A= X-Received: by 2002:a81:48c5:0:b0:5ea:1ea8:9ca1 with SMTP id v188-20020a8148c5000000b005ea1ea89ca1mr939959ywa.43.1704406408782; Thu, 04 Jan 2024 14:13: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: <20231223220432.712093-7-kmatsui@gcc.gnu.org> From: Jonathan Wakely Date: Thu, 4 Jan 2024 22:13:13 +0000 Message-ID: Subject: Re: [PATCH v2 6/8] libstdc++: Optimize std::is_pointer compilation performance To: Ken Matsui Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.6 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=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 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 = _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; > + }; Why is this partial specialization outside the #else group? > + > // > // 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; > +#endif > + > template > inline constexpr bool is_lvalue_reference_v = false; > template > -- > 2.43.0 >