From 43b167c385b1eb96e169ba7dbf6509c608a43dd8 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 7 Nov 2023 13:34:27 +0100 Subject: [PATCH] Make more shift constants explicitly ULL --- src/sequali/wanghash.h | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/sequali/wanghash.h b/src/sequali/wanghash.h index 4951e216..cf28bab2 100644 --- a/src/sequali/wanghash.h +++ b/src/sequali/wanghash.h @@ -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; } @@ -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; }