mirror of https://github.com/YosysHQ/yosys.git
hashlib: acc -> eat
This commit is contained in:
parent
4c07564203
commit
838eb9c280
|
@ -98,13 +98,13 @@ Making a type hashable
|
|||
Let's first take a look at the external interface on a simplified level.
|
||||
Generally, to get the hash for ``T obj``, you would call the utility function
|
||||
``run_hash<T>(const T& obj)``, corresponding to ``hash_top_ops<T>::hash(obj)``,
|
||||
the default implementation of which is ``hash_ops<T>::hash_acc(Hasher(), obj)``.
|
||||
the default implementation of which is ``hash_ops<T>::hash_eat(Hasher(), obj)``.
|
||||
``Hasher`` is the class actually implementing the hash function, hiding its
|
||||
initialized internal state, and passing it out on ``hash_t yield()`` with
|
||||
perhaps some finalization steps.
|
||||
|
||||
``hash_ops<T>`` is the star of the show. By default it pulls the ``Hasher h``
|
||||
through a ``Hasher T::hash_acc(Hasher h)`` method. That's the method you have to
|
||||
through a ``Hasher T::hash_eat(Hasher h)`` method. That's the method you have to
|
||||
implement to make a record (class or struct) type easily hashable with Yosys
|
||||
hashlib associative data structures.
|
||||
|
||||
|
@ -113,13 +113,13 @@ treats pointers the same as integers, so it doesn't dereference pointers. Since
|
|||
many RTLIL data structures like ``RTLIL::Wire`` carry their own unique index
|
||||
``Hasher::hash_t hashidx_;``, there are specializations for ``hash_ops<Wire*>``
|
||||
and others in ``kernel/hashlib.h`` that actually dereference the pointers and
|
||||
call ``hash_acc`` on the instances pointed to.
|
||||
call ``hash_eat`` on the instances pointed to.
|
||||
|
||||
``hash_ops<T>`` is also specialized for simple compound types like
|
||||
``std::pair<U>`` by calling hash_acc in sequence on its members. For flexible
|
||||
``std::pair<U>`` by calling hash_eat in sequence on its members. For flexible
|
||||
size containers like ``std::vector<U>`` the size of the container is hashed
|
||||
first. That is also how implementing hashing for a custom record data type
|
||||
should be - unless there is strong reason to do otherwise, call ``h.acc(m)`` on
|
||||
should be - unless there is strong reason to do otherwise, call ``h.eat(m)`` on
|
||||
the ``Hasher h`` you have received for each member in sequence and ``return
|
||||
h;``. If you do have a strong reason to do so, look at how
|
||||
``hash_top_ops<RTLIL::SigBit>`` is implemented in ``kernel/rtlil.h``.
|
||||
|
@ -134,7 +134,7 @@ operations thrown in to mix bits together somewhat. A plugin can stay compatible
|
|||
with both versions prior and after the break by implementing the aforementioned
|
||||
current interface and redirecting the legacy one:
|
||||
|
||||
``void Hasher::acc(const T& t)`` hashes ``t`` into its internal state by also
|
||||
``void Hasher::eat(const T& t)`` hashes ``t`` into its internal state by also
|
||||
redirecting to ``hash_ops<T>``
|
||||
|
||||
.. code-block:: cpp
|
||||
|
@ -143,7 +143,7 @@ redirecting to ``hash_ops<T>``
|
|||
|
||||
inline unsigned int T::hash() const {
|
||||
Hasher h;
|
||||
return (unsigned int)hash_acc(h).yield();
|
||||
return (unsigned int)hash_eat(h).yield();
|
||||
}
|
||||
|
||||
To get hashes for Yosys types, you can temporarily use the templated deprecated
|
||||
|
|
|
@ -177,7 +177,7 @@ namespace AST
|
|||
{
|
||||
// for dict<> and pool<>
|
||||
unsigned int hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
// this nodes type
|
||||
AstNodeType type;
|
||||
|
|
|
@ -43,10 +43,10 @@ struct BitPatternPool
|
|||
return false;
|
||||
return bitdata == other.bitdata;
|
||||
}
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
if (!cached_hash)
|
||||
cached_hash = run_hash(bitdata);
|
||||
h.acc(cached_hash);
|
||||
h.eat(cached_hash);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -39,13 +39,13 @@ bool AigNode::operator==(const AigNode &other) const
|
|||
return true;
|
||||
}
|
||||
|
||||
Hasher AigNode::hash_acc(Hasher h) const
|
||||
Hasher AigNode::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(portname);
|
||||
h.acc(portbit);
|
||||
h.acc(inverter);
|
||||
h.acc(left_parent);
|
||||
h.acc(right_parent);
|
||||
h.eat(portname);
|
||||
h.eat(portbit);
|
||||
h.eat(inverter);
|
||||
h.eat(left_parent);
|
||||
h.eat(right_parent);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ bool Aig::operator==(const Aig &other) const
|
|||
return name == other.name;
|
||||
}
|
||||
|
||||
Hasher Aig::hash_acc(Hasher h) const
|
||||
Hasher Aig::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(name);
|
||||
h.eat(name);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ struct AigNode
|
|||
|
||||
AigNode();
|
||||
bool operator==(const AigNode &other) const;
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
struct Aig
|
||||
|
@ -44,7 +44,7 @@ struct Aig
|
|||
Aig(Cell *cell);
|
||||
|
||||
bool operator==(const Aig &other) const;
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
|
|
@ -74,7 +74,7 @@ struct DriveBitWire
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
|
||||
operator SigBit() const
|
||||
|
@ -105,7 +105,7 @@ struct DriveBitPort
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -129,7 +129,7 @@ struct DriveBitMarker
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
return multiple_ == other.multiple_;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
struct DriveBit
|
||||
|
@ -352,7 +352,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
bool operator==(const DriveBit &other) const
|
||||
{
|
||||
|
@ -473,7 +473,7 @@ struct DriveChunkWire
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
explicit operator SigChunk() const
|
||||
{
|
||||
|
@ -531,7 +531,7 @@ struct DriveChunkPort
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -572,7 +572,7 @@ struct DriveChunkMarker
|
|||
return offset < other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
struct DriveChunkMultiple
|
||||
|
@ -612,7 +612,7 @@ public:
|
|||
return false; // TODO implement, canonicalize order
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
|
||||
struct DriveChunk
|
||||
|
@ -863,7 +863,7 @@ public:
|
|||
bool try_append(DriveBit const &bit);
|
||||
bool try_append(DriveChunk const &chunk);
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
bool operator==(const DriveChunk &other) const
|
||||
{
|
||||
|
@ -1073,7 +1073,7 @@ public:
|
|||
that->hash_ |= (that->hash_ == 0);
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
|
||||
bool operator==(DriveSpec const &other) const {
|
||||
updhash();
|
||||
|
@ -1112,7 +1112,7 @@ private:
|
|||
bool operator!=(const DriveBitId &other) const { return id != other.id; }
|
||||
bool operator<(const DriveBitId &other) const { return id < other.id; }
|
||||
// unsigned int hash() const { return id; }
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
};
|
||||
// Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory
|
||||
// and fewer allocations
|
||||
|
@ -1258,130 +1258,130 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
inline Hasher DriveBitWire::hash_acc(Hasher h) const
|
||||
inline Hasher DriveBitWire::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(wire->name);
|
||||
h.acc(offset);
|
||||
h.eat(wire->name);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveBitPort::hash_acc(Hasher h) const
|
||||
inline Hasher DriveBitPort::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(cell->name);
|
||||
h.acc(port);
|
||||
h.acc(offset);
|
||||
h.eat(cell->name);
|
||||
h.eat(port);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveBitMarker::hash_acc(Hasher h) const
|
||||
inline Hasher DriveBitMarker::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(marker);
|
||||
h.acc(offset);
|
||||
h.eat(marker);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveBitMultiple::hash_acc(Hasher h) const
|
||||
inline Hasher DriveBitMultiple::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(multiple_);
|
||||
h.eat(multiple_);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveBit::hash_acc(Hasher h) const
|
||||
inline Hasher DriveBit::hash_eat(Hasher h) const
|
||||
{
|
||||
switch (type_) {
|
||||
case DriveType::NONE:
|
||||
h.acc(0);
|
||||
h.eat(0);
|
||||
break;
|
||||
case DriveType::CONSTANT:
|
||||
h.acc(constant_);
|
||||
h.eat(constant_);
|
||||
break;
|
||||
case DriveType::WIRE:
|
||||
h.acc(wire_);
|
||||
h.eat(wire_);
|
||||
break;
|
||||
case DriveType::PORT:
|
||||
h.acc(port_);
|
||||
h.eat(port_);
|
||||
break;
|
||||
case DriveType::MARKER:
|
||||
h.acc(marker_);
|
||||
h.eat(marker_);
|
||||
break;
|
||||
case DriveType::MULTIPLE:
|
||||
h.acc(multiple_);
|
||||
h.eat(multiple_);
|
||||
break;
|
||||
}
|
||||
h.acc(type_);
|
||||
h.eat(type_);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveChunkWire::hash_acc(Hasher h) const
|
||||
inline Hasher DriveChunkWire::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(wire->name);
|
||||
h.acc(width);
|
||||
h.acc(offset);
|
||||
h.eat(wire->name);
|
||||
h.eat(width);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveChunkPort::hash_acc(Hasher h) const
|
||||
inline Hasher DriveChunkPort::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(cell->name);
|
||||
h.acc(port);
|
||||
h.acc(width);
|
||||
h.acc(offset);
|
||||
h.eat(cell->name);
|
||||
h.eat(port);
|
||||
h.eat(width);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveChunkMarker::hash_acc(Hasher h) const
|
||||
inline Hasher DriveChunkMarker::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(marker);
|
||||
h.acc(width);
|
||||
h.acc(offset);
|
||||
h.eat(marker);
|
||||
h.eat(width);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveChunkMultiple::hash_acc(Hasher h) const
|
||||
inline Hasher DriveChunkMultiple::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(width_);
|
||||
h.acc(multiple_);
|
||||
h.eat(width_);
|
||||
h.eat(multiple_);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveChunk::hash_acc(Hasher h) const
|
||||
inline Hasher DriveChunk::hash_eat(Hasher h) const
|
||||
{
|
||||
switch (type_) {
|
||||
case DriveType::NONE:
|
||||
h.acc(0);
|
||||
h.eat(0);
|
||||
break;
|
||||
case DriveType::CONSTANT:
|
||||
h.acc(constant_);
|
||||
h.eat(constant_);
|
||||
break;
|
||||
case DriveType::WIRE:
|
||||
h.acc(wire_);
|
||||
h.eat(wire_);
|
||||
break;
|
||||
case DriveType::PORT:
|
||||
h.acc(port_);
|
||||
h.eat(port_);
|
||||
break;
|
||||
case DriveType::MARKER:
|
||||
h.acc(marker_);
|
||||
h.eat(marker_);
|
||||
break;
|
||||
case DriveType::MULTIPLE:
|
||||
h.acc(multiple_);
|
||||
h.eat(multiple_);
|
||||
break;
|
||||
}
|
||||
h.acc(type_);
|
||||
h.eat(type_);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriveSpec::hash_acc(Hasher h) const
|
||||
inline Hasher DriveSpec::hash_eat(Hasher h) const
|
||||
{
|
||||
if (hash_ == 0)
|
||||
updhash();
|
||||
|
||||
h.acc(hash_);
|
||||
h.eat(hash_);
|
||||
return h;
|
||||
}
|
||||
|
||||
inline Hasher DriverMap::DriveBitId::hash_acc(Hasher h) const
|
||||
inline Hasher DriverMap::DriveBitId::hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(id);
|
||||
h.eat(id);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace Functional {
|
|||
// returns the data width of a bitvector sort, errors out for other sorts
|
||||
int data_width() const { return std::get<1>(_v).second; }
|
||||
bool operator==(Sort const& other) const { return _v == other._v; }
|
||||
Hasher hash_acc(Hasher h) const { h.acc(_v); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(_v); return h; }
|
||||
};
|
||||
class IR;
|
||||
class Factory;
|
||||
|
@ -225,9 +225,9 @@ namespace Functional {
|
|||
const RTLIL::Const &as_const() const { return std::get<RTLIL::Const>(_extra); }
|
||||
std::pair<IdString, IdString> as_idstring_pair() const { return std::get<std::pair<IdString, IdString>>(_extra); }
|
||||
int as_int() const { return std::get<int>(_extra); }
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc((unsigned int) _fn);
|
||||
h.acc(_extra);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat((unsigned int) _fn);
|
||||
h.eat(_extra);
|
||||
return h;
|
||||
}
|
||||
bool operator==(NodeData const &other) const {
|
||||
|
|
|
@ -125,16 +125,16 @@ private:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void acc(T&& t) {
|
||||
*this = hash_ops<std::remove_cv_t<std::remove_reference_t<T>>>::hash_acc(std::forward<T>(t), *this);
|
||||
void eat(T&& t) {
|
||||
*this = hash_ops<std::remove_cv_t<std::remove_reference_t<T>>>::hash_eat(std::forward<T>(t), *this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void acc(const T& t) {
|
||||
*this = hash_ops<T>::hash_acc(t, *this);
|
||||
void eat(const T& t) {
|
||||
*this = hash_ops<T>::hash_eat(t, *this);
|
||||
}
|
||||
|
||||
void commutative_acc(hash_t t) {
|
||||
void commutative_eat(hash_t t) {
|
||||
state ^= t;
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ struct hash_top_ops {
|
|||
return hash_ops<T>::cmp(a, b);
|
||||
}
|
||||
static inline Hasher hash(const T &a) {
|
||||
return hash_ops<T>::hash_acc(a, Hasher());
|
||||
return hash_ops<T>::hash_eat(a, Hasher());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -160,7 +160,7 @@ struct hash_ops {
|
|||
static inline bool cmp(const T &a, const T &b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(const T &a, Hasher h) {
|
||||
static inline Hasher hash_eat(const T &a, Hasher h) {
|
||||
if constexpr (std::is_same_v<T, bool>) {
|
||||
h.hash32(a ? 1 : 0);
|
||||
return h;
|
||||
|
@ -173,15 +173,15 @@ struct hash_ops {
|
|||
return h;
|
||||
} else if constexpr (std::is_enum_v<T>) {
|
||||
using u_type = std::underlying_type_t<T>;
|
||||
return hash_ops<u_type>::hash_acc((u_type) a, h);
|
||||
return hash_ops<u_type>::hash_eat((u_type) a, h);
|
||||
} else if constexpr (std::is_pointer_v<T>) {
|
||||
return hash_ops<uintptr_t>::hash_acc((uintptr_t) a, h);
|
||||
return hash_ops<uintptr_t>::hash_eat((uintptr_t) a, h);
|
||||
} else if constexpr (std::is_same_v<T, std::string>) {
|
||||
for (auto c : a)
|
||||
h.hash32(c);
|
||||
return h;
|
||||
} else {
|
||||
return a.hash_acc(h);
|
||||
return a.hash_eat(h);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -190,9 +190,9 @@ template<typename P, typename Q> struct hash_ops<std::pair<P, Q>> {
|
|||
static inline bool cmp(std::pair<P, Q> a, std::pair<P, Q> b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::pair<P, Q> a, Hasher h) {
|
||||
h = hash_ops<P>::hash_acc(a.first, h);
|
||||
h = hash_ops<Q>::hash_acc(a.second, h);
|
||||
static inline Hasher hash_eat(std::pair<P, Q> a, Hasher h) {
|
||||
h = hash_ops<P>::hash_eat(a.first, h);
|
||||
h = hash_ops<Q>::hash_eat(a.second, h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -202,14 +202,14 @@ template<typename... T> struct hash_ops<std::tuple<T...>> {
|
|||
return a == b;
|
||||
}
|
||||
template<size_t I = 0>
|
||||
static inline typename std::enable_if<I == sizeof...(T), Hasher>::type hash_acc(std::tuple<T...>, Hasher h) {
|
||||
static inline typename std::enable_if<I == sizeof...(T), Hasher>::type hash_eat(std::tuple<T...>, Hasher h) {
|
||||
return h;
|
||||
}
|
||||
template<size_t I = 0>
|
||||
static inline typename std::enable_if<I != sizeof...(T), Hasher>::type hash_acc(std::tuple<T...> a, Hasher h) {
|
||||
static inline typename std::enable_if<I != sizeof...(T), Hasher>::type hash_eat(std::tuple<T...> a, Hasher h) {
|
||||
typedef hash_ops<typename std::tuple_element<I, std::tuple<T...>>::type> element_ops_t;
|
||||
h = hash_acc<I+1>(a, h);
|
||||
h = element_ops_t::hash_acc(std::get<I>(a), h);
|
||||
h = hash_eat<I+1>(a, h);
|
||||
h = element_ops_t::hash_eat(std::get<I>(a), h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -218,10 +218,10 @@ template<typename T> struct hash_ops<std::vector<T>> {
|
|||
static inline bool cmp(std::vector<T> a, std::vector<T> b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::vector<T> a, Hasher h) {
|
||||
h.acc(a.size());
|
||||
static inline Hasher hash_eat(std::vector<T> a, Hasher h) {
|
||||
h.eat(a.size());
|
||||
for (auto k : a)
|
||||
h.acc(k);
|
||||
h.eat(k);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -230,9 +230,9 @@ template<typename T, size_t N> struct hash_ops<std::array<T, N>> {
|
|||
static inline bool cmp(std::array<T, N> a, std::array<T, N> b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::array<T, N> a, Hasher h) {
|
||||
static inline Hasher hash_eat(std::array<T, N> a, Hasher h) {
|
||||
for (const auto& k : a)
|
||||
h = hash_ops<T>::hash_acc(k, h);
|
||||
h = hash_ops<T>::hash_eat(k, h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -244,7 +244,7 @@ struct hash_cstr_ops {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
static inline Hasher hash_acc(const char *a, Hasher h) {
|
||||
static inline Hasher hash_eat(const char *a, Hasher h) {
|
||||
while (*a)
|
||||
h.hash32(*(a++));
|
||||
return h;
|
||||
|
@ -257,8 +257,8 @@ struct hash_ptr_ops {
|
|||
static inline bool cmp(const void *a, const void *b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(const void *a, Hasher h) {
|
||||
return hash_ops<uintptr_t>::hash_acc((uintptr_t)a, h);
|
||||
static inline Hasher hash_eat(const void *a, Hasher h) {
|
||||
return hash_ops<uintptr_t>::hash_eat((uintptr_t)a, h);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -267,8 +267,8 @@ struct hash_obj_ops {
|
|||
return a == b;
|
||||
}
|
||||
template<typename T>
|
||||
static inline Hasher hash_acc(const T *a, Hasher h) {
|
||||
return a ? a->hash_acc(h) : h;
|
||||
static inline Hasher hash_eat(const T *a, Hasher h) {
|
||||
return a ? a->hash_eat(h) : h;
|
||||
}
|
||||
};
|
||||
/**
|
||||
|
@ -295,7 +295,7 @@ template<> struct hash_ops<std::monostate> {
|
|||
static inline bool cmp(std::monostate a, std::monostate b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::monostate, Hasher h) {
|
||||
static inline Hasher hash_eat(std::monostate, Hasher h) {
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -304,9 +304,9 @@ template<typename... T> struct hash_ops<std::variant<T...>> {
|
|||
static inline bool cmp(std::variant<T...> a, std::variant<T...> b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::variant<T...> a, Hasher h) {
|
||||
std::visit([& h](const auto &v) { h.acc(v); }, a);
|
||||
h.acc(a.index());
|
||||
static inline Hasher hash_eat(std::variant<T...> a, Hasher h) {
|
||||
std::visit([& h](const auto &v) { h.eat(v); }, a);
|
||||
h.eat(a.index());
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -315,11 +315,11 @@ template<typename T> struct hash_ops<std::optional<T>> {
|
|||
static inline bool cmp(std::optional<T> a, std::optional<T> b) {
|
||||
return a == b;
|
||||
}
|
||||
static inline Hasher hash_acc(std::optional<T> a, Hasher h) {
|
||||
static inline Hasher hash_eat(std::optional<T> a, Hasher h) {
|
||||
if(a.has_value())
|
||||
h.acc(*a);
|
||||
h.eat(*a);
|
||||
else
|
||||
h.acc(0);
|
||||
h.eat(0);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -788,13 +788,13 @@ public:
|
|||
return !operator==(other);
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(entries.size());
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(entries.size());
|
||||
for (auto &it : entries) {
|
||||
Hasher entry_hash;
|
||||
entry_hash.acc(it.udata.first);
|
||||
entry_hash.acc(it.udata.second);
|
||||
h.commutative_acc(entry_hash.yield());
|
||||
entry_hash.eat(it.udata.first);
|
||||
entry_hash.eat(it.udata.second);
|
||||
h.commutative_eat(entry_hash.yield());
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
@ -1158,10 +1158,10 @@ public:
|
|||
return !operator==(other);
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(entries.size());
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(entries.size());
|
||||
for (auto &it : entries) {
|
||||
h.commutative_acc(ops.hash(it.udata).yield());
|
||||
h.commutative_eat(ops.hash(it.udata).yield());
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ struct ModIndex : public RTLIL::Monitor
|
|||
return cell == other.cell && port == other.port && offset == other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(cell->name);
|
||||
h.acc(port);
|
||||
h.acc(offset);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(cell->name);
|
||||
h.eat(port);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -324,10 +324,10 @@ struct ModWalker
|
|||
return cell == other.cell && port == other.port && offset == other.offset;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(cell->name);
|
||||
h.acc(port);
|
||||
h.acc(offset);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(cell->name);
|
||||
h.eat(port);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4465,11 +4465,11 @@ void RTLIL::SigSpec::updhash() const
|
|||
for (auto &c : that->chunks_)
|
||||
if (c.wire == NULL) {
|
||||
for (auto &v : c.data)
|
||||
h.acc(v);
|
||||
h.eat(v);
|
||||
} else {
|
||||
h.acc(c.wire->name.index_);
|
||||
h.acc(c.offset);
|
||||
h.acc(c.width);
|
||||
h.eat(c.wire->name.index_);
|
||||
h.eat(c.offset);
|
||||
h.eat(c.width);
|
||||
}
|
||||
that->hash_ = h.yield();
|
||||
if (that->hash_ == 0)
|
||||
|
|
|
@ -362,7 +362,7 @@ struct RTLIL::IdString
|
|||
*this = IdString();
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const { return hash_ops<int>::hash_acc(index_, h); }
|
||||
Hasher hash_eat(Hasher h) const { return hash_ops<int>::hash_eat(index_, h); }
|
||||
|
||||
Hasher hash_top() const {
|
||||
Hasher h;
|
||||
|
@ -815,10 +815,10 @@ public:
|
|||
bv.resize(width, bv.empty() ? RTLIL::State::Sx : bv.back());
|
||||
}
|
||||
|
||||
inline Hasher hash_acc(Hasher h) const {
|
||||
inline Hasher hash_eat(Hasher h) const {
|
||||
// TODO hash size
|
||||
for (auto b : *this)
|
||||
h.acc(b);
|
||||
h.eat(b);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -907,7 +907,7 @@ struct RTLIL::SigBit
|
|||
bool operator <(const RTLIL::SigBit &other) const;
|
||||
bool operator ==(const RTLIL::SigBit &other) const;
|
||||
bool operator !=(const RTLIL::SigBit &other) const;
|
||||
Hasher hash_acc(Hasher h) const;
|
||||
Hasher hash_eat(Hasher h) const;
|
||||
Hasher hash_top() const;
|
||||
};
|
||||
|
||||
|
@ -1114,7 +1114,7 @@ public:
|
|||
operator std::vector<RTLIL::SigBit>() const { return bits(); }
|
||||
const RTLIL::SigBit &at(int offset, const RTLIL::SigBit &defval) { return offset < width_ ? (*this)[offset] : defval; }
|
||||
|
||||
Hasher hash_acc(Hasher h) const { if (!hash_) updhash(); h.acc(hash_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { if (!hash_) updhash(); h.eat(hash_); return h; }
|
||||
|
||||
#ifndef NDEBUG
|
||||
void check(Module *mod = nullptr) const;
|
||||
|
@ -1156,7 +1156,7 @@ struct RTLIL::Selection
|
|||
struct RTLIL::Monitor
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
Monitor() {
|
||||
static unsigned int hashidx_count = 123456789;
|
||||
|
@ -1179,7 +1179,7 @@ struct define_map_t;
|
|||
struct RTLIL::Design
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
pool<RTLIL::Monitor*> monitors;
|
||||
dict<std::string, std::string> scratchpad;
|
||||
|
@ -1284,7 +1284,7 @@ struct RTLIL::Design
|
|||
struct RTLIL::Module : public RTLIL::AttrObject
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
protected:
|
||||
void add(RTLIL::Wire *wire);
|
||||
|
@ -1635,7 +1635,7 @@ void dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire);
|
|||
struct RTLIL::Wire : public RTLIL::AttrObject
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
protected:
|
||||
// use module->addWire() and module->remove() to create or destroy wires
|
||||
|
@ -1674,7 +1674,7 @@ inline int GetSize(RTLIL::Wire *wire) {
|
|||
struct RTLIL::Memory : public RTLIL::AttrObject
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
Memory();
|
||||
|
||||
|
@ -1689,7 +1689,7 @@ struct RTLIL::Memory : public RTLIL::AttrObject
|
|||
struct RTLIL::Cell : public RTLIL::AttrObject
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
protected:
|
||||
// use module->addCell() and module->remove() to create or destroy cells
|
||||
|
@ -1799,7 +1799,7 @@ struct RTLIL::SyncRule
|
|||
struct RTLIL::Process : public RTLIL::AttrObject
|
||||
{
|
||||
Hasher::hash_t hashidx_;
|
||||
Hasher hash_acc(Hasher h) const { h.acc(hashidx_); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
protected:
|
||||
// use module->addProcess() and module->remove() to create or destroy processes
|
||||
|
@ -1843,13 +1843,13 @@ inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit &other) const {
|
|||
return (wire != other.wire) || (wire ? (offset != other.offset) : (data != other.data));
|
||||
}
|
||||
|
||||
inline Hasher RTLIL::SigBit::hash_acc(Hasher h) const {
|
||||
inline Hasher RTLIL::SigBit::hash_eat(Hasher h) const {
|
||||
if (wire) {
|
||||
h.acc(offset);
|
||||
h.acc(wire->name);
|
||||
h.eat(offset);
|
||||
h.eat(wire->name);
|
||||
return h;
|
||||
}
|
||||
h.acc(data);
|
||||
h.eat(data);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ struct ModuleItem {
|
|||
Cell *cell() const { return type == Type::Cell ? static_cast<Cell *>(ptr) : nullptr; }
|
||||
|
||||
bool operator==(const ModuleItem &other) const { return ptr == other.ptr && type == other.type; }
|
||||
Hasher hash_acc(Hasher h) const { h.acc(ptr); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(ptr); return h; }
|
||||
};
|
||||
|
||||
static inline void log_dump_val_worker(typename IdTree<ModuleItem>::Cursor cursor ) { log("%p %s", cursor.target, log_id(cursor.scope_name)); }
|
||||
|
|
|
@ -29,9 +29,9 @@ struct SigPool
|
|||
struct bitDef_t : public std::pair<RTLIL::Wire*, int> {
|
||||
bitDef_t() : std::pair<RTLIL::Wire*, int>(NULL, 0) { }
|
||||
bitDef_t(const RTLIL::SigBit &bit) : std::pair<RTLIL::Wire*, int>(bit.wire, bit.offset) { }
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(first->name);
|
||||
h.acc(second);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(first->name);
|
||||
h.eat(second);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -147,9 +147,9 @@ struct SigSet
|
|||
struct bitDef_t : public std::pair<RTLIL::Wire*, int> {
|
||||
bitDef_t() : std::pair<RTLIL::Wire*, int>(NULL, 0) { }
|
||||
bitDef_t(const RTLIL::SigBit &bit) : std::pair<RTLIL::Wire*, int>(bit.wire, bit.offset) { }
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(first->name);
|
||||
h.acc(second);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(first->name);
|
||||
h.eat(second);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -44,9 +44,9 @@ struct TimingInfo
|
|||
return {};
|
||||
return port[offset];
|
||||
}
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(name);
|
||||
h.acc(offset);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(name);
|
||||
h.eat(offset);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
@ -56,9 +56,9 @@ struct TimingInfo
|
|||
BitBit(const NameBit &first, const NameBit &second) : first(first), second(second) {}
|
||||
BitBit(const SigBit &first, const SigBit &second) : first(first), second(second) {}
|
||||
bool operator==(const BitBit& bb) const { return bb.first == first && bb.second == second; }
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(first);
|
||||
h.acc(second);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(first);
|
||||
h.eat(second);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -194,8 +194,8 @@ struct shared_str {
|
|||
const char *c_str() const { return content->c_str(); }
|
||||
const string &str() const { return *content; }
|
||||
bool operator==(const shared_str &other) const { return *content == *other.content; }
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(*content);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(*content);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ struct IdPath : public std::vector<RTLIL::IdString>
|
|||
bool has_address() const { int tmp; return get_address(tmp); };
|
||||
bool get_address(int &addr) const;
|
||||
|
||||
Hasher hash_acc(Hasher h) const { h.acc(*this); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(*this); return h; }
|
||||
};
|
||||
|
||||
struct WitnessHierarchyItem {
|
||||
|
|
|
@ -47,7 +47,7 @@ struct DftTagWorker {
|
|||
bool operator<(const tag_set &other) const { return index < other.index; }
|
||||
bool operator==(const tag_set &other) const { return index == other.index; }
|
||||
|
||||
Hasher hash_acc(Hasher h) const { h.acc(index); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(index); return h; }
|
||||
|
||||
bool empty() const { return index == 0; }
|
||||
};
|
||||
|
|
|
@ -52,9 +52,9 @@ struct ExampleDtPass : public Pass
|
|||
return name == other.name && parameters == other.parameters;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(name);
|
||||
h.acc(parameters);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(name);
|
||||
h.eat(parameters);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -46,11 +46,11 @@ struct EquivStructWorker
|
|||
parameters == other.parameters && port_sizes == other.port_sizes;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(type);
|
||||
h.acc(parameters);
|
||||
h.acc(port_sizes);
|
||||
h.acc(connections);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(type);
|
||||
h.eat(parameters);
|
||||
h.eat(port_sizes);
|
||||
h.eat(connections);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -127,10 +127,10 @@ struct proc_dlatch_db_t
|
|||
return signal == other.signal && match == other.match && children == other.children;
|
||||
}
|
||||
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(signal);
|
||||
h.acc(match);
|
||||
h.acc(children);
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
h.eat(signal);
|
||||
h.eat(match);
|
||||
h.eat(children);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -46,10 +46,10 @@ struct IdBit {
|
|||
|
||||
bool operator==(const IdBit &other) const { return name == other.name && bit == other.bit; };
|
||||
bool operator!=(const IdBit &other) const { return name != other.name || bit != other.bit; };
|
||||
Hasher hash_acc(Hasher h) const
|
||||
Hasher hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(name);
|
||||
h.acc(bit);
|
||||
h.eat(name);
|
||||
h.eat(bit);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,10 @@ struct InvBit {
|
|||
|
||||
bool operator==(const InvBit &other) const { return bit == other.bit && inverted == other.inverted; };
|
||||
bool operator!=(const InvBit &other) const { return bit != other.bit || inverted != other.inverted; };
|
||||
Hasher hash_acc(Hasher h) const
|
||||
Hasher hash_eat(Hasher h) const
|
||||
{
|
||||
h.acc(bit);
|
||||
h.acc(inverted);
|
||||
h.eat(bit);
|
||||
h.eat(inverted);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -247,9 +247,9 @@ struct ClockgatePass : public Pass {
|
|||
SigBit ce_bit;
|
||||
bool pol_clk;
|
||||
bool pol_ce;
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
Hasher hash_eat(Hasher h) const {
|
||||
auto t = std::make_tuple(clk_bit, ce_bit, pol_clk, pol_ce);
|
||||
h.acc(t);
|
||||
h.eat(t);
|
||||
return h;
|
||||
}
|
||||
bool operator==(const ClkNetInfo& other) const {
|
||||
|
|
|
@ -250,10 +250,10 @@ struct FlowGraph
|
|||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
Hasher hash_acc(Hasher h) const
|
||||
Hasher hash_eat(Hasher h) const
|
||||
{
|
||||
std::pair<RTLIL::SigBit, int> p = {node, is_bottom};
|
||||
h.acc(p);
|
||||
h.eat(p);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ struct QlDspSimdPass : public Pass {
|
|||
DspConfig(const DspConfig &ref) = default;
|
||||
DspConfig(DspConfig &&ref) = default;
|
||||
|
||||
Hasher hash_acc(Hasher h) const { h.acc(connections); return h; }
|
||||
Hasher hash_eat(Hasher h) const { h.eat(connections); return h; }
|
||||
|
||||
bool operator==(const DspConfig &ref) const { return connections == ref.connections; }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue