Skip to content

Commit

Permalink
Clean and assert our ARM extensions on Apple hardware
Browse files Browse the repository at this point in the history
Only check runtime when it makes sense, and assert compile-time
assumptions.

Change-Id: Ie9fe802c6e19814414ccc5f78a3df0d48a3e92a2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
Allan Sandfeld Jensen committed Sep 29, 2024
1 parent 899c89c commit aeeb118
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/corelib/global/qsimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,27 @@ static inline quint64 detectProcessorFeatures()
#elif defined(Q_OS_DARWIN) && defined(Q_PROCESSOR_ARM)
unsigned feature;
size_t len = sizeof(feature);
if (sysctlbyname("hw.optional.neon", &feature, &len, nullptr, 0) == 0)
features |= feature ? CpuFeatureNEON : 0;
Q_UNUSED(len);
#if defined(__ARM_NEON)
features |= CpuFeatureNEON;
#else
#error "Misconfiguration, NEON should always be enabled on Apple hardware"
#endif
#if defined(__ARM_FEATURE_CRC32)
features |= CpuFeatureCRC32;
#elif defined(Q_OS_MACOS)
#error "Misconfiguration, CRC32 should always be enabled on Apple desktop hardware"
#else
if (sysctlbyname("hw.optional.armv8_crc32", &feature, &len, nullptr, 0) == 0)
features |= feature ? CpuFeatureCRC32 : 0;
if (sysctlbyname("hw.optional.arm.FEAT_AES", &feature, &len, nullptr, 0) == 0)
features |= feature ? CpuFeatureAES : 0;
#endif
#if defined(__ARM_FEATURE_CRYPTO)
features |= CpuFeatureAES;
#elif defined(Q_OS_MACOS)
#error "Misconfiguration, CRYPTO/AES should always be enabled on Apple desktop hardware"
#else
if (sysctlbyname("hw.optional.arm.FEAT_AES", &feature, &len, nullptr, 0) == 0)
features |= feature ? CpuFeatureAES : 0;
#endif
return features;
#elif defined(Q_OS_WIN) && defined(Q_PROCESSOR_ARM_64)
Expand Down

0 comments on commit aeeb118

Please sign in to comment.