title: Fast counting the number of equal bytes between two arrays
body: <p>I wrote the function <code>int compare_16bytes(__m128i lhs, __m128i rhs)</code> in order to compare two 16 byte numbers using SSE instructions: this function returns how many bytes are equal after performing the comparison.</p>
  
  <p>Now I would like use the above function in order to compare two byte arrays of arbitrary length: the length may not be a multiple of 16 bytes, so I need deal with this problem. How could I complete the implementation of the function below? How could I improve the function below?</p>
  
  <pre><code>int fast_compare(const char* s, const char* t, int length)
  {
      int result = 0;
  
      const char* sPtr = s;
      const char* tPtr = t;
  
      while(...)
      {
          const __m128i* lhs = (const __m128i*)sPtr;
          const __m128i* rhs = (const __m128i*)tPtr;
  
          // compare the next 16 bytes of s and t
          result += compare_16bytes(*lhs,*rhs);
  
          sPtr += 16;
          tPtr += 16;
      }
  
      return result;
  }
  </code></pre>