From eca1a4cee4f310c7e2c1216bd678143c1967edd4 Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 2 Jun 2021 11:36:56 +0100 Subject: [PATCH] Use hashlib in most remaining code Signed-off-by: gatecat --- common/archcheck.cc | 18 +++++++++--------- common/basectx.h | 1 + common/command.cc | 4 ++-- common/command.h | 2 +- common/constraints.h | 4 ++-- common/log.cc | 2 +- common/log.h | 20 ++++++++------------ common/timing_opt.cc | 18 ++++++++---------- common/timing_opt.h | 2 +- ecp5/main.cc | 4 ++-- fpga_interchange/main.cc | 4 ++-- generic/main.cc | 4 ++-- gowin/main.cc | 4 ++-- gui/treemodel.cc | 2 +- gui/treemodel.h | 4 ++-- ice40/main.cc | 4 ++-- json/jsonwrite.cc | 2 +- machxo2/main.cc | 4 ++-- mistral/main.cc | 4 ++-- nexus/main.cc | 4 ++-- 20 files changed, 53 insertions(+), 58 deletions(-) diff --git a/common/archcheck.cc b/common/archcheck.cc index f46db95c..89a61007 100644 --- a/common/archcheck.cc +++ b/common/archcheck.cc @@ -108,7 +108,7 @@ void archcheck_locs(const Context *ctx) for (int x = 0; x < ctx->getGridDimX(); x++) for (int y = 0; y < ctx->getGridDimY(); y++) { dbg("> %d %d\n", x, y); - std::unordered_set usedz; + pool usedz; for (int z = 0; z < ctx->getTileBelDimZ(x, y); z++) { BelId bel = ctx->getBelByLocation(Loc(x, y, z)); @@ -162,10 +162,10 @@ struct LruWireCacheMap // list is oldest wire in cache. std::list last_access_list; // Quick wire -> list element lookup. - std::unordered_map::iterator> last_access_map; + dict::iterator> last_access_map; - std::unordered_map pips_downhill; - std::unordered_map pips_uphill; + dict pips_downhill; + dict pips_uphill; void removeWireFromCache(WireId wire_to_remove) { @@ -255,8 +255,8 @@ void archcheck_conn(const Context *ctx) log_info("Checking all wires...\n"); #ifndef USING_LRU_CACHE - std::unordered_map pips_downhill; - std::unordered_map pips_uphill; + dict pips_downhill; + dict pips_uphill; #endif for (WireId wire : ctx->getWires()) { @@ -347,7 +347,7 @@ void archcheck_buckets(const Context *ctx) for (BelBucketId bucket : ctx->getBelBuckets()) { // Find out which cell types are in this bucket. - std::unordered_set cell_types_in_bucket; + pool cell_types_in_bucket; for (IdString cell_type : ctx->getCellTypes()) { if (ctx->getBelBucketForCellType(cell_type) == bucket) { cell_types_in_bucket.insert(cell_type); @@ -356,9 +356,9 @@ void archcheck_buckets(const Context *ctx) // Make sure that all cell types in this bucket have at least one // BelId they can be placed at. - std::unordered_set cell_types_unused; + pool cell_types_unused; - std::unordered_set bels_in_bucket; + pool bels_in_bucket; for (BelId bel : ctx->getBelsInBucket(bucket)) { BelBucketId bucket2 = ctx->getBelBucketForBel(bel); log_assert(bucket == bucket2); diff --git a/common/basectx.h b/common/basectx.h index dd48c33c..12f63f98 100644 --- a/common/basectx.h +++ b/common/basectx.h @@ -28,6 +28,7 @@ #include #endif +#include "hashlib.h" #include "idstring.h" #include "nextpnr_namespaces.h" #include "nextpnr_types.h" diff --git a/common/command.cc b/common/command.cc index f48d6adf..27e59260 100644 --- a/common/command.cc +++ b/common/command.cc @@ -458,7 +458,7 @@ int CommandHandler::exec() if (executeBeforeContext()) return 0; - std::unordered_map values; + dict values; std::unique_ptr ctx = createContext(values); setupContext(ctx.get()); setupArchContext(ctx.get()); @@ -475,7 +475,7 @@ int CommandHandler::exec() std::unique_ptr CommandHandler::load_json(std::string filename) { - std::unordered_map values; + dict values; std::unique_ptr ctx = createContext(values); setupContext(ctx.get()); setupArchContext(ctx.get()); diff --git a/common/command.h b/common/command.h index 36b6d8ab..ba606ea2 100644 --- a/common/command.h +++ b/common/command.h @@ -42,7 +42,7 @@ class CommandHandler protected: virtual void setupArchContext(Context *ctx) = 0; - virtual std::unique_ptr createContext(std::unordered_map &values) = 0; + virtual std::unique_ptr createContext(dict &values) = 0; virtual po::options_description getArchOptions() = 0; virtual void validate(){}; virtual void customAfterLoad(Context *ctx){}; diff --git a/common/constraints.h b/common/constraints.h index 9ec8372d..65abf12c 100644 --- a/common/constraints.h +++ b/common/constraints.h @@ -21,11 +21,11 @@ #define CONSTRAINTS_H #include -#include #include #include "archdefs.h" #include "exclusive_state_groups.h" +#include "hashlib.h" #include "idstring.h" #include "nextpnr_namespaces.h" @@ -53,7 +53,7 @@ template TagState; - std::unordered_map> definitions; + dict> definitions; template void bindBel(TagState *tags, const ConstraintRange constraints); diff --git a/common/log.cc b/common/log.cc index 01aec79a..a429d172 100644 --- a/common/log.cc +++ b/common/log.cc @@ -38,7 +38,7 @@ log_write_type log_write_function = nullptr; std::string log_last_error; void (*log_error_atexit)() = NULL; -std::unordered_map message_count_by_level; +dict message_count_by_level; static int log_newline_count = 0; bool had_nonfatal_error = false; diff --git a/common/log.h b/common/log.h index 7dfdf165..e9237446 100644 --- a/common/log.h +++ b/common/log.h @@ -26,8 +26,8 @@ #include #include #include -#include #include +#include "hashlib.h" #include "nextpnr_namespaces.h" NEXTPNR_NAMESPACE_BEGIN @@ -51,13 +51,19 @@ enum class LogLevel ALWAYS_MSG }; +struct loglevel_hash_ops +{ + static inline bool cmp(LogLevel a, LogLevel b) { return a == b; } + static inline unsigned int hash(LogLevel a) { return unsigned(a); } +}; + extern std::vector> log_streams; extern log_write_type log_write_function; extern std::string log_last_error; extern void (*log_error_atexit)(); extern bool had_nonfatal_error; -extern std::unordered_map message_count_by_level; +extern dict message_count_by_level; std::string stringf(const char *fmt, ...); std::string vstringf(const char *fmt, va_list ap); @@ -83,14 +89,4 @@ static inline void log_assert_worker(bool cond, const char *expr, const char *fi NEXTPNR_NAMESPACE_END -namespace std { -template <> struct hash -{ - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX LogLevel &loglevel) const noexcept - { - return std::hash()((int)loglevel); - } -}; -} // namespace std - #endif diff --git a/common/timing_opt.cc b/common/timing_opt.cc index 2659f04e..da4907b6 100644 --- a/common/timing_opt.cc +++ b/common/timing_opt.cc @@ -35,8 +35,6 @@ #include "timing.h" #include "util.h" -#include "hash_table.h" - NEXTPNR_NAMESPACE_BEGIN class TimingOptimiser @@ -167,7 +165,7 @@ class TimingOptimiser BelId curr = cell->bel; Loc curr_loc = ctx->getBelLocation(curr); int found_count = 0; - cell_neighbour_bels[cell->name] = std::unordered_set{}; + cell_neighbour_bels[cell->name] = pool{}; for (int dy = -d; dy <= d; dy++) { for (int dx = -d; dx <= d; dx++) { // Go through all the Bels at this location @@ -267,7 +265,7 @@ class TimingOptimiser } NPNR_ASSERT_FALSE("port user not found on net"); }; - std::unordered_set used_ports; + pool used_ports; for (auto crit_net : crit_nets) { @@ -439,10 +437,10 @@ class TimingOptimiser } // Actual BFS path optimisation algorithm - std::unordered_map> cumul_costs; - std::unordered_map, std::pair, PairHash> backtrace; + dict> cumul_costs; + dict, std::pair> backtrace; std::queue> visit; - std::unordered_set, PairHash> to_visit; + pool> to_visit; for (auto startbel : cell_neighbour_bels[path_cells.front()]) { // Swap for legality check @@ -568,10 +566,10 @@ class TimingOptimiser // Current candidate Bels for cells (linked in both direction> std::vector path_cells; - std::unordered_map> cell_neighbour_bels; - std::unordered_map> bel_candidate_cells; + dict> cell_neighbour_bels; + dict> bel_candidate_cells; // Map cell ports to net delay limit - std::unordered_map, delay_t, PairHash> max_net_delay; + dict, delay_t> max_net_delay; Context *ctx; TimingOptCfg cfg; TimingAnalyser tmg; diff --git a/common/timing_opt.h b/common/timing_opt.h index 775d9596..46bf3500 100644 --- a/common/timing_opt.h +++ b/common/timing_opt.h @@ -29,7 +29,7 @@ struct TimingOptCfg // The timing optimiser will *only* optimise cells of these types // Normally these would only be logic cells (or tiles if applicable), the algorithm makes little sense // for other cell types - std::unordered_set cellTypes; + pool cellTypes; }; extern bool timing_opt(Context *ctx, TimingOptCfg cfg); diff --git a/ecp5/main.cc b/ecp5/main.cc index f6d734e1..711c4944 100644 --- a/ecp5/main.cc +++ b/ecp5/main.cc @@ -34,7 +34,7 @@ class ECP5CommandHandler : public CommandHandler public: ECP5CommandHandler(int argc, char **argv); virtual ~ECP5CommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customAfterLoad(Context *ctx) override; void validate() override; @@ -132,7 +132,7 @@ static std::string speedString(ArchArgs::SpeedGrade speed) return ""; } -std::unique_ptr ECP5CommandHandler::createContext(std::unordered_map &values) +std::unique_ptr ECP5CommandHandler::createContext(dict &values) { ArchArgs chipArgs; chipArgs.type = ArchArgs::NONE; diff --git a/fpga_interchange/main.cc b/fpga_interchange/main.cc index 4d331a32..1e1ac71f 100644 --- a/fpga_interchange/main.cc +++ b/fpga_interchange/main.cc @@ -36,7 +36,7 @@ class FpgaInterchangeCommandHandler : public CommandHandler public: FpgaInterchangeCommandHandler(int argc, char **argv); virtual ~FpgaInterchangeCommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customBitstream(Context *ctx) override; void customAfterLoad(Context *ctx) override; @@ -69,7 +69,7 @@ void FpgaInterchangeCommandHandler::customBitstream(Context *ctx) } } -std::unique_ptr FpgaInterchangeCommandHandler::createContext(std::unordered_map &values) +std::unique_ptr FpgaInterchangeCommandHandler::createContext(dict &values) { auto start = std::chrono::high_resolution_clock::now(); diff --git a/generic/main.cc b/generic/main.cc index 784178c6..2352b246 100644 --- a/generic/main.cc +++ b/generic/main.cc @@ -32,7 +32,7 @@ class GenericCommandHandler : public CommandHandler public: GenericCommandHandler(int argc, char **argv); virtual ~GenericCommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customBitstream(Context *ctx) override; @@ -52,7 +52,7 @@ po::options_description GenericCommandHandler::getArchOptions() void GenericCommandHandler::customBitstream(Context *ctx) {} -std::unique_ptr GenericCommandHandler::createContext(std::unordered_map &values) +std::unique_ptr GenericCommandHandler::createContext(dict &values) { ArchArgs chipArgs; if (values.find("arch.name") != values.end()) { diff --git a/gowin/main.cc b/gowin/main.cc index 674eac03..0f3a61cb 100644 --- a/gowin/main.cc +++ b/gowin/main.cc @@ -34,7 +34,7 @@ class GowinCommandHandler : public CommandHandler public: GowinCommandHandler(int argc, char **argv); virtual ~GowinCommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customAfterLoad(Context *ctx) override; @@ -52,7 +52,7 @@ po::options_description GowinCommandHandler::getArchOptions() return specific; } -std::unique_ptr GowinCommandHandler::createContext(std::unordered_map &values) +std::unique_ptr GowinCommandHandler::createContext(dict &values) { std::regex devicere = std::regex("GW1N([A-Z]*)-(LV|UV)([0-9])([A-Z]{2}[0-9]+)(C[0-9]/I[0-9])"); std::smatch match; diff --git a/gui/treemodel.cc b/gui/treemodel.cc index cc563202..b0dc51db 100644 --- a/gui/treemodel.cc +++ b/gui/treemodel.cc @@ -58,7 +58,7 @@ void IdList::updateElements(Context *ctx, std::vector elements) bool changed = false; // For any elements that are not yet in managed_, created them. - std::unordered_set element_set; + pool element_set; for (auto elem : elements) { element_set.insert(elem); auto existing = managed_.find(elem); diff --git a/gui/treemodel.h b/gui/treemodel.h index e9c42a0f..e2692f3e 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -140,7 +140,7 @@ class IdList : public Item private: // Children that we manage the memory for, stored for quick lookup from // IdString to child. - std::unordered_map> managed_; + dict> managed_; // Type of children that the list creates. ElementType child_type_; @@ -184,7 +184,7 @@ template class ElementList : public Item ElementGetter getter_; // Children that we manage the memory for, stored for quick lookup from // IdString to child. - std::unordered_map> managed_; + dict> managed_; // Type of children that he list creates. ElementType child_type_; diff --git a/ice40/main.cc b/ice40/main.cc index e537c2f4..28e6de9a 100644 --- a/ice40/main.cc +++ b/ice40/main.cc @@ -35,7 +35,7 @@ class Ice40CommandHandler : public CommandHandler public: Ice40CommandHandler(int argc, char **argv); virtual ~Ice40CommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override; void validate() override; void customAfterLoad(Context *ctx) override; @@ -129,7 +129,7 @@ void Ice40CommandHandler::setupArchContext(Context *ctx) } } -std::unique_ptr Ice40CommandHandler::createContext(std::unordered_map &values) +std::unique_ptr Ice40CommandHandler::createContext(dict &values) { ArchArgs chipArgs; chipArgs.type = ArchArgs::NONE; diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index dbf43351..88d66519 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -67,7 +67,7 @@ struct PortGroup std::vector group_ports(Context *ctx, const dict &ports, bool is_cell = false) { std::vector groups; - std::unordered_map base_to_group; + dict base_to_group; for (auto &pair : ports) { std::string name = pair.second.name.str(ctx); if ((name.back() != ']') || (name.find('[') == std::string::npos)) { diff --git a/machxo2/main.cc b/machxo2/main.cc index 961fe9ae..1dfee16a 100644 --- a/machxo2/main.cc +++ b/machxo2/main.cc @@ -34,7 +34,7 @@ class MachXO2CommandHandler : public CommandHandler public: MachXO2CommandHandler(int argc, char **argv); virtual ~MachXO2CommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customBitstream(Context *ctx) override; @@ -82,7 +82,7 @@ void MachXO2CommandHandler::customBitstream(Context *ctx) write_bitstream(ctx, textcfg); } -std::unique_ptr MachXO2CommandHandler::createContext(std::unordered_map &values) +std::unique_ptr MachXO2CommandHandler::createContext(dict &values) { ArchArgs chipArgs; chipArgs.type = ArchArgs::NONE; diff --git a/mistral/main.cc b/mistral/main.cc index 7b4f9594..0afba3d8 100644 --- a/mistral/main.cc +++ b/mistral/main.cc @@ -33,7 +33,7 @@ class MistralCommandHandler : public CommandHandler public: MistralCommandHandler(int argc, char **argv); virtual ~MistralCommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customBitstream(Context *ctx) override; void customAfterLoad(Context *ctx) override; @@ -71,7 +71,7 @@ void MistralCommandHandler::customBitstream(Context *ctx) } } -std::unique_ptr MistralCommandHandler::createContext(std::unordered_map &values) +std::unique_ptr MistralCommandHandler::createContext(dict &values) { ArchArgs chipArgs; if (!vm.count("mistral")) { diff --git a/nexus/main.cc b/nexus/main.cc index cced1b95..66b1a61e 100644 --- a/nexus/main.cc +++ b/nexus/main.cc @@ -33,7 +33,7 @@ class NexusCommandHandler : public CommandHandler public: NexusCommandHandler(int argc, char **argv); virtual ~NexusCommandHandler(){}; - std::unique_ptr createContext(std::unordered_map &values) override; + std::unique_ptr createContext(dict &values) override; void setupArchContext(Context *ctx) override{}; void customBitstream(Context *ctx) override; void customAfterLoad(Context *ctx) override; @@ -66,7 +66,7 @@ void NexusCommandHandler::customBitstream(Context *ctx) } } -std::unique_ptr NexusCommandHandler::createContext(std::unordered_map &values) +std::unique_ptr NexusCommandHandler::createContext(dict &values) { ArchArgs chipArgs; if (!vm.count("device")) {