title: Count leading zero bits for each element in AVX2 vector, emulate _mm256_lzcnt_epi32
body: <p>With AVX512, there is the intrinsic <code>_mm256_lzcnt_epi32</code>, which returns a vector that, for each of the 8 32-bit elements, contains the number of leading zero bits in the input vector's element.</p>
  
  <p>Is there an efficient way to implement this using AVX and AVX2 instructions only?</p>
  
  <p>Currently I'm using a loop which extracts each element and applies the <code>_lzcnt_u32</code> function.</p>
  
  <hr>
  
  <p>Related: to bit-scan one large bitmap, see <a href="https://stackoverflow.com/questions/49213611/count-leading-zeros-in-m256i-word">Count leading zeros in __m256i word</a> which uses <code>pmovmskb</code> -> bitscan to find which byte to do a scalar bitscan on.</p>
  
  <p>This question is about doing 8 separate lzcnts on 8 separate 32-bit elements when you're actually going to use all 8 results, not just select one.</p>