From 936fb65dc73baafef1ec93690becdb422dae12e5 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Wed, 28 Feb 2024 10:20:03 +0500 Subject: [PATCH] Workaround for MSVC. By default MSVC does not define the __SSE*__ macros. Fix it if AVX is enabled. Signed-off-by: Vladislav Shchapov --- .github/workflows/cmake.yml | 15 +++++++++++++++ CMakeLists.txt | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e5bb33ba..f8769c70 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -468,6 +468,11 @@ jobs: compiler: cl cmake-args: -G "Visual Studio 17 2022" -A x64 -T v143 + - name: Windows MSVC 2022 v143 Win64 Native Instructions (AVX) + os: windows-latest + compiler: cl + cmake-args: -G "Visual Studio 17 2022" -A x64 -T v143 -DWITH_NATIVE_INSTRUCTIONS=ON -DNATIVE_ARCH_OVERRIDE=/arch:AVX + - name: Windows MSVC 2022 v142 Win32 os: windows-latest compiler: cl @@ -516,6 +521,10 @@ jobs: os: windows-latest cmake-args: -T ClangCl -A x64 + - name: Windows ClangCl Win64 Native Instructions (AVX) + os: windows-latest + cmake-args: -T ClangCl -A x64 -DWITH_NATIVE_INSTRUCTIONS=ON -DNATIVE_ARCH_OVERRIDE="-mavx -mpclmul" + - name: Windows GCC os: windows-latest compiler: gcc @@ -523,6 +532,12 @@ jobs: cmake-args: -G Ninja codecov: win64_gcc + - name: Windows GCC Native Instructions (AVX) + os: windows-latest + compiler: gcc + cxx-compiler: g++ + cmake-args: -G Ninja -DWITH_NATIVE_INSTRUCTIONS=ON -DNATIVE_ARCH_OVERRIDE="-mavx -mpclmul" + - name: Windows GCC Compat No Opt os: windows-latest compiler: gcc diff --git a/CMakeLists.txt b/CMakeLists.txt index b5abd6f9..ef69f864 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,28 @@ endif() if(NOT WITH_RUNTIME_CPU_DETECTION) if(MSVC AND BASEARCH_X86_FOUND) message(STATUS "WARNING: Microsoft Visual Studio does not support compile time detection of CPU features for \"/arch\" before \"AVX\"") + # Workaround for MSVC. By default MSVC does not define the __SSE*__ macros. + # Fix it if AVX is enabled. + set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG}") + check_c_source_compiles( + "#ifndef __AVX__ + # error \"AVX is not enabled.\" + #endif + int main(void) { return 0; }" + MSVC_IS_ENABLED_AVX + ) + set(CMAKE_REQUIRED_FLAGS) + if(MSVC_IS_ENABLED_AVX) + add_definitions( + -D__SSE__=1 + -D__SSE2__=1 + -D__SSE3__=1 + -D__SSSE3__=1 + -D__SSE4_1__=1 + -D__SSE4_2__=1 + -D__PCLMUL__=1 + ) + endif() endif() add_definitions(-DDISABLE_RUNTIME_CPU_DETECTION) endif() -- 2.47.2