From aeeb11841b3e37c7f227d1232e9c30a55307d534 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 27 Sep 2024 10:10:39 +0200 Subject: [PATCH] Clean and assert our ARM extensions on Apple hardware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only check runtime when it makes sense, and assert compile-time assumptions. Change-Id: Ie9fe802c6e19814414ccc5f78a3df0d48a3e92a2 Reviewed-by: Tor Arne Vestbø Reviewed-by: Thiago Macieira --- src/corelib/global/qsimd.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/corelib/global/qsimd.cpp b/src/corelib/global/qsimd.cpp index 5e0e8380d49..28d25b5baca 100644 --- a/src/corelib/global/qsimd.cpp +++ b/src/corelib/global/qsimd.cpp @@ -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)