mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 09:05:32 +00:00
Speed up OptMergePass by 1.7x.
The main speedup comes from swithing from using a SHA1 hash to std::hash<std::string>. There is no need to use an expensive cryptographic hash for fingerprinting in this context.
This commit is contained in:
parent
7aa26b3a0b
commit
bce984fa60
3 changed files with 15 additions and 12 deletions
|
@ -41,7 +41,7 @@ struct OptMergeWorker
|
|||
|
||||
CellTypes ct;
|
||||
int total_count;
|
||||
SHA1 checksum;
|
||||
using FingerPrint = std::hash<std::string>::result_type;
|
||||
|
||||
static void sort_pmux_conn(dict<RTLIL::IdString, RTLIL::SigSpec> &conn)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ struct OptMergeWorker
|
|||
return str;
|
||||
}
|
||||
|
||||
std::string hash_cell_parameters_and_connections(const RTLIL::Cell *cell)
|
||||
FingerPrint hash_cell_parameters_and_connections(const RTLIL::Cell *cell)
|
||||
{
|
||||
vector<string> hash_conn_strings;
|
||||
std::string hash_string = cell->type.str() + "\n";
|
||||
|
@ -149,8 +149,7 @@ struct OptMergeWorker
|
|||
for (auto it : hash_conn_strings)
|
||||
hash_string += it;
|
||||
|
||||
checksum.update(hash_string);
|
||||
return checksum.final();
|
||||
return std::hash<std::string>{}(hash_string);
|
||||
}
|
||||
|
||||
bool compare_cell_parameters_and_connections(const RTLIL::Cell *cell1, const RTLIL::Cell *cell2)
|
||||
|
@ -268,13 +267,13 @@ struct OptMergeWorker
|
|||
}
|
||||
|
||||
did_something = false;
|
||||
dict<std::string, RTLIL::Cell*> sharemap;
|
||||
std::unordered_map<FingerPrint, RTLIL::Cell*> sharemap;
|
||||
for (auto cell : cells)
|
||||
{
|
||||
if ((!mode_share_all && !ct.cell_known(cell->type)) || !cell->known())
|
||||
continue;
|
||||
|
||||
auto hash = hash_cell_parameters_and_connections(cell);
|
||||
FingerPrint hash = hash_cell_parameters_and_connections(cell);
|
||||
auto r = sharemap.insert(std::make_pair(hash, cell));
|
||||
if (!r.second) {
|
||||
if (compare_cell_parameters_and_connections(cell, r.first->second)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue