Skip to content

Commit 2db459a

Browse files
committed
Split implementation
1 parent d9fb604 commit 2db459a

File tree

3 files changed

+56
-38
lines changed

3 files changed

+56
-38
lines changed

include/xsimd/config/xsimd_cpu_features_arm.hpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,51 @@ namespace xsimd
3737
class arm_cpu_features : private linux_hwcap_backend_default
3838
{
3939
public:
40-
arm_cpu_features() noexcept = default;
40+
inline bool neon() const noexcept;
41+
inline bool neon64() const noexcept;
42+
inline bool sve() const noexcept;
43+
inline bool i8mm() const noexcept;
44+
};
45+
46+
/********************
47+
* Implementation *
48+
********************/
4149

42-
inline bool neon() const noexcept
43-
{
50+
inline bool arm_cpu_features::neon() const noexcept
51+
{
4452
#if XSIMD_TARGET_ARM && !XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
45-
return hwcap().has_feature(HWCAP_NEON);
53+
return hwcap().has_feature(HWCAP_NEON);
4654
#else
47-
return static_cast<bool>(XSIMD_WITH_NEON);
55+
return static_cast<bool>(XSIMD_WITH_NEON);
4856
#endif
49-
}
57+
}
5058

51-
constexpr bool neon64() const noexcept
52-
{
53-
return static_cast<bool>(XSIMD_WITH_NEON64);
54-
}
59+
inline bool arm_cpu_features::neon64() const noexcept
60+
{
61+
return static_cast<bool>(XSIMD_WITH_NEON64);
62+
}
5563

56-
inline bool sve() const noexcept
57-
{
64+
inline bool arm_cpu_features::sve() const noexcept
65+
{
5866
#if XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
59-
return hwcap().has_feature(HWCAP_SVE);
67+
return hwcap().has_feature(HWCAP_SVE);
6068
#else
61-
return false;
69+
return false;
6270
#endif
63-
}
64-
65-
inline bool i8mm() const noexcept
66-
{
71+
}
6772

73+
inline bool arm_cpu_features::i8mm() const noexcept
74+
{
6875
#if XSIMD_TARGET_ARM64 && XSIMD_HAVE_LINUX_GETAUXVAL
6976
#ifdef HWCAP2_I8MM
70-
return hwcap2().has_feature(HWCAP2_I8MM);
77+
return hwcap2().has_feature(HWCAP2_I8MM);
7178
#else
72-
// Possibly missing on older Linux distributions
73-
return hwcap2().has_feature(1 << 13);
79+
// Possibly missing on older Linux distributions
80+
return hwcap2().has_feature(1 << 13);
7481
#endif
7582
#else
76-
return false;
83+
return false;
7784
#endif
78-
}
79-
};
85+
}
8086
}
8187
#endif

include/xsimd/config/xsimd_cpu_features_riscv.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,26 @@ namespace xsimd
2727
class riscv_cpu_features : private linux_hwcap_backend_default
2828
{
2929
public:
30-
riscv_cpu_features() noexcept = default;
30+
inline bool rvv() const noexcept;
31+
};
32+
33+
/********************
34+
* Implementation *
35+
********************/
3136

32-
inline bool rvv() const noexcept
33-
{
37+
inline bool riscv_cpu_features::rvv() const noexcept
38+
{
3439
#if XSIMD_TARGET_RISCV && XSIMD_HAVE_LINUX_GETAUXVAL
3540
#ifdef HWCAP_V
36-
return hwcap().has_feature(HWCAP_V);
41+
return hwcap().has_feature(HWCAP_V);
3742
#else
38-
// Possibly missing on older Linux distributions
39-
return hwcap().has_feature(1 << ('V' - 'A'));
43+
// Possibly missing on older Linux distributions
44+
return hwcap().has_feature(1 << ('V' - 'A'));
4045
#endif
4146
#else
42-
return false;
47+
return false;
4348
#endif
44-
}
45-
};
49+
}
4650
}
4751

4852
#endif

include/xsimd/config/xsimd_getauxval.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace xsimd
6969
}
7070
};
7171

72-
class linux_hwcap_backend_full
72+
class linux_hwcap_backend
7373
{
7474
public:
7575
inline linux_auxval hwcap() const noexcept;
@@ -99,9 +99,17 @@ namespace xsimd
9999
};
100100

101101
#if XSIMD_HAVE_LINUX_GETAUXVAL
102-
using linux_hwcap_backend_default = linux_hwcap_backend_full;
102+
using linux_hwcap_backend_default = linux_hwcap_backend;
103103
#else
104-
using linux_hwcap_backend_default = linux_hwcap_backend_noop;
104+
// Contrary to CPUID that is only used on one architecture, HWCAP are
105+
// available on multiple architectures with different meaning for the
106+
// different bit fields.
107+
// We use the Linux `HWCAP` constants directly to avoid repetition, so
108+
// we could not use a default implementation without already being on
109+
// Linux anyways.
110+
struct linux_hwcap_backend_default
111+
{
112+
};
105113
#endif
106114

107115
/********************
@@ -123,7 +131,7 @@ namespace xsimd
123131
#endif
124132
}
125133

126-
inline linux_auxval linux_hwcap_backend_full::hwcap() const noexcept
134+
inline linux_auxval linux_hwcap_backend::hwcap() const noexcept
127135
{
128136
if (!m_status.bit_is_set<status::hwcap_valid>())
129137
{
@@ -135,7 +143,7 @@ namespace xsimd
135143
return m_hwcap;
136144
}
137145

138-
inline linux_auxval linux_hwcap_backend_full::hwcap2() const noexcept
146+
inline linux_auxval linux_hwcap_backend::hwcap2() const noexcept
139147
{
140148
if (!m_status.bit_is_set<status::hwcap2_valid>())
141149
{

0 commit comments

Comments
 (0)