generic: Add some extra helpers for viaduct uarches

Signed-off-by: gatecat <gatecat@ds0.me>
This commit is contained in:
gatecat 2022-05-02 09:56:36 +01:00 committed by Lofty
parent 20cfafa109
commit f0d4e4fbc3
4 changed files with 52 additions and 4 deletions

View File

@ -43,6 +43,30 @@ WireId Arch::addWire(IdStringList name, IdString type, int x, int y)
return wire;
}
WireId Arch::addWireAsBelInput(BelId bel, IdString name)
{
Loc l = getBelLocation(bel);
WireId w = addWire(IdStringList::concat(getBelName(bel), name), name, l.x, l.y);
addBelInput(bel, name, w);
return w;
}
WireId Arch::addWireAsBelOutput(BelId bel, IdString name)
{
Loc l = getBelLocation(bel);
WireId w = addWire(IdStringList::concat(getBelName(bel), name), name, l.x, l.y);
addBelOutput(bel, name, w);
return w;
}
WireId Arch::addWireAsBelInout(BelId bel, IdString name)
{
Loc l = getBelLocation(bel);
WireId w = addWire(IdStringList::concat(getBelName(bel), name), name, l.x, l.y);
addBelInout(bel, name, w);
return w;
}
PipId Arch::addPip(IdStringList name, IdString type, WireId srcWire, WireId dstWire, delay_t delay, Loc loc)
{
NPNR_ASSERT(pip_by_name.count(name) == 0);

View File

@ -201,6 +201,10 @@ struct Arch : BaseArch<ArchRanges>
void addBelOutput(BelId bel, IdString name, WireId wire);
void addBelInout(BelId bel, IdString name, WireId wire);
WireId addWireAsBelInput(BelId bel, IdString name);
WireId addWireAsBelOutput(BelId bel, IdString name);
WireId addWireAsBelInout(BelId bel, IdString name);
void addGroupBel(IdStringList group, BelId bel);
void addGroupWire(IdStringList group, WireId wire);
void addGroupPip(IdStringList group, PipId pip);

View File

@ -25,9 +25,9 @@
NEXTPNR_NAMESPACE_BEGIN
void ViaductHelpers::resize_ids(int x, int y)
void ViaductHelpers::resize_ids(int x, int y, int z)
{
NPNR_ASSERT(x >= 0 && y >= 0 && x <= 20000 && y <= 20000);
NPNR_ASSERT(x >= 0 && y >= 0 && x <= 20000 && y <= 20000 && z <= 1000);
while (int(x_ids.size()) <= x) {
IdString next = ctx->id(stringf("X%d", int(x_ids.size())));
x_ids.push_back(next);
@ -36,6 +36,10 @@ void ViaductHelpers::resize_ids(int x, int y)
IdString next = ctx->id(stringf("Y%d", int(y_ids.size())));
y_ids.push_back(next);
}
while (int(z_ids.size()) <= y) {
IdString next = ctx->id(stringf("Z%d", int(z_ids.size())));
z_ids.push_back(next);
}
}
IdStringList ViaductHelpers::xy_id(int x, int y, IdString base)
@ -52,6 +56,20 @@ IdStringList ViaductHelpers::xy_id(int x, int y, IdStringList base)
return IdStringList::concat(IdStringList(prefix), base);
}
IdStringList ViaductHelpers::xyz_id(int x, int y, int z, IdString base)
{
resize_ids(x, y, z);
std::array<IdString, 4> result{x_ids.at(x), y_ids.at(y), z_ids.at(z), base};
return IdStringList(result);
}
IdStringList ViaductHelpers::xyz_id(int x, int y, int z, IdStringList base)
{
resize_ids(x, y, z);
std::array<IdString, 3> prefix{x_ids.at(x), y_ids.at(y), z_ids.at(z)};
return IdStringList::concat(IdStringList(prefix), base);
}
void ViaductHelpers::remove_nextpnr_iobs(const pool<CellTypePort> &top_ports)
{
std::vector<IdString> to_remove;

View File

@ -58,13 +58,15 @@ struct ViaductHelpers
Context *ctx;
void init(Context *ctx) { this->ctx = ctx; }
// IdStringList components for x and y locations
std::vector<IdString> x_ids, y_ids;
void resize_ids(int x, int y);
std::vector<IdString> x_ids, y_ids, z_ids;
void resize_ids(int x, int y, int z = 0);
// Get an IdStringList for a hierarchical ID
// Because this uses an IdStringList with seperate X and Y components; this will be much more efficient than
// creating unique strings for each object in each X and Y position
IdStringList xy_id(int x, int y, IdString base);
IdStringList xy_id(int x, int y, IdStringList base);
IdStringList xyz_id(int x, int y, int z, IdString base);
IdStringList xyz_id(int x, int y, int z, IdStringList base);
// Common packing functions
// Remove nextpnr-inserted IO buffers; where IO buffer insertion is done in synthesis
// expects a set of top-level port types