In my current project, I have to compare 128bit values (actually md5 hashes) and I thought it would be possible to accelerate the comparison by using SSE instructions. My problem is that I can’t manage to find good documentation on SSE instructions; I’m searching for a 128bit integer comparison instruction that let me know if one hash is larger, smaller or equal to another. Does such an instruction exists?
PS: The targeted machines are x86_64 servers with SSE2 instructions; I’m also interested in a NEON instruction for the same job.
There are no 128-bit integer comparison instructions in the SSE or NEON instruction sets.
SSE4.1 added vector 64-bit integer comparisons: PCMPEQQ and PCMPGTQ, but because of the way they are implemented it is not straightforward to piece two of them together into a 128-bit comparison.
The preferred way to accomplish a 128-bit comparison on x86_64 is to use a 64-bit comparison on the high word, then an additional 64-bit comparison on the low word only if the high words compare equal:
On ARM, the usual idiom is a sequence of conditional comparisons word-by-word to set the flags as needed.