From 4e346ecfba86880c2528e3463b9beb42932d8567 Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 14 Apr 2021 10:14:51 +0100 Subject: Hash table refactoring Signed-off-by: gatecat --- common/hash_table.h | 33 ++++++++++++++++++++++++--------- common/timing_opt.cc | 45 ++++----------------------------------------- 2 files changed, 28 insertions(+), 50 deletions(-) (limited to 'common') diff --git a/common/hash_table.h b/common/hash_table.h index 759580da..21ca8887 100644 --- a/common/hash_table.h +++ b/common/hash_table.h @@ -20,29 +20,44 @@ #ifndef HASH_TABLE_H #define HASH_TABLE_H -#if defined(NPNR_DISABLE_THREADS) -#include -#include -#else +#if defined(USE_ABSEIL) #include #include +#else +#include +#include #endif +#include + #include "nextpnr_namespaces.h" NEXTPNR_NAMESPACE_BEGIN namespace HashTables { -#if defined(NPNR_DISABLE_THREADS) -template using HashMap = std::unordered_map; -template using HashSet = std::unordered_set; +#if defined(USE_ABSEIL) +template > +using HashMap = absl::flat_hash_map; +template > using HashSet = absl::flat_hash_set; #else -template using HashMap = absl::flat_hash_map; -template using HashSet = absl::flat_hash_set; +template > +using HashMap = std::unordered_map; +template > using HashSet = std::unordered_set; #endif }; // namespace HashTables +struct PairHash +{ + template std::size_t operator()(const std::pair &idp) const noexcept + { + std::size_t seed = 0; + boost::hash_combine(seed, std::hash()(idp.first)); + boost::hash_combine(seed, std::hash()(idp.second)); + return seed; + } +}; + NEXTPNR_NAMESPACE_END #endif /* HASH_TABLE_H */ diff --git a/common/timing_opt.cc b/common/timing_opt.cc index fd2a3f83..dba96bf1 100644 --- a/common/timing_opt.cc +++ b/common/timing_opt.cc @@ -35,44 +35,7 @@ #include "timing.h" #include "util.h" -namespace std { - -template <> struct hash> -{ - std::size_t operator()( - const std::pair &idp) const noexcept - { - std::size_t seed = 0; - boost::hash_combine(seed, hash()(idp.first)); - boost::hash_combine(seed, hash()(idp.second)); - return seed; - } -}; - -template <> struct hash> -{ - std::size_t operator()(const std::pair &idp) const noexcept - { - std::size_t seed = 0; - boost::hash_combine(seed, hash()(idp.first)); - boost::hash_combine(seed, hash()(idp.second)); - return seed; - } -}; -#if !defined(ARCH_GOWIN) -template <> struct hash> -{ - std::size_t - operator()(const std::pair &idp) const noexcept - { - std::size_t seed = 0; - boost::hash_combine(seed, hash()(idp.first)); - boost::hash_combine(seed, hash()(idp.second)); - return seed; - } -}; -#endif -} // namespace std +#include "hash_table.h" NEXTPNR_NAMESPACE_BEGIN @@ -478,9 +441,9 @@ class TimingOptimiser // Actual BFS path optimisation algorithm std::unordered_map> cumul_costs; - std::unordered_map, std::pair> backtrace; + std::unordered_map, std::pair, PairHash> backtrace; std::queue> visit; - std::unordered_set> to_visit; + std::unordered_set, PairHash> to_visit; for (auto startbel : cell_neighbour_bels[path_cells.front()]) { // Swap for legality check @@ -609,7 +572,7 @@ class TimingOptimiser std::unordered_map> cell_neighbour_bels; std::unordered_map> bel_candidate_cells; // Map cell ports to net delay limit - std::unordered_map, delay_t> max_net_delay; + std::unordered_map, delay_t, PairHash> max_net_delay; Context *ctx; TimingOptCfg cfg; TimingAnalyser tmg; -- cgit v1.2.3