[PATCH] InstrProf: Calculate a better function hash

Justin Bogner mail at justinbogner.com
Tue Mar 25 13:08:00 PDT 2014


Chandler Carruth <chandlerc at google.com> writes:
> Bernstein's hash happens to be effective of short strings of *ascii* printable
> characters. It is not highly rilient to single bit flips in all bits of the
> input. Notably, as pointed out by Bob Jenkins and others, there is a funnel
> where 0x21 and 0x100 have the same hash (33). Bernstein's hash became popular
> in no small part because it has unusual properties with *ascii* text:
> lowercase alpha strings of 6 characters or smaller have zero collisions in
> 32-bits. I don't see any way that it is a useful hashing algorithm for
> something like this.
>
> FNV is slightly better in that it works for any byte stream rather than being
> carefully chosen to work with ascii characters. This is primarily because it
> uses a prime multiplier. However, it *requires* fast integer multiplies (and
> thus is often quite slow on non-Intel chips) and has a tendency to scale
> *very* poorly to large input messages due to the byte-stream nature of the
> beast.

Interesting stuff. Thanks for the enlightenment.



More information about the cfe-commits mailing list