From 1f878636c85edaf4c99bdf599e54d2e4c46297b4 Mon Sep 17 00:00:00 2001 From: Ayan Shafqat Date: Sun, 23 Aug 2020 14:27:45 -0400 Subject: [PATCH] Adding NEON detection during runtime --- libs/ardour/globals.cc | 4 ++-- libs/pbd/fpu.cc | 13 +++++++++++++ libs/pbd/pbd/fpu.h | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index ae33ab32b3..8a7391f5f9 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -219,7 +219,7 @@ setup_hardware_optimization (bool try_optimization) #elif defined ARM_NEON_SUPPORT /* Use NEON routines */ - do { + if (fpu->has_neon ()) { info << "Using ARM NEON optimized routines" << endmsg; compute_peak = arm_neon_compute_peak; @@ -230,7 +230,7 @@ setup_hardware_optimization (bool try_optimization) copy_vector = arm_neon_copy_vector; generic_mix_functions = false; - } while (0); + } #elif defined(__APPLE__) && defined(BUILD_VECLIB_OPTIMIZATIONS) diff --git a/libs/pbd/fpu.cc b/libs/pbd/fpu.cc index 206ce2499f..9ad7cc94e9 100644 --- a/libs/pbd/fpu.cc +++ b/libs/pbd/fpu.cc @@ -31,6 +31,12 @@ #include #endif +#ifdef ARM_NEON_SUPPORT +/* Needed for ARM NEON detection */ +#include +#include +#endif + #include "pbd/compose.h" #include "pbd/fpu.h" #include "pbd/error.h" @@ -155,6 +161,13 @@ FPU::FPU () return; } + +#ifdef ARM_NEON_SUPPORT + if (getauxval(AT_HWCAP) & HWCAP_NEON) { + _flags = Flags(_flags & HasNEON); + } +#endif + #if !( (defined __x86_64__) || (defined __i386__) || (defined _M_X64) || (defined _M_IX86) ) // !ARCH_X86 /* Non-Intel architecture, nothing to do here */ return; diff --git a/libs/pbd/pbd/fpu.h b/libs/pbd/pbd/fpu.h index 91992f77c0..b0979daa9e 100644 --- a/libs/pbd/pbd/fpu.h +++ b/libs/pbd/pbd/fpu.h @@ -31,7 +31,8 @@ class LIBPBD_API FPU { HasDenormalsAreZero = 0x2, HasSSE = 0x4, HasSSE2 = 0x8, - HasAVX = 0x10 + HasAVX = 0x10, + HasNEON = 0x20, }; public: @@ -45,6 +46,7 @@ class LIBPBD_API FPU { bool has_sse () const { return _flags & HasSSE; } bool has_sse2 () const { return _flags & HasSSE2; } bool has_avx () const { return _flags & HasAVX; } + bool has_neon () const { return _flags & HasNEON; } private: Flags _flags;