Add Location APIs to generic arch
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
f6fa0300ae
commit
fd8239e170
@ -339,10 +339,6 @@ struct Context : Arch
|
||||
|
||||
Context(ArchArgs args) : Arch(args) {}
|
||||
|
||||
BelId getBelByLocation(Loc loc) const {
|
||||
return getBelByLocation(loc.x, loc.y, loc.z);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
// provided by router1.cc
|
||||
|
@ -29,8 +29,8 @@ void Arch::addWire(IdString name, int x, int y)
|
||||
NPNR_ASSERT(wires.count(name) == 0);
|
||||
WireInfo &wi = wires[name];
|
||||
wi.name = name;
|
||||
wi.grid_x = x;
|
||||
wi.grid_y = y;
|
||||
wi.x = x;
|
||||
wi.y = y;
|
||||
|
||||
wire_ids.push_back(name);
|
||||
}
|
||||
@ -62,18 +62,28 @@ void Arch::addAlias(IdString name, IdString srcWire, IdString dstWire, DelayInfo
|
||||
pip_ids.push_back(name);
|
||||
}
|
||||
|
||||
void Arch::addBel(IdString name, IdString type, int x, int y, bool gb)
|
||||
void Arch::addBel(IdString name, IdString type, int x, int y, int z, bool gb)
|
||||
{
|
||||
Loc loc;
|
||||
loc.x = x;
|
||||
loc.y = y;
|
||||
loc.z = z;
|
||||
|
||||
NPNR_ASSERT(bels.count(name) == 0);
|
||||
NPNR_ASSERT(bel_by_loc.count(loc) == 0);
|
||||
BelInfo &bi = bels[name];
|
||||
bi.name = name;
|
||||
bi.type = type;
|
||||
bi.grid_x = x;
|
||||
bi.grid_y = y;
|
||||
bi.x = x;
|
||||
bi.y = y;
|
||||
bi.z = z;
|
||||
bi.gb = gb;
|
||||
|
||||
bel_ids.push_back(name);
|
||||
bel_ids_by_type[type].push_back(name);
|
||||
|
||||
bel_by_loc[loc] = name;
|
||||
bels_by_tile[x][y].push_back(name);
|
||||
}
|
||||
|
||||
void Arch::addBelInput(IdString bel, IdString name, IdString wire)
|
||||
@ -348,8 +358,8 @@ const std::vector<GroupId> &Arch::getGroupGroups(GroupId group) const { return g
|
||||
|
||||
void Arch::estimatePosition(BelId bel, int &x, int &y, bool &gb) const
|
||||
{
|
||||
x = bels.at(bel).grid_x;
|
||||
y = bels.at(bel).grid_y;
|
||||
x = bels.at(bel).x;
|
||||
y = bels.at(bel).y;
|
||||
gb = bels.at(bel).gb;
|
||||
}
|
||||
|
||||
@ -357,8 +367,8 @@ delay_t Arch::estimateDelay(WireId src, WireId dst) const
|
||||
{
|
||||
const WireInfo &s = wires.at(src);
|
||||
const WireInfo &d = wires.at(dst);
|
||||
int dx = abs(s.grid_x - d.grid_x);
|
||||
int dy = abs(s.grid_y - d.grid_y);
|
||||
int dx = abs(s.x - d.x);
|
||||
int dy = abs(s.y - d.y);
|
||||
return (dx + dy) * grid_distance_to_delay;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ struct WireInfo
|
||||
BelPin uphill_bel_pin;
|
||||
std::vector<BelPin> downhill_bel_pins;
|
||||
DecalXY decalxy;
|
||||
int grid_x, grid_y;
|
||||
int x, y;
|
||||
};
|
||||
|
||||
struct PinInfo
|
||||
@ -59,7 +59,7 @@ struct BelInfo
|
||||
IdString name, type, bound_cell;
|
||||
std::unordered_map<IdString, PinInfo> pins;
|
||||
DecalXY decalxy;
|
||||
int grid_x, grid_y;
|
||||
int x, y, z;
|
||||
bool gb;
|
||||
};
|
||||
|
||||
@ -85,6 +85,9 @@ struct Arch : BaseCtx
|
||||
std::vector<IdString> bel_ids, wire_ids, pip_ids;
|
||||
std::unordered_map<IdString, std::vector<IdString>> bel_ids_by_type;
|
||||
|
||||
std::unordered_map<Loc, BelId> bel_by_loc;
|
||||
std::unordered_map<int, std::unordered_map<int, std::vector<BelId>>> bels_by_tile;
|
||||
|
||||
std::unordered_map<DecalId, std::vector<GraphicElement>> decal_graphics;
|
||||
DecalXY frame_decalxy;
|
||||
|
||||
@ -94,7 +97,7 @@ struct Arch : BaseCtx
|
||||
void addPip(IdString name, IdString srcWire, IdString dstWire, DelayInfo delay);
|
||||
void addAlias(IdString name, IdString srcWire, IdString dstWire, DelayInfo delay);
|
||||
|
||||
void addBel(IdString name, IdString type, int x, int y, bool gb);
|
||||
void addBel(IdString name, IdString type, int x, int y, int z, bool gb);
|
||||
void addBelInput(IdString bel, IdString name, IdString wire);
|
||||
void addBelOutput(IdString bel, IdString name, IdString wire);
|
||||
void addBelInout(IdString bel, IdString name, IdString wire);
|
||||
@ -129,6 +132,10 @@ struct Arch : BaseCtx
|
||||
|
||||
BelId getBelByName(IdString name) const;
|
||||
IdString getBelName(BelId bel) const;
|
||||
Loc getBelLocation(BelId bel) const;
|
||||
BelId getBelByLocation(Loc loc) const;
|
||||
std::vector<BelId> getBelsByTile(int x, int y) const;
|
||||
bool getBelGlobalBuf(BelId bel) const;
|
||||
uint32_t getBelChecksum(BelId bel) const;
|
||||
void bindBel(BelId bel, IdString cell, PlaceStrength strength);
|
||||
void unbindBel(BelId bel);
|
||||
|
@ -255,24 +255,36 @@ BelId Arch::getBelByName(IdString name) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
BelId Arch::getBelByLocation(int x, int y, int z) const
|
||||
BelId Arch::getBelByLocation(Loc loc) const
|
||||
{
|
||||
BelId bel;
|
||||
|
||||
if (bel_by_loc.empty()) {
|
||||
for (int i = 0; i < chip_info->num_bels; i++)
|
||||
bel_by_loc[getBelLocation(BelId{i})] = i;
|
||||
for (int i = 0; i < chip_info->num_bels; i++) {
|
||||
BelId b;
|
||||
b.index = i;
|
||||
bel_by_loc[getBelLocation(b)] = i;
|
||||
}
|
||||
}
|
||||
|
||||
auto it = bel_by_loc.find(Loc{x, y, z});
|
||||
auto it = bel_by_loc.find(loc);
|
||||
if (it != bel_by_loc.end())
|
||||
return BelId{it->second};
|
||||
return BelId();
|
||||
bel.index = it->second;
|
||||
|
||||
return bel;
|
||||
}
|
||||
|
||||
BelRange Arch::getBelsByTile(int x, int y) const
|
||||
{
|
||||
// In iCE40 chipdb bels at the same tile are consecutive and dense z ordinates are used
|
||||
BelRange br;
|
||||
br.b.cursor = Arch::getBelByLocation(x, y, 0);
|
||||
|
||||
Loc loc;
|
||||
loc.x = x;
|
||||
loc.y = y;
|
||||
loc.z = 0;
|
||||
|
||||
br.b.cursor = Arch::getBelByLocation(loc).index;
|
||||
br.e.cursor = br.b.cursor;
|
||||
|
||||
if (br.e.cursor != -1) {
|
||||
|
@ -450,7 +450,7 @@ struct Arch : BaseCtx
|
||||
return loc;
|
||||
}
|
||||
|
||||
BelId getBelByLocation(int x, int y, int z) const;
|
||||
BelId getBelByLocation(Loc loc) const;
|
||||
BelRange getBelsByTile(int x, int y) const;
|
||||
|
||||
bool getBelGlobalBuf(BelId bel) const
|
||||
|
Loading…
Reference in New Issue
Block a user