Skip to content

Commit

Permalink
Merge pull request #3975 from rmlarsen/optmerge
Browse files Browse the repository at this point in the history
  • Loading branch information
nakengelhardt authored Oct 9, 2023
2 parents 11b9deb + 57a2b4b commit 3e22791
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 6 additions & 0 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions passes/opt/opt_merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct OptMergeWorker

CellTypes ct;
int total_count;
SHA1 checksum;

static void sort_pmux_conn(dict<RTLIL::IdString, RTLIL::SigSpec> &conn)
{
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down
9 changes: 1 addition & 8 deletions passes/sat/recover_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit 3e22791

Please sign in to comment.