Fix CPU_QueryARMv7 for Clang (GH #844)

This fixes the query under Clang. This appears to be a trickier problem because there is no explicit define for HWCAP_ARMv7. We rely on HWCAP_NEON as a proxy, or fallback to a CPU_ProbeARMv7.
pull/853/head
Jeffrey Walton 2019-05-20 23:02:36 -04:00
parent a164c1f41d
commit a9be7ced86
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 6 additions and 4 deletions

10
cpu.cpp
View File

@ -519,6 +519,7 @@ extern bool CPU_ProbeSM3();
extern bool CPU_ProbeSM4(); extern bool CPU_ProbeSM4();
extern bool CPU_ProbePMULL(); extern bool CPU_ProbePMULL();
// https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwcap.h
// https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h // https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/hwcap.h
#ifndef HWCAP_ARMv7 #ifndef HWCAP_ARMv7
# define HWCAP_ARMv7 (1 << 29) # define HWCAP_ARMv7 (1 << 29)
@ -526,8 +527,8 @@ extern bool CPU_ProbePMULL();
#ifndef HWCAP_ASIMD #ifndef HWCAP_ASIMD
# define HWCAP_ASIMD (1 << 1) # define HWCAP_ASIMD (1 << 1)
#endif #endif
#ifndef HWCAP_ARM_NEON #ifndef HWCAP_NEON
# define HWCAP_ARM_NEON 4096 # define HWCAP_NEON (1 << 12)
#endif #endif
#ifndef HWCAP_CRC32 #ifndef HWCAP_CRC32
# define HWCAP_CRC32 (1 << 7) # define HWCAP_CRC32 (1 << 7)
@ -582,7 +583,8 @@ inline bool CPU_QueryARMv7()
((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0)) ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0))
return true; return true;
#elif defined(__linux__) && defined(__arm__) #elif defined(__linux__) && defined(__arm__)
if ((getauxval(AT_HWCAP) & HWCAP_ARMv7) != 0) if ((getauxval(AT_HWCAP) & HWCAP_ARMv7) != 0 ||
(getauxval(AT_HWCAP) & HWCAP_NEON) != 0)
return true; return true;
#elif defined(__APPLE__) && defined(__arm__) #elif defined(__APPLE__) && defined(__arm__)
// Apple hardware is ARMv7 or above. // Apple hardware is ARMv7 or above.
@ -608,7 +610,7 @@ inline bool CPU_QueryNEON()
if ((getauxval(AT_HWCAP2) & HWCAP2_ASIMD) != 0) if ((getauxval(AT_HWCAP2) & HWCAP2_ASIMD) != 0)
return true; return true;
#elif defined(__linux__) && defined(__arm__) #elif defined(__linux__) && defined(__arm__)
if ((getauxval(AT_HWCAP) & HWCAP_ARM_NEON) != 0) if ((getauxval(AT_HWCAP) & HWCAP_NEON) != 0)
return true; return true;
#elif defined(__APPLE__) && defined(__aarch64__) #elif defined(__APPLE__) && defined(__aarch64__)
// Core feature set for Aarch32 and Aarch64. // Core feature set for Aarch32 and Aarch64.