Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

Extract non-zero byte from _m128i

Ravi_K_
Beginner
144 Views
Hi, I have 4 _m128i 64byte elements which can contain 0 or non-zero (+ve, -ve) values. I want to extract non-zero values from them. I looked at _mm_extract_epi8/_mmextract_epi16 but the syntax is int _mm_extract_epi16 (__m128i a, int imm) where imm is the index, hence I have to loop to get non-zero values. Any intrinsics functions that can be used to avoid loop will be helpful. Inputs appreciated. Thanks.
0 Kudos
3 Replies
andysem
New Contributor III
144 Views

I'm thinking _mm_cmpeq_epi8, _mm_movemask_epi8 and then dispatch through a table of pointers to series of _mm_extract_epi8. But I'm not sure this approach will be beneficial compared to a regular std::find_if in memory.

jimdempseyatthecove
Black Belt
144 Views

Ravi,

Can you describe in more detail (widen the scope of your description) of what you are trying to do?

IOW are you intending to squish out the 0's of 4 x _mm_epi8 registers (to left, to right, across registers), or is this a squish of a larger number of bytes in memory?

Jim Dempsey

Ravi_K_
Beginner
144 Views
Thanks andysem for your inputs, will look into it. Jim, I want to use it for ipv6 source/destination address and mask and want to implement TCAM like Longest-Prefix-Match behavior. Thanks.
Reply