@@ -76,6 +76,16 @@ SACoreSoftMacro::SACoreSoftMacro(PhysicalHierarchy* tree,
7676 logger_ = logger;
7777}
7878
79+ void SACoreSoftMacro::findFixedMacros ()
80+ {
81+ for (const int macro_id : pos_seq_) {
82+ const SoftMacro& macro = macros_[macro_id];
83+ if (macro.isFixed ()) {
84+ fixed_macros_.push_back (macro.getBBox ());
85+ }
86+ }
87+ }
88+
7989void SACoreSoftMacro::run ()
8090{
8191 if (graphics_) {
@@ -93,6 +103,15 @@ void SACoreSoftMacro::run()
93103 }
94104}
95105
106+ bool SACoreSoftMacro::isValid () const
107+ {
108+ if (!fixed_macros_.empty () && fixed_macros_penalty_ > 0 .0f ) {
109+ return false ;
110+ }
111+
112+ return resultFitsInOutline ();
113+ }
114+
96115// acessors functions
97116float SACoreSoftMacro::getBoundaryPenalty () const
98117{
@@ -152,6 +171,10 @@ float SACoreSoftMacro::calNormCost() const
152171 cost += macro_blockage_weight_ * macro_blockage_penalty_
153172 / norm_macro_blockage_penalty_;
154173 }
174+ if (norm_fixed_macros_penalty_ > 0.0 ) {
175+ cost += fixed_macros_weight_ * fixed_macros_penalty_
176+ / norm_fixed_macros_penalty_;
177+ }
155178 if (norm_notch_penalty_ > 0.0 ) {
156179 cost += notch_weight_ * notch_penalty_ / norm_notch_penalty_;
157180 }
@@ -167,6 +190,7 @@ void SACoreSoftMacro::calPenalty()
167190 calBoundaryPenalty ();
168191 calMacroBlockagePenalty ();
169192 calNotchPenalty ();
193+ calFixedMacrosPenalty ();
170194 if (graphics_) {
171195 graphics_->setAreaPenalty (
172196 {" Area" , core_weights_.area , getAreaPenalty (), norm_area_penalty_});
@@ -268,6 +292,7 @@ void SACoreSoftMacro::restoreState()
268292void SACoreSoftMacro::initialize ()
269293{
270294 initSequencePair ();
295+ findFixedMacros ();
271296
272297 std::vector<float > outline_penalty_list;
273298 std::vector<float > wirelength_list;
@@ -277,6 +302,7 @@ void SACoreSoftMacro::initialize()
277302 std::vector<float > macro_blockage_penalty_list;
278303 std::vector<float > notch_penalty_list;
279304 std::vector<float > area_penalty_list;
305+ std::vector<float > fixed_macros_penalty_list;
280306 std::vector<float > width_list;
281307 std::vector<float > height_list;
282308
@@ -298,6 +324,7 @@ void SACoreSoftMacro::initialize()
298324 boundary_penalty_list.push_back (boundary_penalty_);
299325 macro_blockage_penalty_list.push_back (macro_blockage_penalty_);
300326 notch_penalty_list.push_back (notch_penalty_);
327+ fixed_macros_penalty_list.push_back (fixed_macros_penalty_);
301328 }
302329 graphics_ = save_graphics;
303330
@@ -309,6 +336,7 @@ void SACoreSoftMacro::initialize()
309336 norm_boundary_penalty_ = calAverage (boundary_penalty_list);
310337 norm_macro_blockage_penalty_ = calAverage (macro_blockage_penalty_list);
311338 norm_notch_penalty_ = calAverage (notch_penalty_list);
339+ norm_fixed_macros_penalty_ = calAverage (fixed_macros_penalty_list);
312340
313341 // Reset penalites if lower than threshold
314342
@@ -344,6 +372,10 @@ void SACoreSoftMacro::initialize()
344372 norm_notch_penalty_ = 1.0 ;
345373 }
346374
375+ if (norm_fixed_macros_penalty_ <= 1e-4 ) {
376+ norm_fixed_macros_penalty_ = 1.0 ;
377+ }
378+
347379 // Calculate initial temperature
348380 std::vector<float > cost_list;
349381 for (int i = 0 ; i < outline_penalty_list.size (); i++) {
@@ -356,6 +388,7 @@ void SACoreSoftMacro::initialize()
356388 boundary_penalty_ = boundary_penalty_list[i];
357389 macro_blockage_penalty_ = macro_blockage_penalty_list[i];
358390 notch_penalty_ = notch_penalty_list[i];
391+ fixed_macros_penalty_ = fixed_macros_penalty_list[i];
359392 cost_list.push_back (calNormCost ());
360393 }
361394 float delta_cost = 0.0 ;
@@ -383,12 +416,17 @@ void SACoreSoftMacro::calBoundaryPenalty()
383416 return ;
384417 }
385418
386- int tot_num_macros = 0 ;
419+ int number_of_movable_macros = 0 ;
387420 for (const auto & macro_id : pos_seq_) {
388- tot_num_macros += macros_[macro_id].getNumMacro ();
421+ const SoftMacro& soft_macro = macros_[macro_id];
422+ if (soft_macro.isFixed ()) {
423+ continue ;
424+ }
425+
426+ number_of_movable_macros += soft_macro.getNumMacro ();
389427 }
390428
391- if (tot_num_macros < = 0 ) {
429+ if (number_of_movable_macros = = 0 ) {
392430 return ;
393431 }
394432
@@ -397,23 +435,28 @@ void SACoreSoftMacro::calBoundaryPenalty()
397435 float x_dist_from_root = 0 .0f , y_dist_from_root = 0 .0f ;
398436
399437 for (const auto & macro_id : pos_seq_) {
400- if (macros_[macro_id].getNumMacro () > 0 ) {
401- global_lx = macros_[macro_id].getX () + outline_.xMin () - root_->getX ();
402- global_ly = macros_[macro_id].getY () + outline_.yMin () - root_->getY ();
403- global_ux = global_lx + macros_[macro_id].getWidth ();
404- global_uy = global_ly + macros_[macro_id].getHeight ();
438+ const SoftMacro& soft_macro = macros_[macro_id];
439+ if (soft_macro.isFixed ()) {
440+ continue ;
441+ }
442+
443+ if (soft_macro.getNumMacro () > 0 ) {
444+ global_lx = soft_macro.getX () + outline_.xMin () - root_->getX ();
445+ global_ly = soft_macro.getY () + outline_.yMin () - root_->getY ();
446+ global_ux = global_lx + soft_macro.getWidth ();
447+ global_uy = global_ly + soft_macro.getHeight ();
405448
406449 x_dist_from_root
407450 = std::min (global_lx, std::abs (root_->getWidth () - global_ux));
408451 y_dist_from_root
409452 = std::min (global_ly, std::abs (root_->getHeight () - global_uy));
410453
411454 boundary_penalty_ += std::min (x_dist_from_root, y_dist_from_root)
412- * macros_[macro_id] .getNumMacro ();
455+ * soft_macro .getNumMacro ();
413456 }
414457 }
415458 // normalization
416- boundary_penalty_ = boundary_penalty_ / tot_num_macros ;
459+ boundary_penalty_ = boundary_penalty_ / number_of_movable_macros ;
417460 if (graphics_) {
418461 graphics_->setBoundaryPenalty ({" Boundary" ,
419462 boundary_weight_,
@@ -474,6 +517,42 @@ void SACoreSoftMacro::calMacroBlockagePenalty()
474517 }
475518}
476519
520+ void SACoreSoftMacro::calFixedMacrosPenalty ()
521+ {
522+ if (fixed_macros_.empty ()) {
523+ return ;
524+ }
525+
526+ fixed_macros_penalty_ = 0 .0f ;
527+
528+ for (const Rect& fixed_macro : fixed_macros_) {
529+ for (const int macro_id : pos_seq_) {
530+ const SoftMacro& macro = macros_[macro_id];
531+
532+ // Skip the current fixed macro itself and unneeded computation.
533+ if (macro.isFixed ()) {
534+ continue ;
535+ }
536+
537+ Tiling overlap_shape = computeOverlapShape (fixed_macro, macro.getBBox ());
538+
539+ // If any of the dimensions is negative, then there's no overlap.
540+ if (overlap_shape.width () < 0 || overlap_shape.height () < 0 ) {
541+ continue ;
542+ }
543+
544+ fixed_macros_penalty_ += overlap_shape.width () * overlap_shape.height ();
545+ }
546+ }
547+
548+ if (graphics_) {
549+ graphics_->setFixedMacrosPenalty ({" Fixed Macros" ,
550+ fixed_macros_weight_,
551+ fixed_macros_penalty_,
552+ norm_fixed_macros_penalty_});
553+ }
554+ }
555+
477556// Align macro clusters to reduce notch
478557void SACoreSoftMacro::alignMacroClusters ()
479558{
0 commit comments