From 2285c8dbbdbc5b7e718fa849952c560bef69a8fc Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 28 Jan 2021 15:40:26 -0800 Subject: Initial refactoring of placer API. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- nexus/arch.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nexus') diff --git a/nexus/arch.h b/nexus/arch.h index 56b48bf3..31bfa603 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -1335,6 +1335,11 @@ struct Arch : BaseCtx // Perform placement validity checks, returning false on failure (all // implemented in arch_place.cc) + // Whether this cell type can be placed at this BEL. + bool isValidBelForCellType(IdString cell_type, BelId bel) const { + return cell_type == getBelType(bel); + } + // Whether or not a given cell can be placed at a given Bel // This is not intended for Bel type checks, but finer-grained constraints // such as conflicting set/reset signals, etc -- cgit v1.2.3 From 0338368afa369d097dfb35e0705fef10baa3d20e Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:24:00 -0800 Subject: Add Partition APIs to ice40, nexus, gowin archs. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- nexus/arch.cc | 17 +++++++++++++++-- nexus/arch.h | 43 +++++++++++++++++++++++++++++++++++++++++++ nexus/archdefs.h | 22 ++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) (limited to 'nexus') diff --git a/nexus/arch.cc b/nexus/arch.cc index eadfaa4b..659703de 100644 --- a/nexus/arch.cc +++ b/nexus/arch.cc @@ -171,6 +171,19 @@ Arch::Arch(ArchArgs args) : args(args) } if (!speed_grade) log_error("Unknown speed grade '%s'.\n", speed.c_str()); + + std::unordered_set bel_types; + for(BelId bel : getBels()) { + bel_types.insert(getBelType(bel)); + } + + for(IdString bel_type : bel_types) { + cell_types.push_back(bel_type); + + PartitionId partition; + partition.name = bel_type; + partitions.push_back(partition); + } } // ----------------------------------------------------------------------- @@ -635,8 +648,8 @@ bool Arch::place() cfg.ioBufTypes.insert(id_SEIO18_CORE); cfg.ioBufTypes.insert(id_OSC_CORE); cfg.cellGroups.emplace_back(); - cfg.cellGroups.back().insert(id_OXIDE_COMB); - cfg.cellGroups.back().insert(id_OXIDE_FF); + cfg.cellGroups.back().insert({id_OXIDE_COMB}); + cfg.cellGroups.back().insert({id_OXIDE_FF}); cfg.beta = 0.5; cfg.criticalityExponent = 7; diff --git a/nexus/arch.h b/nexus/arch.h index 31bfa603..dfd00f90 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -1340,6 +1340,46 @@ struct Arch : BaseCtx return cell_type == getBelType(bel); } + const std::vector &getCellTypes() const { + return cell_types; + } + + std::vector getPartitions() const { + return partitions; + } + + IdString getPartitionName(PartitionId partition) const { + return partition.name; + } + + PartitionId getPartitionByName(IdString name) const { + PartitionId partition; + partition.name = name; + return partition; + } + + PartitionId getPartitionForBel(BelId bel) const { + PartitionId partition; + partition.name = getBelType(bel); + return partition; + } + + PartitionId getPartitionForCellType(IdString cell_type) const { + PartitionId partition; + partition.name = cell_type; + return partition; + } + + std::vector getBelsForPartition(PartitionId partition) const { + std::vector bels; + for(BelId bel : getBels()) { + if(getBelType(bel) == partition.name) { + bels.push_back(bel); + } + } + return bels; + } + // Whether or not a given cell can be placed at a given Bel // This is not intended for Bel type checks, but finer-grained constraints // such as conflicting set/reset signals, etc @@ -1541,6 +1581,9 @@ struct Arch : BaseCtx // ------------------------------------------------- void write_fasm(std::ostream &out) const; + + std::vector cell_types; + std::vector partitions; }; NEXTPNR_NAMESPACE_END diff --git a/nexus/archdefs.h b/nexus/archdefs.h index adc1342c..12bbd228 100644 --- a/nexus/archdefs.h +++ b/nexus/archdefs.h @@ -114,6 +114,17 @@ struct PipId } }; +struct PartitionId { + IdString name; + + bool operator==(const PartitionId &other) const { return (name == other.name); } + bool operator!=(const PartitionId &other) const { return (name != other.name); } + bool operator<(const PartitionId &other) const + { + return name < other.name; + } +}; + struct GroupId { enum : int8_t @@ -250,4 +261,15 @@ template <> struct hash return seed; } }; + +template <> struct hash +{ + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PartitionId &partition) const noexcept + { + std::size_t seed = 0; + boost::hash_combine(seed, hash()(partition.name)); + return seed; + } +}; + } // namespace std -- cgit v1.2.3 From 9fe546f279cd643a308322ffa6af622630892315 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Fri, 29 Jan 2021 14:55:10 -0800 Subject: Rename Partition -> BelBucket. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- nexus/arch.cc | 6 +++--- nexus/arch.h | 38 +++++++++++++++++++------------------- nexus/archdefs.h | 14 +++++++------- 3 files changed, 29 insertions(+), 29 deletions(-) (limited to 'nexus') diff --git a/nexus/arch.cc b/nexus/arch.cc index 659703de..79e00e0d 100644 --- a/nexus/arch.cc +++ b/nexus/arch.cc @@ -180,9 +180,9 @@ Arch::Arch(ArchArgs args) : args(args) for(IdString bel_type : bel_types) { cell_types.push_back(bel_type); - PartitionId partition; - partition.name = bel_type; - partitions.push_back(partition); + BelBucketId bucket; + bucket.name = bel_type; + buckets.push_back(bucket); } } diff --git a/nexus/arch.h b/nexus/arch.h index dfd00f90..9b3aea20 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -1344,36 +1344,36 @@ struct Arch : BaseCtx return cell_types; } - std::vector getPartitions() const { - return partitions; + std::vector getBelBuckets() const { + return buckets; } - IdString getPartitionName(PartitionId partition) const { - return partition.name; + IdString getBelBucketName(BelBucketId bucket) const { + return bucket.name; } - PartitionId getPartitionByName(IdString name) const { - PartitionId partition; - partition.name = name; - return partition; + BelBucketId getBelBucketByName(IdString name) const { + BelBucketId bucket; + bucket.name = name; + return bucket; } - PartitionId getPartitionForBel(BelId bel) const { - PartitionId partition; - partition.name = getBelType(bel); - return partition; + BelBucketId getBelBucketForBel(BelId bel) const { + BelBucketId bucket; + bucket.name = getBelType(bel); + return bucket; } - PartitionId getPartitionForCellType(IdString cell_type) const { - PartitionId partition; - partition.name = cell_type; - return partition; + BelBucketId getBelBucketForCellType(IdString cell_type) const { + BelBucketId bucket; + bucket.name = cell_type; + return bucket; } - std::vector getBelsForPartition(PartitionId partition) const { + std::vector getBelsInBucket(BelBucketId bucket) const { std::vector bels; for(BelId bel : getBels()) { - if(getBelType(bel) == partition.name) { + if(getBelType(bel) == bucket.name) { bels.push_back(bel); } } @@ -1583,7 +1583,7 @@ struct Arch : BaseCtx void write_fasm(std::ostream &out) const; std::vector cell_types; - std::vector partitions; + std::vector buckets; }; NEXTPNR_NAMESPACE_END diff --git a/nexus/archdefs.h b/nexus/archdefs.h index 12bbd228..52f5cf58 100644 --- a/nexus/archdefs.h +++ b/nexus/archdefs.h @@ -114,12 +114,12 @@ struct PipId } }; -struct PartitionId { +struct BelBucketId { IdString name; - bool operator==(const PartitionId &other) const { return (name == other.name); } - bool operator!=(const PartitionId &other) const { return (name != other.name); } - bool operator<(const PartitionId &other) const + bool operator==(const BelBucketId &other) const { return (name == other.name); } + bool operator!=(const BelBucketId &other) const { return (name != other.name); } + bool operator<(const BelBucketId &other) const { return name < other.name; } @@ -262,12 +262,12 @@ template <> struct hash } }; -template <> struct hash +template <> struct hash { - std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PartitionId &partition) const noexcept + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelBucketId &bucket) const noexcept { std::size_t seed = 0; - boost::hash_combine(seed, hash()(partition.name)); + boost::hash_combine(seed, hash()(bucket.name)); return seed; } }; -- cgit v1.2.3 From 9089ee2d1631fe2346143823c2896a2a85a27e8b Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Fri, 29 Jan 2021 15:35:00 -0800 Subject: Add pybindings for new APIs. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- nexus/arch_pybindings.cc | 3 +++ nexus/arch_pybindings.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'nexus') diff --git a/nexus/arch_pybindings.cc b/nexus/arch_pybindings.cc index 1a3890ff..cf0badae 100644 --- a/nexus/arch_pybindings.cc +++ b/nexus/arch_pybindings.cc @@ -55,6 +55,9 @@ void arch_wrap_python(py::module &m) typedef UpDownhillPipRange DownhillPipRange; typedef WireBelPinRange BelPinRange; + typedef const std::vector & BelBucketRange; + typedef const std::vector & BelRangeForBelBucket; + #include "arch_pybindings_shared.h" WRAP_RANGE(m, Bel, conv_to_str); diff --git a/nexus/arch_pybindings.h b/nexus/arch_pybindings.h index 326af306..7694090b 100644 --- a/nexus/arch_pybindings.h +++ b/nexus/arch_pybindings.h @@ -76,6 +76,18 @@ template <> struct string_converter } }; +template <> struct string_converter +{ + BelBucketId from_str(Context *ctx, std::string name) { return ctx->getBelBucketByName(ctx->id(name)); } + + std::string to_str(Context *ctx, BelBucketId id) + { + if (id == BelBucketId()) + throw bad_wrap(); + return ctx->getBelBucketName(id).str(ctx); + } +}; + template <> struct string_converter { BelPin from_str(Context *ctx, std::string name) -- cgit v1.2.3 From da74a425d23352d7cddf9d1c4b0b7c86dd567c40 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:28:32 -0800 Subject: Run "make clangformat". Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- nexus/arch.cc | 4 ++-- nexus/arch.h | 32 ++++++++++++++------------------ nexus/arch_pybindings.cc | 4 ++-- nexus/archdefs.h | 8 +++----- 4 files changed, 21 insertions(+), 27 deletions(-) (limited to 'nexus') diff --git a/nexus/arch.cc b/nexus/arch.cc index 79e00e0d..95b409bf 100644 --- a/nexus/arch.cc +++ b/nexus/arch.cc @@ -173,11 +173,11 @@ Arch::Arch(ArchArgs args) : args(args) log_error("Unknown speed grade '%s'.\n", speed.c_str()); std::unordered_set bel_types; - for(BelId bel : getBels()) { + for (BelId bel : getBels()) { bel_types.insert(getBelType(bel)); } - for(IdString bel_type : bel_types) { + for (IdString bel_type : bel_types) { cell_types.push_back(bel_type); BelBucketId bucket; diff --git a/nexus/arch.h b/nexus/arch.h index 9b3aea20..ee66599a 100644 --- a/nexus/arch.h +++ b/nexus/arch.h @@ -1336,44 +1336,40 @@ struct Arch : BaseCtx // implemented in arch_place.cc) // Whether this cell type can be placed at this BEL. - bool isValidBelForCellType(IdString cell_type, BelId bel) const { - return cell_type == getBelType(bel); - } + bool isValidBelForCellType(IdString cell_type, BelId bel) const { return cell_type == getBelType(bel); } - const std::vector &getCellTypes() const { - return cell_types; - } + const std::vector &getCellTypes() const { return cell_types; } - std::vector getBelBuckets() const { - return buckets; - } + std::vector getBelBuckets() const { return buckets; } - IdString getBelBucketName(BelBucketId bucket) const { - return bucket.name; - } + IdString getBelBucketName(BelBucketId bucket) const { return bucket.name; } - BelBucketId getBelBucketByName(IdString name) const { + BelBucketId getBelBucketByName(IdString name) const + { BelBucketId bucket; bucket.name = name; return bucket; } - BelBucketId getBelBucketForBel(BelId bel) const { + BelBucketId getBelBucketForBel(BelId bel) const + { BelBucketId bucket; bucket.name = getBelType(bel); return bucket; } - BelBucketId getBelBucketForCellType(IdString cell_type) const { + BelBucketId getBelBucketForCellType(IdString cell_type) const + { BelBucketId bucket; bucket.name = cell_type; return bucket; } - std::vector getBelsInBucket(BelBucketId bucket) const { + std::vector getBelsInBucket(BelBucketId bucket) const + { std::vector bels; - for(BelId bel : getBels()) { - if(getBelType(bel) == bucket.name) { + for (BelId bel : getBels()) { + if (getBelType(bel) == bucket.name) { bels.push_back(bel); } } diff --git a/nexus/arch_pybindings.cc b/nexus/arch_pybindings.cc index cf0badae..b07031f7 100644 --- a/nexus/arch_pybindings.cc +++ b/nexus/arch_pybindings.cc @@ -55,8 +55,8 @@ void arch_wrap_python(py::module &m) typedef UpDownhillPipRange DownhillPipRange; typedef WireBelPinRange BelPinRange; - typedef const std::vector & BelBucketRange; - typedef const std::vector & BelRangeForBelBucket; + typedef const std::vector &BelBucketRange; + typedef const std::vector &BelRangeForBelBucket; #include "arch_pybindings_shared.h" diff --git a/nexus/archdefs.h b/nexus/archdefs.h index 52f5cf58..7e427e06 100644 --- a/nexus/archdefs.h +++ b/nexus/archdefs.h @@ -114,15 +114,13 @@ struct PipId } }; -struct BelBucketId { +struct BelBucketId +{ IdString name; bool operator==(const BelBucketId &other) const { return (name == other.name); } bool operator!=(const BelBucketId &other) const { return (name != other.name); } - bool operator<(const BelBucketId &other) const - { - return name < other.name; - } + bool operator<(const BelBucketId &other) const { return name < other.name; } }; struct GroupId -- cgit v1.2.3