From 4d14399749a31cf18826548332a48c6418d5e7e0 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 30 Oct 2024 10:49:17 +0100 Subject: [PATCH] hashlib: allow forcing Hasher state, use it for IdString trivial hashing --- kernel/hashlib.h | 7 +++++++ kernel/rtlil.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 33a1e04f8..aa9f43ff4 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -132,6 +132,13 @@ class Hasher { state ^= t; } + void force(hash_t new_state) { + state = new_state; + } + + bool is_new() const { + return state == Hasher().state; + } }; template diff --git a/kernel/rtlil.h b/kernel/rtlil.h index a1f8668d0..b048b1a44 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -361,6 +361,12 @@ namespace RTLIL } Hasher hash_acc(Hasher h) const { + // If we're starting a hashing sequence, simply start with unhashed ID + if (h.is_new()) { + h.force((Hasher::hash_t) index_); + return h; + } + return hash_ops::hash_acc(index_, h); }