
How it works
Most modern processors provide vector instruction sets. Carefully crafted code can exploit these and achieve enhanced performance with respect to non-vectorized code. The Eigen library has been written with vectorization explicitly in mind since linear algebra operations can greatly benefit from it. All we need to do is instruct the compiler to inspect the processor for us and generate the native set of instructions for the current architecture. Different compiler vendors use different flags to achieve this: the GNU compiler implements this by means of the -march=native flag, whereas the Intel compiler uses the -xHost flag. We then use the check_cxx_compiler_flag function offered by the CheckCXXCompilerFlag.cmake module:
check_cxx_compiler_flag("-march=native" _march_native_works)
This function accepts two arguments: the first one is the compiler flag to check, the second is a variable for storing the result, true or false, of the check. If the check is positive, we add the working flag to the _CXX_FLAGS variable, which will then be used to set the compiler flags for our executable target.