From 9901a5fafc8ea05e21eae434e4a56c921eb951e7 Mon Sep 17 00:00:00 2001 From: gatecat Date: Sat, 1 May 2021 13:12:33 +0100 Subject: cyclonev: Add wire and pip types Signed-off-by: gatecat --- cyclonev/arch.h | 20 ++++++++++++++++++-- cyclonev/archdefs.h | 37 +++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/cyclonev/arch.h b/cyclonev/arch.h index 84ab72f2..e1294e3f 100644 --- a/cyclonev/arch.h +++ b/cyclonev/arch.h @@ -54,6 +54,22 @@ struct BelInfo bool gb; }; +struct WireInfo +{ + // name_override is only used for nextpnr-created wires + // otherwise; this is empty and a name is created according to mistral rules + IdString name_override; + + // these are transformed on-the-fly to PipId by the iterator, to save space (WireId is half the size of PipId) + std::vector wires_downhill; + std::vector wires_uphill; + + std::vector bel_pins; + + // flags for special wires (currently unused) + uint64_t flags; +}; + struct ArchRanges : BaseArchRanges { using ArchArgsT = ArchArgs; @@ -117,8 +133,8 @@ struct Arch : BaseArch const std::vector &getPips() const override; Loc getPipLocation(PipId pip) const override; IdStringList getPipName(PipId pip) const override; - WireId getPipSrcWire(PipId pip) const override; - WireId getPipDstWire(PipId pip) const override; + WireId getPipSrcWire(PipId pip) const override { return WireId(pip.src); }; + WireId getPipDstWire(PipId pip) const override { return WireId(pip.dst); }; DelayQuad getPipDelay(PipId pip) const override; const std::vector &getPipsDownhill(WireId wire) const override; const std::vector &getPipsUphill(WireId wire) const override; diff --git a/cyclonev/archdefs.h b/cyclonev/archdefs.h index 71948ca1..249fd3d2 100644 --- a/cyclonev/archdefs.h +++ b/cyclonev/archdefs.h @@ -25,6 +25,7 @@ #include "cyclonev.h" #include "idstring.h" +#include "nextpnr_assertions.h" #include "nextpnr_namespaces.h" NEXTPNR_NAMESPACE_BEGIN @@ -84,22 +85,35 @@ struct BelId bool operator<(const BelId &other) const { return pos < other.pos || (pos == other.pos && z < other.z); } }; +static constexpr auto invalid_rnode = std::numeric_limits::max(); + struct WireId { - int32_t index = -1; + WireId() = default; + explicit WireId(CycloneV::rnode_t node) : node(node){}; + CycloneV::rnode_t node = invalid_rnode; + + // Wires created by nextpnr have rnode type >= 128 + bool is_nextpnr_created() const + { + NPNR_ASSERT(node != invalid_rnode); + return CycloneV::rn2t(node) >= 128; + } - bool operator==(const WireId &other) const { return index == other.index; } - bool operator!=(const WireId &other) const { return index != other.index; } - bool operator<(const WireId &other) const { return index < other.index; } + bool operator==(const WireId &other) const { return node == other.node; } + bool operator!=(const WireId &other) const { return node != other.node; } + bool operator<(const WireId &other) const { return node < other.node; } }; struct PipId { - int32_t index = -1; + PipId() = default; + PipId(CycloneV::rnode_t src, CycloneV::rnode_t dst) : src(src), dst(dst){}; + CycloneV::rnode_t src = invalid_rnode, dst = invalid_rnode; - bool operator==(const PipId &other) const { return index == other.index; } - bool operator!=(const PipId &other) const { return index != other.index; } - bool operator<(const PipId &other) const { return index < other.index; } + bool operator==(const PipId &other) const { return src == other.src && dst == other.dst; } + bool operator!=(const PipId &other) const { return src != other.src || dst != other.dst; } + bool operator<(const PipId &other) const { return dst < other.dst || (dst == other.dst && src < other.src); } }; typedef IdString DecalId; @@ -129,13 +143,16 @@ template <> struct hash { std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const noexcept { - return hash()(wire.index); + return hash()(wire.node); } }; template <> struct hash { - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &pip) const noexcept { return hash()(pip.index); } + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &pip) const noexcept + { + return hash()((uint64_t(pip.dst) << 32) | pip.src); + } }; } // namespace std -- cgit v1.2.3