aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-06-02 11:36:56 +0100
committergatecat <gatecat@ds0.me>2021-06-02 15:05:20 +0100
commiteca1a4cee4f310c7e2c1216bd678143c1967edd4 (patch)
tree2106f7895e22f60f6d200cca6d9244bcc81a1ab9
parentb8a68f5f35af49c36d6f4e86a3a1c5afa1b3215f (diff)
downloadnextpnr-eca1a4cee4f310c7e2c1216bd678143c1967edd4.tar.gz
nextpnr-eca1a4cee4f310c7e2c1216bd678143c1967edd4.tar.bz2
nextpnr-eca1a4cee4f310c7e2c1216bd678143c1967edd4.zip
Use hashlib in most remaining code
Signed-off-by: gatecat <gatecat@ds0.me>
-rw-r--r--common/archcheck.cc18
-rw-r--r--common/basectx.h1
-rw-r--r--common/command.cc4
-rw-r--r--common/command.h2
-rw-r--r--common/constraints.h4
-rw-r--r--common/log.cc2
-rw-r--r--common/log.h20
-rw-r--r--common/timing_opt.cc18
-rw-r--r--common/timing_opt.h2
-rw-r--r--ecp5/main.cc4
-rw-r--r--fpga_interchange/main.cc4
-rw-r--r--generic/main.cc4
-rw-r--r--gowin/main.cc4
-rw-r--r--gui/treemodel.cc2
-rw-r--r--gui/treemodel.h4
-rw-r--r--ice40/main.cc4
-rw-r--r--json/jsonwrite.cc2
-rw-r--r--machxo2/main.cc4
-rw-r--r--mistral/main.cc4
-rw-r--r--nexus/main.cc4
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<int> usedz;
+ pool<int> 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<WireId> last_access_list;
// Quick wire -> list element lookup.
- std::unordered_map<WireId, std::list<WireId>::iterator> last_access_map;
+ dict<WireId, std::list<WireId>::iterator> last_access_map;
- std::unordered_map<PipId, WireId> pips_downhill;
- std::unordered_map<PipId, WireId> pips_uphill;
+ dict<PipId, WireId> pips_downhill;
+ dict<PipId, WireId> 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<PipId, WireId> pips_downhill;
- std::unordered_map<PipId, WireId> pips_uphill;
+ dict<PipId, WireId> pips_downhill;
+ dict<PipId, WireId> 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<IdString> cell_types_in_bucket;
+ pool<IdString> 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<IdString> cell_types_unused;
+ pool<IdString> cell_types_unused;
- std::unordered_set<BelId> bels_in_bucket;
+ pool<BelId> 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 <boost/thread.hpp>
#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<std::string, Property> values;
+ dict<std::string, Property> values;
std::unique_ptr<Context> ctx = createContext(values);
setupContext(ctx.get());
setupArchContext(ctx.get());
@@ -475,7 +475,7 @@ int CommandHandler::exec()
std::unique_ptr<Context> CommandHandler::load_json(std::string filename)
{
- std::unordered_map<std::string, Property> values;
+ dict<std::string, Property> values;
std::unique_ptr<Context> 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<Context> createContext(std::unordered_map<std::string, Property> &values) = 0;
+ virtual std::unique_ptr<Context> createContext(dict<std::string, Property> &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 <cstdint>
-#include <unordered_map>
#include <vector>
#include "archdefs.h"
#include "exclusive_state_groups.h"
+#include "hashlib.h"
#include "idstring.h"
#include "nextpnr_namespaces.h"
@@ -53,7 +53,7 @@ template <std::size_t StateCount, typename StateType = int8_t, typename CountTyp
};
typedef ExclusiveStateGroup<StateCount, StateType, CountType> TagState;
- std::unordered_map<uint32_t, std::vector<typename TagState::Definition>> definitions;
+ dict<uint32_t, std::vector<typename TagState::Definition>> definitions;
template <typename ConstraintRange> 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<LogLevel, int> message_count_by_level;
+dict<LogLevel, int, loglevel_hash_ops> 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 <stdarg.h>
#include <stdio.h>
#include <string>
-#include <unordered_map>
#include <vector>
+#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<std::pair<std::ostream *, LogLevel>> 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<LogLevel, int> message_count_by_level;
+extern dict<LogLevel, int, loglevel_hash_ops> 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<NEXTPNR_NAMESPACE_PREFIX LogLevel>
-{
- std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX LogLevel &loglevel) const noexcept
- {
- return std::hash<int>()((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<BelId>{};
+ cell_neighbour_bels[cell->name] = pool<BelId>{};
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<PortRef *> used_ports;
+ pool<PortRef *, hash_ptr_ops> used_ports;
for (auto crit_net : crit_nets) {
@@ -439,10 +437,10 @@ 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>, PairHash> backtrace;
+ dict<IdString, dict<BelId, delay_t>> cumul_costs;
+ dict<std::pair<IdString, BelId>, std::pair<IdString, BelId>> backtrace;
std::queue<std::pair<int, BelId>> visit;
- std::unordered_set<std::pair<int, BelId>, PairHash> to_visit;
+ pool<std::pair<int, BelId>> 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<IdString> path_cells;
- std::unordered_map<IdString, std::unordered_set<BelId>> cell_neighbour_bels;
- std::unordered_map<BelId, std::unordered_set<IdString>> bel_candidate_cells;
+ dict<IdString, pool<BelId>> cell_neighbour_bels;
+ dict<BelId, pool<IdString>> bel_candidate_cells;
// Map cell ports to net delay limit
- std::unordered_map<std::pair<IdString, IdString>, delay_t, PairHash> max_net_delay;
+ dict<std::pair<IdString, IdString>, 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<IdString> cellTypes;
+ pool<IdString> 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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> ECP5CommandHandler::createContext(dict<std::string, Property> &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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> FpgaInterchangeCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> FpgaInterchangeCommandHandler::createContext(dict<std::string, Property> &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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> GenericCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> GenericCommandHandler::createContext(dict<std::string, Property> &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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> GowinCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> GowinCommandHandler::createContext(dict<std::string, Property> &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<IdStringList> elements)
bool changed = false;
// For any elements that are not yet in managed_, created them.
- std::unordered_set<IdStringList> element_set;
+ pool<IdStringList> 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<IdStringList, std::unique_ptr<IdStringItem>> managed_;
+ dict<IdStringList, std::unique_ptr<IdStringItem>> managed_;
// Type of children that the list creates.
ElementType child_type_;
@@ -184,7 +184,7 @@ template <typename ElementT> class ElementList : public Item
ElementGetter getter_;
// Children that we manage the memory for, stored for quick lookup from
// IdString to child.
- std::unordered_map<IdStringList, std::unique_ptr<Item>> managed_;
+ dict<IdStringList, std::unique_ptr<Item>> 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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> Ice40CommandHandler::createContext(dict<std::string, Property> &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<PortGroup> group_ports(Context *ctx, const dict<IdString, PortInfo> &ports, bool is_cell = false)
{
std::vector<PortGroup> groups;
- std::unordered_map<std::string, size_t> base_to_group;
+ dict<std::string, size_t> 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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> MachXO2CommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> MachXO2CommandHandler::createContext(dict<std::string, Property> &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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> MistralCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> MistralCommandHandler::createContext(dict<std::string, Property> &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<Context> createContext(std::unordered_map<std::string, Property> &values) override;
+ std::unique_ptr<Context> createContext(dict<std::string, Property> &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<Context> NexusCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
+std::unique_ptr<Context> NexusCommandHandler::createContext(dict<std::string, Property> &values)
{
ArchArgs chipArgs;
if (!vm.count("device")) {