Hi,
It does not seem that msvc provides an automatic setting for /arch (which would be the equivalent of -march=native with gcc/clang).
Is there a way to achieve it with cmake?
I saw in msvc doc about a cpuid command but is it the way to go (I’d like to limit the number of tests I run at configuration time)?
Another thing that I tested is like this:
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("/arch:AVX" COMPILER_SUPPORTS_AVX)
if(COMPILER_SUPPORTS_AVX)
message(STATUS "The compiler supports /arch:AVX")
endif()
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
message(STATUS "The compiler supports /arch:AVX2")
endif()
check_cxx_compiler_flag("/arch:AVX512" COMPILER_SUPPORTS_AVX512)
if(COMPILER_SUPPORTS_AVX512)
message(STATUS "The compiler supports /arch:AVX512")
endif()
Yet I don’t know if a success means that the instruction set actually exists or if it only mean that msvc frontend accepts the value of the argument. MSVC documentation does not say a word about this.
Auto-Parallelization and Auto-Vectorization | Microsoft Learn seems to imply that their is some automatic mechanism by default but its interaction with /arch
argument is unclear for me.
regards,
A.