title: Is there a good way of finding modulus of two variables using SSE? (without SVML)
body: <p>I'm trying to learn to use SSE, one of the programs I was making required the use of modulus division and so I wrote this to do it (sorry it's overcommented):</p>
  
  <pre><code>__m128i SSEModDiv(__m128i input, __m128i divisors)
  {
      //Error Checking (div by zero)
      /*__m128i zeros = _mm_set1_epi32(0);
      __m128i error = _mm_set1_epi32(-1);
      __m128i zerocheck = _mm_cmpeq_epi32(zeros, divisors);
      if (_mm_extract_epi16(zerocheck, 0) != 0)
          return error;
      if (_mm_extract_epi16(zerocheck, 2) != 0)
          return error;
      if (_mm_extract_epi16(zerocheck, 4) != 0)
          return error;
      if (_mm_extract_epi16(zerocheck, 6) != 0)
          return error;*/
  
      //Now for the real work
      __m128 inputf = _mm_cvtepi32_ps(input);
      __m128 divisorsf = _mm_cvtepi32_ps(divisors);
  
      /*__m128 recip = _mm_rcp_ps(divisorsf); //Takes reciprocal
      __m128 divided = _mm_mul_ps(inputf, recip); //multiplies by reciprical values*/
      __m128 divided = _mm_div_ps(inputf, divisorsf);
      __m128i intermediateint = _mm_cvttps_epi32(divided); //makes an integer version truncated
      __m128 intermediate = _mm_cvtepi32_ps(intermediateint);
      __m128 multiplied = _mm_mul_ps(intermediate, divisorsf); //multiplies the intermediate with the divisors
      __m128 mods = _mm_sub_ps(inputf, multiplied); //subtracts to get moduli
      return _mm_cvtps_epi32(mods);
  }
  </code></pre>
  
  <p>The problem is this is about as fast as taking the modulus of each element of the four 32-bit integers individually in release and about 10 times slower in debug (found by profiling).</p>
  
  <p>Could anyone give me any pointers on how to make this function faster?</p>
  
  <p>-I can't use SVML be cause I'm using Visual Studio-</p>