[PATCH v16 22/26] libstdc++: Optimize std::rank compilation performance
Ken Matsui
kmatsui@gcc.gnu.org
Thu May 2 16:13:48 GMT 2024
This patch optimizes the compilation performance of std::rank
by dispatching to the new __builtin_rank trait.
libstdc++-v3/ChangeLog:
* include/std/type_traits (rank): Use __builtin_rank trait.
(rank_v): Likewise.
Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
libstdc++-v3/include/std/type_traits | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 45c73d477d0..15933a0730e 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1473,6 +1473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
/// rank
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_rank)
+ template<typename _Tp>
+ struct rank
+ : public integral_constant<std::size_t, __builtin_rank(_Tp)> { };
+#else
template<typename>
struct rank
: public integral_constant<std::size_t, 0> { };
@@ -1484,6 +1489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct rank<_Tp[]>
: public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
+#endif
/// extent
template<typename, unsigned _Uint = 0>
@@ -3583,12 +3589,17 @@ template <typename _Tp>
template <typename _Tp>
inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_rank)
+template <typename _Tp>
+ inline constexpr size_t rank_v = __builtin_rank(_Tp);
+#else
template <typename _Tp>
inline constexpr size_t rank_v = 0;
template <typename _Tp, size_t _Size>
inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
template <typename _Tp>
inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
+#endif
template <typename _Tp, unsigned _Idx = 0>
inline constexpr size_t extent_v = 0;
--
2.44.0
More information about the Libstdc++
mailing list