From af0bffbae905d92942492e0fdf42a4b02686b224 Mon Sep 17 00:00:00 2001 From: gatecat Date: Sat, 1 May 2021 14:06:13 +0100 Subject: [PATCH] cyclonev: Add some range types Signed-off-by: gatecat --- cyclonev/arch.h | 76 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/cyclonev/arch.h b/cyclonev/arch.h index c23c8cd3..4e6443c4 100644 --- a/cyclonev/arch.h +++ b/cyclonev/arch.h @@ -71,6 +71,61 @@ struct WireInfo uint64_t flags; }; +// This transforms a WireIds, and adds the mising half of the pair to create a PipId +using WireVecIterator = std::vector::const_iterator; +struct UpDownhillPipIterator +{ + WireVecIterator base; + WireId other_wire; + bool is_uphill; + + UpDownhillPipIterator(WireVecIterator base, WireId other_wire, bool is_uphill) + : base(base), other_wire(other_wire), is_uphill(is_uphill){}; + + bool operator!=(const UpDownhillPipIterator &other) { return base != other.base; } + UpDownhillPipIterator operator++() + { + ++base; + return *this; + } + UpDownhillPipIterator operator++(int) + { + UpDownhillPipIterator prior(*this); + ++(*this); + return prior; + } + PipId operator*() { return is_uphill ? PipId(base->node, other_wire.node) : PipId(other_wire.node, base->node); } +}; + +struct UpDownhillPipRange +{ + UpDownhillPipIterator b, e; + + UpDownhillPipRange(const std::vector &v, WireId other_wire, bool is_uphill) + : b(v.cbegin(), other_wire, is_uphill), e(v.cend(), other_wire, is_uphill){}; + + UpDownhillPipIterator begin() const { return b; } + UpDownhillPipIterator end() const { return e; } +}; + +// This transforms a map to a range of keys, used as the wire iterator +template struct key_range +{ + key_range(const T &t) : b(t.cbegin()), e(t.cend()){}; + typename T::const_iterator b, e; + + struct xformed_iterator : public T::const_iterator + { + explicit xformed_iterator(typename T::const_iterator base) : T::const_iterator(base){}; + typename T::key_type operator*() { return this->T::const_iterator::operator*().first; } + }; + + xformed_iterator begin() const { return xformed_iterator(b); } + xformed_iterator end() const { return xformed_iterator(e); } +}; + +using AllWireRange = key_range>; + struct ArchRanges : BaseArchRanges { using ArchArgsT = ArchArgs; @@ -79,9 +134,9 @@ struct ArchRanges : BaseArchRanges using TileBelsRangeT = std::vector; using BelPinsRangeT = std::vector; // Wires - using AllWiresRangeT = const std::unordered_set &; - using DownhillPipRangeT = const std::vector &; - using UphillPipRangeT = const std::vector &; + using AllWiresRangeT = AllWireRange; + using DownhillPipRangeT = UpDownhillPipRange; + using UphillPipRangeT = UpDownhillPipRange; using WireBelPinRangeT = const std::vector &; // Pips using AllPipsRangeT = const std::unordered_set &; @@ -127,7 +182,7 @@ struct Arch : BaseArch IdStringList getWireName(WireId wire) const override { return IdStringList(); } DelayQuad getWireDelay(WireId wire) const override { return DelayQuad(0); } const std::vector &getWireBelPins(WireId wire) const override { return empty_belpin_list; } - const std::unordered_set &getWires() const override { return all_wires; } + AllWireRange getWires() const override { return AllWireRange(wires); } // ------------------------------------------------- @@ -138,8 +193,14 @@ struct Arch : BaseArch 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 { return DelayQuad(0); } - const std::vector &getPipsDownhill(WireId wire) const override { return empty_pip_list; } - const std::vector &getPipsUphill(WireId wire) const override { return empty_pip_list; } + UpDownhillPipRange getPipsDownhill(WireId wire) const override + { + return UpDownhillPipRange(wires.at(wire).wires_downhill, wire, false); + } + UpDownhillPipRange getPipsUphill(WireId wire) const override + { + return UpDownhillPipRange(wires.at(wire).wires_uphill, wire, true); + } // ------------------------------------------------- @@ -166,8 +227,9 @@ struct Arch : BaseArch static const std::string defaultRouter; static const std::vector availableRouters; + std::unordered_map wires; + // WIP to link without failure - std::unordered_set all_wires; std::unordered_set all_pips; std::vector empty_pip_list; std::vector empty_belpin_list;