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> --- ecp5/arch.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ecp5') diff --git a/ecp5/arch.h b/ecp5/arch.h index 58373157..5c543cb3 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -950,6 +950,9 @@ struct Arch : BaseCtx // ------------------------------------------------- // Placement validity checks + bool isValidBelForCellType(IdString cell_type, BelId bel) const { + return cell_type == getBelType(bel); + } bool isValidBelForCell(CellInfo *cell, BelId bel) const; bool isBelLocationValid(BelId bel) const; -- cgit v1.2.3 From 71e210dd4b12f1e91630f83396be236034f68e30 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 28 Jan 2021 18:52:08 -0800 Subject: Refactor ECP5 to new Partition API. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- ecp5/arch.cc | 13 +++++++++++++ ecp5/arch.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ ecp5/archdefs.h | 7 +++++++ 3 files changed, 64 insertions(+) (limited to 'ecp5') diff --git a/ecp5/arch.cc b/ecp5/arch.cc index 74a1b17f..4368f0d0 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -115,6 +115,19 @@ Arch::Arch(ArchArgs args) : args(args) log_error("Unsupported package '%s' for '%s'.\n", args.package.c_str(), getChipName().c_str()); bel_to_cell.resize(chip_info->height * chip_info->width * max_loc_bels, nullptr); + + 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(partitions); + } } // ----------------------------------------------------------------------- diff --git a/ecp5/arch.h b/ecp5/arch.h index 5c543cb3..921cbc29 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -953,6 +953,47 @@ struct Arch : BaseCtx bool isValidBelForCellType(IdString cell_type, BelId bel) const { 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; + } + bool isValidBelForCell(CellInfo *cell, BelId bel) const; bool isBelLocationValid(BelId bel) const; @@ -1025,6 +1066,9 @@ struct Arch : BaseCtx static const std::vector availablePlacers; static const std::string defaultRouter; static const std::vector availableRouters; + + std::vector cell_types; + std::vector partitions; }; NEXTPNR_NAMESPACE_END diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index 586c385f..b0e01e4d 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -126,6 +126,13 @@ 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); } +}; + struct GroupId { enum : int8_t -- cgit v1.2.3 From d03d9d839b7e49a4bf3428e949bda85574adf403 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:08:14 -0800 Subject: Working compile of ECP5. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- ecp5/arch.cc | 2 +- ecp5/archdefs.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'ecp5') diff --git a/ecp5/arch.cc b/ecp5/arch.cc index 4368f0d0..b40b0002 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -126,7 +126,7 @@ Arch::Arch(ArchArgs args) : args(args) PartitionId partition; partition.name = bel_type; - partitions.push_back(partitions); + partitions.push_back(partition); } } diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index b0e01e4d..5bfe13d2 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -131,6 +131,10 @@ struct PartitionId { 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 @@ -269,4 +273,14 @@ template <> struct hash } }; +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> --- ecp5/arch.cc | 6 +++--- ecp5/arch.h | 38 +++++++++++++++++++------------------- ecp5/archdefs.h | 12 ++++++------ 3 files changed, 28 insertions(+), 28 deletions(-) (limited to 'ecp5') diff --git a/ecp5/arch.cc b/ecp5/arch.cc index b40b0002..fc618dac 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -124,9 +124,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/ecp5/arch.h b/ecp5/arch.h index 921cbc29..e91def74 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -958,36 +958,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); } } @@ -1068,7 +1068,7 @@ struct Arch : BaseCtx static const std::vector availableRouters; std::vector cell_types; - std::vector partitions; + std::vector buckets; }; NEXTPNR_NAMESPACE_END diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index 5bfe13d2..f766dee2 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -126,12 +126,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; } @@ -273,9 +273,9 @@ 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 &partition) const noexcept { std::size_t seed = 0; boost::hash_combine(seed, hash()(partition.name)); -- 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> --- ecp5/arch_pybindings.cc | 2 ++ ecp5/arch_pybindings.h | 12 ++++++++++++ 2 files changed, 14 insertions(+) (limited to 'ecp5') diff --git a/ecp5/arch_pybindings.cc b/ecp5/arch_pybindings.cc index 8618bec1..b000ea78 100644 --- a/ecp5/arch_pybindings.cc +++ b/ecp5/arch_pybindings.cc @@ -59,6 +59,8 @@ void arch_wrap_python(py::module &m) typedef const PipRange UphillPipRange; typedef const PipRange DownhillPipRange; + 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/ecp5/arch_pybindings.h b/ecp5/arch_pybindings.h index cf343976..dd3161ae 100644 --- a/ecp5/arch_pybindings.h +++ b/ecp5/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> --- ecp5/arch.cc | 4 ++-- ecp5/arch.h | 32 ++++++++++++++------------------ ecp5/arch_pybindings.cc | 4 ++-- ecp5/archdefs.h | 8 +++----- 4 files changed, 21 insertions(+), 27 deletions(-) (limited to 'ecp5') diff --git a/ecp5/arch.cc b/ecp5/arch.cc index fc618dac..25f95c53 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -117,11 +117,11 @@ Arch::Arch(ArchArgs args) : args(args) bel_to_cell.resize(chip_info->height * chip_info->width * max_loc_bels, nullptr); 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/ecp5/arch.h b/ecp5/arch.h index e91def74..18a70fe8 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -950,44 +950,40 @@ struct Arch : BaseCtx // ------------------------------------------------- // Placement validity checks - 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/ecp5/arch_pybindings.cc b/ecp5/arch_pybindings.cc index b000ea78..e1adbb46 100644 --- a/ecp5/arch_pybindings.cc +++ b/ecp5/arch_pybindings.cc @@ -59,8 +59,8 @@ void arch_wrap_python(py::module &m) typedef const PipRange UphillPipRange; typedef const PipRange DownhillPipRange; - 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" WRAP_RANGE(m, Bel, conv_to_str); diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index f766dee2..3bc75ab4 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -126,15 +126,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