From f6fa0300ae95a0896a12b9acf0c7e76851c13d37 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 20 Jul 2018 17:33:57 +0200 Subject: Improve iCE40 and common Loc code Signed-off-by: Clifford Wolf --- ice40/arch.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'ice40/arch.cc') diff --git a/ice40/arch.cc b/ice40/arch.cc index 786d8ba1..ceafca17 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -255,11 +255,40 @@ BelId Arch::getBelByName(IdString name) const return ret; } +BelId Arch::getBelByLocation(int x, int y, int z) const +{ + if (bel_by_loc.empty()) { + for (int i = 0; i < chip_info->num_bels; i++) + bel_by_loc[getBelLocation(BelId{i})] = i; + } + + auto it = bel_by_loc.find(Loc{x, y, z}); + if (it != bel_by_loc.end()) + return BelId{it->second}; + return BelId(); +} + +BelRange Arch::getBelsByTile(int x, int y) const +{ + // In iCE40 chipdb bels at the same tile are consecutive and dense z ordinates are used + BelRange br; + br.b.cursor = Arch::getBelByLocation(x, y, 0); + br.e.cursor = br.b.cursor; + + if (br.e.cursor != -1) { + while (br.e.cursor < chip_info->num_bels && + chip_info->bel_data[br.e.cursor].x == x && + chip_info->bel_data[br.e.cursor].y == y) + br.e.cursor++; + } + + return br; +} + BelRange Arch::getBelsAtSameTile(BelId bel) const { BelRange br; NPNR_ASSERT(bel != BelId()); - // This requires Bels at the same tile are consecutive int x = chip_info->bel_data[bel.index].x; int y = chip_info->bel_data[bel.index].y; int start = bel.index, end = bel.index; -- cgit v1.2.3 From fd8239e170a7391d9c25d8681083507d9960abef Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 20 Jul 2018 18:09:22 +0200 Subject: Add Location APIs to generic arch Signed-off-by: Clifford Wolf --- ice40/arch.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'ice40/arch.cc') diff --git a/ice40/arch.cc b/ice40/arch.cc index ceafca17..e9a7d2b6 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -255,24 +255,36 @@ BelId Arch::getBelByName(IdString name) const return ret; } -BelId Arch::getBelByLocation(int x, int y, int z) const +BelId Arch::getBelByLocation(Loc loc) const { + BelId bel; + if (bel_by_loc.empty()) { - for (int i = 0; i < chip_info->num_bels; i++) - bel_by_loc[getBelLocation(BelId{i})] = i; + for (int i = 0; i < chip_info->num_bels; i++) { + BelId b; + b.index = i; + bel_by_loc[getBelLocation(b)] = i; + } } - auto it = bel_by_loc.find(Loc{x, y, z}); + auto it = bel_by_loc.find(loc); if (it != bel_by_loc.end()) - return BelId{it->second}; - return BelId(); + bel.index = it->second; + + return bel; } BelRange Arch::getBelsByTile(int x, int y) const { // In iCE40 chipdb bels at the same tile are consecutive and dense z ordinates are used BelRange br; - br.b.cursor = Arch::getBelByLocation(x, y, 0); + + Loc loc; + loc.x = x; + loc.y = y; + loc.z = 0; + + br.b.cursor = Arch::getBelByLocation(loc).index; br.e.cursor = br.b.cursor; if (br.e.cursor != -1) { -- cgit v1.2.3