Skip to content

Commit cd0f4d7

Browse files
committed
dpl: make optimize_mirroring deterministic
net_box_map_ is an unordered_map, so equal-hpwl boxes sorted in heap-address order (ranges::sort is not stable), making the mirroring result and the written db non-deterministic. Tie-break by net id. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 73ab739 commit cd0f4d7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/dpl/src/OptMirror.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ void OptimizeMirroring::run()
6363
}
6464

6565
// Sort net boxes by net hpwl.
66-
std::ranges::sort(sorted_boxes,
67-
[](NetBox* net_box1, NetBox* net_box2) -> bool {
68-
return net_box1->hpwl() > net_box2->hpwl();
69-
});
66+
std::ranges::sort(
67+
sorted_boxes, [](NetBox* net_box1, NetBox* net_box2) -> bool {
68+
if (net_box1->hpwl() != net_box2->hpwl()) {
69+
return net_box1->hpwl() > net_box2->hpwl();
70+
}
71+
// net_box_map_ is unordered; tie-break for stable output.
72+
return net_box1->getNet()->getId() < net_box2->getNet()->getId();
73+
});
7074

7175
std::vector<odb::dbInst*> mirror_candidates
7276
= findMirrorCandidates(sorted_boxes);

0 commit comments

Comments
 (0)