Last active
March 15, 2016 11:24
-
-
Save kayru/7a45476b480e9b7039be to your computer and use it in GitHub Desktop.
findIntSSE2
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
const int* findIntSSE2(const int* __restrict begin, const int* __restrict end, int needle) | |
{ | |
const int* it = begin; | |
unsigned long index; | |
__m128i n = _mm_set1_epi32(needle); | |
while (it != end) | |
{ | |
__m128i x = _mm_load_si128(reinterpret_cast<const __m128i*>(it)); | |
__m128i m = _mm_cmpeq_epi32(x, n); | |
unsigned long k = _mm_movemask_epi8(m); | |
if (_BitScanForward(&index, k)) | |
{ | |
return it + index/4; | |
} | |
it += 4; | |
} | |
return it; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment