@@ -624,15 +624,124 @@ void SACoreSoftMacro::attemptMacroClusterAlignment()
624624 }
625625}
626626
627- float SACoreSoftMacro::calSingleNotchPenalty (float width, float height)
627+ void SACoreSoftMacro::fillCoordsLists (std::vector<int >& x_coords,
628+ std::vector<int >& y_coords)
628629{
629- return std::sqrt ((width * height)
630- / block_->dbuAreaToMicrons (outline_.area ()));
630+ std::vector<int > x_point;
631+ std::vector<int > y_point;
632+
633+ for (auto & macro : macros_) {
634+ if (macro.isStdCellCluster ()) {
635+ continue ;
636+ }
637+ x_point.push_back (macro.getX ());
638+ x_point.push_back (macro.getX () + macro.getWidth ());
639+ y_point.push_back (macro.getY ());
640+ y_point.push_back (macro.getY () + macro.getHeight ());
641+ }
642+ x_point.push_back (0 );
643+ y_point.push_back (0 );
644+ x_point.push_back (outline_.dx ());
645+ y_point.push_back (outline_.dy ());
646+
647+ std::ranges::sort (x_point);
648+ std::ranges::sort (y_point);
649+
650+ int epsilon = outline_.dx () / 100 ;
651+ for (int i = 0 ; i < x_point.size (); i++) {
652+ if (i + 1 < x_point.size ()
653+ && std::abs (x_point[i + 1 ] - x_point[i]) <= epsilon) {
654+ continue ;
655+ }
656+ x_coords.push_back (x_point[i]);
657+ }
658+
659+ epsilon = outline_.dy () / 100 ;
660+ for (int i = 0 ; i < y_point.size (); i++) {
661+ if (i + 1 < y_point.size ()
662+ && std::abs (y_point[i + 1 ] - y_point[i]) <= epsilon) {
663+ continue ;
664+ }
665+ y_coords.push_back (y_point[i]);
666+ }
667+ }
668+
669+ SACoreSoftMacro::Neighbors SACoreSoftMacro::findNeighbors (
670+ std::vector<std::vector<bool >>& grid,
671+ int start_row,
672+ int start_col,
673+ int end_row,
674+ int end_col)
675+ {
676+ int num_y = grid.size ();
677+ int num_x = grid.front ().size ();
678+
679+ Neighbors neighbors;
680+ if (start_row > 0 ) {
681+ for (int i = start_col; i <= end_col; i++) {
682+ if (!grid[start_row - 1 ][i]) {
683+ neighbors.bottom = false ;
684+ break ;
685+ }
686+ }
687+ }
688+ if (end_row < num_y - 1 ) {
689+ for (int i = start_col; i <= end_col; i++) {
690+ if (!grid[end_row + 1 ][i]) {
691+ neighbors.top = false ;
692+ break ;
693+ }
694+ }
695+ }
696+ if (start_col > 0 ) {
697+ for (int i = start_row; i <= end_row; i++) {
698+ if (!grid[i][start_col - 1 ]) {
699+ neighbors.left = false ;
700+ break ;
701+ }
702+ }
703+ }
704+ if (end_col < num_x - 1 ) {
705+ for (int i = start_row; i <= end_row; i++) {
706+ if (!grid[i][end_col + 1 ]) {
707+ neighbors.right = false ;
708+ break ;
709+ }
710+ }
711+ }
712+
713+ return neighbors;
714+ }
715+
716+ bool SACoreSoftMacro::isSegmentEmpty (std::vector<std::vector<bool >>& grid,
717+ int start_row,
718+ int start_col,
719+ int end_row,
720+ int end_col)
721+ {
722+ for (int i = start_row; i <= end_row; i++) {
723+ for (int j = start_col; j <= end_col; j++) {
724+ if (grid[i][j]) {
725+ return false ;
726+ }
727+ }
728+ }
729+
730+ return true ;
731+ }
732+
733+ float SACoreSoftMacro::calSingleNotchPenalty (int width, int height)
734+ {
735+ return std::sqrt ((static_cast <double >(width) * height) / outline_.area ());
631736}
632737
633738// If there is no HardMacroCluster, we do not consider the notch penalty
634739void SACoreSoftMacro::calNotchPenalty ()
635740{
741+ if (graphics_) {
742+ graphics_->clearNotches ();
743+ }
744+
636745 if (notch_weight_ <= 0.0 ) {
637746 return ;
638747 }
@@ -649,37 +758,28 @@ void SACoreSoftMacro::calNotchPenalty()
649758 if (!isValid ()) {
650759 width = std::max (width_, outline_.dx ());
651760 height = std::max (height_, outline_.dy ());
652- notch_penalty_ = calSingleNotchPenalty (block_->dbuToMicrons (width),
653- block_->dbuToMicrons (height));
761+ notch_penalty_ = calSingleNotchPenalty (width, height);
762+
763+ if (graphics_) {
764+ graphics_->setNotchPenalty ({.name = " Notch" ,
765+ .weight = notch_weight_,
766+ .value = notch_penalty_,
767+ .normalization_factor = norm_notch_penalty_});
768+ }
654769 return ;
655770 }
656771
657772 // Create grids based on location of MixedCluster and HardMacroCluster
658- std::set<int > x_point;
659- std::set<int > y_point;
660- for (auto & macro : macros_) {
661- if (!macro.isMacroCluster () && !macro.isMixedCluster ()) {
662- continue ;
663- }
664- x_point.insert (macro.getX ());
665- x_point.insert (macro.getX () + macro.getWidth ());
666- y_point.insert (macro.getY ());
667- y_point.insert (macro.getY () + macro.getHeight ());
668- }
669- x_point.insert (0 );
670- y_point.insert (0 );
671- x_point.insert (outline_.dx ());
672- y_point.insert (outline_.dy ());
773+ std::vector<int > x_coords;
774+ std::vector<int > y_coords;
775+ fillCoordsLists (x_coords, y_coords);
673776
674- std::vector<int > x_coords (x_point.begin (), x_point.end ());
675- std::vector<int > y_coords (y_point.begin (), y_point.end ());
676777 int num_x = x_coords.size () - 1 ;
677778 int num_y = y_coords.size () - 1 ;
678779
679- // Assign cluster locations for notch detection
680780 std::vector<std::vector<bool >> grid (num_y, std::vector<bool >(num_x, false ));
681781 for (auto & macro : macros_) {
682- if (! macro.isMacroCluster () && !macro. isMixedCluster ()) {
782+ if (macro.isStdCellCluster ()) {
683783 continue ;
684784 }
685785 int x_start = getSegmentIndex (macro.getX (), x_coords);
@@ -693,34 +793,83 @@ void SACoreSoftMacro::calNotchPenalty()
693793 }
694794 }
695795
696- // An empty grid cell surrounded by 3 or more edges is considered a notch
697- for (int row = 0 ; row < num_y; row++) {
698- for (int col = 0 ; col < num_x; col++) {
699- if (grid[row][col]) {
796+ for (int start_row = 0 ; start_row < num_y; start_row++) {
797+ for (int start_col = 0 ; start_col < num_x; start_col++) {
798+ if (grid[start_row][start_col]) {
700799 continue ;
701800 }
702801
703- int surroundings = 0 ;
704- if (row == 0 || grid[row - 1 ][col]) {
705- surroundings++;
706- }
707- if (row == num_y - 1 || grid[row + 1 ][col]) {
708- surroundings++;
709- }
710- if (col == 0 || grid[row][col - 1 ]) {
711- surroundings++;
712- }
713- if (col == num_x - 1 || grid[row][col + 1 ]) {
714- surroundings++;
802+ int end_row = start_row;
803+ int end_col = start_col;
804+
805+ Neighbors current_neighbors
806+ = findNeighbors (grid, start_row, start_col, end_row, end_col);
807+ bool expand_rows = true ;
808+ bool expand_cols = true ;
809+
810+ while (expand_rows || expand_cols) {
811+ if (expand_rows) {
812+ end_row += 1 ;
813+ if (end_row < num_y
814+ && isSegmentEmpty (grid, start_row, start_col, end_row, end_col)) {
815+ Neighbors expanded_neighbors
816+ = findNeighbors (grid, start_row, start_col, end_row, end_col);
817+ if (expanded_neighbors.total () > current_neighbors.total ()
818+ || expanded_neighbors == current_neighbors) {
819+ current_neighbors = expanded_neighbors;
820+ } else {
821+ expand_rows = false ;
822+ end_row -= 1 ;
823+ }
824+ } else {
825+ expand_rows = false ;
826+ end_row -= 1 ;
827+ }
828+ }
829+
830+ if (expand_cols) {
831+ end_col += 1 ;
832+ if (end_col < num_x
833+ && isSegmentEmpty (grid, start_row, start_col, end_row, end_col)) {
834+ Neighbors expanded_neighbors
835+ = findNeighbors (grid, start_row, start_col, end_row, end_col);
836+ if (expanded_neighbors.total () > current_neighbors.total ()
837+ || expanded_neighbors == current_neighbors) {
838+ current_neighbors = expanded_neighbors;
839+ } else {
840+ expand_cols = false ;
841+ end_col -= 1 ;
842+ }
843+ } else {
844+ expand_cols = false ;
845+ end_col -= 1 ;
846+ }
847+ }
715848 }
716849
717- if (surroundings >= 3 ) {
718- width = x_coords[col + 1 ] - x_coords[col];
719- height = y_coords[row + 1 ] - y_coords[row];
850+ width = x_coords[end_col + 1 ] - x_coords[start_col];
851+ height = y_coords[end_row + 1 ] - y_coords[start_row];
852+
853+ bool is_notch = false ;
854+ if (current_neighbors.total () == 4 ) {
855+ is_notch = true ;
856+ } else if (current_neighbors.top && current_neighbors.bottom ) {
857+ if (height < notch_h_th_) {
858+ is_notch = true ;
859+ }
860+ } else if (current_neighbors.left && current_neighbors.right ) {
861+ if (width < notch_v_th_) {
862+ is_notch = true ;
863+ }
864+ }
720865
721- if (width <= notch_h_th_ || height <= notch_v_th_) {
722- notch_penalty_ += calSingleNotchPenalty (block_->dbuToMicrons (width),
723- block_->dbuToMicrons (height));
866+ if (is_notch) {
867+ notch_penalty_ += calSingleNotchPenalty (width, height);
868+ if (graphics_) {
869+ graphics_->addNotch (odb::Rect (x_coords[start_col],
870+ y_coords[start_row],
871+ x_coords[end_col + 1 ],
872+ y_coords[end_row + 1 ]));
724873 }
725874 }
726875 }
@@ -1052,7 +1201,7 @@ void SACoreSoftMacro::attemptCentralization(const float pre_cost)
10521201 calPenalty ();
10531202
10541203 // revert centralization
1055- if (calNormCost () > pre_cost) {
1204+ if (calNormCost () > pre_cost && !force_centralization_ ) {
10561205 centralization_was_reverted_ = true ;
10571206
10581207 setClustersLocations (clusters_locations);
0 commit comments