[04/14] libstdc++: Optimize std::is_floating_point compilation performance

Message ID 20240110194031.2384005-5-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_floating_point by dispatching to the new
__is_floating_point built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_floating_point): Use
	__is_floating_point built-in trait.
	(is_floating_point_v): Likewise.

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

Comments

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

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


>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_floating_point): Use
>         __is_floating_point built-in trait.
>         (is_floating_point_v): Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index afa281d9cc4..23ea70eca18 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -470,6 +470,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      { };
>  #endif
>
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point)
> +  /// is_floating_point
> +  template<typename _Tp>
> +    struct is_floating_point
> +    : public __bool_constant<__is_floating_point(_Tp)>
> +    { };
> +#else
>    /// @cond undocumented
>    template<typename>
>      struct __is_floating_point_helper
> @@ -529,6 +536,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_floating_point
>      : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
>      { };
> +#endif
>
>    /// is_array
>  #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
> @@ -3238,8 +3246,13 @@ template <typename _Tp>
>    inline constexpr bool is_integral_v = is_integral<_Tp>::value;
>  #endif
>
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point)
> +template <typename _Tp>
> +  inline constexpr bool is_floating_point_v = __is_floating_point(_Tp);
> +#else
>  template <typename _Tp>
>    inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
> +#endif
>
>  #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
>  template <typename _Tp>
> --
> 2.43.0
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index afa281d9cc4..23ea70eca18 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -470,6 +470,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { };
 #endif
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point)
+  /// is_floating_point
+  template<typename _Tp>
+    struct is_floating_point
+    : public __bool_constant<__is_floating_point(_Tp)>
+    { };
+#else
   /// @cond undocumented
   template<typename>
     struct __is_floating_point_helper
@@ -529,6 +536,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_floating_point
     : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type
     { };
+#endif
 
   /// is_array
 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
@@ -3238,8 +3246,13 @@  template <typename _Tp>
   inline constexpr bool is_integral_v = is_integral<_Tp>::value;
 #endif
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point)
+template <typename _Tp>
+  inline constexpr bool is_floating_point_v = __is_floating_point(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
+#endif
 
 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
 template <typename _Tp>