]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Workaround for MSVC. By default MSVC does not define the __SSE*__ macros. Fix it...
authorVladislav Shchapov <vladislav@shchapov.ru>
Wed, 28 Feb 2024 05:20:03 +0000 (10:20 +0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 6 Mar 2024 22:32:15 +0000 (23:32 +0100)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
.github/workflows/cmake.yml
CMakeLists.txt

index e5bb33ba37db8b97fdb301714f93f89e33a200fa..f8769c70b196138f208f186d800d39f6e19945be 100644 (file)
@@ -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
index b5abd6f94961d3ca2643ee783960e97021f41a17..ef69f86458c3c677bc891f363bc95be06b2a352d 100644 (file)
@@ -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()