Just another Perl shrine  
PerlMonks 
Re: The 10**21 Problem (Part I)by oiskuu (Hermit) 
on May 05, 2014 at 20:08 UTC ( #1085114=note: print w/replies, xml )  Need Help?? 
Regarding the hash function and the modulus.Firstly, the if (m9 == 1) continue; clause could just as well be omitted—this may only result in false positives, not a false negative. Unlikely to matter though. I would also test if skipping the 10/13 cmps in the innermost loop(s) might improve performance! Apart from the oddball 1 case, the py_hash() function does not feed high order bits back into the register. Bits propagate higher; low bits of the hash value depend on low bits of input only. The python modulus is trickier. It ((1001+v%1001) % 1001) can be evaluated via unsigned modulus: ((v(v<0)*620U) % 1001). The sign bit therefore mixes into the 3rd lowest bit. Compilers know how to replace a dividebyconstant with multiplication by its reciprocal. (Div operation typically has a very high latency.) A division by 10, for example, may be substituted with mul 0xcccccccd; shift right by 3(+32). The shift size varies: Evidently, the choice of modulus can strengthen the hash function. Mod=2049 is particularly weak: (1U%2049 +1) == 1024. Sign mixes into 10th lowest. Update: it is easily shown that modulus must be odd. Hash function either preserves or inverts the lowest bit of r. Even modulus would also preserve it, making (r^v)&1 constant. But that does not fit the problem.
In Section
Meditations

