From b4f3806d4e894b1885f0627a5431662525db2880 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Mon, 11 Nov 2024 13:27:04 +0100 Subject: [PATCH] hashlib: add deprecated mkhash function to prevent plugin breakage --- docs/source/yosys_internals/hashing.rst | 6 ++++++ kernel/hashlib.h | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/source/yosys_internals/hashing.rst b/docs/source/yosys_internals/hashing.rst index b88bf122327..0d74f9014df 100644 --- a/docs/source/yosys_internals/hashing.rst +++ b/docs/source/yosys_internals/hashing.rst @@ -145,3 +145,9 @@ redirecting to ``hash_ops`` Hasher h; return (unsigned int)hash_acc(h).yield(); } + +To get hashes for Yosys types, you can temporarily use the templated deprecated +``mkhash`` function until the majority of your plugin's users switch to a newer +version and live with the warnings, or set up a custom ``#ifdef``-based solution +if you really need to. +Feel free to contact Yosys maintainers with related issues. diff --git a/kernel/hashlib.h b/kernel/hashlib.h index ca2a04cece4..df6a4853c72 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -103,19 +103,19 @@ class HasherDJB32 { static uint32_t fudge; // The XOR version of DJB2 [[nodiscard]] - static uint32_t mkhash(uint32_t a, uint32_t b) { + static uint32_t djb2_xor(uint32_t a, uint32_t b) { uint32_t hash = ((a << 5) + a) ^ b; return hash; } public: void hash32(uint32_t i) { - state = mkhash(i, state); + state = djb2_xor(i, state); state = mkhash_xorshift(fudge ^ state); return; } void hash64(uint64_t i) { - state = mkhash((uint32_t)(i % (1ULL << 32ULL)), state); - state = mkhash((uint32_t)(i >> 32ULL), state); + state = djb2_xor((uint32_t)(i % (1ULL << 32ULL)), state); + state = djb2_xor((uint32_t)(i >> 32ULL), state); state = mkhash_xorshift(fudge ^ state); return; } @@ -283,6 +283,14 @@ Hasher::hash_t run_hash(const T& obj) { return hash_top_ops::hash(obj).yield(); } +/** Refer to docs/source/yosys_internals/hashing.rst */ +template +[[nodiscard]] +[[deprecated]] +inline unsigned int mkhash(const T &v) { + return (unsigned int) run_hash(v); +} + template<> struct hash_ops { static inline bool cmp(std::monostate a, std::monostate b) { return a == b;