Skip to content

Commit 80a5923

Browse files
dimula73serge-sans-paille
authored andcommitted
Fix xsimd::available_architectures().has() for sve and rvv archs
Ideally the patch CPU detection code should also check if the length of SVE and RVV is actually supported by the current CPU implementation (i.e. ZCR_Elx.LEN register for SVE and something else for RVV), but I don't have such CPUs/emulators handy, so I cannot add such checks. Given that xsimd::available_architectures().has() is a new feature of XSIMD13 and the length check has never been present in XSIMD, this bug is not a regression at least. The patch also adds a unittest that reproduces the error the patch fixes
1 parent 182a460 commit 80a5923

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

include/xsimd/config/xsimd_cpuid.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace xsimd
4242
#define ARCH_FIELD_EX(arch, field_name) \
4343
unsigned field_name; \
4444
XSIMD_INLINE bool has(::xsimd::arch) const { return this->field_name; }
45+
46+
#define ARCH_FIELD_EX_REUSE(arch, field_name) \
47+
XSIMD_INLINE bool has(::xsimd::arch) const { return this->field_name; }
48+
4549
#define ARCH_FIELD(name) ARCH_FIELD_EX(name, name)
4650

4751
ARCH_FIELD(sse2)
@@ -72,8 +76,12 @@ namespace xsimd
7276
ARCH_FIELD(neon)
7377
ARCH_FIELD(neon64)
7478
ARCH_FIELD_EX(i8mm<::xsimd::neon64>, i8mm_neon64)
75-
ARCH_FIELD(sve)
76-
ARCH_FIELD(rvv)
79+
ARCH_FIELD_EX(detail::sve<512>, sve)
80+
ARCH_FIELD_EX_REUSE(detail::sve<256>, sve)
81+
ARCH_FIELD_EX_REUSE(detail::sve<128>, sve)
82+
ARCH_FIELD_EX(detail::rvv<512>, rvv)
83+
ARCH_FIELD_EX_REUSE(detail::rvv<256>, rvv)
84+
ARCH_FIELD_EX_REUSE(detail::rvv<128>, rvv)
7785
ARCH_FIELD(wasm)
7886

7987
#undef ARCH_FIELD

test/test_arch.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ struct check_supported
3838
}
3939
};
4040

41+
struct check_cpu_has_intruction_set
42+
{
43+
template <class Arch>
44+
void operator()(Arch arch) const
45+
{
46+
static_assert(std::is_same<decltype(xsimd::available_architectures().has(arch)), bool>::value,
47+
"cannot test instruction set availability on CPU");
48+
}
49+
};
50+
4151
struct check_available
4252
{
4353
template <class Arch>
@@ -71,6 +81,11 @@ TEST_CASE("[multi arch support]")
7181
xsimd::supported_architectures::for_each(check_supported {});
7282
}
7383

84+
SUBCASE("xsimd::available_architectures::has")
85+
{
86+
xsimd::all_architectures::for_each(check_cpu_has_intruction_set {});
87+
}
88+
7489
SUBCASE("xsimd::default_arch::name")
7590
{
7691
constexpr char const* name = xsimd::default_arch::name();

0 commit comments

Comments
 (0)