From 5f748272fc118f5fdf8b5389188434c6070ca917 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Sun, 6 Dec 2020 22:50:15 -0500 Subject: machxo2: Implement bel_to_cell and API functions using it. --- machxo2/arch.cc | 16 ---------------- machxo2/arch.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/machxo2/arch.cc b/machxo2/arch.cc index 8c8dda5e..42d93f16 100644 --- a/machxo2/arch.cc +++ b/machxo2/arch.cc @@ -167,22 +167,6 @@ uint32_t Arch::getBelChecksum(BelId bel) const return 0; } -void Arch::bindBel(BelId bel, CellInfo *cell, PlaceStrength strength) -{ - -} - -void Arch::unbindBel(BelId bel) -{ - -} - -bool Arch::checkBelAvail(BelId bel) const { return false; } - -CellInfo *Arch::getBoundBelCell(BelId bel) const { return nullptr; } - -CellInfo *Arch::getConflictingBelCell(BelId bel) const { return nullptr; } - const std::map &Arch::getBelAttrs(BelId bel) const { return attrs_dummy; } WireId Arch::getBelPinWire(BelId bel, IdString pin) const diff --git a/machxo2/arch.h b/machxo2/arch.h index 1c848388..b5d6c522 100644 --- a/machxo2/arch.h +++ b/machxo2/arch.h @@ -311,6 +311,8 @@ struct Arch : BaseCtx const ChipInfoPOD *chip_info; const PackageInfoPOD *package_info; + std::vector bel_to_cell; + // Placeholders to be removed. std::unordered_map bel_by_loc; std::vector bel_id_dummy; @@ -327,6 +329,11 @@ struct Arch : BaseCtx return &(chip_info->tiles[id.location.y * chip_info->width + id.location.x]); } + int getBelFlatIndex(BelId bel) const + { + return (bel.location.y * chip_info->width + bel.location.x) * max_loc_bels + bel.index; + } + // --------------------------------------------------------------- // Common Arch API. Every arch must provide the following methods. @@ -373,11 +380,46 @@ struct Arch : BaseCtx const std::vector &getBelsByTile(int x, int y) const; bool getBelGlobalBuf(BelId bel) const; uint32_t getBelChecksum(BelId bel) const; - void bindBel(BelId bel, CellInfo *cell, PlaceStrength strength); - void unbindBel(BelId bel); - bool checkBelAvail(BelId bel) const; - CellInfo *getBoundBelCell(BelId bel) const; - CellInfo *getConflictingBelCell(BelId bel) const; + + void bindBel(BelId bel, CellInfo *cell, PlaceStrength strength) + { + NPNR_ASSERT(bel != BelId()); + int idx = getBelFlatIndex(bel); + NPNR_ASSERT(bel_to_cell.at(idx) == nullptr); + bel_to_cell[idx] = cell; + cell->bel = bel; + cell->belStrength = strength; + refreshUiBel(bel); + } + + void unbindBel(BelId bel) + { + NPNR_ASSERT(bel != BelId()); + int idx = getBelFlatIndex(bel); + NPNR_ASSERT(bel_to_cell.at(idx) != nullptr); + bel_to_cell[idx]->bel = BelId(); + bel_to_cell[idx]->belStrength = STRENGTH_NONE; + bel_to_cell[idx] = nullptr; + refreshUiBel(bel); + } + + bool checkBelAvail(BelId bel) const + { + NPNR_ASSERT(bel != BelId()); + return bel_to_cell[getBelFlatIndex(bel)] == nullptr; + } + + CellInfo *getBoundBelCell(BelId bel) const + { + NPNR_ASSERT(bel != BelId()); + return bel_to_cell[getBelFlatIndex(bel)]; + } + + CellInfo *getConflictingBelCell(BelId bel) const + { + NPNR_ASSERT(bel != BelId()); + return bel_to_cell[getBelFlatIndex(bel)]; + } BelRange getBels() const { -- cgit v1.2.3