c++ - SSE 4.2: alternative to _mm_cmpistri -
i wrote program runs _mm_cmpistri next \n (newline) character. while works great on computer, fails on server due missing sse 4.2 support.
is there alternative using sse commands <= sse 4.1?
regards
ok, actual code is. hasn't been tested, it's give idea.
__m128i lf = _mm_set1_epi8('\n'); // unaligned part __m128i data = _mm_loadu_si128((__m128i *)ptr); int mask = _mm_movemask_epi8(_mm_cmpeq_epi8(data, lf)); if (mask != 0) return ffs(mask); int index = 16 - ((size_t)ptr & 15); // aligned part, possibly overlaps unaligned part that's ok (; index < length; index += 16) { data = _mm_load_si128((__m128i *)(ptr + index)); mask = _mm_movemask_epi8(_mm_cmpeq_epi8(data, lf)); if (mask != 0) return index + ffs(mask); }
for msvc, ffs
can defined in terms of _bitscanforward
.
Comments
Post a Comment