From 6bd4c717a1a11b4fc9cc941490e1535bd720023c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 17 Dec 2020 21:41:23 -0800 Subject: [PATCH] Fixed bug 5402 - ARM support little update proposal David Carlier No fix but mostly an update for ARM architecture. --- CMakeLists.txt | 1 + configure | 2 +- configure.ac | 2 +- include/SDL_config.h.cmake | 1 + include/SDL_config.h.in | 1 + src/atomic/SDL_spinlock.c | 2 ++ src/cpuinfo/SDL_cpuinfo.c | 8 ++++++++ 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6268f465..2f99d71da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -834,6 +834,7 @@ if(LIBC) check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF) check_symbol_exists(sysctlbyname "sys/types.h;sys/sysctl.h" HAVE_SYSCTLBYNAME) check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL) + check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO) check_symbol_exists(poll "poll.h" HAVE_POLL) check_library_exists(m pow "" HAVE_LIBM) diff --git a/configure b/configure index e83010918..e5be453e5 100755 --- a/configure +++ b/configure @@ -17071,7 +17071,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi - for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit + for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 66c1e5549..80863e523 100644 --- a/configure.ac +++ b/configure.ac @@ -345,7 +345,7 @@ if test x$enable_libc = xyes; then AC_DEFINE(HAVE_MPROTECT, 1, [ ]) ]), ) - AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit) + AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 0f8a66237..754b57013 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -195,6 +195,7 @@ #cmakedefine HAVE_PTHREAD_SET_NAME_NP 1 #cmakedefine HAVE_SEM_TIMEDWAIT 1 #cmakedefine HAVE_GETAUXVAL 1 +#cmakedefine HAVE_ELF_AUX_INFO 1 #cmakedefine HAVE_POLL 1 #cmakedefine HAVE__EXIT 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index b4f338b58..3a2a7149d 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -199,6 +199,7 @@ #undef HAVE_PTHREAD_SET_NAME_NP #undef HAVE_SEM_TIMEDWAIT #undef HAVE_GETAUXVAL +#undef HAVE_ELF_AUX_INFO #undef HAVE_POLL #undef HAVE__EXIT diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index aa8ae5747..73ddd012a 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -138,6 +138,8 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) /* "REP NOP" is PAUSE, coded for tools that don't know it by that name. */ #if (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) #define PAUSE_INSTRUCTION() __asm__ __volatile__("pause\n") /* Some assemblers can't do REP NOP, so go with PAUSE. */ +#elif (defined(__arm__) && __ARM_ARCH__ >= 7) || defined(__aarch64__) + #define PAUSE_INSTRUCTION() __asm__ __volatile__("yield" ::: "memory") #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) #define PAUSE_INSTRUCTION() _mm_pause() /* this is actually "rep nop" and not a SIMD instruction. No inline asm in MSVC x86-64! */ #elif defined(__WATCOMC__) && defined(__386__) diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index f2ef5e36e..1920e83d6 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -54,6 +54,9 @@ #include #include /* For AltiVec check */ #include +#if defined(HAVE_ELF_AUX_INFO) +#include +#endif #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP #include #include @@ -462,6 +465,11 @@ CPU_haveNEON(void) return 0; /* assume anything else from Apple doesn't have NEON. */ #elif defined(__OpenBSD__) return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */ +#elif defined(HAVE_ELF_AUX_INFO) + unsigned long hasneon = 0; + if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) + return 0; + return ((hasneon & HWCAP_NEON) == HWCAP_NEON); #elif !defined(__arm__) return 0; /* not an ARM CPU at all. */ #elif defined(__QNXNTO__)