title: How can I use SSE (and SSE2, SSE3, etc.) extensions when building with Visual C++?
body: <p>I'm now working in a small optimisation of a basic dot product function, by using SSE instructions in visual studio.</p>
  
  <p>Here is my code : (function call convention is cdecl) :</p>
  
  <pre><code>float SSEDP4(const vect &amp; vec1, const vect &amp; vec2)
  {
      __asm
      {
          // get addresses
          mov ecx, dword ptr[vec1]
          mov edx, dword ptr[vec2]
          // get the first vector
          movups xmm1, xmmword ptr[ecx]
          // get the second vector (must use movups, because data is not assured to be aligned to 16 bytes =&gt; TODO align data)
          movups xmm1, xmmword ptr[edx]
          // OP by OP multiply with second vector (by address)
          mulps xmm1, xmm2
          // add everything with horizontal add func (SSE3)
          haddps xmm1, xmm1
          // is one addition enough ?
          // try to extract, we'll see
          pextrd eax, xmm1, 03h
      }
  }
  </code></pre>
  
  <p><code>vect</code> is a simple struct that contains 4 single precision floats, non aligned to 16 bytes (that is why I use <code>movups</code> and not <code>movaps</code>)</p>
  
  <p><code>vec1</code> is initialized with <code>(1.0, 1.2, 1.4, 1.0)</code> and <code>vec2</code> with <code>(2.0, 1.8, 1.6, 1.0)</code></p>
  
  <p>Everything compiles well, but at execution, I got 0 in both XMM registers, and so as result
  while debugging, visual studio shows me 2 registers (MMX1 and MMX2, or sometimes MMX2 and MMX3) which are 64 bits registers, but no XMM and everything to 0.</p>
  
  <p>Does someone has an idea of what's happening ?</p>
  
  <p>Thank you in advance :)</p>