Skip to content

Commit

Permalink
Make more shift constants explicitly ULL
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Nov 7, 2023
1 parent 968f6a7 commit 43b167c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/sequali/wanghash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// See https://naml.us/post/inverse-of-a-hash-function/

static uint64_t wanghash64(uint64_t key) {
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
key = key ^ (key >> 24);
key = (key + (key << 3)) + (key << 8); // key * 265
key = key ^ (key >> 14);
key = (key + (key << 2)) + (key << 4); // key * 21
key = key ^ (key >> 28);
key = key + (key << 31);
key = (~key) + (key << 21ULL); // key = (key << 21) - key - 1;
key = key ^ (key >> 24ULL);
key = (key + (key << 3ULL)) + (key << 8ULL); // key * 265
key = key ^ (key >> 14ULL);
key = (key + (key << 2ULL)) + (key << 4ULL); // key * 21
key = key ^ (key >> 28ULL);
key = key + (key << 31ULL);
return key;
}

Expand All @@ -19,34 +19,34 @@ static uint64_t wanghash64_inverse(uint64_t key) {
uint64_t tmp;

// Invert key = key + (key << 31)
tmp = key-(key<<31);
key = key-(tmp<<31);
tmp = key-(key<<31ULL);
key = key-(tmp<<31ULL);

// Invert key = key ^ (key >> 28)
tmp = key^key>>28;
key = key^tmp>>28;
tmp = key^key>>28ULL;
key = key^tmp>>28ULL;

// Invert key *= 21
key *= 14933078535860113213u;
key *= 14933078535860113213ULL;

// Invert key = key ^ (key >> 14)
tmp = key^key>>14;
tmp = key^tmp>>14;
tmp = key^tmp>>14;
key = key^tmp>>14;
tmp = key^key>>14ULL;
tmp = key^tmp>>14ULL;
tmp = key^tmp>>14ULL;
key = key^tmp>>14ULL;

// Invert key *= 265
key *= 15244667743933553977u;
key *= 15244667743933553977ULL;

// Invert key = key ^ (key >> 24)
tmp = key^key>>24;
key = key^tmp>>24;
tmp = key^key>>24ULL;
key = key^tmp>>24ULL;

// Invert key = (~key) + (key << 21)
tmp = ~key;
tmp = ~(key-(tmp<<21));
tmp = ~(key-(tmp<<21));
key = ~(key-(tmp<<21));
tmp = ~(key-(tmp<<21ULL));
tmp = ~(key-(tmp<<21ULL));
key = ~(key-(tmp<<21ULL));

return key;
}

0 comments on commit 43b167c

Please sign in to comment.