Skip to content

Instantly share code, notes, and snippets.

@kayru
Last active March 15, 2016 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayru/7a45476b480e9b7039be to your computer and use it in GitHub Desktop.
Save kayru/7a45476b480e9b7039be to your computer and use it in GitHub Desktop.
findIntSSE2
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