From d99afc1b374cd13e00113de238439583531d7804 Mon Sep 17 00:00:00 2001 From: Robert Clausecker Date: Mon, 22 May 2023 14:33:20 +0200 Subject: [PATCH] Cpu: implement ARM feature detection on FreeBSD. --- src/Corrade/Cpu.cpp | 12 +++++++++--- src/Corrade/Cpu.h | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Corrade/Cpu.cpp b/src/Corrade/Cpu.cpp index 548c2b664..914eb1a4f 100644 --- a/src/Corrade/Cpu.cpp +++ b/src/Corrade/Cpu.cpp @@ -33,8 +33,8 @@ /** @todo these are indented to work around acme.py extracting them to the top, fix properly */ -/* getauxval() for ARM on Linux and Android with API level 18+ */ -#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) +/* getauxval() for ARM on Linux, Android with API level 18+ and FreeBSD */ +#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(__FreeBSD__)) #include /* sysctlbyname() for ARM on macOS / iOS */ #elif defined(CORRADE_TARGET_ARM) && defined(CORRADE_TARGET_APPLE) @@ -80,7 +80,7 @@ int appleSysctlByName(const char* name) { } #endif -#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE)) +#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE) || defined(__FreeBSD__)) Features runtimeFeatures() { /* Use getauxval() on ARM on Linux and Android */ #if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) @@ -127,6 +127,12 @@ Features runtimeFeatures() { return Features{out}; + /* Use elf_aux_info() on ARM on FreeBSD */ + #elif defined(CORRADE_TARGET_ARM) && defined(__FreeBSD__) + unsigned long hwcap = 0; + elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); + return Implementation::runtimeFeatures(hwcap); + /* No other (deinlined) implementation at the moment. The function should not be even defined here in that case -- it's inlined in the header instead, including the x86 implementation. */ diff --git a/src/Corrade/Cpu.h b/src/Corrade/Cpu.h index 3e6a7808c..64640a4a7 100644 --- a/src/Corrade/Cpu.h +++ b/src/Corrade/Cpu.h @@ -1400,7 +1400,7 @@ Returns a tag corresponding to tag type @p T. The following two expressions are */ template constexpr T tag() { return T{Implementation::Init}; } -#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) +#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(__FreeBSD__)) namespace Implementation { /* Needed for a friend declaration, implementation is at the very end of the header */ @@ -1539,7 +1539,7 @@ class Features { #endif Features runtimeFeatures(); #endif - #if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) + #if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(__FreeBSD__)) friend Features Implementation::runtimeFeatures(unsigned long); #endif @@ -1846,7 +1846,7 @@ value is equal to @ref Scalar, which in turn is equivalent to empty (or default-constructed) @ref Features. @see @ref DefaultBase, @ref DefaultExtra, @ref Default */ -#if (defined(CORRADE_TARGET_X86) && (defined(CORRADE_TARGET_MSVC) || defined(CORRADE_TARGET_GCC))) || (defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE))) || defined(DOXYGEN_GENERATING_OUTPUT) +#if (defined(CORRADE_TARGET_X86) && (defined(CORRADE_TARGET_MSVC) || defined(CORRADE_TARGET_GCC))) || (defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE) || defined(__FreeBSD__))) || defined(DOXYGEN_GENERATING_OUTPUT) #ifdef CORRADE_TARGET_ARM CORRADE_UTILITY_EXPORT /* Inlined on x86 at the very end of the header */ #endif @@ -3349,7 +3349,7 @@ inline Features runtimeFeatures() { /** @todo If AT_HWCAP2 or other bits are needed, it's passed to ifunc resolvers only since glibc 2.30 (and Android API 30+, which is the same as before): https://github.com/bminor/glibc/commit/2b8a3c86e7606cf1b0a997dad8af2d45ae8989c3 */ -#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) +#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(__FreeBSD__)) namespace Implementation { inline Features runtimeFeatures(const unsigned long caps) { unsigned int out = 0;