title: Can a movss instruction be used to replace integer data?
body: <p>With the constraint that I can use only SSE and SSE2 instructions, I have a need to replace the least significant (0) element of a 4 element __m128i vector with the 0 element from another vector.</p>
  
  <p>For floating point vectors, the task is simple - one can use the _mm_move_ss() intrinsic to cause the element to be replaced with the 0 element from another vector.  It generates one movss instruction, so is quite efficient.</p>
  
  <p>Using two casting intrinsics, it's possible to also convince the compiler to use a single SSE movss instruction to move integer data.  The source code ends up looking like this:</p>
  
  <pre><code>__m128i NewVector = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(Take3FromThisVector),
                                                   _mm_castsi128_ps(Take1FromThisVector)));
  </code></pre>
  
  <p>It looks a bit messy, but with a suitable amount of commenting it can be acceptable, especially since it generates a minimum of instructions.  In its typical use everything's optimized to be in xmm registers.</p>
  
  <p><strong>My question is this:</strong></p>
  
  <p>Since it's a movss instruction, where the "ss" implies single precision floating point, <strong>is it okay to have it move integer data that could potentially contain some "special" or "illegal" (for floating point) combo of bits in any of the vector positions?</strong></p>
  
  <p>The obvious alternative - which I also implemented and tested - is to AND the first vector with a mask, then OR in a second vector that contains just one value in the least significant element, with all the others being zero.  As you can imagine, this generates more instructions.</p>
  
  <p>I've tested the casting approach I showed above and it doesn't seem to cause any problems, but I note in particular that there's no intrinsic provided that does this same operation for integer data.  It seems as though Intel would have provided one if it was just as good for integer data - e.g., _mm_move_epi32 or similar.  And so I'm skeptical whether this is a good idea.</p>
  
  <p>I did some searches, e.g., "can a movss instruction cause a floating point exception", but did not find any information that would answer my question.</p>
  
  <p>Thanks in advance for knowledge you're willing to share.</p>
  
  <p>-Noel</p>