Skip to content

Commit

Permalink
CMake: add detection of x86 VAES and AVX512VBMI2 features
Browse files Browse the repository at this point in the history
We have VAES code in qhash.cpp that isn't getting compiled right now.

Change-Id: Ibf4acec0f166495998f7fffd16d6961261dec361
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
  • Loading branch information
thiagomacieira committed Mar 8, 2022
1 parent 5235b1b commit 38e6b63
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmake/QtCompilerOptimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if (MSVC)
set(QT_CFLAGS_AVX512VL "-arch:AVX512")
set(QT_CFLAGS_AVX512IFMA "-arch:AVX512")
set(QT_CFLAGS_AVX512VBMI "-arch:AVX512")
set(QT_CFLAGS_AVX512VBMI2 "-arch:AVX512")
set(QT_CFLAGS_VAES "")
endif()

if(GCC OR CLANG OR QCC)
Expand All @@ -51,8 +53,10 @@ if(GCC OR CLANG OR QCC)
set(QT_CFLAGS_AVX512VL "-mavx512vl")
set(QT_CFLAGS_AVX512IFMA "-mavx512ifma")
set(QT_CFLAGS_AVX512VBMI "-mavx512vbmi")
set(QT_CFLAGS_AVX512VBMI2 "-mavx512vbmi2")
set(QT_CFLAGS_AESNI "-maes")
set(QT_CFLAGS_SHANI "-msha")
set(QT_CFLAGS_VAES "-mvaes")
if(NOT UIKIT AND NOT QT_64BIT)
set(QT_CFLAGS_NEON "-mfpu=neon")
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/QtFeature.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ function(qt_config_compile_test_x86simd extension label)
qt_get_platform_try_compile_vars(platform_try_compile_vars)
list(APPEND flags ${platform_try_compile_vars})

message(STATUS "Performing SIMD Test ${label}")
message(STATUS "Performing Test ${label} intrinsics")
try_compile("TEST_X86SIMD_${extension}"
"${CMAKE_CURRENT_BINARY_DIR}/config.tests/x86_simd_${extension}"
"${CMAKE_CURRENT_SOURCE_DIR}/config.tests/x86_simd"
Expand All @@ -1085,7 +1085,7 @@ function(qt_config_compile_test_x86simd extension label)
else()
set(status_label "Failed")
endif()
message(STATUS "Performing SIMD Test ${label} - ${status_label}")
message(STATUS "Performing Test ${label} intrinsics - ${status_label}")
set(TEST_subarch_${extension} "${TEST_X86SIMD_${extension}}" CACHE INTERNAL "${label}")
endfunction()

Expand Down
20 changes: 20 additions & 0 deletions config.tests/x86_simd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,26 @@ attribute_target("avx512ifma") void test_avx512ifma()
}
#endif

#if T(AVX512VBMI2)
attribute_target("avx512vl,avx512vbmi2") void test_avx512vbmi2()
{
/* AVX512 Vector Byte Manipulation Instructions 2 */
__m128i a = _mm_maskz_compress_epi16(-1, _mm_set1_epi16(1));
__m128i b = _mm_shrdi_epi32(a, a, 7);
}
#endif

#if T(VAES)
// VAES does not require AVX512 and works on Alder Lake
attribute_target("avx2,vaes") void test_vaes()
{
/* 256- and 512-bit AES */
__m256i a = _mm256_set1_epi32(-1);
__m256i b = _mm256_aesenc_epi128(a, a);
__m256i c = _mm256_aesdec_epi128(b, a);
}
#endif

int main()
{
return 0;
Expand Down
22 changes: 20 additions & 2 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ qt_config_compile_test_x86simd(avx512ifma "AVX512 IFMA instructions")
# avx512vbmi
qt_config_compile_test_x86simd(avx512vbmi "AVX512 VBMI instructions")

# x86: avx512vbmi2
qt_config_compile_test_x86simd(avx512vbmi2 "AVX512VBMI2")

# x86: vaes
qt_config_compile_test_x86simd(vaes "VAES")

# posix_fallocate
qt_config_compile_test(posix_fallocate
LABEL "POSIX fallocate()"
Expand Down Expand Up @@ -803,12 +809,24 @@ qt_feature("avx512vbmi" PRIVATE
)
qt_feature_definition("avx512vbmi" "QT_COMPILER_SUPPORTS_AVX512VBMI" VALUE "1")
qt_feature_config("avx512vbmi" QMAKE_PRIVATE_CONFIG)
qt_feature("avx512vbmi2" PRIVATE
LABEL "AVX512VBMI2"
CONDITION QT_FEATURE_avx512f AND TEST_subarch_avx512vbmi2
)
qt_feature_definition("avx512vbmi2" "QT_COMPILER_SUPPORTS_AVX512VBMI2" VALUE "1")
qt_feature_config("avx512vbmi2" QMAKE_PRIVATE_CONFIG)
qt_feature("aesni" PRIVATE
LABEL "AES"
CONDITION QT_FEATURE_sse2 AND TEST_subarch_aesni
)
qt_feature_definition("aesni" "QT_COMPILER_SUPPORTS_AES" VALUE "1")
qt_feature_config("aesni" QMAKE_PRIVATE_CONFIG)
qt_feature("vaes" PRIVATE
LABEL "VAES"
CONDITION QT_FEATURE_avx2 AND TEST_subarch_vaes
)
qt_feature_definition("vaes" "QT_COMPILER_SUPPORTS_VAES" VALUE "1")
qt_feature_config("vaes" QMAKE_PRIVATE_CONFIG)
qt_feature("rdrnd" PRIVATE
LABEL "RDRAND"
CONDITION TEST_subarch_rdrnd
Expand Down Expand Up @@ -1065,13 +1083,13 @@ qt_configure_add_summary_entry(
)
qt_configure_add_summary_entry(
TYPE "featureList"
ARGS "avx avx2"
ARGS "avx avx2 vaes"
MESSAGE "AVX"
CONDITION ( ( TEST_architecture_arch STREQUAL i386 ) OR ( TEST_architecture_arch STREQUAL x86_64 ) )
)
qt_configure_add_summary_entry(
TYPE "featureList"
ARGS "avx512f avx512er avx512cd avx512pf avx512dq avx512bw avx512vl avx512ifma avx512vbmi"
ARGS "avx512f avx512er avx512cd avx512pf avx512dq avx512bw avx512vl avx512ifma avx512vbmi avx512vbmi2"
MESSAGE "AVX512"
CONDITION ( ( TEST_architecture_arch STREQUAL i386 ) OR ( TEST_architecture_arch STREQUAL x86_64 ) )
)
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/tools/qhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ aeshash256_lt32_avx256(__m256i state0, const uchar *p, size_t len)
{
__m128i state0_128 = _mm256_castsi256_si128(state0);
if (len) {
__mmask32 mask = _bzhi_u32(-1, len);
__mmask32 mask = _bzhi_u32(-1, unsigned(len));
__m256i data = _mm256_maskz_loadu_epi8(mask, p);
__m128i data0 = _mm256_castsi256_si128(data);
if (len >= sizeof(__m128i)) {
Expand Down

0 comments on commit 38e6b63

Please sign in to comment.