aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-06-17 14:36:19 +0200
committerDavid Shah <davey1576@gmail.com>2018-06-17 14:36:19 +0200
commit681c9654d7c49d407a999b2b03c980d66bcefd8f (patch)
treea0a29eb9249aba6bdfc0c9f44a2b50531b412972 /common
parent153b800f6a5da9af277e64b4cd4aee1c10ca0a01 (diff)
downloadnextpnr-681c9654d7c49d407a999b2b03c980d66bcefd8f.tar.gz
nextpnr-681c9654d7c49d407a999b2b03c980d66bcefd8f.tar.bz2
nextpnr-681c9654d7c49d407a999b2b03c980d66bcefd8f.zip
place_sa: Add a rip-up feature when initial placement fails
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'common')
-rw-r--r--common/place_sa.cc71
1 files changed, 48 insertions, 23 deletions
diff --git a/common/place_sa.cc b/common/place_sa.cc
index 22e750c2..61f9f748 100644
--- a/common/place_sa.cc
+++ b/common/place_sa.cc
@@ -72,33 +72,58 @@ static int random_int_between(rnd_state &rnd, int a, int b)
// Initial random placement
static void place_initial(Design *design, CellInfo *cell, rnd_state &rnd)
{
- BelId best_bel = BelId();
- float best_score = std::numeric_limits<float>::infinity();
- Chip &chip = design->chip;
- if (cell->bel != BelId()) {
- chip.unbindBel(cell->bel);
- cell->bel = BelId();
- }
- BelType targetType = belTypeFromId(cell->type);
- for (auto bel : chip.getBels()) {
- if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
- isValidBelForCell(design, cell, bel)) {
- float score = random_float_upto(rnd, 1.0);
- if (score <= best_score) {
- best_score = score;
- best_bel = bel;
+ bool all_placed = false;
+ int iters = 25;
+ while(!all_placed) {
+ BelId best_bel = BelId();
+ float best_score = std::numeric_limits<float>::infinity(), best_ripup_score = std::numeric_limits<float>::infinity();
+ Chip &chip = design->chip;
+ CellInfo *ripup_target = nullptr;
+ BelId ripup_bel = BelId();
+ if (cell->bel != BelId()) {
+ chip.unbindBel(cell->bel);
+ cell->bel = BelId();
+ }
+ BelType targetType = belTypeFromId(cell->type);
+ for (auto bel : chip.getBels()) {
+ if (chip.getBelType(bel) == targetType && isValidBelForCell(design, cell, bel)) {
+ if (chip.checkBelAvail(bel)) {
+ float score = random_float_upto(rnd, 1.0);
+ if (score <= best_score) {
+ best_score = score;
+ best_bel = bel;
+ }
+ } else {
+ float score = random_float_upto(rnd, 1.0);
+ if (score <= best_ripup_score) {
+ best_ripup_score = score;
+ ripup_target = design->cells.at(chip.getBelCell(bel, true));
+ ripup_bel = bel;
+ }
+
+ }
+
}
}
+ if (best_bel == BelId()) {
+ if (iters == 0 || ripup_bel == BelId())
+ log_error("failed to place cell '%s' of type '%s'\n",
+ cell->name.c_str(), cell->type.c_str());
+ --iters;
+ chip.unbindBel(ripup_target->bel);
+ ripup_target->bel = BelId();
+ best_bel = ripup_bel;
+ } else {
+ all_placed = true;
+ }
+ cell->bel = best_bel;
+ chip.bindBel(cell->bel, cell->name);
+
+ // Back annotate location
+ cell->attrs["BEL"] = chip.getBelName(cell->bel).str();
+ cell = ripup_target;
}
- if (best_bel == BelId()) {
- log_error("failed to place cell '%s' of type '%s'\n",
- cell->name.c_str(), cell->type.c_str());
- }
- cell->bel = best_bel;
- chip.bindBel(cell->bel, cell->name);
- // Back annotate location
- cell->attrs["BEL"] = chip.getBelName(cell->bel).str();
}
// Stores the state of the SA placer