diff options
author | D. Shah <dave@ds0.me> | 2021-02-01 11:46:10 +0000 |
---|---|---|
committer | D. Shah <dave@ds0.me> | 2021-02-02 17:00:33 +0000 |
commit | 6566a011b43289b9b550f3b7f8801156275cb321 (patch) | |
tree | 7c8f89b52c7a18f6df3d2026b5403bf5c1e416f2 | |
parent | b31b21fd5151ab783fbe665e23a0848b2c172339 (diff) | |
download | nextpnr-6566a011b43289b9b550f3b7f8801156275cb321.tar.gz nextpnr-6566a011b43289b9b550f3b7f8801156275cb321.tar.bz2 nextpnr-6566a011b43289b9b550f3b7f8801156275cb321.zip |
nexus: Implement IdStringList for all arch object names
Signed-off-by: D. Shah <dave@ds0.me>
-rw-r--r-- | common/nextpnr.h | 6 | ||||
-rw-r--r-- | nexus/arch.cc | 70 | ||||
-rw-r--r-- | nexus/arch.h | 43 | ||||
-rw-r--r-- | nexus/pack.cc | 2 |
4 files changed, 62 insertions, 59 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index 19d919e1..d4db9e9e 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -181,6 +181,12 @@ template <typename T, size_t N> class SSOArray std::fill(begin(), end(), init); } + SSOArray(const SSOArray &other) : m_size(other.size()) + { + alloc(); + std::copy(other.begin(), other.end(), begin()); + } + template <typename Tother> SSOArray(const Tother &other) : m_size(other.size()) { alloc(); diff --git a/nexus/arch.cc b/nexus/arch.cc index 95b409bf..267795dd 100644 --- a/nexus/arch.cc +++ b/nexus/arch.cc @@ -32,20 +32,6 @@ NEXTPNR_NAMESPACE_BEGIN -namespace { -static std::tuple<int, int, std::string> split_identifier_name(const std::string &name) -{ - size_t first_slash = name.find('/'); - NPNR_ASSERT(first_slash != std::string::npos); - size_t second_slash = name.find('/', first_slash + 1); - NPNR_ASSERT(second_slash != std::string::npos); - return std::make_tuple(std::stoi(name.substr(1, first_slash)), - std::stoi(name.substr(first_slash + 2, second_slash - first_slash)), - name.substr(second_slash + 1)); -}; - -} // namespace - // ----------------------------------------------------------------------- void IdString::initialize_arch(const BaseCtx *ctx) @@ -134,6 +120,17 @@ Arch::Arch(ArchArgs args) : args(args) ts.bels_by_z[bel.z].index = j; } } + + for (int i = 0; i < chip_info->width; i++) { + IdString x_id = id(stringf("X%d", i)); + x_ids.push_back(x_id); + id_to_x[x_id] = i; + } + for (int i = 0; i < chip_info->height; i++) { + IdString y_id = id(stringf("Y%d", i)); + y_ids.push_back(y_id); + id_to_y[y_id] = i; + } init_cell_pin_data(); // Validate and set up package package_idx = -1; @@ -193,17 +190,17 @@ IdString Arch::archArgsToId(ArchArgs args) const { return id(args.device); } // ----------------------------------------------------------------------- -BelId Arch::getBelByName(IdString name) const +BelId Arch::getBelByName(IdStringList name) const { - int x, y; - std::string belname; - std::tie(x, y, belname) = split_identifier_name(name.str(this)); + if (name.size() != 3) + return BelId(); + int x = id_to_x.at(name[0]); + int y = id_to_y.at(name[1]); NPNR_ASSERT(x >= 0 && x < chip_info->width); NPNR_ASSERT(y >= 0 && y < chip_info->height); auto &tile = db->loctypes[chip_info->grid[y * chip_info->width + x].loc_type]; - IdString bn = id(belname); for (size_t i = 0; i < tile.bels.size(); i++) { - if (tile.bels[i].name == bn.index) { + if (tile.bels[i].name == name[2].index) { BelId ret; ret.tile = y * chip_info->width + x; ret.index = i; @@ -305,17 +302,17 @@ std::vector<std::pair<IdString, std::string>> Arch::getBelAttrs(BelId bel) const // ----------------------------------------------------------------------- -WireId Arch::getWireByName(IdString name) const +WireId Arch::getWireByName(IdStringList name) const { - int x, y; - std::string wirename; - std::tie(x, y, wirename) = split_identifier_name(name.str(this)); + if (name.size() != 3) + return WireId(); + int x = id_to_x.at(name[0]); + int y = id_to_y.at(name[1]); NPNR_ASSERT(x >= 0 && x < chip_info->width); NPNR_ASSERT(y >= 0 && y < chip_info->height); auto &tile = db->loctypes[chip_info->grid[y * chip_info->width + x].loc_type]; - IdString wn = id(wirename); for (size_t i = 0; i < tile.wires.size(); i++) { - if (tile.wires[i].name == wn.index) { + if (tile.wires[i].name == name[2].index) { WireId ret; ret.tile = y * chip_info->width + x; ret.index = i; @@ -342,26 +339,27 @@ std::vector<std::pair<IdString, std::string>> Arch::getWireAttrs(WireId wire) co // ----------------------------------------------------------------------- -PipId Arch::getPipByName(IdString name) const +PipId Arch::getPipByName(IdStringList name) const { - int x, y; - std::string pipname; - std::tie(x, y, pipname) = split_identifier_name(name.str(this)); + if (name.size() != 5) + return PipId(); + int x = id_to_x.at(name[0]); + int y = id_to_y.at(name[1]); NPNR_ASSERT(x >= 0 && x < chip_info->width); NPNR_ASSERT(y >= 0 && y < chip_info->height); PipId ret; ret.tile = y * chip_info->width + x; - auto sep_pos = pipname.find(':'); - ret.index = std::stoi(pipname.substr(0, sep_pos)); + ret.index = std::stoi(name[2].str(this)); return ret; } -IdString Arch::getPipName(PipId pip) const +IdStringList Arch::getPipName(PipId pip) const { NPNR_ASSERT(pip != PipId()); - return id(stringf("X%d/Y%d/%d:%s->%s", pip.tile % chip_info->width, pip.tile / chip_info->width, pip.index, - nameOf(loc_data(pip).wires[pip_data(pip).from_wire].name), - nameOf(loc_data(pip).wires[pip_data(pip).to_wire].name))); + std::array<IdString, 5> ids{x_ids.at(pip.tile % chip_info->width), y_ids.at(pip.tile / chip_info->width), + id(stringf("%d", pip.index)), IdString(loc_data(pip).wires[pip_data(pip).to_wire].name), + IdString(loc_data(pip).wires[pip_data(pip).from_wire].name)}; + return IdStringList(ids); } IdString Arch::getPipType(PipId pip) const { return IdString(); } diff --git a/nexus/arch.h b/nexus/arch.h index 3063ce67..d37c5026 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -897,6 +897,11 @@ struct Arch : BaseCtx std::unordered_map<WireId, NetInfo *> wire_to_net; std::unordered_map<PipId, NetInfo *> pip_to_net; + // 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; + // ------------------------------------------------- std::string getChipName() const; @@ -913,17 +918,14 @@ struct Arch : BaseCtx // ------------------------------------------------- - BelId getBelByName(IdString name) const; + BelId getBelByName(IdStringList name) const; - IdString getBelName(BelId bel) const + IdStringList getBelName(BelId bel) const { - std::string name = "X"; - name += std::to_string(bel.tile % chip_info->width); - name += "/Y"; - name += std::to_string(bel.tile / chip_info->width); - name += "/"; - name += nameOf(IdString(bel_data(bel).name)); - return id(name); + NPNR_ASSERT(bel != BelId()); + std::array<IdString, 3> ids{x_ids.at(bel.tile % chip_info->width), y_ids.at(bel.tile / chip_info->width), + IdString(bel_data(bel).name)}; + return IdStringList(ids); } uint32_t getBelChecksum(BelId bel) const { return (bel.tile << 16) ^ bel.index; } @@ -1024,16 +1026,13 @@ struct Arch : BaseCtx // ------------------------------------------------- - WireId getWireByName(IdString name) const; - IdString getWireName(WireId wire) const + WireId getWireByName(IdStringList name) const; + IdStringList getWireName(WireId wire) const { - std::string name = "X"; - name += std::to_string(wire.tile % chip_info->width); - name += "/Y"; - name += std::to_string(wire.tile / chip_info->width); - name += "/"; - name += nameOf(IdString(wire_data(wire).name)); - return id(name); + NPNR_ASSERT(wire != WireId()); + std::array<IdString, 3> ids{x_ids.at(wire.tile % chip_info->width), y_ids.at(wire.tile / chip_info->width), + IdString(wire_data(wire).name)}; + return IdStringList(ids); } IdString getWireType(WireId wire) const; @@ -1137,8 +1136,8 @@ struct Arch : BaseCtx // ------------------------------------------------- - PipId getPipByName(IdString name) const; - IdString getPipName(PipId pip) const; + PipId getPipByName(IdStringList name) const; + IdStringList getPipName(PipId pip) const; void bindPip(PipId pip, NetInfo *net, PlaceStrength strength) { @@ -1290,8 +1289,8 @@ struct Arch : BaseCtx // ------------------------------------------------- - GroupId getGroupByName(IdString name) const { return GroupId(); } - IdString getGroupName(GroupId group) const { return IdString(); } + GroupId getGroupByName(IdStringList name) const { return GroupId(); } + IdStringList getGroupName(GroupId group) const { return IdStringList(); } std::vector<GroupId> getGroups() const { return {}; } std::vector<BelId> getGroupBels(GroupId group) const { return {}; } std::vector<WireId> getGroupWires(GroupId group) const { return {}; } diff --git a/nexus/pack.cc b/nexus/pack.cc index df479ef5..32bdfdb9 100644 --- a/nexus/pack.cc +++ b/nexus/pack.cc @@ -544,7 +544,7 @@ struct NexusPacker { if (!ci->attrs.count(id_BEL)) return BelId(); - return ctx->getBelByName(ctx->id(ci->attrs.at(id_BEL).as_string())); + return ctx->getBelByNameStr(ci->attrs.at(id_BEL).as_string()); } void pack_io() |