From 9a9e556052c808c578b074d5d9e297bdcdbbf396 Mon Sep 17 00:00:00 2001 From: Mark Horvath Date: Thu, 21 Mar 2024 09:58:32 +0100 Subject: [PATCH] Fix build if only the NEON backend is turned on Also refactor dispatch.h --- intrinsiccv/include/intrinsiccv/dispatch.h | 72 ++++++++++------------ 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/intrinsiccv/include/intrinsiccv/dispatch.h b/intrinsiccv/include/intrinsiccv/dispatch.h index fd485da3e..486f934ac 100644 --- a/intrinsiccv/include/intrinsiccv/dispatch.h +++ b/intrinsiccv/include/intrinsiccv/dispatch.h @@ -5,15 +5,13 @@ #ifndef INTRINSICCV_DISPATCH_H #define INTRINSICCV_DISPATCH_H +#include "intrinsiccv/config.h" + #if INTRINSICCV_HAVE_SVE2 || INTRINSICCV_HAVE_SME2 #include -#endif -#include #include -#include "intrinsiccv/config.h" - namespace INTRINSICCV_TARGET_NAMESPACE { using HwCapTy = uint64_t; @@ -23,13 +21,6 @@ struct HwCaps final { HwCapTy hwcap2; }; -#if INTRINSICCV_ALWAYS_ENABLE_SVE2 -#define INTRINSICCV_SVE2_IMPL_IF(func) func -#else -#define INTRINSICCV_SVE2_IMPL_IF(func) nullptr -#endif - -#if INTRINSICCV_HAVE_SVE2 || INTRINSICCV_HAVE_SME2 static inline HwCaps get_hwcaps() { return HwCaps{getauxval(AT_HWCAP), getauxval(AT_HWCAP2)}; } @@ -39,8 +30,6 @@ static inline bool hwcaps_has_sve2(HwCaps hwcaps) { return hwcaps.hwcap2 & (1 << 1); } -} // namespace INTRINSICCV_TARGET_NAMESPACE - #define INTRINSICCV_SVE2_RESOLVE(sve2_impl) \ if (!std::is_null_pointer_v && \ INTRINSICCV_TARGET_NAMESPACE::hwcaps_has_sve2(hwcaps)) { \ @@ -48,17 +37,15 @@ static inline bool hwcaps_has_sve2(HwCaps hwcaps) { } #else #define INTRINSICCV_SVE2_RESOLVE(x) -#endif +#endif // INTRINSICCV_HAVE_SVE2 #ifdef INTRINSICCV_HAVE_SME2 -namespace INTRINSICCV_TARGET_NAMESPACE { static inline bool hwcaps_has_sme2(HwCaps hwcaps) { // Actually checks for SME, not SME2, but this will be changed to check for // SME2 in future. const int kSMEBit = 23; return hwcaps.hwcap2 & (1UL << kSMEBit); } -} // namespace INTRINSICCV_TARGET_NAMESPACE #define INTRINSICCV_SME2_RESOLVE(sme2_impl) \ if (!std::is_null_pointer_v && \ @@ -67,29 +54,38 @@ static inline bool hwcaps_has_sme2(HwCaps hwcaps) { } #else #define INTRINSICCV_SME2_RESOLVE(x) -#endif - -#define INTRINSICCV_DECLARE_RESOLVER(api_name, neon_impl, sve2_impl, \ - sme2_impl) \ - static decltype(neon_impl) *api_name##_resolver() { \ - [[maybe_unused]] INTRINSICCV_TARGET_NAMESPACE::HwCaps hwcaps = \ - INTRINSICCV_TARGET_NAMESPACE::get_hwcaps(); \ - INTRINSICCV_SME2_RESOLVE(sme2_impl); \ - INTRINSICCV_SVE2_RESOLVE(sve2_impl); \ - return neon_impl; \ +#endif // INTRINSICCV_HAVE_SME2 + +} // namespace INTRINSICCV_TARGET_NAMESPACE + +#define INTRINSICCV_MULTIVERSION_C_API(api_name, neon_impl, sve2_impl, \ + sme2_impl) \ + static decltype(neon_impl) *api_name##_resolver() { \ + [[maybe_unused]] INTRINSICCV_TARGET_NAMESPACE::HwCaps hwcaps = \ + INTRINSICCV_TARGET_NAMESPACE::get_hwcaps(); \ + INTRINSICCV_SME2_RESOLVE(sme2_impl); \ + INTRINSICCV_SVE2_RESOLVE(sve2_impl); \ + return neon_impl; \ + } \ + extern "C" { \ + decltype(neon_impl) *api_name = api_name##_resolver(); \ } -#else -#define INTRINSICCV_DECLARE_RESOLVER(api_name, neon_impl, sve2_impl, \ - sme2_impl) \ - static decltype(neon_impl) *api_name##_resolver() { return neon_impl; } -#endif - -#define INTRINSICCV_MULTIVERSION_C_API(api_name, neon_impl, sve2_impl, \ - sme2_impl) \ - INTRINSICCV_DECLARE_RESOLVER(api_name, neon_impl, sve2_impl, sme2_impl) \ - \ - extern "C" { \ - decltype(neon_impl) *api_name = api_name##_resolver(); \ + +#else // INTRINSICCV_HAVE_SVE2 || INTRINSICCV_HAVE_SME2 + +#define INTRINSICCV_MULTIVERSION_C_API(api_name, neon_impl, sve2_impl, \ + sme2_impl) \ + \ + extern "C" { \ + decltype(neon_impl) *api_name = neon_impl; \ } +#endif // INTRINSICCV_HAVE_SVE2 || INTRINSICCV_HAVE_SME2 + +#if INTRINSICCV_ALWAYS_ENABLE_SVE2 +#define INTRINSICCV_SVE2_IMPL_IF(func) func +#else +#define INTRINSICCV_SVE2_IMPL_IF(func) nullptr +#endif // INTRINSICCV_ALWAYS_ENABLE_SVE2 + #endif // INTRINSICCV_DISPATCH_H -- GitLab