#include <string>
#include <vector>
+#define YOSYS_HASHTABLE_SIZE_FACTOR 3
+
inline unsigned int mkhash(unsigned int a, unsigned int b) {
return ((a << 5) + a) ^ b;
}
}
};
+struct hash_obj_ops {
+ bool cmp(const void *a, const void *b) const {
+ return a == b;
+ }
+ template<typename T>
+ unsigned int hash(const T *a) const {
+ return a->name.hash();
+ }
+};
+
inline int hashtable_size(int old_size)
{
+ // prime numbers, approx. in powers of two
if (old_size < 53) return 53;
if (old_size < 113) return 113;
if (old_size < 251) return 251;
entries.clear();
counter = other.size();
- int new_size = hashtable_size(counter);
+ int new_size = hashtable_size(YOSYS_HASHTABLE_SIZE_FACTOR * counter);
+ hashtable.resize(new_size);
+ new_size = new_size / YOSYS_HASHTABLE_SIZE_FACTOR + 1;
entries.reserve(new_size);
for (auto &it : other)
{
free_list = -1;
- hashtable.resize(entries.size());
for (auto &h : hashtable)
h = -1;
if (free_list < 0)
{
int i = entries.size();
- entries.resize(hashtable_size(i));
+ int new_size = hashtable_size(YOSYS_HASHTABLE_SIZE_FACTOR * entries.size());
+ hashtable.resize(new_size);
+ entries.resize(new_size / YOSYS_HASHTABLE_SIZE_FACTOR + 1);
entries[i].udata = value;
entries[i].set_next_used(0);
counter++;
entries.clear();
counter = other.size();
- int new_size = hashtable_size(counter);
+ int new_size = hashtable_size(YOSYS_HASHTABLE_SIZE_FACTOR * counter);
+ hashtable.resize(new_size);
+ new_size = new_size / YOSYS_HASHTABLE_SIZE_FACTOR + 1;
entries.reserve(new_size);
for (auto &it : other)
{
free_list = -1;
- hashtable.resize(entries.size());
for (auto &h : hashtable)
h = -1;
if (free_list < 0)
{
int i = entries.size();
- entries.resize(hashtable_size(i));
+ int new_size = hashtable_size(YOSYS_HASHTABLE_SIZE_FACTOR * entries.size());
+ hashtable.resize(new_size);
+ entries.resize(new_size / YOSYS_HASHTABLE_SIZE_FACTOR + 1);
entries[i].key = key;
entries[i].set_next_used(0);
counter++;
struct DeleteWireWorker
{
RTLIL::Module *module;
- const pool<RTLIL::Wire*, hash_ptr_ops> *wires_p;
+ const pool<RTLIL::Wire*, hash_obj_ops> *wires_p;
void operator()(RTLIL::SigSpec &sig) {
std::vector<RTLIL::SigChunk> chunks = sig;
};
}
-void RTLIL::Module::remove(const pool<RTLIL::Wire*, hash_ptr_ops> &wires)
+void RTLIL::Module::remove(const pool<RTLIL::Wire*, hash_obj_ops> &wires)
{
log_assert(refcount_wires_ == 0);
struct RTLIL::Monitor
{
+ RTLIL::IdString name;
+ Monitor() { name = stringf("$%d", autoidx++); }
virtual ~Monitor() { }
virtual void notify_module_add(RTLIL::Module*) { }
virtual void notify_module_del(RTLIL::Module*) { }
struct RTLIL::Design
{
- pool<RTLIL::Monitor*, hash_ptr_ops> monitors;
+ pool<RTLIL::Monitor*, hash_obj_ops> monitors;
dict<std::string, std::string> scratchpad;
int refcount_modules_;
public:
RTLIL::Design *design;
- pool<RTLIL::Monitor*, hash_ptr_ops> monitors;
+ pool<RTLIL::Monitor*, hash_obj_ops> monitors;
int refcount_wires_;
int refcount_cells_;
RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }
// Removing wires is expensive. If you have to remove wires, remove them all at once.
- void remove(const pool<RTLIL::Wire*, hash_ptr_ops> &wires);
+ void remove(const pool<RTLIL::Wire*, hash_obj_ops> &wires);
void remove(RTLIL::Cell *cell);
void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);
template<typename T> int GetSize(const T &obj) { return obj.size(); }
int GetSize(RTLIL::Wire *wire);
+extern int autoidx;
+
YOSYS_NAMESPACE_END
#include "kernel/log.h"
Tcl_Interp *yosys_get_tcl_interp();
#endif
-extern int autoidx;
extern RTLIL::Design *yosys_design;
RTLIL::IdString new_id(std::string file, int line, std::string func);
continue;
}
- pool<RTLIL::Wire*, hash_ptr_ops> delete_wires;
- pool<RTLIL::Cell*, hash_ptr_ops> delete_cells;
+ pool<RTLIL::Wire*, hash_obj_ops> delete_wires;
+ pool<RTLIL::Cell*, hash_obj_ops> delete_cells;
pool<RTLIL::IdString> delete_procs;
pool<RTLIL::IdString> delete_mems;
module->rewrite_sigspecs(worker);
- pool<RTLIL::Wire*, hash_ptr_ops> delete_wires;
+ pool<RTLIL::Wire*, hash_obj_ops> delete_wires;
for (auto &it : worker.splitmap)
delete_wires.insert(it.first);
module->remove(delete_wires);
}
- pool<RTLIL::Wire*, hash_ptr_ops> del_wires;
+ pool<RTLIL::Wire*, hash_obj_ops> del_wires;
int del_wires_count = 0;
for (auto wire : maybe_del_wires)
dict<RTLIL::SigSpec, RTLIL::SigSpec> invert_map;
TopoSort<RTLIL::Cell*, RTLIL::IdString::compare_ptr_by_name<RTLIL::Cell>> cells;
- dict<RTLIL::Cell*, std::set<RTLIL::SigBit>, hash_ptr_ops> cell_to_inbit;
+ dict<RTLIL::Cell*, std::set<RTLIL::SigBit>, hash_obj_ops> cell_to_inbit;
dict<RTLIL::SigBit, std::set<RTLIL::Cell*>> outbit_to_cell;
for (auto cell : module->cells())
CellTypes ct;
int total_count;
#ifdef USE_CELL_HASH_CACHE
- dict<const RTLIL::Cell*, std::string, hash_ptr_ops> cell_hash_cache;
+ dict<const RTLIL::Cell*, std::string, hash_obj_ops> cell_hash_cache;
#endif
#ifdef USE_CELL_HASH_CACHE