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> --- ice40/arch.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ice40') diff --git a/ice40/arch.h b/ice40/arch.h index fbf26e78..60171a4c 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -821,6 +821,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> --- ice40/arch.cc | 13 +++++++++++++ ice40/arch.h | 43 +++++++++++++++++++++++++++++++++++++++++++ ice40/archdefs.h | 22 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) (limited to 'ice40') diff --git a/ice40/arch.cc b/ice40/arch.cc index e450e682..fcf6506d 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -115,6 +115,19 @@ Arch::Arch(ArchArgs args) : args(args) wire_to_net.resize(chip_info->wire_data.size()); pip_to_net.resize(chip_info->pip_data.size()); switches_locked.resize(chip_info->num_switches); + + 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); + } } // ----------------------------------------------------------------------- diff --git a/ice40/arch.h b/ice40/arch.h index 60171a4c..18fc3aeb 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -826,6 +826,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 @@ -867,6 +907,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; }; void ice40DelayFuzzerMain(Context *ctx); diff --git a/ice40/archdefs.h b/ice40/archdefs.h index e95953f1..1b7821b0 100644 --- a/ice40/archdefs.h +++ b/ice40/archdefs.h @@ -170,6 +170,17 @@ struct ArchCellInfo }; }; +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; + } +}; + NEXTPNR_NAMESPACE_END namespace std { @@ -213,4 +224,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> --- ice40/arch.cc | 6 +++--- ice40/arch.h | 38 +++++++++++++++++++------------------- ice40/archdefs.h | 14 +++++++------- 3 files changed, 29 insertions(+), 29 deletions(-) (limited to 'ice40') diff --git a/ice40/arch.cc b/ice40/arch.cc index fcf6506d..1849d993 100644 --- a/ice40/arch.cc +++ b/ice40/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/ice40/arch.h b/ice40/arch.h index 18fc3aeb..ddad1658 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -830,36 +830,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); } } @@ -909,7 +909,7 @@ struct Arch : BaseCtx static const std::vector availableRouters; std::vector cell_types; - std::vector partitions; + std::vector buckets; }; void ice40DelayFuzzerMain(Context *ctx); diff --git a/ice40/archdefs.h b/ice40/archdefs.h index 1b7821b0..37249331 100644 --- a/ice40/archdefs.h +++ b/ice40/archdefs.h @@ -170,12 +170,12 @@ struct ArchCellInfo }; }; -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; } @@ -225,12 +225,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> --- ice40/arch_pybindings.cc | 2 ++ ice40/arch_pybindings.h | 12 ++++++++++++ 2 files changed, 14 insertions(+) (limited to 'ice40') diff --git a/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc index 921956e8..060cf0b1 100644 --- a/ice40/arch_pybindings.cc +++ b/ice40/arch_pybindings.cc @@ -75,6 +75,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/ice40/arch_pybindings.h b/ice40/arch_pybindings.h index cf343976..dd3161ae 100644 --- a/ice40/arch_pybindings.h +++ b/ice40/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> --- ice40/arch.cc | 4 ++-- ice40/arch.h | 32 ++++++++++++++------------------ ice40/arch_pybindings.cc | 5 ++--- ice40/archdefs.h | 8 +++----- 4 files changed, 21 insertions(+), 28 deletions(-) (limited to 'ice40') diff --git a/ice40/arch.cc b/ice40/arch.cc index 1849d993..6fe77e4b 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -117,11 +117,11 @@ Arch::Arch(ArchArgs args) : args(args) switches_locked.resize(chip_info->num_switches); 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/ice40/arch.h b/ice40/arch.h index ddad1658..fd92d988 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -822,44 +822,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/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc index 060cf0b1..76ce7590 100644 --- a/ice40/arch_pybindings.cc +++ b/ice40/arch_pybindings.cc @@ -75,8 +75,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); @@ -85,7 +85,6 @@ void arch_wrap_python(py::module &m) WRAP_RANGE(m, Pip, conv_to_str); WRAP_RANGE(m, BelPin, wrap_context); - WRAP_MAP_UPTR(m, CellMap, "IdCellMap"); WRAP_MAP_UPTR(m, NetMap, "IdNetMap"); WRAP_MAP(m, HierarchyMap, wrap_context, "HierarchyMap"); diff --git a/ice40/archdefs.h b/ice40/archdefs.h index 37249331..c0a6ac66 100644 --- a/ice40/archdefs.h +++ b/ice40/archdefs.h @@ -170,15 +170,13 @@ struct ArchCellInfo }; }; -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; } }; NEXTPNR_NAMESPACE_END -- cgit v1.2.3