I need a way to compare values of type __m128i
in C++ for a total order between any values of type __m128i
. The type of order doesn't matter as long as it establishes a total order between all values of type __m128i
. Hence the comparison might be less-than between 128-bit integers or something else entirely as long as is provides a total order.
I tried using the <
operator, but that didn't return a bool
, but instead seems to compare the vector components of __m128i
(i.e. SIMD):
#include <emmintrin.h>
inline bool isLessThan(__m128i a, __m128i b) noexcept {
// error: cannot convert '__vector(2) long int' to 'bool' in return
return a < b;
}
Another possibility would be to use memcmp
/strcmp
or similar, but this would very likely not be optimal. Targeting modern Intel x86-64 CPUs with at least SSE4.2 and AVX2, are there any intrinsics / instructions I could use for such comparisons? How to do it?
PS: Similar questions have been asked for checking equality but not for ordering: