Skip to content

Commit

Permalink
Fix compile-time CRYPTO detection, and detection on MSVC ARM64
Browse files Browse the repository at this point in the history
We had a mismatch of the naming of the Qt and compiler defines. Matched
the qt defines to the compiler define, and added detection support for
MSVC (ARM64).

Pick-to: 6.8
Change-Id: I9abfbe8a96bc8c800e86dac3ab9a7abf9c1f7f9f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
  • Loading branch information
Allan Sandfeld Jensen committed Sep 17, 2024
1 parent aac8372 commit bbdd20d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config.tests/arch/arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ const char msg2[] = "==Qt=magic=Qt== Sub-architecture:"
#ifdef __IWMMXT__
" iwmmxt"
#endif
#ifdef __ARM_FEATURE_CRC32
#if defined(__ARM_FEATURE_CRC32) || (defined(_M_ARM64) && __ARM_ARCH >= 800)
" crc32"
#endif
#ifdef __ARM_FEATURE_CRYPTO
#if defined(__ARM_FEATURE_CRYPTO) || (defined(_M_ARM64) && __ARM_ARCH >= 800)
" crypto"
#endif

Expand Down
1 change: 1 addition & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ qt_feature("arm_crypto" PRIVATE
LABEL "AES"
CONDITION ( ( TEST_architecture_arch STREQUAL arm ) OR ( TEST_architecture_arch STREQUAL arm64 ) ) AND TEST_arch_${TEST_architecture_arch}_subarch_crypto
)
qt_feature_definition("arm_crypto" "QT_COMPILER_SUPPORTS_CRYPTO" VALUE "1")
qt_feature_definition("arm_crypto" "QT_COMPILER_SUPPORTS_AES" VALUE "1")
qt_feature_config("arm_crypto" QMAKE_PRIVATE_CONFIG)

Expand Down
8 changes: 6 additions & 2 deletions src/corelib/global/qsimd_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ inline uint32x4_t qvsetq_n_u32(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
}
#endif

#if defined(Q_PROCESSOR_ARM) && defined(__ARM_FEATURE_CRC32)
# include <arm_acle.h>
#if defined(_M_ARM64) && __ARM_ARCH >= 800
#define __ARM_FEATURE_CRYPTO 1
#define __ARM_FEATURE_CRC32 1
#endif

#if defined(Q_PROCESSOR_ARM_64)
Expand All @@ -349,6 +350,9 @@ inline uint32x4_t qvsetq_n_u32(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
#elif defined(Q_CC_GNU)
#define QT_FUNCTION_TARGET_STRING_AES "+crypto"
#define QT_FUNCTION_TARGET_STRING_CRC32 "+crc"
#elif defined(Q_CC_MSVC)
#define QT_FUNCTION_TARGET_STRING_AES
#define QT_FUNCTION_TARGET_STRING_CRC32
#endif
#elif defined(Q_PROCESSOR_ARM_32)
#if defined(Q_CC_CLANG)
Expand Down
4 changes: 2 additions & 2 deletions src/corelib/tools/qhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static size_t aeshash(const uchar *p, size_t len, size_t seed, size_t seed2) noe
}
#endif // x86 AESNI

#if defined(Q_PROCESSOR_ARM) && QT_COMPILER_SUPPORTS_HERE(AES) && !defined(QHASH_AES_SANITIZER_BUILD) && !defined(QT_BOOTSTRAPPED)
#if defined(Q_PROCESSOR_ARM) && QT_COMPILER_SUPPORTS_HERE(CRYPTO) && !defined(QHASH_AES_SANITIZER_BUILD) && !defined(QT_BOOTSTRAPPED)
QT_FUNCTION_TARGET(AES)
static size_t aeshash(const uchar *p, size_t len, size_t seed, size_t seed2) noexcept
{
Expand Down Expand Up @@ -864,7 +864,7 @@ size_t qHashBits(const void *p, size_t size, size_t seed) noexcept
#ifdef AESHASH
if (seed && qCpuHasFeature(AES) && qCpuHasFeature(SSE4_2))
return aeshash(data, size, seed, seed2);
#elif defined(Q_PROCESSOR_ARM) && QT_COMPILER_SUPPORTS_HERE(AES) && !defined(QHASH_AES_SANITIZER_BUILD) && !defined(QT_BOOTSTRAPPED)
#elif defined(Q_PROCESSOR_ARM) && QT_COMPILER_SUPPORTS_HERE(CRYPTO) && !defined(QHASH_AES_SANITIZER_BUILD) && !defined(QT_BOOTSTRAPPED)
if (seed && qCpuHasFeature(AES))
return aeshash(data, size, seed, seed2);
#endif
Expand Down

0 comments on commit bbdd20d

Please sign in to comment.