mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 09:05:32 +00:00
hashlib: redo interface for flexibility
This commit is contained in:
parent
0ab9fccbf1
commit
68e40d8563
36 changed files with 461 additions and 357 deletions
|
@ -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; }
|
||||
|
||||
unsigned int hash() const { return hash_ops<int>::hash(index); }
|
||||
Hasher hash_acc(Hasher h) const { h.acc(index); return h; }
|
||||
|
||||
bool empty() const { return index == 0; }
|
||||
};
|
||||
|
|
|
@ -50,8 +50,10 @@ struct ExampleDtPass : public Pass
|
|||
return name == other.name && parameters == other.parameters;
|
||||
}
|
||||
|
||||
unsigned int hash() const {
|
||||
return mkhash(name.hash(), parameters.hash());
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(name);
|
||||
h.acc(parameters);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -70,13 +70,13 @@ struct GraphNode {
|
|||
|
||||
pool<IdString> names_;
|
||||
dict<int, uint8_t> tags_;
|
||||
pool<GraphNode*, hash_ptr_ops> upstream_;
|
||||
pool<GraphNode*, hash_ptr_ops> downstream_;
|
||||
pool<GraphNode*> upstream_;
|
||||
pool<GraphNode*> downstream_;
|
||||
|
||||
pool<IdString> &names() { return get()->names_; }
|
||||
dict<int, uint8_t> &tags() { return get()->tags_; }
|
||||
pool<GraphNode*, hash_ptr_ops> &upstream() { return get()->upstream_; }
|
||||
pool<GraphNode*, hash_ptr_ops> &downstream() { return get()->downstream_; }
|
||||
pool<GraphNode*> &upstream() { return get()->upstream_; }
|
||||
pool<GraphNode*> &downstream() { return get()->downstream_; }
|
||||
|
||||
uint8_t tag(int index) {
|
||||
return tags().at(index, 0);
|
||||
|
@ -154,8 +154,8 @@ struct Graph {
|
|||
nodes.push_back(n);
|
||||
n->index = GetSize(nodes);
|
||||
|
||||
pool<GraphNode*, hash_ptr_ops> new_upstream;
|
||||
pool<GraphNode*, hash_ptr_ops> new_downstream;
|
||||
pool<GraphNode*> new_upstream;
|
||||
pool<GraphNode*> new_downstream;
|
||||
|
||||
for (auto g : n->upstream()) {
|
||||
if (n != (g = g->get()))
|
||||
|
@ -302,7 +302,7 @@ struct Graph {
|
|||
}
|
||||
}
|
||||
|
||||
pool<GraphNode*, hash_ptr_ops> excluded;
|
||||
pool<GraphNode*> excluded;
|
||||
|
||||
for (auto grp : config.groups)
|
||||
{
|
||||
|
@ -348,7 +348,7 @@ struct Graph {
|
|||
excluded.insert(g->get());
|
||||
|
||||
dict<Cell*, GraphNode*> cell_nodes;
|
||||
dict<SigBit, pool<GraphNode*, hash_ptr_ops>> sig_users;
|
||||
dict<SigBit, pool<GraphNode*>> sig_users;
|
||||
|
||||
for (auto cell : module->selected_cells()) {
|
||||
auto g = new GraphNode;
|
||||
|
@ -483,8 +483,8 @@ struct Graph {
|
|||
|
||||
{
|
||||
header("Any nodes with identical connections");
|
||||
typedef pair<pool<GraphNode*, hash_ptr_ops>, pool<GraphNode*, hash_ptr_ops>> node_conn_t;
|
||||
dict<node_conn_t, pool<GraphNode*, hash_ptr_ops>> nodes_by_conn;
|
||||
typedef pair<pool<GraphNode*>, pool<GraphNode*>> node_conn_t;
|
||||
dict<node_conn_t, pool<GraphNode*>> nodes_by_conn;
|
||||
for (auto g : term ? term_nodes : nonterm_nodes) {
|
||||
auto &entry = nodes_by_conn[node_conn_t(g->upstream(), g->downstream())];
|
||||
for (auto n : entry)
|
||||
|
@ -506,8 +506,8 @@ struct Graph {
|
|||
|
||||
header("Sibblings with identical tags");
|
||||
for (auto g : nonterm_nodes) {
|
||||
auto process_conns = [&](const pool<GraphNode*, hash_ptr_ops> &stream) {
|
||||
dict<std::vector<int>, pool<GraphNode*, hash_ptr_ops>> nodes_by_tags;
|
||||
auto process_conns = [&](const pool<GraphNode*> &stream) {
|
||||
dict<std::vector<int>, pool<GraphNode*>> nodes_by_tags;
|
||||
for (auto n : stream) {
|
||||
if (n->terminal) continue;
|
||||
std::vector<int> key;
|
||||
|
@ -556,7 +556,7 @@ struct Graph {
|
|||
if (!term) {
|
||||
header("Sibblings with similar tags (strict)");
|
||||
for (auto g : nonterm_nodes) {
|
||||
auto process_conns = [&](const pool<GraphNode*, hash_ptr_ops> &stream) {
|
||||
auto process_conns = [&](const pool<GraphNode*> &stream) {
|
||||
std::vector<GraphNode*> nodes;
|
||||
for (auto n : stream)
|
||||
if (!n->terminal) nodes.push_back(n);
|
||||
|
@ -585,7 +585,7 @@ struct Graph {
|
|||
if (!term) {
|
||||
header("Sibblings with similar tags (non-strict)");
|
||||
for (auto g : nonterm_nodes) {
|
||||
auto process_conns = [&](const pool<GraphNode*, hash_ptr_ops> &stream) {
|
||||
auto process_conns = [&](const pool<GraphNode*> &stream) {
|
||||
std::vector<GraphNode*> nodes;
|
||||
for (auto n : stream)
|
||||
if (!n->terminal) nodes.push_back(n);
|
||||
|
@ -603,7 +603,7 @@ struct Graph {
|
|||
|
||||
{
|
||||
header("Any nodes with identical fan-in or fan-out");
|
||||
dict<pool<GraphNode*, hash_ptr_ops>, pool<GraphNode*, hash_ptr_ops>> nodes_by_conn[2];
|
||||
dict<pool<GraphNode*>, pool<GraphNode*>> nodes_by_conn[2];
|
||||
for (auto g : term ? term_nodes : nonterm_nodes) {
|
||||
auto &up_entry = nodes_by_conn[0][g->upstream()];
|
||||
auto &down_entry = nodes_by_conn[1][g->downstream()];
|
||||
|
@ -629,7 +629,7 @@ struct Graph {
|
|||
if (!term) {
|
||||
header("Sibblings with similar tags (lax)");
|
||||
for (auto g : nonterm_nodes) {
|
||||
auto process_conns = [&](const pool<GraphNode*, hash_ptr_ops> &stream) {
|
||||
auto process_conns = [&](const pool<GraphNode*> &stream) {
|
||||
std::vector<GraphNode*> nodes;
|
||||
for (auto n : stream)
|
||||
if (!n->terminal) nodes.push_back(n);
|
||||
|
@ -720,9 +720,9 @@ struct VizWorker
|
|||
fprintf(f, "digraph \"%s\" {\n", log_id(module));
|
||||
fprintf(f, " rankdir = LR;\n");
|
||||
|
||||
dict<GraphNode*, std::vector<std::vector<std::string>>, hash_ptr_ops> extra_lines;
|
||||
dict<GraphNode*, GraphNode*, hash_ptr_ops> bypass_nodes;
|
||||
pool<GraphNode*, hash_ptr_ops> bypass_candidates;
|
||||
dict<GraphNode*, std::vector<std::vector<std::string>>> extra_lines;
|
||||
dict<GraphNode*, GraphNode*> bypass_nodes;
|
||||
pool<GraphNode*> bypass_candidates;
|
||||
|
||||
auto bypass = [&](GraphNode *g, GraphNode *n) {
|
||||
log_assert(g->terminal);
|
||||
|
|
|
@ -46,11 +46,11 @@ struct EquivStructWorker
|
|||
parameters == other.parameters && port_sizes == other.port_sizes;
|
||||
}
|
||||
|
||||
unsigned int hash() const {
|
||||
unsigned int h = mkhash_init;
|
||||
h = mkhash(h, mkhash(type));
|
||||
h = mkhash(h, mkhash(parameters));
|
||||
h = mkhash(h, mkhash(connections));
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(type);
|
||||
h.acc(parameters);
|
||||
h.acc(port_sizes);
|
||||
h.acc(connections);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -148,6 +148,7 @@ struct OptMergeWorker
|
|||
for (auto it : hash_conn_strings)
|
||||
hash_string += it;
|
||||
|
||||
log("hashed string %s\n", hash_string.c_str());
|
||||
return std::hash<std::string>{}(hash_string);
|
||||
}
|
||||
|
||||
|
@ -276,6 +277,7 @@ struct OptMergeWorker
|
|||
continue;
|
||||
|
||||
uint64_t hash = hash_cell_parameters_and_connections(cell);
|
||||
log("cell %s: hash %lX\n", cell->name.c_str(), hash);
|
||||
auto r = sharemap.insert(std::make_pair(hash, cell));
|
||||
if (!r.second) {
|
||||
if (compare_cell_parameters_and_connections(cell, r.first->second)) {
|
||||
|
|
|
@ -127,11 +127,10 @@ struct proc_dlatch_db_t
|
|||
return signal == other.signal && match == other.match && children == other.children;
|
||||
}
|
||||
|
||||
unsigned int hash() const {
|
||||
unsigned int h = mkhash_init;
|
||||
mkhash(h, signal.hash());
|
||||
mkhash(h, match.hash());
|
||||
for (auto i : children) mkhash(h, i);
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
h.acc(signal);
|
||||
h.acc(match);
|
||||
h.acc(children);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -108,8 +108,8 @@ struct SigSnippets
|
|||
|
||||
struct SnippetSwCache
|
||||
{
|
||||
dict<RTLIL::SwitchRule*, pool<RTLIL::SigBit>, hash_ptr_ops> full_case_bits_cache;
|
||||
dict<RTLIL::SwitchRule*, pool<int>, hash_ptr_ops> cache;
|
||||
dict<RTLIL::SwitchRule*, pool<RTLIL::SigBit>> full_case_bits_cache;
|
||||
dict<RTLIL::SwitchRule*, pool<int>> cache;
|
||||
const SigSnippets *snippets;
|
||||
int current_snippet;
|
||||
|
||||
|
@ -318,7 +318,7 @@ const pool<SigBit> &get_full_case_bits(SnippetSwCache &swcache, RTLIL::SwitchRul
|
|||
return swcache.full_case_bits_cache.at(sw);
|
||||
}
|
||||
|
||||
RTLIL::SigSpec signal_to_mux_tree(RTLIL::Module *mod, SnippetSwCache &swcache, dict<RTLIL::SwitchRule*, bool, hash_ptr_ops> &swpara,
|
||||
RTLIL::SigSpec signal_to_mux_tree(RTLIL::Module *mod, SnippetSwCache &swcache, dict<RTLIL::SwitchRule*, bool> &swpara,
|
||||
RTLIL::CaseRule *cs, const RTLIL::SigSpec &sig, const RTLIL::SigSpec &defval, bool ifxmode)
|
||||
{
|
||||
RTLIL::SigSpec result = defval;
|
||||
|
@ -421,7 +421,7 @@ void proc_mux(RTLIL::Module *mod, RTLIL::Process *proc, bool ifxmode)
|
|||
swcache.snippets = &sigsnip;
|
||||
swcache.insert(&proc->root_case);
|
||||
|
||||
dict<RTLIL::SwitchRule*, bool, hash_ptr_ops> swpara;
|
||||
dict<RTLIL::SwitchRule*, bool> swpara;
|
||||
|
||||
int cnt = 0;
|
||||
for (int idx : sigsnip.snippets)
|
||||
|
|
|
@ -176,7 +176,7 @@ struct coverdb_t
|
|||
|
||||
struct mutate_queue_t
|
||||
{
|
||||
pool<mutate_t*, hash_ptr_ops> db;
|
||||
pool<mutate_t*> db;
|
||||
|
||||
mutate_t *pick(xs128_t &rng, coverdb_t &coverdb, const mutate_opts_t &opts) {
|
||||
mutate_t *m = nullptr;
|
||||
|
|
|
@ -46,9 +46,11 @@ 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; };
|
||||
unsigned hash() const
|
||||
Hasher hash_acc(Hasher h) const
|
||||
{
|
||||
return mkhash_add(name.hash(), bit);
|
||||
h.acc(name);
|
||||
h.acc(bit);
|
||||
return h;
|
||||
}
|
||||
|
||||
IdString name;
|
||||
|
@ -62,9 +64,11 @@ 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; };
|
||||
unsigned hash() const
|
||||
Hasher hash_acc(Hasher h) const
|
||||
{
|
||||
return mkhash(bit.hash(), inverted);
|
||||
h.acc(bit);
|
||||
h.acc(inverted);
|
||||
return h;
|
||||
}
|
||||
|
||||
IdBit bit;
|
||||
|
|
|
@ -161,7 +161,7 @@ struct SimInstance
|
|||
pool<SigBit> dirty_bits;
|
||||
pool<Cell*> dirty_cells;
|
||||
pool<IdString> dirty_memories;
|
||||
pool<SimInstance*, hash_ptr_ops> dirty_children;
|
||||
pool<SimInstance*> dirty_children;
|
||||
|
||||
struct ff_state_t
|
||||
{
|
||||
|
|
|
@ -111,7 +111,7 @@ struct AlumaccWorker
|
|||
|
||||
dict<RTLIL::SigBit, int> bit_users;
|
||||
dict<RTLIL::SigSpec, maccnode_t*> sig_macc;
|
||||
dict<RTLIL::SigSig, pool<alunode_t*, hash_ptr_ops>> sig_alu;
|
||||
dict<RTLIL::SigSig, pool<alunode_t*>> sig_alu;
|
||||
int macc_counter, alu_counter;
|
||||
|
||||
AlumaccWorker(RTLIL::Module *module) : module(module), sigmap(module)
|
||||
|
@ -226,7 +226,7 @@ struct AlumaccWorker
|
|||
{
|
||||
while (1)
|
||||
{
|
||||
pool<maccnode_t*, hash_ptr_ops> delete_nodes;
|
||||
pool<maccnode_t*> delete_nodes;
|
||||
|
||||
for (auto &it : sig_macc)
|
||||
{
|
||||
|
@ -278,7 +278,7 @@ struct AlumaccWorker
|
|||
|
||||
void macc_to_alu()
|
||||
{
|
||||
pool<maccnode_t*, hash_ptr_ops> delete_nodes;
|
||||
pool<maccnode_t*> delete_nodes;
|
||||
|
||||
for (auto &it : sig_macc)
|
||||
{
|
||||
|
|
|
@ -77,10 +77,9 @@ struct ClockgatePass : public Pass {
|
|||
SigBit ce_bit;
|
||||
bool pol_clk;
|
||||
bool pol_ce;
|
||||
unsigned int hash() const {
|
||||
Hasher hash_acc(Hasher h) const {
|
||||
auto t = std::make_tuple(clk_bit, ce_bit, pol_clk, pol_ce);
|
||||
unsigned int h = mkhash_init;
|
||||
h = mkhash(h, hash_ops<decltype(t)>::hash(t));
|
||||
h.acc(t);
|
||||
return h;
|
||||
}
|
||||
bool operator==(const ClkNetInfo& other) const {
|
||||
|
|
|
@ -250,9 +250,11 @@ struct FlowGraph
|
|||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
unsigned int hash() const
|
||||
Hasher hash_acc(Hasher h) const
|
||||
{
|
||||
return hash_ops<pair<RTLIL::SigBit, int>>::hash({node, is_bottom});
|
||||
std::pair<RTLIL::SigBit, int> p = {node, is_bottom};
|
||||
h.acc(p);
|
||||
return h;
|
||||
}
|
||||
|
||||
static NodePrime top(RTLIL::SigBit node)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue