Created
June 2, 2017 13:37
-
-
Save x100ex/bffece0136caf19600224b0aba318c2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://schani.wordpress.com/2010/04/30/linear-vs-binary-search/ | |
static int | |
linear_sentinel_sse2 (const int *arr, int n, int key) { | |
v4si *in_data = (v4si*)arr; | |
v4si key4 = { key, key, key, key }; | |
int i = 0; | |
for (;;) { | |
v4si tmp = __builtin_ia32_pcmpgtd128 (key4, in_data [i]); | |
int res = __builtin_ia32_pmovmskb128 ((v16qi)tmp); | |
if (res != 0xffff) | |
break; | |
++i; | |
} | |
return i * 4 + __builtin_ctz (~res) / 4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment