WojciechMula / sse4-strstr

SIMD (SWAR/SSE/SSE4/AVX2/AVX512F/ARM Neon) of Karp-Rabin algorithm's modification
http://0x80.pl/articles/simd-strfind.html
BSD 2-Clause "Simplified" License
237 stars 27 forks source link

avx2_strstr_anysize does not work with pattern of size one #11

Open tbarbette opened 4 years ago

tbarbette commented 4 years ago

With patterns that are a single character, the line: https://github.com/WojciechMula/sse4-strstr/blob/9308a59891f694f63ad6e55e387d244ea7ca4209/avx2-strstr-v2.cpp#L25 will not evaluate to true as k-2 is undefined.

avx2_strstr_anysize should have a precondition to have k > 1 (and not > 0), or change that line to accept also if k == 1 (but that's sad for the non-common case), or start with a special case.

WojciechMula commented 3 years ago

Probably the easiest way is to have the precondition k > 1. For k == 1, we have memchr.