summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qsimd.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-04-21 11:33:44 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-05-20 18:31:05 +0000
commitfe6dc9dc8549cd9de7a0ddb04d921fd3263b51df (patch)
tree88c2121c20c9c6290bd1cbb7b50e1b6c0eb05175 /src/corelib/global/qsimd.cpp
parent5b64e5950cf984abb7d47e0802bcb4b5a21e06fa (diff)
Add runtime ARM64 AES check
Adds runtime CPU detection for Windows and macOS, and switches feature detection of AES to runtime like for x86, So far only on ARM64, since gcc doesn't do function versioning on ARM32, but clang can, so it could be added later. Change-Id: Ibe5d60f48cdae3e366a8ecd6263534ba2b09b131 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/corelib/global/qsimd.cpp')
-rw-r--r--src/corelib/global/qsimd.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/corelib/global/qsimd.cpp b/src/corelib/global/qsimd.cpp
index 37d6dd4e145..025c50b6e8a 100644
--- a/src/corelib/global/qsimd.cpp
+++ b/src/corelib/global/qsimd.cpp
@@ -54,22 +54,19 @@
# if !defined(Q_CC_GNU)
# include <intrin.h>
# endif
-#elif defined(Q_OS_LINUX) && (defined(Q_PROCESSOR_ARM) || defined(Q_PROCESSOR_MIPS_32))
-#include "private/qcore_unix_p.h"
-
-#if QT_CONFIG(getauxval)
+# if defined(Q_PROCESSOR_ARM64)
+# include <processthreadsapi.h>
+# endif
+#elif defined(Q_OS_LINUX) && defined(Q_PROCESSOR_MIPS_32)
+# include "private/qcore_unix_p.h"
+#elif QT_CONFIG(getauxval) && defined(Q_PROCESSOR_ARM)
# include <sys/auxv.h>
-#endif
// the kernel header definitions for HWCAP_*
// (the ones we need/may need anyway)
// copied from <asm/hwcap.h> (ARM)
-#define HWCAP_CRUNCH 1024
-#define HWCAP_THUMBEE 2048
#define HWCAP_NEON 4096
-#define HWCAP_VFPv3 8192
-#define HWCAP_VFPv3D16 16384
// copied from <asm/hwcap.h> (ARM):
#define HWCAP2_AES (1 << 0)
@@ -84,7 +81,9 @@
#define AT_HWCAP2 26 /* extension of AT_HWCAP */
#elif defined(Q_CC_GHS)
-#include <INTEGRITY_types.h>
+# include <INTEGRITY_types.h>
+#elif defined(Q_OS_DARWIN) && defined(Q_PROCESSOR_ARM)
+# include <sys/sysctl.h>
#endif
QT_BEGIN_NAMESPACE
@@ -155,8 +154,26 @@ static inline quint64 detectProcessorFeatures()
return features;
}
// fall back to compile-time flags if getauxval failed
-#endif // QT_CONFIG(getauxval)
-
+#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;
+ if (sysctlbyname("hw.optional.armv8_crc32", &feature, &len, nullptr, 0) == 0)
+ features |= feature ? CpuFeatureCRC32 : 0;
+ // There is currently no optional value for crypto/AES.
+#if defined(__ARM_FEATURE_CRYPTO)
+ features |= CpuFeatureAES;
+#endif
+ return features;
+#elif defined(Q_OS_WIN) && defined(Q_PROCESSOR_ARM64)
+ features |= CpuFeatureNEON;
+ if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) != 0)
+ features |= CpuFeatureCRC32;
+ if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
+ features |= CpuFeatureAES;
+ return features;
+#endif
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
features |= CpuFeatureNEON;
#endif