From f0d4e4fbc3847635e0f6151a9eda52b7fb952c19 Mon Sep 17 00:00:00 2001 From: gatecat Date: Mon, 2 May 2022 09:56:36 +0100 Subject: generic: Add some extra helpers for viaduct uarches Signed-off-by: gatecat --- generic/arch.cc | 24 ++++++++++++++++++++++++ generic/arch.h | 4 ++++ generic/viaduct_helpers.cc | 22 ++++++++++++++++++++-- generic/viaduct_helpers.h | 6 ++++-- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/generic/arch.cc b/generic/arch.cc index f622fed3..11b5868b 100644 --- a/generic/arch.cc +++ b/generic/arch.cc @@ -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); diff --git a/generic/arch.h b/generic/arch.h index e96853f1..157ff8af 100644 --- a/generic/arch.h +++ b/generic/arch.h @@ -201,6 +201,10 @@ struct Arch : BaseArch 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); diff --git a/generic/viaduct_helpers.cc b/generic/viaduct_helpers.cc index a92d0de1..153d2a0e 100644 --- a/generic/viaduct_helpers.cc +++ b/generic/viaduct_helpers.cc @@ -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 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 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 &top_ports) { std::vector to_remove; diff --git a/generic/viaduct_helpers.h b/generic/viaduct_helpers.h index cac22304..213995db 100644 --- a/generic/viaduct_helpers.h +++ b/generic/viaduct_helpers.h @@ -58,13 +58,15 @@ struct ViaductHelpers Context *ctx; void init(Context *ctx) { this->ctx = ctx; } // IdStringList components for x and y locations - std::vector x_ids, y_ids; - void resize_ids(int x, int y); + std::vector 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 -- cgit v1.2.3