diff --git a/common/fast_bels.h b/common/fast_bels.h index 54ac97d9..bc8e39bf 100644 --- a/common/fast_bels.h +++ b/common/fast_bels.h @@ -30,7 +30,7 @@ NEXTPNR_NAMESPACE_BEGIN struct FastBels { struct TypeData { size_t type_index; - size_t number_of_possible_bels; + int number_of_possible_bels; }; FastBels(Context *ctx, int minBelsForGridPick) : ctx(ctx), minBelsForGridPick(minBelsForGridPick) {} @@ -133,7 +133,7 @@ struct FastBels { typedef std::vector>> FastBelsData; - size_t getBelsForCellType(IdString cell_type, FastBelsData **data) { + int getBelsForCellType(IdString cell_type, FastBelsData **data) { auto iter = cell_types.find(cell_type); if(iter == cell_types.end()) { addCellType(cell_type); diff --git a/gowin/arch.cc b/gowin/arch.cc index b3a6a47d..cd4048ca 100644 --- a/gowin/arch.cc +++ b/gowin/arch.cc @@ -739,6 +739,15 @@ Arch::Arch(ArchArgs args) : args(args) } // Dummy for empty decals decal_graphics[IdString()]; + + 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); + } } void IdString::initialize_arch(const BaseCtx *ctx) diff --git a/gowin/arch.h b/gowin/arch.h index 100ba5ba..f7379a3c 100644 --- a/gowin/arch.h +++ b/gowin/arch.h @@ -425,6 +425,41 @@ 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 cell_types; + } + + IdString getPartitionName(PartitionId partition) const { + return partition; + } + + PartitionId getPartitionByName(IdString name) const { + return name; + } + + PartitionId getPartitionForBel(BelId bel) const { + return getBelType(bel); + } + + PartitionId getPartitionForCellType(IdString cell_type) const { + return cell_type; + } + + std::vector getBelsForPartition(PartitionId partition) const { + std::vector bels; + for(BelId bel : getBels()) { + if(getBelType(bel) == partition) { + bels.push_back(bel); + } + } + return bels; + } + bool isValidBelForCell(CellInfo *cell, BelId bel) const; bool isBelLocationValid(BelId bel) const; @@ -437,6 +472,8 @@ struct Arch : BaseCtx // Internal usage void assignArchInfo(); bool cellsCompatible(const CellInfo **cells, int count) const; + + std::vector cell_types; }; NEXTPNR_NAMESPACE_END diff --git a/gowin/archdefs.h b/gowin/archdefs.h index adeb8a0d..96ab5c6d 100644 --- a/gowin/archdefs.h +++ b/gowin/archdefs.h @@ -72,6 +72,7 @@ typedef IdString WireId; typedef IdString PipId; typedef IdString GroupId; typedef IdString DecalId; +typedef IdString PartitionId; struct ArchNetInfo { 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 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