With AVX512, there is the intrinsic `_mm256_lzcnt_epi32`, 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.

Is there an efficient way to implement this using AVX and AVX2 instructions only?

Currently I'm using a loop which extracts each element and applies the `_lzcnt_u32` function.

---

Related: to bit-scan one large bitmap, see [Count leading zeros in \_\_m256i word](https://stackoverflow.com/questions/49213611/count-leading-zeros-in-m256i-word) which uses `pmovmskb` -> bitscan to find which byte to do a scalar bitscan on.

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.