Question

I need to quickly compare two string on the machine with SSE4 support. How can I do it without writing assembler inserts?

Some wrappers like long long bitmask = strcmp(char* a, char* b) would be perfect.

Was it helpful?

Solution

Instead of using inline assembly, you should use the Intel SSE intrinsics.

For string comparison, you'll need the SSE4.2 intrinsics:

Documentation is here: http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/cpp-mac/GUID-6E9CFDF2-5DF6-42A4-B429-0E2CD441342E.htm

OTHER TIPS

Use Agner Fog's asmlib. http://www.agner.org/optimize/#asmlib

He's already taken the trouble for writing the code in assembly for you including using SSE4.2 instructions. Use his function A_strcmp (or the case insensitive version A_stricmp).

It would be interesting so how a method using intrinsics compares in performance.

Here is a good article of using SSE 4.2 for boosting string operations: http://www.strchr.com/strcmp_and_strlen_using_sse_4.2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top