Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Which of these two ways is more effecient to search in a string with SIMD?

HD86
Novice
1,286 Views

The following two code samples achieve the same thing. They search in a string of 8 bit chars and return an index of the first match.

The first way uses a PCMPxSTRx instruction.

int Index = _mm_cmpistri(a, b, _SIDD_CMP_EQUAL_EACH);

 

The second way uses a PCMPEQ instruction.

__m128i VectorMask = _mm_cmpeq_epi8(a, b);
int Mask = _mm_movemask_epi8(VectorMask);
unsigned long Index {};
_BitScanForward(&Index, Mask);

 

Which way is better to use? Supposing that I know that the two vectors contain only 'valid characters' (no zeros) and that I am not interested in any manipulations of the result mask.

The first way looks more compact in the high level code, but I feel that it will produce a bigger number of micro-ops when decoded by the CPU, based on its description in the Intel intrinsics guide. So perhaps the second way is more efficient.

0 Kudos
3 Replies
AbhishekD_Intel
Moderator
1,263 Views

Hi,


We are forwarding this issue to the SME.

Please give us the environment details like compiler version, cpuinfo, OS details etc.

So that SME will have more insight and can dig into this use-case.



Warm Regards,

Abhishek



0 Kudos
HD86
Novice
1,254 Views

Can I cancel the question? I think I know the answer now.

Please delete the question if it is possible.

Sorry,

 

0 Kudos
JenniferJ
Moderator
1,064 Views

No need to delete the question. It would be great if you could post your finding here. thanks! 

FYI on the Intel Intrinsics Guide webpage: https://software.intel.com/sites/landingpage/IntrinsicsGuide/ , it's helpful to find all the details for each intrinsic. 

Jennifer 

0 Kudos
Reply