@@ -181,19 +181,6 @@ void SACoreSoftMacro::perturb()
181181 return ;
182182 }
183183
184- // Keep back up
185- pre_pos_seq_ = pos_seq_;
186- pre_neg_seq_ = neg_seq_;
187- pre_width_ = width_;
188- pre_height_ = height_;
189- pre_outline_penalty_ = outline_penalty_;
190- pre_wirelength_ = wirelength_;
191- pre_guidance_penalty_ = guidance_penalty_;
192- pre_fence_penalty_ = fence_penalty_;
193- pre_boundary_penalty_ = boundary_penalty_;
194- pre_macro_blockage_penalty_ = macro_blockage_penalty_;
195- pre_notch_penalty_ = notch_penalty_;
196-
197184 // generate random number (0 - 1) to determine actions
198185 const float op = distribution_ (generator_);
199186 const float action_prob_1 = pos_swap_prob_;
@@ -215,7 +202,6 @@ void SACoreSoftMacro::perturb()
215202 exchangeMacros (); // exchange two macros in the sequence pair
216203 } else {
217204 action_id_ = 5 ;
218- pre_macros_ = macros_;
219205 resizeOneCluster ();
220206 }
221207
@@ -225,7 +211,29 @@ void SACoreSoftMacro::perturb()
225211 calPenalty ();
226212}
227213
228- void SACoreSoftMacro::restore ()
214+ void SACoreSoftMacro::saveState ()
215+ {
216+ if (macros_.empty ()) {
217+ return ;
218+ }
219+
220+ pre_macros_ = macros_;
221+ pre_pos_seq_ = pos_seq_;
222+ pre_neg_seq_ = neg_seq_;
223+
224+ pre_width_ = width_;
225+ pre_height_ = height_;
226+
227+ pre_outline_penalty_ = outline_penalty_;
228+ pre_wirelength_ = wirelength_;
229+ pre_guidance_penalty_ = guidance_penalty_;
230+ pre_fence_penalty_ = fence_penalty_;
231+ pre_boundary_penalty_ = boundary_penalty_;
232+ pre_macro_blockage_penalty_ = macro_blockage_penalty_;
233+ pre_notch_penalty_ = notch_penalty_;
234+ }
235+
236+ void SACoreSoftMacro::restoreState ()
229237{
230238 if (macros_.empty ()) {
231239 return ;
@@ -234,19 +242,21 @@ void SACoreSoftMacro::restore()
234242 // To reduce the runtime, here we do not call PackFloorplan
235243 // again. So when we need to generate the final floorplan out,
236244 // we need to call PackFloorplan again at the end of SA process
237- if (action_id_ == 5 ) {
238- macros_[macro_id_] = pre_macros_[macro_id_];
239- } else if (action_id_ == 1 ) {
245+
246+ if (action_id_ == 1 ) {
240247 pos_seq_ = pre_pos_seq_;
241248 } else if (action_id_ == 2 ) {
242249 neg_seq_ = pre_neg_seq_;
243- } else {
250+ } else if (action_id_ == 3 || action_id_ == 4 ) {
244251 pos_seq_ = pre_pos_seq_;
245252 neg_seq_ = pre_neg_seq_;
246253 }
247254
255+ macros_ = pre_macros_;
256+
248257 width_ = pre_width_;
249258 height_ = pre_height_;
259+
250260 outline_penalty_ = pre_outline_penalty_;
251261 wirelength_ = pre_wirelength_;
252262 guidance_penalty_ = pre_guidance_penalty_;
@@ -539,7 +549,9 @@ void SACoreSoftMacro::calNotchPenalty()
539549 return ;
540550 }
541551
542- pre_macros_ = macros_;
552+ // Macros need to be saved (and restored) since alignMacroClusters and
553+ // fillDeadSpace move them
554+ std::vector<SoftMacro> pre_macros = macros_;
543555 // align macro clusters to reduce notches
544556 alignMacroClusters ();
545557 // Fill dead space
@@ -709,7 +721,7 @@ void SACoreSoftMacro::calNotchPenalty()
709721 += (y_grid[y_end_new] - y_grid[y_end]) * macros_[macro_id].getWidth ();
710722 }
711723 }
712- macros_ = pre_macros_ ;
724+ macros_ = pre_macros ;
713725 // normalization
714726 notch_penalty_
715727 = notch_penalty_ / (outline_.getWidth () * outline_.getHeight ());
0 commit comments