Open xortator opened 2 years ago
Another (also pretty straightforward) version of same algorithm doesn't vectorize either:
unsigned rabin_karp_naive_v2(unsigned *s, unsigned len) {
unsigned hash = 0;
unsigned mul = 1;
for (unsigned i = 0; i < len; i++) {
hash += mul * s[len - 1 - i];
mul *= 31;
}
return hash;
}
Here is example of a simple polynomial hash that could not be auto-vectorized with SSE 4.1 (LV could not prove legality):
https://godbolt.org/z/86o9zPT51 Original test:
This is a very typical example of polynomial hash, used, for example, in Rabin-Karp algorithm (https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm). Another iconic application is Java String hashcode.
When we restructure the code into its equivalent, LV can vectorize it:
It would be nice if the original example was vectorizable.