Created
December 26, 2020 03:12
-
-
Save Const-me/5999328a743128a86f7f5a93d07f2463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <emmintrin.h> | |
#include <tmmintrin.h> | |
__m128i cmpgt_epu64_ssse3( __m128i a, __m128i b ) | |
{ | |
// Compare uint32_t lanes for a > b and a < b | |
const __m128i signBits = _mm_set1_epi32( 0x80000000 ); | |
a = _mm_xor_si128( a, signBits ); | |
b = _mm_xor_si128( b, signBits ); | |
__m128i gt = _mm_cmpgt_epi32( a, b ); | |
__m128i lt = _mm_cmpgt_epi32( b, a ); | |
// Shuffle bytes making two pairs of equal uint32_t values to compare. | |
// Each uint32_t combines two bytes from lower and higher parts of the vectors. | |
const __m128i shuffleIndices = _mm_setr_epi8( | |
0, 4, -1, -1, | |
0, 4, -1, -1, | |
8, 12, -1, -1, | |
8, 12, -1, -1 ); | |
gt = _mm_shuffle_epi8( gt, shuffleIndices ); | |
lt = _mm_shuffle_epi8( lt, shuffleIndices ); | |
// Make the result | |
return _mm_cmpgt_epi32( gt, lt ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment