title: Strange assembler generated by VS 2008
body: <p>I have a c++ function, looking like:</p>
  
  <pre><code>inline unsigned short function_name(float x, float y, someStruct *cfg) 
  {
      int x_pos = (int)(x*2 + 0.5f);
      int y_pos = (int)(y*2 + 0.5f);  
  
      int dict_index = x_pos + (y_pos * cfg-&gt;subdivisions_adj);
  
      [...]
  </code></pre>
  
  <p>while <code>someStruct</code> is declared as:</p>
  
  <pre><code>struct someStruct {
   int subdivisions;
   int subdivisions_adj;
   [...]
  }
  </code></pre>
  
  <p>The generated assembly for the third line (<code>int dict_index = [...]</code>) is:</p>
  
  <pre><code>cvttss2si edi,xmm3
  imul edi,[ecx+04h]
  movss xmm3,[ecx+0ch]
  movaps xmm4,xmm3
  mulss xmm4,xmm0
  addss xmm4,xmm1
  cvttss2si eax,xmm4
  add edi,eax
  </code></pre>
  
  <p>(See also the <a href="http://s22.postimg.org/6z1inyvr5/screenshot_137.png" rel="nofollow">result by AMDCodeAnalyst</a>)</p>
  
  <p>Can anyone explain what this assembly does? I don't know why <code>cvttss2si</code> and <code>movaps</code> are used at all, aren't they for floating point numbers?</p>
  
  <p>I am using Visual Studio 2008 on Windows 7, with the SSE2 instruction set enabled.</p>