3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-06 14:13:23 +00:00

hash: solo hashing interface, override for SigBit

This commit is contained in:
Emil J. Tywoniak 2024-11-04 12:41:00 +01:00
parent b7991ed1f5
commit 52b0fc03b7
2 changed files with 66 additions and 20 deletions

View file

@ -896,6 +896,19 @@ struct RTLIL::SigBit
bool operator ==(const RTLIL::SigBit &other) const;
bool operator !=(const RTLIL::SigBit &other) const;
Hasher hash_acc(Hasher h) const;
Hasher hash_top() const;
};
namespace hashlib {
template <>
struct hash_top_ops<RTLIL::SigBit> {
static inline bool cmp(const RTLIL::SigBit &a, const RTLIL::SigBit &b) {
return a == b;
}
static inline Hasher hash(const RTLIL::SigBit sb) {
return sb.hash_top();
}
};
};
struct RTLIL::SigSpecIterator
@ -1825,15 +1838,24 @@ inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit &other) const {
inline Hasher RTLIL::SigBit::hash_acc(Hasher h) const {
if (wire) {
h.acc(offset);
// hash_acc isn't allowed to come first, or it might hash trivially
// and possibly ruin things
h = wire->name.hash_acc(h);
h.acc(wire->name);
return h;
}
h.acc(data);
return h;
}
inline Hasher RTLIL::SigBit::hash_top() const {
Hasher h;
if (wire) {
h.force(hashlib::legacy::mkhash_add(wire->name.index_, offset));
return h;
}
h.force(data);
return h;
}
inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const {
return (*sig_p)[index];
}