1010#include < cstddef>
1111#include < functional>
1212#include < limits>
13+ #include < map>
1314#include < queue>
1415#include < tuple>
1516#include < unordered_map>
@@ -523,13 +524,8 @@ bool NegotiationLegalizer::initFromDb()
523524 die_xhi_ = core_area.xMax ();
524525 die_yhi_ = core_area.yMax ();
525526
526- // Site width from the DPL grid; row height from the first DB row.
527527 site_width_ = dpl_grid->getSiteWidth ().v ;
528- for (auto * row : block->getRows ()) {
529- row_height_ = row->getSite ()->getHeight ();
530- break ;
531- }
532- assert (site_width_ > 0 && row_height_ > 0 );
528+ assert (site_width_ > 0 );
533529
534530 // Grid dimensions from the DPL grid (accounts for actual DB rows).
535531 grid_w_ = dpl_grid->getRowSiteCount ().v ;
@@ -578,10 +574,7 @@ bool NegotiationLegalizer::initFromDb()
578574 1 ,
579575 static_cast <int >(
580576 std::round (static_cast <double >(master->getWidth ()) / site_width_)));
581- cell.height = std::max (
582- 1 ,
583- static_cast <int >(std::round (static_cast <double >(master->getHeight ())
584- / row_height_)));
577+ cell.height = dpl_grid->gridHeight (master).v ;
585578
586579 // Clamp to valid grid range – gridRoundY can return grid_h_ when the
587580 // instance is near the top edge. Use (grid_w_ - width) so the full
@@ -647,9 +640,9 @@ bool NegotiationLegalizer::initFromDb()
647640 for (auto * box : odb_region->getBoundaries ()) {
648641 RegionRectInline r;
649642 r.xlo = (box->xMin () - die_xlo_) / site_width_;
650- r.ylo = ( box->yMin () - die_ylo_) / row_height_ ;
643+ r.ylo = dpl_grid-> gridEndY (DbuY{ box->yMin () - die_ylo_}). v ;
651644 r.xhi = (box->xMax () - die_xlo_) / site_width_;
652- r.yhi = ( box->yMax () - die_ylo_) / row_height_ ;
645+ r.yhi = dpl_grid-> gridSnapDownY (DbuY{ box->yMax () - die_ylo_}). v ;
653646 rects.push_back (r);
654647 }
655648 it = region_rect_cache.emplace (odb_region, std::move (rects)).first ;
@@ -684,11 +677,12 @@ bool NegotiationLegalizer::initFromDb()
684677 db_x,
685678 db_y,
686679 die_xlo_ + cell.init_x * site_width_,
687- die_ylo_ + cell.init_y * row_height_ );
680+ die_ylo_ + dpl_grid-> gridYToDbu (GridY{ cell.init_y }). v );
688681
689682 // Priority queue keyed on physical Manhattan distance (DBU) so the
690683 // search expands in true physical proximity, not grid-unit proximity.
691- // One step in X = site_width_ DBU; one step in Y = row_height_ DBU.
684+ // One step in X = site_width_ DBU; Y distance is computed via the
685+ // DPL grid since pixel rows may have non-uniform heights.
692686 using PQEntry = std::tuple<int , int , int >; // physDist, gx, gy
693687 std::
694688 priority_queue<PQEntry, std::vector<PQEntry>, std::greater<PQEntry>>
@@ -704,8 +698,10 @@ bool NegotiationLegalizer::initFromDb()
704698 if (!visited.insert (gy * grid_w_ + gx).second ) {
705699 return ;
706700 }
707- const int dist = std::abs (gx - cell.init_x ) * site_width_
708- + std::abs (gy - cell.init_y ) * row_height_;
701+ const int dy_dbu = dpl_grid->gridYToDbu (GridY{gy}).v
702+ - dpl_grid->gridYToDbu (GridY{cell.init_y }).v ;
703+ const int dist
704+ = std::abs (gx - cell.init_x ) * site_width_ + std::abs (dy_dbu);
709705 pq.emplace (dist, gx, gy);
710706 };
711707
@@ -745,6 +741,19 @@ bool NegotiationLegalizer::initFromDb()
745741 cells_.push_back (cell);
746742 }
747743
744+ std::map<int , int > neg_height_counts;
745+ for (const NegCell& c : cells_) {
746+ neg_height_counts[c.height ]++;
747+ }
748+ logger_->info (
749+ utl::DPL ,
750+ 392 ,
751+ " Negotiation cell height distribution ({} unique row-count(s)):" ,
752+ neg_height_counts.size ());
753+ for (const auto & [height, count] : neg_height_counts) {
754+ logger_->info (utl::DPL , 393 , " height {} row(s): {} cells" , height, count);
755+ }
756+
748757 return true ;
749758}
750759
@@ -813,12 +822,13 @@ void NegotiationLegalizer::initFenceRegions()
813822 FenceRegion fr;
814823 fr.id = region->getId ();
815824
825+ const Grid* dpl_grid = opendp_->grid_ .get ();
816826 for (auto * box : region->getBoundaries ()) {
817827 FenceRect r;
818828 r.xlo = (box->xMin () - die_xlo_) / site_width_;
819- r.ylo = ( box->yMin () - die_ylo_) / row_height_ ;
829+ r.ylo = dpl_grid-> gridEndY (DbuY{ box->yMin () - die_ylo_}). v ;
820830 r.xhi = (box->xMax () - die_xlo_) / site_width_;
821- r.yhi = ( box->yMax () - die_ylo_) / row_height_ ;
831+ r.yhi = dpl_grid-> gridSnapDownY (DbuY{ box->yMax () - die_ylo_}). v ;
822832 fr.rects .push_back (r);
823833 }
824834
0 commit comments