title: Detecting SIMD instruction sets to be used with C++ Macros in Visual Studio 2015
body: <p>So, here is what I am trying to accomplish. In my C++ project that <em>has to be compiled with Microsoft Visual Studio 2015 or above</em>, I need to have some code have different versions depending on the newest SIMD instrunction set available in the CPU of the user, among: <code>SSE</code>, <code>SSE2</code>, <code>SSE3</code>, <code>SSSE3</code>, <code>SSE4.1</code>, <code>SSE4.2</code>, <code>AVX</code>, <code>AVX2</code> and <code>AVX512</code>.</p>
  
  <p>Since what I am look for at this point is <strong>compile-time CPU dispatching</strong>, my first guess was that it could be easily accomplished using compiler macros. However, to my astonishment, it has been quite hard to find information on how to achieve such CPU dispatching with macros in VS2015.</p>
  
  <p>For instance, the former question "<a href="https://stackoverflow.com/questions/18563978/sse-sse2-is-enabled-control-in-visual-studio">Detect the availability of SSE/SSE2 instruction set in Visual Studio</a>" has information on how to detect SSE and SSE2 for x86 code, but not for x64 code. Although, they make a reference to this Microsoft's document: <a href="http://msdn.microsoft.com/en-us/library/b0084kay.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/b0084kay.aspx</a></p>
  
  <p>There, we only have information on how to detect whether SSE, SSE2, AVX and AVX2 are <em>enabled</em> in the compiler - not exactly whether they are supported by CPU. Also, there is nothing at all about the other instrunction sets, like SSE3, SSSE3, SSE4.1, SSE4.2 and AVX512.</p>
  
  <p>So, my question becomes: how can I detect whether the user's CPU supports those instrunction sets via macro, just like other compilers do, but with Microsoft Visual Studio 2015?</p>