diff options
author | gatecat <gatecat@ds0.me> | 2021-06-03 09:04:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 09:04:34 +0100 |
commit | a3d8b4f9d198226ec0903e34a8d290b376b45c0b (patch) | |
tree | ada2c6a5d48e766fa523e633aaa28179baea3273 /machxo2 | |
parent | 589ca8ded5da2012e4388a3ec4c8fae74dff75e4 (diff) | |
parent | dcbb322447a7fb59cabe197ec1dd2307acfa3681 (diff) | |
download | nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.tar.gz nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.tar.bz2 nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.zip |
Merge pull request #718 from YosysHQ/gatecat/hashlib
Moving from unordered_{map, set} to hashlib
Diffstat (limited to 'machxo2')
-rw-r--r-- | machxo2/arch.h | 4 | ||||
-rw-r--r-- | machxo2/arch_pybindings.cc | 8 | ||||
-rw-r--r-- | machxo2/archdefs.h | 48 | ||||
-rw-r--r-- | machxo2/bitstream.cc | 3 | ||||
-rw-r--r-- | machxo2/cells.cc | 2 | ||||
-rw-r--r-- | machxo2/cells.h | 2 | ||||
-rw-r--r-- | machxo2/main.cc | 4 | ||||
-rw-r--r-- | machxo2/pack.cc | 34 |
8 files changed, 34 insertions, 71 deletions
diff --git a/machxo2/arch.h b/machxo2/arch.h index 15535fe1..219e87f2 100644 --- a/machxo2/arch.h +++ b/machxo2/arch.h @@ -403,12 +403,12 @@ struct Arch : BaseArch<ArchRanges> const ChipInfoPOD *chip_info; const PackageInfoPOD *package_info; - mutable std::unordered_map<IdStringList, PipId> pip_by_name; + mutable dict<IdStringList, PipId> pip_by_name; // fast access to X and Y IdStrings for building object names std::vector<IdString> x_ids, y_ids; // inverse of the above for name->object mapping - std::unordered_map<IdString, int> id_to_x, id_to_y; + dict<IdString, int> id_to_x, id_to_y; // Helpers template <typename Id> const TileTypePOD *tile_info(Id &id) const diff --git a/machxo2/arch_pybindings.cc b/machxo2/arch_pybindings.cc index 07e25437..aaca813a 100644 --- a/machxo2/arch_pybindings.cc +++ b/machxo2/arch_pybindings.cc @@ -45,10 +45,10 @@ void arch_wrap_python(py::module &m) .def("place", &Context::place) .def("route", &Context::route); - typedef std::unordered_map<IdString, std::unique_ptr<CellInfo>> CellMap; - typedef std::unordered_map<IdString, std::unique_ptr<NetInfo>> NetMap; - typedef std::unordered_map<IdString, IdString> AliasMap; - typedef std::unordered_map<IdString, HierarchicalCell> HierarchyMap; + typedef dict<IdString, std::unique_ptr<CellInfo>> CellMap; + typedef dict<IdString, std::unique_ptr<NetInfo>> NetMap; + typedef dict<IdString, IdString> AliasMap; + typedef dict<IdString, HierarchicalCell> HierarchyMap; auto belpin_cls = py::class_<ContextualWrapper<BelPin>>(m, "BelPin"); readonly_wrapper<BelPin, decltype(&BelPin::bel), &BelPin::bel, conv_to_str<BelId>>::def_wrap(belpin_cls, "bel"); diff --git a/machxo2/archdefs.h b/machxo2/archdefs.h index 2d50dddb..de633673 100644 --- a/machxo2/archdefs.h +++ b/machxo2/archdefs.h @@ -22,6 +22,7 @@ #define MACHXO2_ARCHDEFS_H #include "base_clusterinfo.h" +#include "hashlib.h" #include "idstring.h" #include "nextpnr_namespaces.h" @@ -59,6 +60,7 @@ struct Location bool operator==(const Location &other) const { return x == other.x && y == other.y; } bool operator!=(const Location &other) const { return x != other.x || y != other.y; } bool operator<(const Location &other) const { return y == other.y ? x < other.x : y < other.y; } + unsigned int hash() const { return mkhash(x, y); } }; inline Location operator+(const Location &a, const Location &b) { return Location(a.x + b.x, a.y + b.y); } @@ -74,6 +76,7 @@ struct BelId { return location == other.location ? index < other.index : location < other.location; } + unsigned int hash() const { return mkhash(location.hash(), index); } }; struct WireId @@ -87,6 +90,7 @@ struct WireId { return location == other.location ? index < other.index : location < other.location; } + unsigned int hash() const { return mkhash(location.hash(), index); } }; struct PipId @@ -100,6 +104,7 @@ struct PipId { return location == other.location ? index < other.index : location < other.location; } + unsigned int hash() const { return mkhash(location.hash(), index); } }; typedef IdString GroupId; @@ -119,47 +124,4 @@ struct ArchCellInfo : BaseClusterInfo NEXTPNR_NAMESPACE_END -namespace std { -template <> struct hash<NEXTPNR_NAMESPACE_PREFIX Location> -{ - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX Location &loc) const noexcept - { - std::size_t seed = std::hash<int>()(loc.x); - seed ^= std::hash<int>()(loc.y) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId> -{ - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const noexcept - { - std::size_t seed = std::hash<NEXTPNR_NAMESPACE_PREFIX Location>()(bel.location); - seed ^= std::hash<int>()(bel.index) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId> -{ - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const noexcept - { - std::size_t seed = std::hash<NEXTPNR_NAMESPACE_PREFIX Location>()(wire.location); - seed ^= std::hash<int>()(wire.index) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -template <> struct hash<NEXTPNR_NAMESPACE_PREFIX PipId> -{ - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &pip) const noexcept - { - std::size_t seed = std::hash<NEXTPNR_NAMESPACE_PREFIX Location>()(pip.location); - seed ^= std::hash<int>()(pip.index) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -} // namespace std - #endif /* MACHXO2_ARCHDEFS_H */ diff --git a/machxo2/bitstream.cc b/machxo2/bitstream.cc index d695b094..8c538bae 100644 --- a/machxo2/bitstream.cc +++ b/machxo2/bitstream.cc @@ -114,8 +114,7 @@ static std::vector<bool> int_to_bitvector(int val, int size) return bv; } -std::string intstr_or_default(const std::unordered_map<IdString, Property> &ct, const IdString &key, - std::string def = "0") +std::string intstr_or_default(const dict<IdString, Property> &ct, const IdString &key, std::string def = "0") { auto found = ct.find(key); if (found == ct.end()) diff --git a/machxo2/cells.cc b/machxo2/cells.cc index 03ba0a41..c71247f2 100644 --- a/machxo2/cells.cc +++ b/machxo2/cells.cc @@ -175,6 +175,6 @@ void dff_to_lc(Context *ctx, CellInfo *dff, CellInfo *lc, bool pass_thru_lut) } } -void nxio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *iob, std::unordered_set<IdString> &todelete_cells) {} +void nxio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *iob, pool<IdString> &todelete_cells) {} NEXTPNR_NAMESPACE_END diff --git a/machxo2/cells.h b/machxo2/cells.h index a6de219e..afb08138 100644 --- a/machxo2/cells.h +++ b/machxo2/cells.h @@ -49,7 +49,7 @@ void lut_to_lc(const Context *ctx, CellInfo *lut, CellInfo *lc, bool no_dff = tr void dff_to_lc(Context *ctx, CellInfo *dff, CellInfo *lc, bool pass_thru_lut = false); // Convert a nextpnr IO buffer to a GENERIC_IOB -void nxio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *sbio, std::unordered_set<IdString> &todelete_cells); +void nxio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *sbio, pool<IdString> &todelete_cells); NEXTPNR_NAMESPACE_END 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/machxo2/pack.cc b/machxo2/pack.cc index 5a6cd97b..6f2ee8e4 100644 --- a/machxo2/pack.cc +++ b/machxo2/pack.cc @@ -20,7 +20,6 @@ #include <algorithm> #include <iterator> -#include <unordered_set> #include "cells.h" #include "design_utils.h" #include "log.h" @@ -33,15 +32,16 @@ static void pack_lut_lutffs(Context *ctx) { log_info("Packing LUT-FFs..\n"); - std::unordered_set<IdString> packed_cells; + pool<IdString> packed_cells; std::vector<std::unique_ptr<CellInfo>> new_cells; - for (auto cell : sorted(ctx->cells)) { - CellInfo *ci = cell.second; + for (auto &cell : ctx->cells) { + CellInfo *ci = cell.second.get(); if (ctx->verbose) log_info("cell '%s' is of type '%s'\n", ci->name.c_str(ctx), ci->type.c_str(ctx)); if (is_lut(ctx, ci)) { std::unique_ptr<CellInfo> packed = create_machxo2_cell(ctx, id_FACADE_SLICE, ci->name.str(ctx) + "_LC"); - std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(packed->attrs, packed->attrs.begin())); + for (auto &attr : ci->attrs) + packed->attrs[attr.first] = attr.second; packed_cells.insert(ci->name); if (ctx->verbose) @@ -90,18 +90,19 @@ static void pack_remaining_ffs(Context *ctx) { log_info("Packing remaining FFs..\n"); - std::unordered_set<IdString> packed_cells; + pool<IdString> packed_cells; std::vector<std::unique_ptr<CellInfo>> new_cells; - for (auto cell : sorted(ctx->cells)) { - CellInfo *ci = cell.second; + for (auto &cell : ctx->cells) { + CellInfo *ci = cell.second.get(); if (is_ff(ctx, ci)) { if (ctx->verbose) log_info("cell '%s' of type '%s remains unpacked'\n", ci->name.c_str(ctx), ci->type.c_str(ctx)); std::unique_ptr<CellInfo> packed = create_machxo2_cell(ctx, id_FACADE_SLICE, ci->name.str(ctx) + "_LC"); - std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(packed->attrs, packed->attrs.begin())); + for (auto &attr : ci->attrs) + packed->attrs[attr.first] = attr.second; auto dff_bel = ci->attrs.find(ctx->id("BEL")); dff_to_lc(ctx, ci, packed.get(), false); @@ -128,7 +129,7 @@ static void set_net_constant(Context *ctx, NetInfo *orig, NetInfo *constnet, boo { (void)constval; - std::unordered_set<IdString> packed_cells; + pool<IdString> packed_cells; std::vector<std::unique_ptr<CellInfo>> new_cells; orig->driver.cell = nullptr; @@ -142,7 +143,8 @@ static void set_net_constant(Context *ctx, NetInfo *orig, NetInfo *constnet, boo log_info("FACADE_FF %s is driven by a constant\n", uc->name.c_str(ctx)); std::unique_ptr<CellInfo> lc = create_machxo2_cell(ctx, id_FACADE_SLICE, uc->name.str(ctx) + "_CONST"); - std::copy(uc->attrs.begin(), uc->attrs.end(), std::inserter(lc->attrs, lc->attrs.begin())); + for (auto &attr : uc->attrs) + lc->attrs[attr.first] = attr.second; dff_to_lc(ctx, uc, lc.get(), true); packed_cells.insert(uc->name); @@ -193,8 +195,8 @@ static void pack_constants(Context *ctx) std::vector<IdString> dead_nets; - for (auto net : sorted(ctx->nets)) { - NetInfo *ni = net.second; + for (auto &net : ctx->nets) { + NetInfo *ni = net.second.get(); if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("GND")) { IdString drv_cell = ni->driver.cell->name; set_net_constant(ctx, ni, gnd_net.get(), false); @@ -230,12 +232,12 @@ static bool is_facade_iob(const Context *ctx, const CellInfo *cell) { return cel // attributes. static void pack_io(Context *ctx) { - std::unordered_set<IdString> packed_cells; + pool<IdString> packed_cells; log_info("Packing IOs..\n"); - for (auto cell : sorted(ctx->cells)) { - CellInfo *ci = cell.second; + for (auto &cell : ctx->cells) { + CellInfo *ci = cell.second.get(); if (is_nextpnr_iob(ctx, ci)) { for (auto &p : ci->ports) disconnect_port(ctx, ci, p.first); |