aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-04-14 10:14:51 +0100
committergatecat <gatecat@ds0.me>2021-04-14 10:30:19 +0100
commit4e346ecfba86880c2528e3463b9beb42932d8567 (patch)
tree37c620946f8dda1937ba1fa4b6ce6f0e2126c4ea /common
parent2912860c9788033a7501726e77bb4962b394280d (diff)
downloadnextpnr-4e346ecfba86880c2528e3463b9beb42932d8567.tar.gz
nextpnr-4e346ecfba86880c2528e3463b9beb42932d8567.tar.bz2
nextpnr-4e346ecfba86880c2528e3463b9beb42932d8567.zip
Hash table refactoring
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to 'common')
-rw-r--r--common/hash_table.h33
-rw-r--r--common/timing_opt.cc45
2 files changed, 28 insertions, 50 deletions
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 <unordered_map>
-#include <unordered_set>
-#else
+#if defined(USE_ABSEIL)
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>
+#else
+#include <unordered_map>
+#include <unordered_set>
#endif
+#include <boost/functional/hash.hpp>
+
#include "nextpnr_namespaces.h"
NEXTPNR_NAMESPACE_BEGIN
namespace HashTables {
-#if defined(NPNR_DISABLE_THREADS)
-template <typename Key, typename Value> using HashMap = std::unordered_map<Key, Value>;
-template <typename Value> using HashSet = std::unordered_set<Value>;
+#if defined(USE_ABSEIL)
+template <typename Key, typename Value, typename Hash = std::hash<Key>>
+using HashMap = absl::flat_hash_map<Key, Value, Hash>;
+template <typename Value, typename Hash = std::hash<Value>> using HashSet = absl::flat_hash_set<Value, Hash>;
#else
-template <typename Key, typename Value> using HashMap = absl::flat_hash_map<Key, Value>;
-template <typename Value> using HashSet = absl::flat_hash_set<Value>;
+template <typename Key, typename Value, typename Hash = std::hash<Key>>
+using HashMap = std::unordered_map<Key, Value, Hash>;
+template <typename Value, typename Hash = std::hash<Value>> using HashSet = std::unordered_set<Value, Hash>;
#endif
}; // namespace HashTables
+struct PairHash
+{
+ template <typename T1, typename T2> std::size_t operator()(const std::pair<T1, T2> &idp) const noexcept
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, std::hash<T1>()(idp.first));
+ boost::hash_combine(seed, std::hash<T2>()(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::pair<NEXTPNR_NAMESPACE_PREFIX IdString, NEXTPNR_NAMESPACE_PREFIX IdString>>
-{
- std::size_t operator()(
- const std::pair<NEXTPNR_NAMESPACE_PREFIX IdString, NEXTPNR_NAMESPACE_PREFIX IdString> &idp) const noexcept
- {
- std::size_t seed = 0;
- boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX IdString>()(idp.first));
- boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX IdString>()(idp.second));
- return seed;
- }
-};
-
-template <> struct hash<std::pair<int, NEXTPNR_NAMESPACE_PREFIX BelId>>
-{
- std::size_t operator()(const std::pair<int, NEXTPNR_NAMESPACE_PREFIX BelId> &idp) const noexcept
- {
- std::size_t seed = 0;
- boost::hash_combine(seed, hash<int>()(idp.first));
- boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX BelId>()(idp.second));
- return seed;
- }
-};
-#if !defined(ARCH_GOWIN)
-template <> struct hash<std::pair<NEXTPNR_NAMESPACE_PREFIX IdString, NEXTPNR_NAMESPACE_PREFIX BelId>>
-{
- std::size_t
- operator()(const std::pair<NEXTPNR_NAMESPACE_PREFIX IdString, NEXTPNR_NAMESPACE_PREFIX BelId> &idp) const noexcept
- {
- std::size_t seed = 0;
- boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX IdString>()(idp.first));
- boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX BelId>()(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<IdString, std::unordered_map<BelId, delay_t>> cumul_costs;
- std::unordered_map<std::pair<IdString, BelId>, std::pair<IdString, BelId>> backtrace;
+ std::unordered_map<std::pair<IdString, BelId>, std::pair<IdString, BelId>, PairHash> backtrace;
std::queue<std::pair<int, BelId>> visit;
- std::unordered_set<std::pair<int, BelId>> to_visit;
+ std::unordered_set<std::pair<int, BelId>, 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<IdString, std::unordered_set<BelId>> cell_neighbour_bels;
std::unordered_map<BelId, std::unordered_set<IdString>> bel_candidate_cells;
// Map cell ports to net delay limit
- std::unordered_map<std::pair<IdString, IdString>, delay_t> max_net_delay;
+ std::unordered_map<std::pair<IdString, IdString>, delay_t, PairHash> max_net_delay;
Context *ctx;
TimingOptCfg cfg;
TimingAnalyser tmg;