Skip to content

Commit

Permalink
Cpu: implement ARM feature detection on FreeBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
clausecker authored and mosra committed Dec 10, 2023
1 parent d40ff9d commit d99afc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/Corrade/Cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/auxv.h>
/* sysctlbyname() for ARM on macOS / iOS */
#elif defined(CORRADE_TARGET_ARM) && defined(CORRADE_TARGET_APPLE)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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. */
Expand Down
8 changes: 4 additions & 4 deletions src/Corrade/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ Returns a tag corresponding to tag type @p T. The following two expressions are
*/
template<class T> 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 */
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d99afc1

Please sign in to comment.