Is there an efficient way to get the first non-zero element in an SIMD register using SIMD intrinsics?
17:12 13 Oct 2016

As the title reads, if a 256-bit SIMD register is:

0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 |

How can I efficiently get the index of the first non-zero element (i.e. the index 2 of the first 1)? The most straightforward way is to store into memory and check one by one, but it may cost to much. Is there any cute ideas to do so?

x86 bit-manipulation simd intrinsics avx