1212#ifndef XSIMD_CPU_FEATURES_ARM_HPP
1313#define XSIMD_CPU_FEATURES_ARM_HPP
1414
15+ #include < cstddef>
16+ #include < cstdint>
17+
1518#include " ./xsimd_config.hpp"
1619#include " ./xsimd_getauxval.hpp"
1720
2427
2528namespace xsimd
2629{
30+
31+ namespace detail
32+ {
33+ using arm_reg64_t = std::uint64_t ;
34+
35+ /* *
36+ * Return the SVE vector length in bytes for the current thread.
37+ *
38+ * SVE vector length can be restricted
39+ * Contrary to `svcntb` this does not require to be compiles with SVE, which
40+ * should not be done in a dynamic dispatch jump function.
41+ *
42+ * Safety: It is the user responsibility to first make sure that SVE is
43+ * available.
44+ */
45+ inline arm_reg64_t arm_rdvl_unsafe ();
46+ }
47+
2748 /* *
2849 * An opinionated CPU feature detection utility for ARM.
2950 *
@@ -40,13 +61,28 @@ namespace xsimd
4061 inline bool neon () const noexcept ;
4162 inline bool neon64 () const noexcept ;
4263 inline bool sve () const noexcept ;
64+ inline std::size_t sve_size_bytes () const noexcept ;
4365 inline bool i8mm () const noexcept ;
4466 };
4567
4668 /* *******************
4769 * Implementation *
4870 ********************/
4971
72+ namespace detail
73+ {
74+ #if XSIMD_TARGET_ARM64 && (defined(__GNUC__) || defined(__clang__))
75+ __attribute__ ((target(" arch=armv8-a+sve" ))) inline arm_reg64_t arm_rdvl_unsafe()
76+ {
77+ arm_reg64_t vl;
78+ __asm__ volatile (" rdvl %0, #1" : " =r" (vl));
79+ return vl;
80+ }
81+ #else
82+ inline arm_reg64_t arm_rdvl_unsafe () { return 0 ; }
83+ #endif
84+ }
85+
5086 inline bool arm_cpu_features::neon () const noexcept
5187 {
5288#if XSIMD_TARGET_ARM && !XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
@@ -70,6 +106,15 @@ namespace xsimd
70106#endif
71107 }
72108
109+ inline std::size_t arm_cpu_features::sve_size_bytes () const noexcept
110+ {
111+ if (sve ())
112+ {
113+ return detail::arm_rdvl_unsafe ();
114+ }
115+ return 0 ;
116+ }
117+
73118 inline bool arm_cpu_features::i8mm () const noexcept
74119 {
75120#if XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
0 commit comments