title: Fast Popcount instruction or Hamming distance for binary array?
body: <p>I'm implementing on Visual Studio 2010 C++</p>
  
  <p>I have two binary arrays. For example,</p>
  
  <pre><code>array1[100] = {1,0,1,0,0,1,1, .... }
  array2[100] = {0,0,1,1,1,0,1, .... }
  </code></pre>
  
  <p>To calculate the <a href="http://en.wikipedia.org/wiki/Hamming_distance" rel="nofollow">Hamming distance</a> between <code>array1</code> and <code>array2</code>,
  <code>array3[100]</code> stores the <code>xor</code> result of <code>array1</code> and <code>array2</code>.</p>
  
  <p>Then I have to count the number of <code>1</code> bits in <code>array3</code>. To do this, I know I can use the <code>__popcnt</code> instruction.</p>
  
  <p>For now, I'm doing something like below:</p>
  
  <pre><code>popcnt_result = 0;
  for (i=0; i&lt;100; i++) {
      popcnt_result = popcnt_result + __popcnt(array3[i]);
  }
  </code></pre>
  
  <p>It shows a good result but is slow. How can I make it faster?</p>