I am working on a piece of code that needs SIMD vectorization, and I need to make a set of macros to decide which vector types and intrinsics to use (i.e. MYLIB_HAS_SSE
, MYLIB_HAS_AVX
, etc.).
On GCC and CLang this is fairly straightforward, I just need to check for the corresponding pre-defined macros such as __SSE__
or __SSE4_1__
. MSVC on the other hand does not define any such macros other than __AVX__
and __AVX2__
to my knowledge, and support for SSE and SSE2 must be checked via the _M_IX86_FP
macro. _M_IX86_FP
however, does not seem to give any information beyond SSE2, so if I want to check for SSE3 and beyond I am out of luck. As such, I need to "emulate" the missing macros in some other way.
Is it safe to assume that if MSVC has the __AVX__
macro defined (i.e. the target supports AVX), then the target CPU also supports all levels of SSE up to SSE4.2? Is there any other way to check for SSE support on x86 targets (other than runtime cpuid)?
Also if anyone knows, is there some convenient table of x86 architectures and their corresponding feature levels?