Merge pull request #3975 from rmlarsen/optmerge

This commit is contained in:
N. Engelhardt 2023-10-09 17:05:19 +02:00 committed by GitHub
commit 3e22791810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 15 deletions

View File

@ -90,6 +90,12 @@ template<> struct hash_ops<uint32_t> : hash_int_ops
return a;
}
};
template<> struct hash_ops<uint64_t> : hash_int_ops
{
static inline unsigned int hash(uint64_t a) {
return mkhash((unsigned int)(a), (unsigned int)(a >> 32));
}
};
template<> struct hash_ops<std::string> {
static inline bool cmp(const std::string &a, const std::string &b) {

View File

@ -308,10 +308,14 @@ namespace RTLIL
bool operator!=(const char *rhs) const { return strcmp(c_str(), rhs) != 0; }
char operator[](size_t i) const {
const char *p = c_str();
const char *p = c_str();
#ifndef NDEBUG
for (; i != 0; i--, p++)
log_assert(*p != 0);
return *p;
#else
return *(p + i);
#endif
}
std::string substr(size_t pos = 0, size_t len = std::string::npos) const {

View File

@ -41,7 +41,6 @@ struct OptMergeWorker
CellTypes ct;
int total_count;
SHA1 checksum;
static void sort_pmux_conn(dict<RTLIL::IdString, RTLIL::SigSpec> &conn)
{
@ -78,7 +77,7 @@ struct OptMergeWorker
return str;
}
std::string hash_cell_parameters_and_connections(const RTLIL::Cell *cell)
uint64_t hash_cell_parameters_and_connections(const RTLIL::Cell *cell)
{
vector<string> hash_conn_strings;
std::string hash_string = cell->type.str() + "\n";
@ -149,8 +148,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 +266,13 @@ struct OptMergeWorker
}
did_something = false;
dict<std::string, RTLIL::Cell*> sharemap;
dict<uint64_t, 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);
uint64_t 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)) {

View File

@ -29,13 +29,6 @@
USING_YOSYS_NAMESPACE
template<> struct hashlib::hash_ops<uint64_t> : hashlib::hash_int_ops
{
static inline unsigned int hash(uint64_t a) {
return mkhash((unsigned int)(a), (unsigned int)(a >> 32));
}
};
PRIVATE_NAMESPACE_BEGIN
// xorshift128 params
@ -453,7 +446,7 @@ struct RecoverNamesWorker {
pool<IdString> comb_whiteboxes, buffer_types;
// class -> (gold, (gate, inverted))
dict<equiv_cls_t, std::pair<pool<IdBit>, dict<IdBit, bool>>> cls2bits;
dict<equiv_cls_t, std::pair<pool<IdBit>, dict<IdBit, bool>>> cls2bits;
void analyse_boxes()
{