From eca1a4cee4f310c7e2c1216bd678143c1967edd4 Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 2 Jun 2021 11:36:56 +0100 Subject: 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 +- 9 files changed, 33 insertions(+), 38 deletions(-) (limited to 'common') 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); -- cgit v1.2.3