Skip to content

Commit

Permalink
hashlib: fixes from jix
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Nov 26, 2024
1 parent 55efd46 commit e2f1cf6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
1 change: 0 additions & 1 deletion kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,6 @@ struct DriverMap
bool operator==(const DriveBitId &other) const { return id == other.id; }
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_into(Hasher h) const;
};
// Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory
Expand Down
10 changes: 7 additions & 3 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ struct hash_obj_ops {
}
template<typename T>
static inline Hasher hash_into(const T *a, Hasher h) {
return a ? a->hash_into(h) : h;
if (a)
a->hash_into(h);
else
h.eat(0);
return h;
}
};
/**
Expand Down Expand Up @@ -785,13 +789,13 @@ class dict {
}

Hasher hash_into(Hasher h) const {
h.eat(entries.size());
for (auto &it : entries) {
Hasher entry_hash;
entry_hash.eat(it.udata.first);
entry_hash.eat(it.udata.second);
h.commutative_eat(entry_hash.yield());
}
h.eat(entries.size());
return h;
}

Expand Down Expand Up @@ -1155,10 +1159,10 @@ class pool
}

Hasher hash_into(Hasher h) const {
h.eat(entries.size());
for (auto &it : entries) {
h.commutative_eat(ops.hash(it.udata).yield());
}
h.eat(entries.size());
return h;
}

Expand Down
3 changes: 0 additions & 3 deletions kernel/modtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ struct ModIndex : public RTLIL::Monitor
{
bool is_input, is_output;
pool<PortInfo> ports;
// SigBitInfo() : SigBitInfo{} {}
// SigBitInfo& operator=(const SigBitInfo&) = default;

SigBitInfo() : is_input(false), is_output(false) { }

Expand Down Expand Up @@ -310,7 +308,6 @@ struct ModWalker
RTLIL::IdString port;
int offset;
PortBit(Cell* c, IdString p, int o) : cell(c), port(p), offset(o) {}
// PortBit& operator=(const PortBit&) = default;

bool operator<(const PortBit &other) const {
if (cell != other.cell)
Expand Down
16 changes: 8 additions & 8 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,14 @@ namespace hashlib {
};
};

// TODO deprecate this
/**
* How to not use these methods:
* 1. if(celltype.in({...})) -> if(celltype.in(...))
* 2. pool<IdString> p; ... a.in(p) -> (bool)p.count(a)
*/
[[deprecated]]
inline bool RTLIL::IdString::in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; }
[[deprecated]]
inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; }

namespace RTLIL {
Expand Down Expand Up @@ -816,7 +822,7 @@ struct RTLIL::Const
}

inline Hasher hash_into(Hasher h) const {
// TODO hash size
h.eat(size());
for (auto b : *this)
h.eat(b);
return h;
Expand Down Expand Up @@ -1002,12 +1008,6 @@ struct RTLIL::SigSpec
SigSpec(const std::set<RTLIL::SigBit> &bits);
explicit SigSpec(bool bit);

[[deprecated]]
size_t get_hash() const {
log_assert(false && "deprecated");
return 0;
}

inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }

Expand Down

0 comments on commit e2f1cf6

Please sign in to comment.