Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

Extract non-zero byte from _m128i

Ravi_K_
Beginner
538 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
538 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.

0 Kudos
jimdempseyatthecove
Honored Contributor III
538 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

0 Kudos
Ravi_K_
Beginner
538 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.
0 Kudos
Reply