The C code of MurmurHash3 has this part:
uint64_t k1 = 0;
uint64_t k2 = 0;
switch(len & 15)
{
case 15: k2 ^= ((uint64_t)tail[14]) << 48;
case 14: k2 ^= ((uint64_t)tail[13]) << 40;
case 13: k2 ^= ((uint64_t)tail[12]) << 32;
case 12: k2 ^= ((uint64_t)tail[11]) << 24;
case 11: k2 ^= ((uint64_t)tail[10]) << 16;
case 10: k2 ^= ((uint64_t)tail[ 9]) << 8;
case 9: k2 ^= ((uint64_t)tail[ 8]) << 0;
(The type of tail
is uint8_t *
)
As far as I can see it's no different than an OR operation. What difference does it make to use XOR here? Is it optimization? If it is, what kind of it is? Or am I missing something about behavior differences of those two operators?
I already know about the differences between XOR and OR. But in this case since the value is zeroed out at the beginning and xored values do not overlap, the behavior shouldn't be any different than OR at all. So I'm asking why author chose this over OR (which conveys its intent better than XOR imho).