Skip to content

Commit 0b63378

Browse files
committed
CMakeLists: define INTEL_INTRINSICS_AVX512 is avx512 modules can safely be used.
1 parent c506611 commit 0b63378

1 file changed

Lines changed: 33 additions & 21 deletions

File tree

avs_core/CMakeLists.txt

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,41 @@ endif()
1414
project("AvsCore" VERSION "${PROJECT_VERSION}" LANGUAGES CXX)
1515
Include("Files.cmake")
1616

17-
# Remove AVX512 specific files if it's a 32-bit build
18-
if(CMAKE_SIZEOF_VOID_P EQUAL 4) # Check for 32-bit
19-
list(FILTER AvsCore_Sources EXCLUDE REGEX ".*_avx512\\.(cpp|h)$")
20-
endif()
21-
22-
# Remove AVX512 specific files for older MSVC versions
23-
# Check MSVC version for lack of full AVX-512BW mask intrinsics (older than MSVC 19.22)
24-
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC_IDE AND NOT CLANG_IN_VS AND NOT IntelLLVM_IN_VS)
25-
string(REGEX MATCH "^19\\.([0-9]+)\\.([0-9]+)" MSVC_VERSION_MATCH "${CMAKE_CXX_COMPILER_VERSION}")
26-
if(MSVC_VERSION_MATCH)
27-
set(MSVC_MAJOR 19)
28-
set(MSVC_MINOR ${CMAKE_MATCH_1})
29-
set(MSVC_PATCH ${CMAKE_MATCH_2})
30-
31-
if(MSVC_MAJOR LESS 19 OR (MSVC_MAJOR EQUAL 19 AND MSVC_MINOR LESS 22)) # Before MSVC 2019 16.2 (19.22)
32-
list(FILTER AvsCore_Sources EXCLUDE REGEX ".*_avx512\\.(cpp|h)$")
33-
message(WARNING "Detected older native 64-bit MSVC (version ${CMAKE_CXX_COMPILER_VERSION}). AVX-512 files are excluded due to missing AVX512BW mask intrinsics before Visual Studio 2019 16.2.")
17+
# Initialize a variable to control INTEL_INTRINSICS_AVX512 definition
18+
# AVX512 support is only available on Intel architectures and 64-bit builds and specific compilers
19+
set(DEFINE_AVX512 FALSE)
20+
if(ENABLE_INTEL_SIMD)
21+
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit build
22+
if(MSVC_IDE AND NOT CLANG_IN_VS AND NOT IntelLLVM_IN_VS) # Native MSVC, need to check version
23+
string(REGEX MATCH "^19\\.([0-9]+)\\.([0-9]+)" MSVC_VERSION_MATCH "${CMAKE_CXX_COMPILER_VERSION}")
24+
if(MSVC_VERSION_MATCH)
25+
set(MSVC_MAJOR 19)
26+
set(MSVC_MINOR ${CMAKE_MATCH_1})
27+
set(MSVC_PATCH ${CMAKE_MATCH_2})
28+
29+
if(MSVC_MAJOR GREATER_EQUAL 19 AND MSVC_MINOR GREATER_EQUAL 22) # MSVC 2019 16.2 (19.22) or newer
30+
set(DEFINE_AVX512 TRUE)
31+
endif()
32+
else()
33+
message(WARNING "Could not parse native 64-bit MSVC version. AVX-512 support might be incomplete.")
34+
endif()
35+
else() # Not native old MSVC (likely GCC, Clang, or newer MSVC via Clang/IntelLLVM)
36+
# all supports AVX512
37+
set(DEFINE_AVX512 TRUE)
3438
endif()
39+
endif()
40+
41+
# Add the AVX-512 definition if the flag is TRUE
42+
if(DEFINE_AVX512)
43+
add_definitions(-DINTEL_INTRINSICS_AVX512)
3544
else()
36-
# If version parsing fails, assume potential issues and warn
37-
message(WARNING "Could not parse native 64-bit MSVC version. AVX-512 support might be incomplete.")
45+
# Remove AVX512 specific files if it's a 32-bit build
46+
# or not supported compiler version
47+
list(FILTER AvsCore_Sources EXCLUDE REGEX ".*_avx512\\.(cpp|h)$")
3848
endif()
49+
50+
# Note: AVX512 related source must be guarded with #ifdef INTEL_INTRINSICS_AVX512 within the
51+
# already existing #ifdef INTEL_INTRINSICS
3952
endif()
4053

4154
add_library("AvsCore" ${AvsCore_Sources})
@@ -93,9 +106,8 @@ handle_arch_flags(SSE41 " -msse4.1 " " /arch:SSE2 ") # no special SSE4.1 option
93106
handle_arch_flags(AVX " -mavx " " /arch:AVX ")
94107
handle_arch_flags(AVX2 " -mavx2 -mfma " " /arch:AVX2 ")
95108

96-
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # AVX512 exists only on 64-bit
109+
if(DEFINE_AVX512)
97110
handle_arch_flags(AVX512 " -mavx512f -mavx512bw " " /arch:AVX512 ")
98-
# though such source patterns were already removed from source list
99111
endif()
100112

101113
# Specify include directories

0 commit comments

Comments
 (0)