aboutsummaryrefslogtreecommitdiffstats
path: root/ecp5/arch.h
diff options
context:
space:
mode:
Diffstat (limited to 'ecp5/arch.h')
-rw-r--r--ecp5/arch.h263
1 files changed, 161 insertions, 102 deletions
diff --git a/ecp5/arch.h b/ecp5/arch.h
index 06cf6488..930c488e 100644
--- a/ecp5/arch.h
+++ b/ecp5/arch.h
@@ -339,10 +339,8 @@ struct ArchArgs
struct Arch : BaseCtx
{
- // We let proxy methods access our state.
- friend class ArchMutateMethods;
- friend class ArchReadMethods;
-private:
+ const ChipInfoPOD *chip_info;
+
mutable std::unordered_map<IdString, BelId> bel_by_name;
mutable std::unordered_map<IdString, WireId> wire_by_name;
mutable std::unordered_map<IdString, PipId> pip_by_name;
@@ -352,9 +350,6 @@ private:
std::unordered_map<PipId, IdString> pip_to_net;
std::unordered_map<PipId, IdString> switches_locked;
-public:
- const ChipInfoPOD *chip_info;
-
ArchArgs args;
Arch(ArchArgs args);
@@ -371,6 +366,8 @@ public:
// -------------------------------------------------
+ BelId getBelByName(IdString name) const;
+
template <typename Id> const LocationTypePOD *locInfo(Id &id) const
{
return &(chip_info->locations[chip_info->location_type[id.location.y * chip_info->width + id.location.x]]);
@@ -386,6 +383,48 @@ public:
uint32_t getBelChecksum(BelId bel) const { return bel.index; }
+ void bindBel(BelId bel, IdString cell, PlaceStrength strength)
+ {
+ NPNR_ASSERT(bel != BelId());
+ NPNR_ASSERT(bel_to_cell[bel] == IdString());
+ bel_to_cell[bel] = cell;
+ cells[cell]->bel = bel;
+ cells[cell]->belStrength = strength;
+ }
+
+ void unbindBel(BelId bel)
+ {
+ NPNR_ASSERT(bel != BelId());
+ NPNR_ASSERT(bel_to_cell[bel] != IdString());
+ cells[bel_to_cell[bel]]->bel = BelId();
+ cells[bel_to_cell[bel]]->belStrength = STRENGTH_NONE;
+ bel_to_cell[bel] = IdString();
+ }
+
+ bool checkBelAvail(BelId bel) const
+ {
+ NPNR_ASSERT(bel != BelId());
+ return bel_to_cell.find(bel) == bel_to_cell.end() || bel_to_cell.at(bel) == IdString();
+ }
+
+ IdString getBoundBelCell(BelId bel) const
+ {
+ NPNR_ASSERT(bel != BelId());
+ if (bel_to_cell.find(bel) == bel_to_cell.end())
+ return IdString();
+ else
+ return bel_to_cell.at(bel);
+ }
+
+ IdString getConflictingBelCell(BelId bel) const
+ {
+ NPNR_ASSERT(bel != BelId());
+ if (bel_to_cell.find(bel) == bel_to_cell.end())
+ return IdString();
+ else
+ return bel_to_cell.at(bel);
+ }
+
BelRange getBels() const
{
BelRange range;
@@ -421,6 +460,8 @@ public:
return locInfo(bel)->bel_data[bel.index].type;
}
+ WireId getWireBelPin(BelId bel, PortPin pin) const;
+
BelPin getBelPinUphill(WireId wire) const
{
BelPin ret;
@@ -448,6 +489,8 @@ public:
// -------------------------------------------------
+ WireId getWireByName(IdString name) const;
+
IdString getWireName(WireId wire) const
{
NPNR_ASSERT(wire != WireId());
@@ -460,6 +503,57 @@ public:
uint32_t getWireChecksum(WireId wire) const { return wire.index; }
+ void bindWire(WireId wire, IdString net, PlaceStrength strength)
+ {
+ NPNR_ASSERT(wire != WireId());
+ NPNR_ASSERT(wire_to_net[wire] == IdString());
+ wire_to_net[wire] = net;
+ nets[net]->wires[wire].pip = PipId();
+ nets[net]->wires[wire].strength = strength;
+ }
+
+ void unbindWire(WireId wire)
+ {
+ NPNR_ASSERT(wire != WireId());
+ NPNR_ASSERT(wire_to_net[wire] != IdString());
+
+ auto &net_wires = nets[wire_to_net[wire]]->wires;
+ auto it = net_wires.find(wire);
+ NPNR_ASSERT(it != net_wires.end());
+
+ auto pip = it->second.pip;
+ if (pip != PipId()) {
+ pip_to_net[pip] = IdString();
+ }
+
+ net_wires.erase(it);
+ wire_to_net[wire] = IdString();
+ }
+
+ bool checkWireAvail(WireId wire) const
+ {
+ NPNR_ASSERT(wire != WireId());
+ return wire_to_net.find(wire) == wire_to_net.end() || wire_to_net.at(wire) == IdString();
+ }
+
+ IdString getBoundWireNet(WireId wire) const
+ {
+ NPNR_ASSERT(wire != WireId());
+ if (wire_to_net.find(wire) == wire_to_net.end())
+ return IdString();
+ else
+ return wire_to_net.at(wire);
+ }
+
+ IdString getConflictingWireNet(WireId wire) const
+ {
+ NPNR_ASSERT(wire != WireId());
+ if (wire_to_net.find(wire) == wire_to_net.end())
+ return IdString();
+ else
+ return wire_to_net.at(wire);
+ }
+
WireRange getWires() const
{
WireRange range;
@@ -475,10 +569,66 @@ public:
// -------------------------------------------------
+ PipId getPipByName(IdString name) const;
IdString getPipName(PipId pip) const;
uint32_t getPipChecksum(PipId pip) const { return pip.index; }
+ void bindPip(PipId pip, IdString net, PlaceStrength strength)
+ {
+ NPNR_ASSERT(pip != PipId());
+ NPNR_ASSERT(pip_to_net[pip] == IdString());
+
+ pip_to_net[pip] = net;
+
+ WireId dst;
+ dst.index = locInfo(pip)->pip_data[pip.index].dst_idx;
+ dst.location = pip.location + locInfo(pip)->pip_data[pip.index].rel_dst_loc;
+ NPNR_ASSERT(wire_to_net[dst] == IdString());
+ wire_to_net[dst] = net;
+ nets[net]->wires[dst].pip = pip;
+ nets[net]->wires[dst].strength = strength;
+ }
+
+ void unbindPip(PipId pip)
+ {
+ NPNR_ASSERT(pip != PipId());
+ NPNR_ASSERT(pip_to_net[pip] != IdString());
+
+ WireId dst;
+ dst.index = locInfo(pip)->pip_data[pip.index].dst_idx;
+ dst.location = pip.location + locInfo(pip)->pip_data[pip.index].rel_dst_loc;
+ NPNR_ASSERT(wire_to_net[dst] != IdString());
+ wire_to_net[dst] = IdString();
+ nets[pip_to_net[pip]]->wires.erase(dst);
+
+ pip_to_net[pip] = IdString();
+ }
+
+ bool checkPipAvail(PipId pip) const
+ {
+ NPNR_ASSERT(pip != PipId());
+ return pip_to_net.find(pip) == pip_to_net.end() || pip_to_net.at(pip) == IdString();
+ }
+
+ IdString getBoundPipNet(PipId pip) const
+ {
+ NPNR_ASSERT(pip != PipId());
+ if (pip_to_net.find(pip) == pip_to_net.end())
+ return IdString();
+ else
+ return pip_to_net.at(pip);
+ }
+
+ IdString getConflictingPipNet(PipId pip) const
+ {
+ NPNR_ASSERT(pip != PipId());
+ if (pip_to_net.find(pip) == pip_to_net.end())
+ return IdString();
+ else
+ return pip_to_net.at(pip);
+ }
+
AllPipRange getPips() const
{
AllPipRange range;
@@ -561,7 +711,6 @@ public:
// -------------------------------------------------
- // TODO(q3k) move this to archproxies?
GroupId getGroupByName(IdString name) const { return GroupId(); }
IdString getGroupName(GroupId group) const { return IdString(); }
std::vector<GroupId> getGroups() const { return std::vector<GroupId>(); }
@@ -572,8 +721,6 @@ public:
// -------------------------------------------------
- // These are also specific to the chip and not state, so they're available
- // on arch directly.
void estimatePosition(BelId bel, int &x, int &y, bool &gb) const;
delay_t estimateDelay(WireId src, WireId dst) const;
delay_t getDelayEpsilon() const { return 20; }
@@ -589,7 +736,8 @@ public:
// -------------------------------------------------
- // TODO(q3k) move this to archproxies?
+ std::vector<GraphicElement> getDecalGraphics(DecalId decal) const;
+
DecalXY getFrameDecal() const;
DecalXY getBelDecal(BelId bel) const;
DecalXY getWireDecal(WireId wire) const;
@@ -607,100 +755,11 @@ public:
bool isClockPort(const CellInfo *cell, IdString port) const;
// Return true if a port is a net
bool isGlobalNet(const NetInfo *net) const;
-};
-
-class ArchReadMethods : public BaseReadCtx
-{
- private:
- const Arch *parent_;
- const ChipInfoPOD *chip_info;
- const std::unordered_map<BelId, IdString> &bel_to_cell;
- const std::unordered_map<WireId, IdString> &wire_to_net;
- const std::unordered_map<PipId, IdString> &pip_to_net;
- const std::unordered_map<PipId, IdString> &switches_locked;
- std::unordered_map<IdString, BelId> &bel_by_name;
- std::unordered_map<IdString, WireId> &wire_by_name;
- std::unordered_map<IdString, PipId> &pip_by_name;
-
- public:
- ~ArchReadMethods() noexcept {}
- ArchReadMethods(const Arch *parent)
- : BaseReadCtx(parent), parent_(parent), chip_info(parent->chip_info), bel_to_cell(parent->bel_to_cell),
- wire_to_net(parent->wire_to_net), pip_to_net(parent->pip_to_net),
- switches_locked(parent->switches_locked), bel_by_name(parent->bel_by_name),
- wire_by_name(parent->wire_by_name), pip_by_name(parent->pip_by_name)
- {
- }
- ArchReadMethods(ArchReadMethods &&other) noexcept : ArchReadMethods(other.parent_) {}
- ArchReadMethods(const ArchReadMethods &other) : ArchReadMethods(other.parent_) {}
-
- /// Perform placement validity checks, returning false on failure (all implemented in arch_place.cc)
- // Whether or not a given cell can be placed at a given Bel
- // This is not intended for Bel type checks, but finer-grained constraints
- // such as conflicting set/reset signals, etc
+ // -------------------------------------------------
+ // Placement validity checks
bool isValidBelForCell(CellInfo *cell, BelId bel) const;
- // Return true whether all Bels at a given location are valid
bool isBelLocationValid(BelId bel) const;
-
- bool checkWireAvail(WireId wire) const;
- bool checkPipAvail(PipId pip) const;
- bool checkBelAvail(BelId bel) const;
-
- WireId getWireByName(IdString name) const;
- WireId getWireBelPin(BelId bel, PortPin pin) const;
- PipId getPipByName(IdString name) const;
-
- IdString getConflictingWireNet(WireId wire) const;
- IdString getConflictingPipNet(PipId pip) const;
- IdString getConflictingBelCell(BelId bel) const;
-
- IdString getBoundWireNet(WireId wire) const;
- IdString getBoundPipNet(PipId pip) const;
- IdString getBoundBelCell(BelId bel) const;
-
- BelId getBelByName(IdString name) const;
-
- std::vector<GraphicElement> getDecalGraphics(DecalId decal) const;
};
-class ArchMutateMethods : public BaseMutateCtx
-{
- friend class MutateContext;
-
- private:
- Arch *parent_;
- const ChipInfoPOD *chip_info;
-
- std::unordered_map<BelId, IdString> &bel_to_cell;
- std::unordered_map<WireId, IdString> &wire_to_net;
- std::unordered_map<PipId, IdString> &pip_to_net;
- std::unordered_map<PipId, IdString> &switches_locked;
- std::unordered_map<IdString, BelId> &bel_by_name;
- std::unordered_map<IdString, WireId> &wire_by_name;
- std::unordered_map<IdString, PipId> &pip_by_name;
-
- public:
- ~ArchMutateMethods() noexcept {}
- ArchMutateMethods(Arch *parent)
- : BaseMutateCtx(parent), parent_(parent), chip_info(parent->chip_info), bel_to_cell(parent->bel_to_cell),
- wire_to_net(parent->wire_to_net), pip_to_net(parent->pip_to_net),
- switches_locked(parent->switches_locked), bel_by_name(parent->bel_by_name),
- wire_by_name(parent->wire_by_name), pip_by_name(parent->pip_by_name)
- {
- }
- ArchMutateMethods(ArchMutateMethods &&other) noexcept : ArchMutateMethods(other.parent_) {}
- ArchMutateMethods(const ArchMutateMethods &other) : ArchMutateMethods(other.parent_) {}
-
- void unbindWire(WireId wire);
- void unbindPip(PipId pip);
- void unbindBel(BelId bel);
- void bindWire(WireId wire, IdString net, PlaceStrength strength);
- void bindPip(PipId pip, IdString net, PlaceStrength strength);
- void bindBel(BelId bel, IdString cell, PlaceStrength strength);
- // Returned pointer is valid as long as Proxy object exists.
- CellInfo *getCell(IdString cell);
-};
-
-
NEXTPNR_NAMESPACE_END