[02/14] libstdc++: Optimize std::is_integral compilation performance

Message ID 20240110194031.2384005-3-kmatsui@gcc.gnu.org
State Accepted
Headers
Series Optimize integral-related type traits |

Commit Message

Ken Matsui Jan. 10, 2024, 9:22 a.m. UTC
  This patch optimizes the compilation performance of std::is_integral
by dispatching to the new __is_integral built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_integral): Use __is_integral
	built-in trait.
	(is_integral_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/std/type_traits | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
  

Comments

Jonathan Wakely Jan. 10, 2024, 9:19 p.m. UTC | #1
On Wed, 10 Jan 2024 at 19:48, Ken Matsui <kmatsui@gcc.gnu.org> wrote:
>
> This patch optimizes the compilation performance of std::is_integral
> by dispatching to the new __is_integral built-in trait.

OK for trunk (if the new built-in gets approved).


>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_integral): Use __is_integral
>         built-in trait.
>         (is_integral_v): Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 1cec0822b73..afa281d9cc4 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -334,6 +334,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_void<const volatile void>
>      : public true_type { };
>
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral)
> +  /// is_integral
> +  template<typename _Tp>
> +    struct is_integral
> +    : public __bool_constant<__is_integral(_Tp)>
> +    { };
> +#else
>    /// @cond undocumented
>    template<typename>
>      struct __is_integral_helper
> @@ -461,6 +468,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_integral
>      : public __is_integral_helper<__remove_cv_t<_Tp>>::type
>      { };
> +#endif
>
>    /// @cond undocumented
>    template<typename>
> @@ -3221,8 +3229,15 @@ template <typename _Tp>
>    inline constexpr bool is_void_v = is_void<_Tp>::value;
>  template <typename _Tp>
>    inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
> +
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral)
> +template <typename _Tp>
> +  inline constexpr bool is_integral_v = __is_integral(_Tp);
> +#else
>  template <typename _Tp>
>    inline constexpr bool is_integral_v = is_integral<_Tp>::value;
> +#endif
> +
>  template <typename _Tp>
>    inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
>
> --
> 2.43.0
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 1cec0822b73..afa281d9cc4 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -334,6 +334,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_void<const volatile void>
     : public true_type { };
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral)
+  /// is_integral
+  template<typename _Tp>
+    struct is_integral
+    : public __bool_constant<__is_integral(_Tp)>
+    { };
+#else
   /// @cond undocumented
   template<typename>
     struct __is_integral_helper
@@ -461,6 +468,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_integral
     : public __is_integral_helper<__remove_cv_t<_Tp>>::type
     { };
+#endif
 
   /// @cond undocumented
   template<typename>
@@ -3221,8 +3229,15 @@  template <typename _Tp>
   inline constexpr bool is_void_v = is_void<_Tp>::value;
 template <typename _Tp>
   inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
+
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral)
+template <typename _Tp>
+  inline constexpr bool is_integral_v = __is_integral(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_integral_v = is_integral<_Tp>::value;
+#endif
+
 template <typename _Tp>
   inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;