Clean and assert our ARM extensions on Apple hardware

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>
This commit is contained in:
Allan Sandfeld Jensen 2024-09-27 10:10:39 +02:00
parent 899c89c8d7
commit aeeb11841b

View File

@ -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)